Skip to content

Commit

Permalink
k4run: return exit code 0 if -n -1 was used and Gaudi returned exit…
Browse files Browse the repository at this point in the history
… code 4 (#132)
  • Loading branch information
Zehvogel authored Sep 1, 2023
1 parent 4a0b6a8 commit acff8e5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 14 deletions.
4 changes: 3 additions & 1 deletion k4FWCore/include/k4FWCore/PodioDataSvc.h
Original file line number Diff line number Diff line change
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
3 changes: 3 additions & 0 deletions k4FWCore/scripts/k4run
Original file line number Diff line number Diff line change
Expand Up @@ -173,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
18 changes: 18 additions & 0 deletions test/k4FWCoreTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,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
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 acff8e5

Please sign in to comment.