Skip to content

Commit

Permalink
Merge branch 'main' into eventHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener authored Sep 6, 2023
2 parents feedae3 + cdf8ded commit 1f30df8
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ repos:
"-n", "Key4hep",
"-u", "https://key4hep.github.io/key4hep-doc/",
"-x", ".github/*", ".pre-commit-config.yaml", "README.md",
"doc/ReleaseNotes.md", ".k4fwcore-ci.d/*", "init.sh",
"doc/ReleaseNotes.md", ".k4fwcore-ci.d/*",
"-f"]
3 changes: 0 additions & 3 deletions init.sh

This file was deleted.

16 changes: 9 additions & 7 deletions k4FWCore/include/k4FWCore/PodioDataSvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class PodioDataSvc : public DataSvc {
public:
typedef std::vector<std::pair<std::string, podio::CollectionBase*>> CollRegistry;

virtual StatusCode initialize();
virtual StatusCode reinitialize();
virtual StatusCode finalize();
virtual StatusCode clearStore();
virtual StatusCode i_setRoot(std::string root_path, IOpaqueAddress* pRootAddr);
virtual StatusCode i_setRoot(std::string root_path, DataObject* pRootObj);
StatusCode initialize() final;
StatusCode reinitialize() final;
StatusCode finalize() final;
StatusCode clearStore() final;
StatusCode i_setRoot(std::string root_path, IOpaqueAddress* pRootAddr) final;
StatusCode i_setRoot(std::string root_path, DataObject* pRootObj) final;

/// Standard Constructor
PodioDataSvc(const std::string& name, ISvcLocator* svc);
Expand Down Expand Up @@ -85,7 +85,8 @@ class PodioDataSvc : public DataSvc {
/// Counter of the event number
int m_eventNum{0};
/// Number of events in the file / to process
int m_eventMax{-1};
int m_numAvailableEvents{-1};
int m_requestedEventMax{-1};
/// Whether reading from file at all
bool m_reading_from_file{false};

Expand All @@ -101,5 +102,6 @@ class PodioDataSvc : public DataSvc {
/// Jump to nth events at the beginning. Set by option FirstEventEntry
/// This option is helpful when we want to debug an event in the middle of a file
unsigned m_1stEvtEntry{0};
bool m_bounds_check_needed{true};
};
#endif // CORE_PODIODATASVC_H
8 changes: 4 additions & 4 deletions k4FWCore/include/k4FWCore/PodioLegacyDataSvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class PodioLegacyDataSvc : public DataSvc {
public:
typedef std::vector<std::pair<std::string, podio::CollectionBase*>> CollRegistry;

virtual StatusCode initialize();
virtual StatusCode reinitialize();
virtual StatusCode finalize();
virtual StatusCode clearStore();
StatusCode initialize() final;
StatusCode reinitialize() final;
StatusCode finalize() final;
StatusCode clearStore() final;

/// Standard Constructor
PodioLegacyDataSvc(const std::string& name, ISvcLocator* svc);
Expand Down
9 changes: 7 additions & 2 deletions k4FWCore/scripts/k4run
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ seen_files = set()
option_db = {}

def load_file(file):
exec(file.read())
exec(file.read(), {})


def add_arguments(parser, app_mgr):
# length increases when properties of an algorithm with tools are inspected
# see https://github.com/key4hep/k4FWCore/pull/138
for conf in tuple(app_mgr.allConfigurables.values()):
# can contain the same value multiple times
# see https://github.com/key4hep/k4FWCore/issues/141
for conf in frozenset(app_mgr.allConfigurables.values()):
# skip public tools and the applicationmgr itself
if "ToolSvc" in conf.name() or "ApplicationMgr" in conf.name():
continue
Expand Down Expand Up @@ -171,4 +173,7 @@ if __name__ == "__main__":
if not opts.dry_run:
# Do the real processing
retcode = c.run(opts.gdb, opts.ncpus)
# User requested stop returns non-zero exit code see: https://github.com/key4hep/k4FWCore/issues/125
if ApplicationMgr().EvtMax == -1 and retcode == 4:
retcode = 0
sys.exit(retcode)
44 changes: 32 additions & 12 deletions k4FWCore/src/PodioDataSvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "k4FWCore/PodioDataSvc.h"
#include "GaudiKernel/IConversionSvc.h"
#include "GaudiKernel/IEventProcessor.h"
#include "GaudiKernel/IProperty.h"
#include "GaudiKernel/ISvcLocator.h"

#include "k4FWCore/DataWrapper.h"
Expand All @@ -43,11 +44,8 @@ StatusCode PodioDataSvc::initialize() {
if (m_filenames[0] != "") {
m_reading_from_file = true;
m_reader.openFiles(m_filenames);
m_eventMax = m_reader.getEntries("events");

if (m_1stEvtEntry != 0) {
m_eventMax -= m_1stEvtEntry;
}
m_numAvailableEvents = m_reader.getEntries("events");
m_numAvailableEvents -= m_1stEvtEntry;
}
}

Expand All @@ -62,6 +60,22 @@ StatusCode PodioDataSvc::initialize() {
m_metadataframe = podio::Frame();
}

IProperty* property;
auto sc = service("ApplicationMgr", property);
if (sc == StatusCode::FAILURE) {
error() << "Could not get ApplicationMgr properties" << std::endl;
}
Gaudi::Property<int> evtMax;
evtMax.assign(property->getProperty("EvtMax"));
m_requestedEventMax = evtMax;
m_requestedEventMax -= m_1stEvtEntry;

// if run with a fixed number of requested events and we have enough
// in the file we don't need to check if we run out of events
if (m_requestedEventMax > 0 && m_requestedEventMax <= m_numAvailableEvents) {
m_bounds_check_needed = false;
}

return status;
}
/// Service reinitialisation
Expand Down Expand Up @@ -109,14 +123,20 @@ StatusCode PodioDataSvc::i_setRoot(std::string root_path, DataObject* pRootObj)
}

void PodioDataSvc::endOfRead() {
m_eventNum++;

if (!m_bounds_check_needed) {
return;
}

StatusCode sc;
if (m_eventMax != -1) {
if (m_eventNum++ >= m_eventMax - 1) { // we start counting at 0 thus the -1.
info() << "Reached end of file with event " << m_eventMax << endmsg;
IEventProcessor* eventProcessor;
sc = service("ApplicationMgr", eventProcessor);
sc = eventProcessor->stopRun();
}
// m_eventNum already points to the next event here so check if it is available
if (m_eventNum >= m_numAvailableEvents) {
info() << "Reached end of file with event " << m_eventNum << " (" << m_requestedEventMax << " events requested)"
<< endmsg;
IEventProcessor* eventProcessor;
sc = service("ApplicationMgr", eventProcessor);
sc = eventProcessor->stopRun();
}
// todo: figure out sthg to do with sc (added to silence -Wunused-result)
}
Expand Down
47 changes: 31 additions & 16 deletions test/k4FWCoreTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ include(CTest)

set(K4RUN ${PROJECT_SOURCE_DIR}/k4FWCore/scripts/k4run)

get_target_property(edm4hep_lib EDM4HEP::edm4hepDict LOCATION)
get_filename_component(edm4hep_loc ${edm4hep_lib} DIRECTORY)

get_target_property(root_lib ROOT::Core LOCATION)
get_filename_component(root_loc ${root_lib} DIRECTORY)

get_target_property(podio_lib podio::podio LOCATION)
get_filename_component(podio_loc ${podio_lib} DIRECTORY)

#--- The genConf directory has been renamed to genConfDir in Gaudi 35r1
#--- See https://gitlab.cern.ch/gaudi/Gaudi/-/merge_requests/1158
set(GAUDI_GENCONF_DIR "genConfDir")
Expand All @@ -60,8 +51,8 @@ endif()


function(set_test_env _testname)
set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT "ROOT_INCLUDE_PATH=${podio_loc}/../include/podio:${edm4hep_loc}/../include:$ENV{ROOT_INCLUDE_PATH}")
set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${PROJECT_BINARY_DIR}:${PROJECT_BINARY_DIR}/${CMAKE_PROJECT_NAME}:${PROJECT_BINARY_DIR}/test/k4FWCoreTest:${root_loc}:${edm4hep_loc}:${podio_loc}:$ENV{LD_LIBRARY_PATH}")
set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT "ROOT_INCLUDE_PATH=$<$<TARGET_EXISTS:podio::podio>:$<TARGET_FILE_DIR:podio::podio>/../include>:$<$<TARGET_EXISTS:EDM4HEP::edm4hep>:$<TARGET_FILE_DIR:EDM4HEP::edm4hep>/../include>:$ENV{ROOT_INCLUDE_PATH}")
set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${PROJECT_BINARY_DIR}:${PROJECT_BINARY_DIR}/${CMAKE_PROJECT_NAME}:${PROJECT_BINARY_DIR}/test/k4FWCoreTest:$<$<TARGET_EXISTS:ROOT::Core>:$<TARGET_FILE_DIR:ROOT::Core>>:$<$<TARGET_EXISTS:EDM4HEP::edm4hep>:$<TARGET_FILE_DIR:EDM4HEP::edm4hep>>:$<$<TARGET_EXISTS:podio::podio>:$<TARGET_FILE_DIR:podio::podio>>:$ENV{LD_LIBRARY_PATH}")
set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT "PYTHONPATH=${PROJECT_BINARY_DIR}/${CMAKE_PROJECT_NAME}/${GAUDI_GENCONF_DIR}:${PROJECT_BINARY_DIR}/test/k4FWCoreTest/${GAUDI_GENCONF_DIR}:$ENV{PYTHONPATH}")
endfunction()

