Skip to content

Commit

Permalink
Making building of the source optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvbrt committed Mar 1, 2024
1 parent c6902d5 commit 77dfa99
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 29 deletions.
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ option(USE_EXTERNAL_CATCH2 "Link against an external Catch2 v3 static library, o

option(FCCANALYSES_DOCUMENTATION "Whether or not to create doxygen doc target." ON)

set(WITH_SOURCE ON CACHE STRING "Enable EDM4hep RDataSource")
set_property(CACHE WITH_SOURCE PROPERTY STRINGS ON OFF)

#--- Set a better default for installation directory---------------------------
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/install" CACHE PATH "default install path" FORCE)
Expand Down Expand Up @@ -147,7 +150,9 @@ install(DIRECTORY examples DESTINATION ${CMAKE_INSTALL_PREFIX}/share/examples)

#--- Descend into subdirectories ----------------------------------------------

add_subdirectory(e4hsource)
if(WITH_SOURCE)
add_subdirectory(e4hsource)
endif()

set(ADDONS_LIBRARIES CACHE STRING "List of external libraries the RDF utilities will be linked against")
add_subdirectory(addons)
Expand Down
6 changes: 3 additions & 3 deletions analyzers/dataframe/FCCAnalyses/Association.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace FCCAnalyses :: Association {
* \param pdg Desired PDG ID of the partile.
*/
struct sel_PDG {
sel_PDG(const int pdg);
explicit sel_PDG(const int pdg);
const int m_pdg;
template <typename T>
T operator() (
Expand All @@ -30,7 +30,7 @@ namespace FCCAnalyses :: Association {
struct sel_absPDG {
const int m_pdg;

sel_absPDG(const int pdg) : m_pdg(pdg) {
explicit sel_absPDG(const int pdg) : m_pdg(pdg) {
if (m_pdg < 0) {
throw std::invalid_argument(
"Association::sel_absPDG: Received negative value!");
Expand Down Expand Up @@ -61,7 +61,7 @@ namespace FCCAnalyses :: Association {
* \param pdg Desired generator status of the partile.
*/
struct sel_genStatus {
sel_genStatus(const int status);
explicit sel_genStatus(const int status);
const int m_status;
template <typename T>
T operator() (
Expand Down
14 changes: 7 additions & 7 deletions e4hsource/src/EDM4hepDataSource.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ namespace FCCAnalyses {

for (const auto& filePath : m_filePathList) {
// Check if file exists
if (!std::filesystem::exists(filePath)) {
throw std::runtime_error("EDM4hepDataSource: Provided file \""
+ filePath + "\" does not exist!");
}
// Warning: file can be coming from web or eos
// if (!std::filesystem::exists(filePath)) {
// throw std::runtime_error("EDM4hepDataSource: Provided file \""
// + filePath + "\" does not exist!");
// }

// Check if the provided file contains required metadata
TFile infile = TFile(filePath.data(), "READ");
auto metadata = infile.Get("podio_metadata");
infile.Close();
std::unique_ptr<TFile> inFile(TFile::Open(filePath.data(), "READ"));
auto metadata = inFile->Get("podio_metadata");
if (!metadata) {
throw std::runtime_error(
"EDM4hepDataSource: Provided file is missing podio metadata!");
Expand Down
9 changes: 5 additions & 4 deletions e4hsource/src/EDM4hepLegacySource.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ namespace FCCAnalyses {

for (const auto& filePath : m_filePathList) {
// Check if file exists
if (!std::filesystem::exists(filePath)) {
throw std::runtime_error("EDM4hepLegacySource: Provided file \"" + filePath
+ "\" does not exist!");
}
// File can be comming from remote
// if (!std::filesystem::exists(filePath)) {
// throw std::runtime_error("EDM4hepLegacySource: Provided file \"" + filePath
// + "\" does not exist!");
// }

// Check if the provided file contains required metadata
TFile infile = TFile(filePath.data(), "READ");
Expand Down
4 changes: 2 additions & 2 deletions e4hsource/test/stages_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# How to read input files
useDataSource = True

testFile = '/eos/experiment/fcc/ee/generation/DelphesEvents/winter2023/' \
'IDEA/p8_ee_WW_ecm240/events_192112516.root'
testFile = 'https://fccsw.web.cern.ch/fccsw/testsamples/fccanalyses/' \
'events_192112516.root'

# RDFanalysis class where the use defines the operations on the TTree
# (mandatory)
Expand Down
6 changes: 5 additions & 1 deletion man/man1/fccanalysis-build.1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[\fB\-h\fR | \fB\-\-help\fR]
[\fB\-c\fR]
[\fB\-j\fR \fIBUILD_THREADS\fR]
[\fB\-\-no\-source\fR]
.SH DESCRIPTION
.B fccanalysis\-build
will build the whole FCCAnalyses framework\&.
Expand All @@ -24,7 +25,10 @@ Prints short help message and exits\&.
Completely clean build directory before compilation\&.
.TP
\fB\-j\fR \fIBUILD_THREADS\fR, \fB\-\-build\-threads\fR \fIBUILD_THREADS\fR
Specify number of threads used when compiling (equivalent to `make -j`)
Specify number of threads used when compiling (equivalent to `make -j`)\&.
.TP
.B \-\-no\-source
Do not build EDM4hep RDataSource\&.
.SH SEE ALSO
fccanalysis(1), fccanalysis\-test(7), cmake(1)
.SH BUGS
Expand Down
10 changes: 7 additions & 3 deletions python/build_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ def build_analysis(mainparser):
LOGGER.info('Creating build directory...')
os.makedirs(build_path)

run_subprocess(['cmake', '-DCMAKE_INSTALL_PREFIX=../install',
'-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', '..'],
local_dir + '/build')
build_cmd = ['cmake', '..', '-DCMAKE_INSTALL_PREFIX=../install',
'-DCMAKE_EXPORT_COMPILE_COMMANDS=ON']

if args.no_source:
build_cmd += ['-DWITH_SOURCE=OFF']

run_subprocess(build_cmd, local_dir + '/build')

if not install_path.is_dir():
LOGGER.info('Creating install directory...')
Expand Down
6 changes: 6 additions & 0 deletions python/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ def setup_build_parser(parser):
default=1,
help='number of threads when building (equivalent to `make -j`)'
)
build_args.add_argument(
'--no-source',
action='store_true',
default=False,
help='do not build EDM4hep RDataSource'
)


def setup_test_parser(parser):
Expand Down
14 changes: 11 additions & 3 deletions python/run_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,11 @@ def run_rdf(rdf_module,
'''
if args.use_data_source:
LOGGER.info('Loading events through EDM4hep RDataSource...')
ROOT.gSystem.Load("libe4hsource")
if ROOT.gSystem.Load("libe4hsource") < 0:
LOGGER.error('Unable to load EDM4hep RDataSource library!\n'
'Aborting...')
sys.exit(3)

if ROOT.loadEDM4hepDataSource():
LOGGER.debug('EDM4hep RDataSource loaded.')
try:
Expand All @@ -337,7 +341,7 @@ def run_rdf(rdf_module,
'RDataSource!\n%s', excp)
sys.exit(3)
else:
dframe = ROOT.RDataFrame("events", input_list)
dframe = ROOT.RDataFrame("events", input_list)

# limit number of events processed
if args.nevents > 0:
Expand Down Expand Up @@ -788,7 +792,11 @@ def run_histmaker(args, rdf_module, anapath):

if args.use_data_source:
LOGGER.info('Loading events through EDM4hep RDataSource...')
ROOT.gSystem.Load("libe4hsource")
if ROOT.gSystem.Load("libe4hsource") < 0:
LOGGER.error('Unable to load EDM4hep RDataSource library!\n'
'Aborting...')
sys.exit(3)

if ROOT.loadEDM4hepDataSource():
LOGGER.debug('EDM4hep RDataSource loaded.')
try:
Expand Down
11 changes: 7 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ add_integration_test("examples/FCCee/higgs/mH-recoil/mumu/analysis_stage1.py")
add_integration_test("examples/FCCee/flavour/Bc2TauNu/analysis_B2TauNu_truth.py")
add_integration_test("examples/FCCee/test/jet_constituents.py")
add_integration_test("examples/FCCee/vertex_lcfiplus/analysis_V0.py")
add_integration_test("e4hsource/test/histmaker_source.py")
add_integration_test("e4hsource/test/stages_source.py")
add_standalone_test("e4hsource/test/standalone.py")
# add_standalone_test("e4hsource/test/standalone_legacy.py")

if(WITH_SOURCE)
add_integration_test("e4hsource/test/histmaker_source.py")
add_integration_test("e4hsource/test/stages_source.py")
add_standalone_test("e4hsource/test/standalone.py")
# add_standalone_test("e4hsource/test/standalone_legacy.py")
endif()

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

Expand Down
4 changes: 3 additions & 1 deletion tests/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ add_executable(unittest unittest.cpp
algorithms.cpp
ReconstructedParticle.cpp
)
target_link_libraries(unittest PUBLIC FCCAnalyses gfortran PRIVATE Catch2::Catch2WithMain)
target_link_libraries(unittest PUBLIC FCCAnalyses
gfortran
PRIVATE Catch2::Catch2WithMain)
target_include_directories(unittest PUBLIC ${VDT_INCLUDE_DIR})
target_compile_definitions(unittest PUBLIC "-DTEST_INPUT_DATA_DIR=${TEST_INPUT_DATA_DIR}")
include(Catch)
Expand Down

0 comments on commit 77dfa99

Please sign in to comment.