Skip to content

Commit

Permalink
using podio::DataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvbrt committed Aug 28, 2024
1 parent 62f833b commit c9da963
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 39 deletions.
2 changes: 2 additions & 0 deletions analyzers/dataframe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ target_link_libraries(FCCAnalyses PUBLIC
EDM4HEP::edm4hep
EDM4HEP::edm4hepDict
podio::podio
podio::podioRootIO
podio::podioDataSource
${ADDONS_LIBRARIES}
${DELPHES_LIBRARY}
gfortran # todo: why necessary?
Expand Down
6 changes: 3 additions & 3 deletions examples/data_source/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def main():
print('----> Debug: Found FCCAnalyses library.')
print("----> Info: Loading analyzers from libFCCAnalyses... ",)

if ROOT.podio.ROOTReader():
print('----> Debug: Found Podio ROOT I/O.')
print('----> Info: Loading events through EDM4hep RDataSource...')
if ROOT.podio.DataSource:
print('----> Debug: Found Podio ROOT DataSource.')
print('----> Info: Loading events through podio::DataSource...')

try:
dframe = ROOT.podio.CreateDataFrame(input_list)
Expand Down
46 changes: 25 additions & 21 deletions python/run_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,19 @@ def run_rdf(rdf_module,
Create RDataFrame and snapshot it.
'''
if args.use_data_source:
if ROOT.podio.ROOTReader():
LOGGER.debug('Found Podio ROOT I/O.')
if ROOT.podio.DataSource:
LOGGER.debug('Found PODIO ROOT DataSource.')
else:
LOGGER.error('Podio ROOT I/O library not found!\nAborting...')
LOGGER.error('PODIO ROOT DataSource library not found!\n'
'Aborting...')
sys.exit(3)
LOGGER.info('Loading events through podio::ROOTDataSource...')
LOGGER.info('Loading events through podio::DataSource...')

try:
dframe = ROOT.podio.CreateDataFrame(input_list)
except TypeError as excp:
LOGGER.error('Unable to build dataframe using'
'podio::RDataSource!\n%s', excp)
LOGGER.error('Unable to build dataframe using '
'podio::DataSource!\n%s', excp)
sys.exit(3)
else:
dframe = ROOT.RDataFrame("events", input_list)
Expand Down Expand Up @@ -382,7 +383,7 @@ def send_to_batch(rdf_module, chunk_list, process, anapath: str):
stderr=subprocess.DEVNULL
)
except subprocess.CalledProcessError:
LOGGER.error('The FCCanalyses libraries are not properly build and '
LOGGER.error('The FCCAnalyses libraries are not properly build and '
'installed!\nAborting job submission...')
sys.exit(3)

Expand Down Expand Up @@ -538,7 +539,7 @@ def run_local(rdf_module, infile_list, args):
start_time = time.time()
inn, outn = run_rdf(rdf_module, file_list, outfile_path, args)
elapsed_time = time.time() - start_time

# replace nevents_local by inn = the amount of processed events

info_msg = f"{' SUMMARY ':=^80}\n"
Expand Down Expand Up @@ -611,6 +612,10 @@ def run_stages(args, rdf_module, anapath):
if not os.path.exists(output_dir_eos) and output_dir_eos:
os.system(f'mkdir -p {output_dir_eos}')

# Check whether to use PODIO ROOT DataSource to load the events
if get_element(rdf_module, "useDataSource", False):
args.use_data_source = True

# Check if test mode is specified, and if so run the analysis on it (this
# will exit after)
if args.test:
Expand Down Expand Up @@ -733,6 +738,10 @@ def run_histmaker(args, rdf_module, anapath):
do_scale = get_element(rdf_module, "doScale", True)
int_lumi = get_element(rdf_module, "intLumi", True)

# Check whether to use PODIO ROOT DataSource to load the events
if get_element(rdf_module, "useDataSource", False):
args.use_data_source = True

# check if the process list is specified, and create graphs for them
process_list = get_element(rdf_module, "processList")
graph_function = getattr(rdf_module, "build_graph")
Expand Down Expand Up @@ -804,18 +813,19 @@ def run_histmaker(args, rdf_module, anapath):
LOGGER.info(info_msg)

if args.use_data_source:
if ROOT.podio.ROOTReader():
LOGGER.debug('Found Podio ROOT I/O.')
if ROOT.podio.DataSource:
LOGGER.debug('Found Podio ROOT DataSource.')
else:
LOGGER.error('Podio ROOT I/O library not found!\nAborting...')
LOGGER.error('Podio ROOT DataSource library not found!'
'\nAborting...')
sys.exit(3)
LOGGER.info('Loading events through podio::ROOTDataSource...')
LOGGER.info('Loading events through podio::DataSource...')

try:
dframe = ROOT.podio.CreateDataFrame(file_list_root)
except TypeError as excp:
LOGGER.error('Unable to build dataframe using EDM4hep '
'RDataSource!\n%s', excp)
LOGGER.error('Unable to build dataframe using '
'podio::DataSource!\n%s', excp)
sys.exit(3)
else:
dframe = ROOT.ROOT.RDataFrame("events", file_list_root)
Expand Down Expand Up @@ -998,14 +1008,8 @@ def run(parser):
err)
sys.exit(3)

# Merge command line arguments with anascript
# Check whether to use RDataSource to load the events
use_data_source = get_element(rdf_module, "useDataSource")
if use_data_source:
args.use_data_source = True

# Merge configuration from analysis script file with command line arguments
if get_element(rdf_module, 'graph'):
if get_element(rdf_module, 'graph', False):
args.graph = True

if get_element(rdf_module, 'graphPath') != '':
Expand Down
25 changes: 23 additions & 2 deletions python/run_fccanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,23 @@ def run_rdf(args,
Run the analysis ROOTDataFrame and snapshot it.
'''
# Create initial dataframe
dframe = ROOT.RDataFrame("events", input_list)
if args.use_data_source:
if ROOT.podio.DataSource:
LOGGER.debug('Found PODIO ROOT DataSource.')
else:
LOGGER.error('PODIO ROOT DataSource library not found!\n'
'Aborting...')
sys.exit(3)
LOGGER.info('Loading events through podio::DataSource...')

try:
dframe = ROOT.podio.CreateDataFrame(input_list)
except TypeError as excp:
LOGGER.error('Unable to build dataframe using '
'podio::DataSource!\n%s', excp)
sys.exit(3)
else:
dframe = ROOT.RDataFrame("events", input_list)

# Limit number of events processed
if args.nevents > 0:
Expand Down Expand Up @@ -469,7 +485,8 @@ def run_local(args, analysis, infile_list):
nevents_local = 0
for filepath in infile_list:

filepath = apply_filepath_rewrites(filepath)
if not args.use_data_source:
filepath = apply_filepath_rewrites(filepath)

file_list.push_back(filepath)
info_msg += f'- {filepath}\t\n'
Expand Down Expand Up @@ -590,6 +607,10 @@ def run_fccanalysis(args, analysis_module):
if output_dir_eos is not None and not os.path.exists(output_dir_eos):
os.system(f'mkdir -p {output_dir_eos}')

# Check whether to use PODIO ROOT DataSource to load the events
if get_element(analysis, "use_data_source", False):
args.use_data_source = True

# Check if test mode is specified, and if so run the analysis on it (this
# will exit after)
if args.test:
Expand Down
18 changes: 9 additions & 9 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,44 @@ add_integration_test("examples/FCCee/test/jet_constituents.py")
add_integration_test("examples/FCCee/vertex_lcfiplus/analysis_V0.py")

if(WITH_SOURCE)
add_integration_test("e4hsource/test/histmaker_source.py")
add_integration_test("e4hsource/test/stages_source.py")
add_integration_test("e4hsource/test/analysis_stage1.py")
add_standalone_test("e4hsource/test/standalone.py")
add_integration_test("examples/data_source/histmaker_source.py")
add_integration_test("examples/data_source/stages_source.py")
add_integration_test("examples/data_source/analysis_stage1.py")
add_standalone_test("examples/data_source/standalone.py")
endif()

add_standalone_test("examples/FCCee/fullSim/caloNtupleizer/analysis.py")

# C++ Analyses

# podio::ROOTDataSource
# podio::DataSource
add_executable(test_data_source ${CMAKE_SOURCE_DIR}/tests/data_source/test_source.cxx)
target_include_directories(test_data_source PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(test_data_source podio::podioRootIO
target_link_libraries(test_data_source podio::podioDataSource
EDM4HEP::edm4hep
)

add_executable(test_source_associations
${CMAKE_SOURCE_DIR}/tests/data_source/test_source_associations.cxx)
target_include_directories(test_source_associations PRIVATE
${CMAKE_SOURCE_DIR}/include)
target_link_libraries(test_source_associations podio::podioRootIO
target_link_libraries(test_source_associations podio::podioDataSource
EDM4HEP::edm4hep
FCCAnalyses
)

# Low level access
add_executable(test_low_level ${CMAKE_SOURCE_DIR}/tests/data_source/test_low_level.cxx)
target_link_libraries(test_low_level ROOT::ROOTDataFrame
podio::podioRootIO
podio::podioDataSource
EDM4HEP::edm4hep
EDM4HEP::edm4hepDict
)

add_executable(test_low_level_associations
${CMAKE_SOURCE_DIR}/tests/data_source/test_low_level_associations.cxx)
target_link_libraries(test_low_level_associations ROOT::ROOTDataFrame
podio::podioRootIO
podio::podioDataSource
EDM4HEP::edm4hep
EDM4HEP::edm4hepDict
FCCAnalyses
Expand Down
4 changes: 2 additions & 2 deletions tests/data_source/test_source.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <TCanvas.h>

// PODIO
#include <podio/ROOTDataSource.h>
#include <podio/DataSource.h>

// EDM4hep
#include <edm4hep/ReconstructedParticle.h>
Expand Down Expand Up @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) {

ROOT::EnableImplicitMT(nCPU);

ROOT::RDataFrame rdf(std::make_unique<podio::ROOTDataSource>(filePathList));
ROOT::RDataFrame rdf(std::make_unique<podio::DataSource>(filePathList));

// rdf.Describe().Print();
std::cout << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions tests/data_source/test_source_associations.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <TMatrixDSym.h>

// PODIO
#include <podio/ROOTDataSource.h>
#include <podio/DataSource.h>

// EDM4hep
#include <edm4hep/MCParticle.h>
Expand Down Expand Up @@ -256,7 +256,7 @@ int main(int argc, char *argv[]) {

ROOT::EnableImplicitMT(nCPU);

ROOT::RDataFrame rdf(std::make_unique<podio::ROOTDataSource>(filePathList));
ROOT::RDataFrame rdf(std::make_unique<podio::DataSource>(filePathList));

// rdf.Describe().Print();
std::cout << std::endl;
Expand Down

0 comments on commit c9da963

Please sign in to comment.