Expand All @@ -77,9 +68,27 @@ add_test(NAME CheckExampleEventData
)
set_test_env(CheckExampleEventData)
set_tests_properties( CheckExampleEventData
PROPERTIES
DEPENDS CreateExampleEventData)

add_test(NAME CheckExampleEventData_toolong
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND ${K4RUN} -n 999 options/checkExampleEventData.py
)
set_test_env(CheckExampleEventData_toolong)
set_tests_properties( CheckExampleEventData_toolong
PROPERTIES PASS_REGULAR_EXPRESSION "Application Manager Terminated successfully with a user requested ScheduledStop"
DEPENDS CreateExampleEventData)

add_test(NAME CheckExampleEventData_unbounded
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND ${K4RUN} -n -1 options/checkExampleEventData.py
)
set_test_env(CheckExampleEventData_unbounded)
set_tests_properties( CheckExampleEventData_unbounded
PROPERTIES
DEPENDS CreateExampleEventData)

add_test(NAME CreateExampleEventData_cellID
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND ${K4RUN} options/createExampleEventData_cellID.py)
Expand Down Expand Up @@ -150,18 +159,20 @@ add_test(NAME CreateLegacyExampleEventData
COMMAND ${K4RUN} options/createLegacyExampleEventData.py)
set_test_env(CreateLegacyExampleEventData)


add_test(NAME TestEventHeaderFiller
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND ${K4RUN} options/createEventHeader.py)
set_test_env(TestEventHeaderFiller)


add_test(NAME Testk4runNoArguments
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND ${K4RUN})
set_test_env(Testk4runNoArguments)
set_tests_properties(Testk4runNoArguments
PROPERTIES PASS_REGULAR_EXPRESSION "Usage: k4run <options_file.py>, use --help to get a complete list of arguments")

add_test(NAME TestEventHeaderFiller
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND ${K4RUN} options/createEventHeader.py)
set_test_env(TestEventHeaderFiller)

add_test(NAME Testk4runCustomArguments
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND ${K4RUN} --foo=42 options/TestArgs.py)
Expand All @@ -183,3 +194,7 @@ set_test_env(Testk4runHelpOnly)
set_tests_properties(Testk4runHelpOnly
PROPERTIES PASS_REGULAR_EXPRESSION "show this help message and exit")

add_test(NAME TestExec
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND ${K4RUN} --dry-run options/TestExec.py)
set_test_env(TestExec)
20 changes: 20 additions & 0 deletions test/k4FWCoreTest/options/TestExec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Copyright (c) 2014-2023 Key4hep-Project.
#
# This file is part of Key4hep.
# See https://key4hep.github.io/key4hep-doc/ for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
a = 5
comp = [a for i in range(3)]
2 changes: 1 addition & 1 deletion test/k4FWCoreTest/options/checkExampleEventData.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
ApplicationMgr(
TopAlg=[inp, checker],
EvtSel="NONE",
EvtMax=-1,
EvtMax=100,
ExtSvc=[podioevent],
OutputLevel=INFO,
StopOnSignal=True,
Expand Down

0 comments on commit 1f30df8

Please sign in to comment.