ATLAS Offline Software
Loading...
Searching...
No Matches
EL::Worker Class Referencefinal

#include <Worker.h>

Inheritance diagram for EL::Worker:
Collaboration diagram for EL::Worker:

Public Member Functions

void testInvariant () const
 effects: test the invariant of this object guarantee: no-fail
virtual ~Worker ()
 effects: standard destructor guarantee: no-fail
void addOutput (TObject *output_swallow) final override
 effects: add an object to the output.
void addOutputList (const std::string &name, TObject *output_swallow) override
 effects: add a given object to the output.
TObject * getOutputHist (const std::string &name) const final override
 get the output histogram with the given name
TFile * getOutputFile (const std::string &label) const override
 effects: get the output file that goes into the dataset with the given label.
TFile * getOutputFileNull (const std::string &label) const override
 effects: get the output file that goes into the dataset with the given label.
::StatusCode addTree (const TTree &tree, const std::string &stream) final override
 effects: adds a tree to an output file specified by the stream/label failures: Incorrect stream/label specified, called at the wrong time note: See getOutputFile for failure types...
TTree * getOutputTree (const std::string &name, const std::string &stream) const final override
 effects: get the tree that was added to an output file earlier failures: Tree doesn't exist
const SH::MetaObjectmetaData () const override
 description: the sample meta-data we are working on guarantee: no-fail invariant: metaData != 0 rationale: this can be used for accessing sample meta-data
TTree * tree () const override
 description: the tree we are running on guarantee: no-fail
Long64_t treeEntry () const override
 description: the entry in the tree we are reading guarantee: no-fail
TFile * inputFile () const override
 description: the file we are reading the current tree from guarantee: no-fail
bool hasInputEvents () const override
 flag whether the most recently opened input file has events or not
std::string inputFileName () const override
 the name of the file we are reading the current tree from, without the path component
TTree * triggerConfig () const override
 description: the trigger config tree from the input file, or NULL if we did not find it guarantee: strong failures: i/o errors
xAOD::EventxaodEvent () const override
 description: the xAOD event and store guarantee: strong failures: out of memory I failures: EventSvc not configured postcondition: result != 0
xAOD::TStorexaodStore () const override
EL::AlgorithmgetAlg (const std::string &name) const override
 effects: returns the algorithms with the given name or NULL if there is none guarantee: strong failures: out of memory II
void skipEvent () override
 effects: skip the current event, i.e.
virtual bool filterPassed () const noexcept final override
 whether the current algorithm passed its filter criterion for the current event
virtual void setFilterPassed (bool val_filterPassed) noexcept final override
 set the value of filterPassed
 Worker ()
 standard constructor
::StatusCode directExecute (const SH::SamplePtr &sample, const Job &job, const std::string &location, const SH::MetaObject &options)
 run the job
::StatusCode batchExecute (unsigned job_id, const char *confFile)
 effects: do what is needed to execute the given job segment guarantee: basic failures: job specific
::StatusCode gridExecute (const std::string &sampleName, Long64_t SkipEvents, Long64_t nEventsPerJob)

Protected Member Functions

void setMetaData (const SH::MetaObject *val_metaData)
 set the metaData
void setOutputHist (const std::string &val_outputTarget)
 set the histogram output list
void setSegmentName (const std::string &val_segmentName)
 set the segment name
void setJobConfig (JobConfig &&jobConfig)
 set the JobConfig
::StatusCode initialize ()
 initialize the worker
::StatusCode processInputs ()
 process all the inputs
::StatusCode finalize ()
 finalize the worker
::StatusCode processEvents (EventRange &eventRange) override
 process the given event range
::StatusCode openInputFile (const std::string &inputFileUrl) override
 open the given input file without processing it
::StatusCode addOutputStream (const std::string &label, Detail::OutputStreamData output)
 effects: add another output file guarantee: strong failures: low level errors II failures: label already used
Long64_t inputFileNumEntries () const override
 the number of events in the input file
uint64_t eventsProcessed () const noexcept
 the number of events that have been processed

Private Types

enum  GridErrorCodes { EC_FAIL = 220 , EC_ABORT = 221 , EC_NOTFINISHED = 222 , EC_BADINPUT = 223 }
typedef std::map< std::string, TH1 * >::const_iterator OutputHistMapIter
 the output map
typedef std::map< std::pair< std::string, std::string >, TTree * >::const_iterator OutputTreeMapIter
 description: the list of output trees

Private Member Functions

void gridCreateJobSummary (uint64_t eventsProcessed)
void addOutput (std::unique_ptr< TObject > output)
 add the given output object to the histogram output stream

Static Private Member Functions

static bool fileOpenErrorFilter (int level, bool, const char *, const char *)
 Error handler for file opening.

Private Attributes

std::map< std::string, TH1 * > m_outputHistMap
std::map< std::pair< std::string, std::string >, TTree * > m_outputTreeMap
std::vector< std::unique_ptr< Detail::Module > > m_modules
 the list of modules we hold
bool m_firstInputFile {true}
 whether this is the first input file
bool m_newInputFile {false}
 whether this is a new input file (i.e.
std::string m_outputTarget
 the target file to which we will write the histogram output
std::string m_segmentName
 the name of the segment we are processing
bool m_algorithmsInitialized {false}
 whether the algorithms are initialized
bool m_firstEvent {true}
 whether we are still to process the first event
std::vector< asg::AsgComponentConfigm_moduleConfig
 the module configurations we use
std::vector< Detail::AlgorithmDatam_algs
 the list of algorithms
std::string m_inputFileUrl
 the input file url of the currently opened file
std::unique_ptr< TFile > m_inputFile
 the input file pointer of the currently opened filed
TTree * m_inputTree {nullptr}
 the (main) tree in the input file
uint64_t m_inputEntry {0}
 the entry in the input tree we are currently looking at
bool m_hasInputEvents = false
 flag whether the most recently opened input file has events or not
bool m_skipEvent = false
 whether we are skipping the current event
const SH::MetaObjectm_metaData {nullptr}
 the meta-data we use
uint64_t m_eventsProcessed {0}
 the number of events that have been processed
OutputStreamData * m_histOutput {nullptr}
 the histogram output stream
std::unique_ptr< TTree > m_jobStats
 Tree saving per-job statistics information.
xAOD::Eventm_event {nullptr}
 the Event object, if we use one
xAOD::TStorem_tstore {nullptr}
 the TStore structure, if we use one
asg::SgEventm_evtStore {nullptr}
 the SgEvent structure, if we use one
Workerm_worker {nullptr}
 the worker (to pass on to the algorithms)
std::map< std::string, std::shared_ptr< Detail::OutputStreamData > > m_outputs
 the list of output files
BatchJobm_batchJob = nullptr
 the BatchJob configuration (if used)

Detailed Description

Definition at line 25 of file Worker.h.

Member Typedef Documentation

◆ OutputHistMapIter

typedef std::map<std::string,TH1*>::const_iterator EL::Worker::OutputHistMapIter
private

the output map

Definition at line 408 of file Worker.h.

◆ OutputTreeMapIter

typedef std::map<std::pair<std::string,std::string>,TTree*>::const_iterator EL::Worker::OutputTreeMapIter
private

description: the list of output trees

Definition at line 415 of file Worker.h.

Member Enumeration Documentation

◆ GridErrorCodes

Enumerator
EC_FAIL 
EC_ABORT 
EC_NOTFINISHED 
EC_BADINPUT 

Definition at line 256 of file Worker.h.

256 {
257 EC_FAIL = 220,
258 EC_ABORT = 221,
259 EC_NOTFINISHED = 222,
260 EC_BADINPUT = 223
261 };
@ EC_NOTFINISHED
Definition Worker.h:259
@ EC_BADINPUT
Definition Worker.h:260

Constructor & Destructor Documentation

◆ ~Worker()

EL::Worker::~Worker ( )
virtual

effects: standard destructor guarantee: no-fail

Definition at line 81 of file Worker.cxx.

83 {
85 }
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:235

◆ Worker()

EL::Worker::Worker ( )

standard constructor

Guarantee
strong
Failures
out of memory I

Definition at line 332 of file Worker.cxx.

334 {
335 m_worker = this;
336
337 RCU_NEW_INVARIANT (this);
338 }
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
Worker * m_worker
the worker (to pass on to the algorithms)
Definition ModuleData.h:110

Member Function Documentation

◆ addOutput() [1/2]

void EL::Detail::ModuleData::addOutput ( std::unique_ptr< TObject > output)
inherited

add the given output object to the histogram output stream

Guarantee
basic
Failures
out of memory II

Definition at line 33 of file ModuleData.cxx.

35 {
36 RCU_ASSERT (m_histOutput != nullptr);
37 m_histOutput->addOutput (std::move (output));
38 }
#define RCU_ASSERT(x)
Definition Assert.h:222
OutputStreamData * m_histOutput
the histogram output stream
Definition ModuleData.h:95

◆ addOutput() [2/2]

void EL::Worker::addOutput ( TObject * output_swallow)
finaloverridevirtual

effects: add an object to the output.

the worker takes over ownership of the object, but the caller may maintain a reference to it guarantee: basic, argument is always swallowed failures: out of memory I requires: output_swallow != 0 warning: so far I placed no requirements on the output objects. I may do that at a later stage though, possibly breaking existing code.

Implements EL::IHistogramWorker.

Definition at line 89 of file Worker.cxx.

91 {
92 std::unique_ptr<TObject> output (output_swallow);
93
95 RCU_REQUIRE_SOFT (output_swallow != 0);
96
97 RCU::SetDirectory (output_swallow, 0);
98 ModuleData::addOutput (std::move (output));
99 }
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231
#define RCU_REQUIRE_SOFT(x)
Definition Assert.h:153
bool SetDirectory(TObject *object, TDirectory *directory)
effects: set the directory this object is associated with returns: whether the object type actively k...
Definition RootUtils.cxx:28
output
Definition merge.py:16

◆ addOutputList()

void EL::Worker::addOutputList ( const std::string & name,
TObject * output_swallow )
overridevirtual

effects: add a given object to the output.

instead of trying to merge the outputs from multiple jobs the output file will contain a TList of the given name with the objects from all the output. guarantee: basic, argument is always swallowed failures: out of memory II requires: output_swallow != 0 rationale: This was primarily build to allow the GRL output to be collected from EventLoop jobs, but it can be used for any kind of output that can not or should not be merged.

Implements EL::IWorker.

Definition at line 103 of file Worker.cxx.

105 {
106 std::unique_ptr<TObject> output (output_swallow);
107
109 RCU_REQUIRE_SOFT (output_swallow != 0);
110
111 RCU::SetDirectory (output_swallow, 0);
112 std::unique_ptr<TList> list (new TList);
113 list->SetName (name.c_str());
114 list->Add (output.release());
115 addOutput (list.release());
116 }
void addOutput(TObject *output_swallow) final override
effects: add an object to the output.
Definition Worker.cxx:90
list(name, path='/')
Definition histSizes.py:38

◆ addOutputStream()

StatusCode EL::Worker::addOutputStream ( const std::string & label,
Detail::OutputStreamData output )
protected

effects: add another output file guarantee: strong failures: low level errors II failures: label already used

Definition at line 768 of file Worker.cxx.

771 {
772 using namespace msgEventLoop;
774
775 if (m_outputs.find (label) != m_outputs.end())
776 {
777 ANA_MSG_ERROR ("output file already defined for label: " + label);
778 return ::StatusCode::FAILURE;
779 }
780 if (data.file() == nullptr)
781 {
782 ANA_MSG_ERROR ("output stream does not have a file attached");
783 return ::StatusCode::FAILURE;
784 }
785 if (data.mainStreamName().empty())
786 data.setMainStreamName (label);
787 m_outputs.insert (std::make_pair (label, std::make_shared<Detail::OutputStreamData>(std::move (data))));
788 return ::StatusCode::SUCCESS;
789 }
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::string label(const std::string &format, int i)
Definition label.h:19
std::map< std::string, std::shared_ptr< Detail::OutputStreamData > > m_outputs
the list of output files
Definition ModuleData.h:113

◆ addTree()

StatusCode EL::Worker::addTree ( const TTree & tree,
const std::string & stream )
finaloverridevirtual

effects: adds a tree to an output file specified by the stream/label failures: Incorrect stream/label specified, called at the wrong time note: See getOutputFile for failure types...

Implements EL::ITreeWorker.

Definition at line 156 of file Worker.cxx.

158 {
159 using namespace msgEventLoop;
160 RCU_READ_INVARIANT( this );
161
162 auto outputIter = m_outputs.find (stream);
163 if (outputIter == m_outputs.end())
164 {
165 ANA_MSG_ERROR ( "No output file with stream name \"" + stream +
166 "\" found" );
167 return ::StatusCode::FAILURE;
168 }
169
170 outputIter->second->addClone (tree);
171
172 // Return gracefully:
173 return ::StatusCode::SUCCESS;
174 }
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229
TTree * tree() const override
description: the tree we are running on guarantee: no-fail
Definition Worker.cxx:211

◆ batchExecute()

StatusCode EL::Worker::batchExecute ( unsigned job_id,
const char * confFile )

effects: do what is needed to execute the given job segment guarantee: basic failures: job specific

Definition at line 864 of file Worker.cxx.

866 {
867 using namespace msgEventLoop;
869
870 try
871 {
872 std::unique_ptr<TFile> file (TFile::Open (confFile, "READ"));
873 if (file.get() == nullptr || file->IsZombie())
874 {
875 ANA_MSG_ERROR ("failed to open file: " << confFile);
876 return ::StatusCode::FAILURE;
877 }
878
879 std::unique_ptr<BatchJob> job (dynamic_cast<BatchJob*>(file->Get ("job")));
880 m_batchJob = job.get();
881 if (job.get() == nullptr)
882 {
883 ANA_MSG_ERROR ("failed to retrieve BatchJob object");
884 return ::StatusCode::FAILURE;
885 }
886
887 if (job_id >= job->segments.size())
888 {
889 ANA_MSG_ERROR ("invalid job-id " << job_id << ", max is " << job->segments.size());
890 return ::StatusCode::FAILURE;
891 }
892 BatchSegment *segment = &job->segments[job_id];
893 RCU_ASSERT (segment->job_id == job_id);
894 RCU_ASSERT (segment->sample < job->samples.size());
895 BatchSample *sample = &job->samples[segment->sample];
896
897 gSystem->Exec ("pwd");
898 gSystem->MakeDirectory ("output");
899
900 setMetaData (&sample->meta);
901 setOutputHist (job->location + "/fetch");
902 setSegmentName (segment->fullName);
903
904 setJobConfig (JobConfig (job->job.jobConfig()));
905
906 for (Job::outputIter out = job->job.outputBegin(),
907 end = job->job.outputEnd(); out != end; ++ out)
908 {
909 Detail::OutputStreamData data {
910 out->output()->makeWriter (segment->sampleName, segment->segmentName, ".root")};
911 ANA_CHECK (addOutputStream (out->label(), std::move (data)));
912 }
913
914 {
915 m_moduleConfig.emplace_back ("EL::Detail::BatchInputModule/BatchInputModule");
916 ANA_CHECK (m_moduleConfig.back().setProperty ("jobId", job_id));
918 if (maxEvents != -1)
919 ANA_CHECK (m_moduleConfig.back().setProperty ("maxEvents", maxEvents));
920 }
921
924 ANA_CHECK (finalize ());
925
926 std::ostringstream job_name;
927 job_name << job_id;
928 std::ofstream completed ((job->location + "/status/completed-" + job_name.str()).c_str());
929 return ::StatusCode::SUCCESS;
930 } catch (...)
931 {
932 Detail::report_exception (std::current_exception());
933 return ::StatusCode::FAILURE;
934 }
935 }
#define ANA_CHECK(EXP)
check whether the given expression was successful
static const std::string optMaxEvents
description: the name of the option used for setting the maximum number of events to process per samp...
Definition Job.h:230
const OutputStream * outputIter
Definition Job.h:148
void setOutputHist(const std::string &val_outputTarget)
set the histogram output list
Definition Worker.cxx:354
std::vector< asg::AsgComponentConfig > m_moduleConfig
the module configurations we use
Definition Worker.h:457
::StatusCode addOutputStream(const std::string &label, Detail::OutputStreamData output)
effects: add another output file guarantee: strong failures: low level errors II failures: label alre...
Definition Worker.cxx:769
const SH::MetaObject * metaData() const override
description: the sample meta-data we are working on guarantee: no-fail invariant: metaData !...
Definition Worker.cxx:202
::StatusCode finalize()
finalize the worker
Definition Worker.cxx:515
void setJobConfig(JobConfig &&jobConfig)
set the JobConfig
Definition Worker.cxx:374
void setMetaData(const SH::MetaObject *val_metaData)
set the metaData
Definition Worker.cxx:343
::StatusCode initialize()
initialize the worker
Definition Worker.cxx:386
void setSegmentName(const std::string &val_segmentName)
set the segment name
Definition Worker.cxx:364
::StatusCode processInputs()
process all the inputs
Definition Worker.cxx:500
double castDouble(const std::string &name, double def_val=0, CastMode mode=CAST_ERROR_THROW) const
the meta-data double with the given name
void report_exception(std::exception_ptr eptr)
print out the currently evaluated exception
BatchJob * m_batchJob
the BatchJob configuration (if used)
Definition ModuleData.h:116
TFile * file

◆ directExecute()

StatusCode EL::Worker::directExecute ( const SH::SamplePtr & sample,
const Job & job,
const std::string & location,
const SH::MetaObject & options )

run the job

Guarantee
basic

Definition at line 819 of file Worker.cxx.

822 {
823 using namespace msgEventLoop;
825
826 SH::MetaObject meta (*sample->meta());
827 meta.fetchDefaults (options);
828
829 setMetaData (&meta);
830 setOutputHist (location);
831 setSegmentName (sample->name());
832
833 ANA_MSG_INFO ("Running sample: " << sample->name());
834
835 setJobConfig (JobConfig (job.jobConfig()));
836
837 for (Job::outputIter out = job.outputBegin(),
838 end = job.outputEnd(); out != end; ++ out)
839 {
840 Detail::OutputStreamData data {
841 out->output()->makeWriter (sample->name(), "", ".root")};
842 ANA_CHECK (addOutputStream (out->label(), std::move (data)));
843 }
844
845 {
846 m_moduleConfig.emplace_back ("EL::Detail::DirectInputModule/DirectInputModule");
847 ANA_CHECK (m_moduleConfig.back().setProperty ("fileList", sample->makeFileList()));
849 if (maxEvents != -1)
850 ANA_CHECK (m_moduleConfig.back().setProperty ("maxEvents", maxEvents));
852 if (skipEvents != 0)
853 ANA_CHECK (m_moduleConfig.back().setProperty ("skipEvents", skipEvents));
854 }
855
858 ANA_CHECK (finalize ());
859 return ::StatusCode::SUCCESS;
860 }
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
static const std::string optSkipEvents
description: the name of the option used for skipping a certain number of events in the beginning rat...
Definition Job.h:238

◆ eventsProcessed()

uint64_t EL::Worker::eventsProcessed ( ) const
protectednoexcept

the number of events that have been processed

Guarantee
no-fail

Definition at line 810 of file Worker.cxx.

812 {
813 RCU_READ_INVARIANT (this);
814 return m_eventsProcessed;
815 }
uint64_t m_eventsProcessed
the number of events that have been processed
Definition ModuleData.h:92

◆ fileOpenErrorFilter()

bool EL::Worker::fileOpenErrorFilter ( int level,
bool ,
const char * s1,
const char * s2 )
staticprivate

Error handler for file opening.

Definition at line 645 of file Worker.cxx.

647 {
648 // Don't fail on missing dictionary messages.
649 if (strstr (s2, "no streamer or dictionary") != nullptr) {
650 return true;
651 }
652
653 // For messages above warning level (SysError, Error, Fatal)
654 if( level > kWarning ) {
655 // We won't output further; ROOT should have already put something in the log file
656 std::string msg = "ROOT error detected in Worker.cxx: ";
657 msg += s1;
658 msg += " ";
659 msg += s2;
660 throw std::runtime_error(msg);
661
662 // No need for further error handling
663 return false;
664 }
665
666 // Pass to the default error handlers
667 return true;
668 }
MsgStream & msg
Definition testRead.cxx:32

◆ filterPassed()

bool EL::Worker::filterPassed ( ) const
finaloverridevirtualnoexcept

whether the current algorithm passed its filter criterion for the current event

Guarantee
no-fail

Implements EL::IFilterWorker.

Definition at line 314 of file Worker.cxx.

316 {
317 RCU_READ_INVARIANT (this);
318 return !m_skipEvent;
319 }
bool m_skipEvent
whether we are skipping the current event
Definition ModuleData.h:86

◆ finalize()

StatusCode EL::Worker::finalize ( )
protected

finalize the worker

This method ought to be called after all events have been processed. It is meant to ensure that the job is ended properly and all outputs are written out and files are closed.

Guarantee
basic
Failures
finalization failures

Definition at line 514 of file Worker.cxx.

516 {
517 using namespace msgEventLoop;
518
520
521 if (m_algorithmsInitialized == false)
522 {
523 ANA_MSG_ERROR ("algorithms never got initialized");
524 return StatusCode::FAILURE;
525 }
526
528 for (auto& module : m_modules)
529 ANA_CHECK (module->onFinalize (*this));
530 for (auto& output : m_outputs)
531 {
532 if (output.first != Job::histogramStreamName && output.second->mainStreamName() == output.first)
533 {
534 output.second->saveOutput ();
535 output.second->close ();
536 std::string path = output.second->finalFileName ();
537 if (!path.empty())
538 addOutputList ("EventLoop_OutputStream_" + output.first, new TObjString (path.c_str()));
539 }
540 }
541 for (auto& module : m_modules)
542 ANA_CHECK (module->postFinalize (*this));
543 if (m_jobStats->GetListOfBranches()->GetEntries() > 0)
544 {
545 if (m_jobStats->Fill() <= 0)
546 {
547 ANA_MSG_ERROR ("failed to fill the job statistics tree");
548 return ::StatusCode::FAILURE;
549 }
550 ModuleData::addOutput (std::move (m_jobStats));
551 }
552 m_histOutput->saveOutput ();
553 for (auto& module : m_modules)
554 ANA_CHECK (module->onWorkerEnd (*this));
555 m_histOutput->saveOutput ();
556 m_histOutput->close ();
557
558 for (auto& module : m_modules){
559 ANA_CHECK (module->postFileClose(*this));
560 }
561 ANA_MSG_INFO ("worker finished successfully");
562 return ::StatusCode::SUCCESS;
563 }
static const std::string histogramStreamName
the name of the histogram output stream
Definition Job.h:606
void addOutputList(const std::string &name, TObject *output_swallow) override
effects: add a given object to the output.
Definition Worker.cxx:104
::StatusCode openInputFile(const std::string &inputFileUrl) override
open the given input file without processing it
Definition Worker.cxx:671
bool m_algorithmsInitialized
whether the algorithms are initialized
Definition Worker.h:447
std::vector< std::unique_ptr< Detail::Module > > m_modules
the list of modules we hold
Definition Worker.h:421
path
python interpreter configuration --------------------------------------—
Definition athena.py:130
std::unique_ptr< TTree > m_jobStats
Tree saving per-job statistics information.
Definition ModuleData.h:98

◆ getAlg()

Algorithm * EL::Worker::getAlg ( const std::string & name) const
overridevirtual

effects: returns the algorithms with the given name or NULL if there is none guarantee: strong failures: out of memory II

Implements EL::IWorker.

Definition at line 291 of file Worker.cxx.

293 {
294 RCU_READ_INVARIANT (this);
295 for (auto& alg : m_algs)
296 {
297 if (alg->hasName (name))
298 return alg.m_algorithm->getLegacyAlg();
299 }
300 return 0;
301 }
std::vector< Detail::AlgorithmData > m_algs
the list of algorithms
Definition ModuleData.h:67

◆ getOutputFile()

TFile * EL::Worker::getOutputFile ( const std::string & label) const
overridevirtual

effects: get the output file that goes into the dataset with the given label.

this dataset has to be registered before the job is submitted. typically that happens in the doSetupJob method. guarantee: strong failures: no dataset with the given label postcondition: result != 0 note: the default value for the argument corresponds to the default label value in the OutputInfo class.

Implements EL::IWorker.

Definition at line 132 of file Worker.cxx.

134 {
135 RCU_READ_INVARIANT (this);
136 TFile *result = getOutputFileNull (label);
137 if (result == 0)
138 RCU_THROW_MSG ("no output dataset defined with label: " + label);
139 return result;
140 }
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
TFile * getOutputFileNull(const std::string &label) const override
effects: get the output file that goes into the dataset with the given label.
Definition Worker.cxx:145

◆ getOutputFileNull()

TFile * EL::Worker::getOutputFileNull ( const std::string & label) const
overridevirtual

effects: get the output file that goes into the dataset with the given label.

this dataset has to be registered before the job is submitted. typically that happens in the doSetupJob method. guarantee: strong failures: internal errors note: the default value for the argument corresponds to the default label value in the OutputInfo class. rationale: this method was added to support optional output files, i.e.: the algorithm leaves it to the user whether or not the output file gets configured. then the algorithm just checks whether the output file is there. if so it fills it, otherwise it ignores it.

Implements EL::IWorker.

Definition at line 144 of file Worker.cxx.

146 {
147 RCU_READ_INVARIANT (this);
148 auto iter = m_outputs.find (label);
149 if (iter == m_outputs.end())
150 return 0;
151 return iter->second->file();
152 }

◆ getOutputHist()

TObject * EL::Worker::getOutputHist ( const std::string & name) const
finaloverridevirtual

get the output histogram with the given name

This is mostly meant, so that I can emulate the Athena histogram mechanism.

Guarantee
strong
Failures
object not found
Postcondition
result != 0

Implements EL::IHistogramWorker.

Definition at line 120 of file Worker.cxx.

122 {
123 RCU_READ_INVARIANT (this);
124
125 TObject *result = m_histOutput->getOutputHist (name);
126 if (result == nullptr) RCU_THROW_MSG ("unknown output histogram: " + name);
127 return result;
128 }

◆ getOutputTree()

TTree * EL::Worker::getOutputTree ( const std::string & name,
const std::string & stream ) const
finaloverridevirtual

effects: get the tree that was added to an output file earlier failures: Tree doesn't exist

Implements EL::ITreeWorker.

Definition at line 178 of file Worker.cxx.

180 {
181 using namespace msgEventLoop;
182 RCU_READ_INVARIANT( this );
183
184 auto outputIter = m_outputs.find (stream);
185 if (outputIter == m_outputs.end())
186 {
187 RCU_THROW_MSG ( "No output file with stream name \"" + stream
188 + "\" found" );
189 }
190
191 TTree *result = outputIter->second->getOutputTree( name );
192 if( result == nullptr ) {
193 RCU_THROW_MSG ( "No tree with name \"" + name + "\" in stream \"" +
194 stream + "\"" );
195 }
196 return result;
197 }

◆ gridCreateJobSummary()

void EL::Worker::gridCreateJobSummary ( uint64_t eventsProcessed)
private

◆ gridExecute()

StatusCode EL::Worker::gridExecute ( const std::string & sampleName,
Long64_t SkipEvents,
Long64_t nEventsPerJob )

Definition at line 939 of file Worker.cxx.

941 {
942 using namespace msgEventLoop;
944
945 ANA_MSG_INFO ("Running with ROOT version " << gROOT->GetVersion()
946 << " (" << gROOT->GetVersionDate() << ")");
947
948 ANA_MSG_INFO ("Loading EventLoop grid job");
949
950
951 TList bigOutputs;
952 std::unique_ptr<JobConfig> jobConfig;
953 SH::MetaObject *mo = 0;
954
955 std::unique_ptr<TFile> f (TFile::Open("jobdef.root"));
956 if (f == nullptr || f->IsZombie()) {
957 ANA_MSG_ERROR ("Could not read jobdef");
958 return ::StatusCode::FAILURE;
959 }
960
961 mo = dynamic_cast<SH::MetaObject*>(f->Get(sampleName.c_str()));
962 if (!mo)
963 mo = dynamic_cast<SH::MetaObject*>(f->Get("defaultMetaObject"));
964 if (!mo) {
965 ANA_MSG_ERROR ("Could not read in sample meta object");
966 return ::StatusCode::FAILURE;
967 }
968
969 jobConfig.reset (dynamic_cast<JobConfig*>(f->Get("jobConfig")));
970 if (jobConfig == nullptr)
971 {
972 ANA_MSG_ERROR ("failed to read jobConfig object");
973 return ::StatusCode::FAILURE;
974 }
975
976 {
977 std::unique_ptr<TList> outs ((TList*)f->Get("outputs"));
978 if (outs == nullptr)
979 {
980 ANA_MSG_ERROR ("Could not read list of outputs");
981 return ::StatusCode::FAILURE;
982 }
983
984 TIter itr(outs.get());
985 TObject *obj = 0;
986 while ((obj = itr())) {
987 EL::OutputStream * out = dynamic_cast<EL::OutputStream*>(obj);
988 if (out) {
989 bigOutputs.Add(out);
990 }
991 else {
992 ANA_MSG_ERROR ("Encountered unexpected entry in list of outputs");
993 return ::StatusCode::FAILURE;
994 }
995 }
996 }
997
998 f->Close();
999 f.reset ();
1000
1001 const std::string location = ".";
1002
1003 mo->setBool (Job::optGridReporting, true);
1004 setMetaData (mo);
1005 setOutputHist (location);
1006 setSegmentName ("output");
1007
1008 ANA_MSG_INFO ("Starting EventLoop Grid worker");
1009
1010 {//Create and register the "big" output files with base class
1011 TIter itr(&bigOutputs);
1012 TObject *obj = 0;
1013 while ((obj = itr())) {
1014 EL::OutputStream *os = dynamic_cast<EL::OutputStream*>(obj);
1015 if (os == nullptr)
1016 {
1017 ANA_MSG_ERROR ("Bad input");
1018 return ::StatusCode::FAILURE;
1019 }
1020 {
1021 Detail::OutputStreamData data {
1022 location + "/" + os->label() + ".root", "RECREATE"};
1023 ANA_CHECK (addOutputStream (os->label(), std::move (data)));
1024 }
1025 }
1026 }
1027
1028 setJobConfig (std::move (*jobConfig));
1029
1030 {
1031 std::vector<std::string> fileList;
1032 std::ifstream infile("input.txt");
1033 while (infile) {
1034 std::string sLine;
1035 if (!getline(infile, sLine)) break;
1036 std::istringstream ssLine(sLine);
1037 while (ssLine) {
1038 std::string sFile;
1039 if (!getline(ssLine, sFile, ',')) break;
1040 fileList.push_back(sFile);
1041 }
1042 }
1043 if (fileList.size() == 0) {
1044 ANA_MSG_ERROR ("no input files provided");
1045 //User was expecting input after all.
1046 gSystem->Exit(EC_BADINPUT);
1047 }
1048 m_moduleConfig.emplace_back ("EL::Detail::DirectInputModule/DirectInputModule");
1049 ANA_CHECK (m_moduleConfig.back().setProperty ("fileList", fileList));
1050
1051 if (nEventsPerJob != -1)
1052 ANA_CHECK (m_moduleConfig.back().setProperty ("maxEvents", nEventsPerJob));
1053 if (SkipEvents != 0)
1054 ANA_CHECK (m_moduleConfig.back().setProperty ("skipEvents", SkipEvents));
1055 }
1056
1059 ANA_CHECK (finalize ());
1060
1061 int nEvents = eventsProcessed();
1062 ANA_MSG_INFO ("Loop finished.");
1063 ANA_MSG_INFO ("Read/processed " << nEvents << " events.");
1064
1065 ANA_MSG_INFO ("EventLoop Grid worker finished");
1066 ANA_MSG_INFO ("Saving output");
1067 return ::StatusCode::SUCCESS;
1068 }
static const std::string optGridReporting
whether to use grid reporting even when not running on the grid
Definition Job.h:498
uint64_t eventsProcessed() const noexcept
the number of events that have been processed
Definition Worker.cxx:811
void setBool(const std::string &name, bool value)
set the meta-data boolean with the given name
const int nEvents

◆ hasInputEvents()

bool EL::Worker::hasInputEvents ( ) const
overridevirtual

flag whether the most recently opened input file has events or not

Guarantee no-fail

Implements EL::IWorker.

Definition at line 236 of file Worker.cxx.

238 {
239 // no invariant used
240 return m_hasInputEvents;
241 }
bool m_hasInputEvents
flag whether the most recently opened input file has events or not
Definition ModuleData.h:83

◆ initialize()

StatusCode EL::Worker::initialize ( )
protected

initialize the worker

This method ought to be called after the options on the worker are set and before any events are processed. It is meant to make sure everything is ready and set up for event processing.

Guarantee
basic
Failures
initialization failures

Definition at line 385 of file Worker.cxx.

387 {
388 using namespace msgEventLoop;
390
391 const bool xAODInput = m_metaData->castBool (Job::optXAODInput, false);
392
393 ANA_MSG_INFO ("xAODInput = " << xAODInput);
394
395 if (metaData()->castBool (Job::optAlgorithmMemoryMonitor, false))
396 m_moduleConfig.emplace_back ("EL::Detail::MemoryMonitorModule/EarlyMemoryMonitorModule");
397 if (auto cacheSize = metaData()->castDouble (Job::optCacheSize, 0); cacheSize > 0)
398 {
399 m_moduleConfig.emplace_back ("EL::Detail::TreeCacheModule/TreeCacheModule");
400 ANA_CHECK (m_moduleConfig.back().setProperty ("cacheSize", Long64_t (cacheSize)));
401 ANA_CHECK (m_moduleConfig.back().setProperty ("cacheLearnEntries", Long64_t (metaData()->castInteger (Job::optCacheLearnEntries, 0))));
402 ANA_CHECK (m_moduleConfig.back().setProperty ("printPerFileStats", metaData()->castBool (Job::optPrintPerFileStats, false)));
403 }
404 if (xAODInput)
405 {
406 m_moduleConfig.emplace_back ("EL::Detail::EventModule/EventModule");
407 if (metaData()->castDouble (Job::optXAODSummaryReport, 1) == 0)
408 ANA_CHECK (m_moduleConfig.back().setProperty ("summaryReport", false));
409 ANA_CHECK (m_moduleConfig.back().setProperty ("useStats", metaData()->castBool (Job::optXAODPerfStats, false)));
410 }
411 auto factoryPreload = metaData()->castString (Job::optFactoryPreload, "");
412 if (!factoryPreload.empty())
413 {
414 m_moduleConfig.emplace_back ("EL::Detail::FactoryPreloadModule/FactoryPreloadModule");
415 ANA_CHECK (m_moduleConfig.back().setProperty ("preloader", factoryPreload));
416 }
417 m_moduleConfig.emplace_back ("EL::Detail::LeakCheckModule/LeakCheckModule");
418 ANA_CHECK (m_moduleConfig.back().setProperty ("failOnLeak", metaData()->castBool (Job::optMemFailOnLeak, false)));
419 ANA_CHECK (m_moduleConfig.back().setProperty ("absResidentLimit", metaData()->castInteger (Job::optMemResidentIncreaseLimit, 10000)));
420 ANA_CHECK (m_moduleConfig.back().setProperty ("absVirtualLimit", metaData()->castInteger (Job::optMemVirtualIncreaseLimit, 0)));
421 ANA_CHECK (m_moduleConfig.back().setProperty ("perEvResidentLimit", metaData()->castInteger (Job::optMemResidentPerEventIncreaseLimit, 10)));
422 ANA_CHECK (m_moduleConfig.back().setProperty ("perEvVirtualLimit", metaData()->castInteger (Job::optMemVirtualPerEventIncreaseLimit, 0)));
423 m_moduleConfig.emplace_back ("EL::Detail::StopwatchModule/StopwatchModule");
424 if (metaData()->castBool (Job::optGridReporting, false))
425 m_moduleConfig.emplace_back ("EL::Detail::GridReportingModule/GridReportingModule");
426 if (metaData()->castBool (Job::optAlgorithmTimer, false))
427 m_moduleConfig.emplace_back ("EL::Detail::AlgorithmTimerModule/AlgorithmTimerModule");
428 if (metaData()->castBool (Job::optAlgorithmMemoryMonitor, false))
429 m_moduleConfig.emplace_back ("EL::Detail::AlgorithmMemoryModule/AlgorithmMemoryModule");
430 m_moduleConfig.emplace_back ("EL::Detail::FileExecutedModule/FileExecutedModule");
431 m_moduleConfig.emplace_back ("EL::Detail::EventCountModule/EventCountModule");
432 m_moduleConfig.emplace_back ("EL::Detail::WorkerConfigModule/WorkerConfigModule");
433 m_moduleConfig.emplace_back ("EL::Detail::AlgorithmStateModule/AlgorithmStateModule");
434 m_moduleConfig.emplace_back ("EL::Detail::PostClosedOutputsModule/PostClosedOutputsModule");
435 if (metaData()->castBool (Job::optAlgorithmMemoryMonitor, false))
436 m_moduleConfig.emplace_back ("EL::Detail::MemoryMonitorModule/LateMemoryMonitorModule");
437
438 for (const auto& config : m_moduleConfig)
439 {
440 std::unique_ptr<Detail::Module> module;
441 ANA_CHECK (make_module (module, config));
442 m_modules.push_back (std::move (module));
443 }
444
445 if (m_outputs.find (Job::histogramStreamName) == m_outputs.end())
446 {
447 Detail::OutputStreamData data {
448 m_outputTarget + "/hist-" + m_segmentName + ".root", "RECREATE"};
450 }
453 if (auto aliases = metaData()->castString (Job::optStreamAliases, ""); !aliases.empty())
454 {
455 // the format of aliases is "alias1=realname1,alias2=realname2"
456 std::istringstream iss (aliases);
457 std::string alias;
458 while (std::getline (iss, alias, ','))
459 {
460 auto pos = alias.find ('=');
461 if (pos == std::string::npos)
462 {
463 ANA_MSG_ERROR ("Invalid alias format: " << alias);
464 return ::StatusCode::FAILURE;
465 }
466 auto aliasName = alias.substr (0, pos);
467 auto realName = alias.substr (pos + 1);
468 auto realOutput = m_outputs.find (realName);
469 if (realOutput == m_outputs.end())
470 {
471 ANA_MSG_ERROR ("output stream " << realName << " not found for alias " << aliasName);
472 return ::StatusCode::FAILURE;
473 }
474 auto [aliasOutput, success] = m_outputs.emplace (aliasName, realOutput->second);
475 if (!success)
476 {
477 ANA_MSG_ERROR ("output stream " << aliasName << " already exists, can't make alias");
478 return ::StatusCode::FAILURE;
479 }
480 }
481 }
482
483 m_jobStats = std::make_unique<TTree>
484 ("EventLoop_JobStats", "EventLoop job statistics");
485 m_jobStats->SetDirectory (nullptr);
486
487 ANA_MSG_INFO ("calling firstInitialize on all modules");
488 for (auto& module : m_modules)
489 ANA_CHECK (module->firstInitialize (*this));
490 ANA_MSG_INFO ("calling preFileInitialize on all modules");
491 for (auto& module : m_modules)
492 ANA_CHECK (module->preFileInitialize (*this));
493
494 return ::StatusCode::SUCCESS;
495 }
static const std::string optPrintPerFileStats
description: the option to turn on printing of i/o statistics at the end of each file rationale: whil...
Definition Job.h:413
static const std::string optMemFailOnLeak
Failure behaviour of the code when a "significant memory leak" is found.
Definition Job.h:595
static const std::string optAlgorithmTimer
a boolean flag for whether to add a timer for the algorithms
Definition Job.h:210
static const std::string optMemResidentIncreaseLimit
The minimal resident memory increase necessary to trigger an error.
Definition Job.h:573
static const std::string optXAODPerfStats
description: the name of the option for turning on XAODPerfStats.
Definition Job.h:361
static const std::string optXAODSummaryReport
the option to turn on/off the xAOD summary reporting at the end of the job
Definition Job.h:403
static const std::string optCacheLearnEntries
description: this option allows to configure the number of tree entries used for learning cache behav...
Definition Job.h:332
static const std::string optCacheSize
description: this option allows to configure the TTreeCache size for this job.
Definition Job.h:317
static const std::string optAlgorithmMemoryMonitor
a boolean flag for whether to add a memory monitor for the algorithms
Definition Job.h:215
static const std::string optXAODInput
the option to select whether our input is xAODs
Definition Job.h:398
static const std::string optMemResidentPerEventIncreaseLimit
The minimal per-event resident memory increase for triggering an error.
Definition Job.h:555
static const std::string optMemVirtualIncreaseLimit
The minimal virtual memory increase necessary to trigger an error.
Definition Job.h:581
static const std::string optMemVirtualPerEventIncreaseLimit
The minimal per-event virtual memory increase for triggering an error.
Definition Job.h:565
static const std::string optStreamAliases
an option for stream aliases
Definition Job.h:222
static const std::string optFactoryPreload
a boolean flag for whether to perform a component factory preload
Definition Job.h:219
std::string m_segmentName
the name of the segment we are processing
Definition Worker.h:442
std::string m_outputTarget
the target file to which we will write the histogram output
Definition Worker.h:437
std::string castString(const std::string &name, const std::string &def_val="", CastMode mode=CAST_ERROR_THROW) const
the meta-data string with the given name
const SH::MetaObject * m_metaData
the meta-data we use
Definition ModuleData.h:89

◆ inputFile()

TFile * EL::Worker::inputFile ( ) const
overridevirtual

description: the file we are reading the current tree from guarantee: no-fail

Implements EL::IWorker.

Definition at line 228 of file Worker.cxx.

230 {
231 RCU_READ_INVARIANT (this);
232 return m_inputFile.get();
233 }
std::unique_ptr< TFile > m_inputFile
the input file pointer of the currently opened filed
Definition ModuleData.h:73

◆ inputFileName()

std::string EL::Worker::inputFileName ( ) const
overridevirtual

the name of the file we are reading the current tree from, without the path component

Guarantee
no-fail

Implements EL::IWorker.

Definition at line 244 of file Worker.cxx.

246 {
247 // no invariant used
248 std::string path = inputFile()->GetName();
249 auto split = path.rfind ('/');
250 if (split != std::string::npos)
251 return path.substr (split + 1);
252 else
253 return path;
254 }
TFile * inputFile() const override
description: the file we are reading the current tree from guarantee: no-fail
Definition Worker.cxx:229
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

◆ inputFileNumEntries()

Long64_t EL::Worker::inputFileNumEntries ( ) const
overrideprotectedvirtual

the number of events in the input file

Guarantee
no-fail
Precondition
inputFile() != 0

Implements EL::Detail::IInputModuleActions.

Definition at line 793 of file Worker.cxx.

795 {
796 RCU_READ_INVARIANT (this);
797 RCU_REQUIRE (inputFile() != 0);
798
799 if (m_event) {
800 return m_event->getEntries();
801 }
802 else if (m_inputTree != 0)
803 return m_inputTree->GetEntries();
804 else
805 return 0;
806 }
#define RCU_REQUIRE(x)
Definition Assert.h:208
TTree * m_inputTree
the (main) tree in the input file
Definition ModuleData.h:76
xAOD::Event * m_event
the Event object, if we use one
Definition ModuleData.h:101

◆ metaData()

const SH::MetaObject * EL::Worker::metaData ( ) const
overridevirtual

description: the sample meta-data we are working on guarantee: no-fail invariant: metaData != 0 rationale: this can be used for accessing sample meta-data

Implements EL::IWorker.

Definition at line 201 of file Worker.cxx.

203 {
204 RCU_READ_INVARIANT (this);
205 return m_metaData;
206 }

◆ openInputFile()

StatusCode EL::Worker::openInputFile ( const std::string & inputFileUrl)
overrideprotectedvirtual

open the given input file without processing it

This is mostly to allow the driver to query the number of events in the input file without processing it, usually to determine the range of events to process.

Guarantee
basic
Failures
file can't be opened

Implements EL::Detail::IInputModuleActions.

Definition at line 670 of file Worker.cxx.

672 {
673 using namespace msgEventLoop;
674
675 // Enable custom error handling in a nice way
676 RootUtils::WithRootErrorHandler my_handler( fileOpenErrorFilter );
677
679
680 if (m_inputFileUrl == inputFileUrl)
681 return ::StatusCode::SUCCESS;
682
683 if (!m_inputFileUrl.empty())
684 {
685 if (m_newInputFile == false)
686 {
687 for (auto& module : m_modules)
688 ANA_CHECK (module->onCloseInputFile (*this));
689 for (auto& module : m_modules)
690 ANA_CHECK (module->postCloseInputFile (*this));
691 }
692 m_newInputFile = false;
693 m_hasInputEvents = false;
694 m_inputTree = nullptr;
695 m_inputFile.reset ();
696 m_inputFileUrl.clear ();
697 }
698
699 if (inputFileUrl.empty())
700 return ::StatusCode::SUCCESS;
701
702 ANA_MSG_INFO ("Opening file " << inputFileUrl);
703 std::unique_ptr<TFile> inputFile;
704 try
705 {
706 inputFile = SH::openFile (inputFileUrl, *metaData());
707 } catch (...)
708 {
709 Detail::report_exception (std::current_exception());
710 }
711 if (inputFile.get() == 0)
712 {
713 ANA_MSG_ERROR ("failed to open file " << inputFileUrl);
714 for (auto& module : m_modules)
715 module->reportInputFailure (*this);
716 return ::StatusCode::FAILURE;
717 }
718 if (inputFile->IsZombie())
719 {
720 ANA_MSG_ERROR ("input file is a zombie: " << inputFileUrl);
721 for (auto& module : m_modules)
722 module->reportInputFailure (*this);
723 return ::StatusCode::FAILURE;
724 }
725
726 // Direct TTree access
727 TTree *tree = 0;
728 const std::string treeName
730 tree = dynamic_cast<TTree*>(inputFile->Get (treeName.c_str()));
731 if (tree == nullptr)
732 {
733 ANA_MSG_INFO ("tree " << treeName << " not found in input file: " << inputFileUrl);
734 ANA_MSG_INFO ("treating this like a tree with no events");
735 }
736 else {
737 m_hasInputEvents = (tree->GetEntries() > 0);
738 }
739
740 m_newInputFile = true;
742 m_inputEntry = 0;
743 m_inputFile = std::move (inputFile);
744 m_inputFileUrl = std::move (inputFileUrl);
745
746 // onFirstInputFile to setup Event object
748 {
749 for (auto& module : m_modules)
750 ANA_CHECK (module->onFirstInputFile (*this));
751 m_firstInputFile = false;
752 }
753 else {
754 for (auto& module : m_modules)
755 ANA_CHECK (module->onNextInputFile (*this));
756 }
757
758 // Check if we have input events - done above for TTree
759 if (m_inputTree == nullptr) {
760 if (m_event) m_hasInputEvents = (m_event->getEntries() > 0);
761 }
762
763 return ::StatusCode::SUCCESS;
764 }
static bool fileOpenErrorFilter(int level, bool, const char *, const char *)
Error handler for file opening.
Definition Worker.cxx:646
bool m_firstInputFile
whether this is the first input file
Definition Worker.h:426
bool m_newInputFile
whether this is a new input file (i.e.
Definition Worker.h:432
std::unique_ptr< TFile > openFile(const std::string &name, const MetaObject &options)
open a file with the given options
std::string m_inputFileUrl
the input file url of the currently opened file
Definition ModuleData.h:70
uint64_t m_inputEntry
the entry in the input tree we are currently looking at
Definition ModuleData.h:80
static const std::string treeName_default
the default value of treeName
Definition MetaFields.h:55
static const std::string treeName
the name of the tree in the sample
Definition MetaFields.h:52

◆ processEvents()

StatusCode EL::Worker::processEvents ( EventRange & eventRange)
overrideprotectedvirtual

process the given event range

This will update eventRange if the end is set to eof

Guarantee
basic
Failures
file can't be opened
event range exceeds length of file
processing failures

Implements EL::Detail::IInputModuleActions.

Definition at line 567 of file Worker.cxx.

569 {
570 using namespace msgEventLoop;
571
573 RCU_REQUIRE (!eventRange.m_url.empty());
574 RCU_REQUIRE (eventRange.m_beginEvent >= 0);
575 RCU_REQUIRE (eventRange.m_endEvent == EventRange::eof || eventRange.m_endEvent >= eventRange.m_beginEvent);
576
577 ANA_CHECK (openInputFile (eventRange.m_url));
578
579 if (eventRange.m_beginEvent > inputFileNumEntries())
580 {
581 ANA_MSG_ERROR ("first event (" << eventRange.m_beginEvent << ") points beyond last event in file (" << inputFileNumEntries() << ")");
582 return ::StatusCode::FAILURE;
583 }
584 if (eventRange.m_endEvent == EventRange::eof)
585 {
586 eventRange.m_endEvent = inputFileNumEntries();
587 } else if (eventRange.m_endEvent > inputFileNumEntries())
588 {
589 ANA_MSG_ERROR ("end event (" << eventRange.m_endEvent << ") points beyond last event in file (" << inputFileNumEntries() << ")");
590 return ::StatusCode::FAILURE;
591 }
592
593 m_inputEntry = eventRange.m_beginEvent;
594
595 if (m_algorithmsInitialized == false)
596 {
597 for (auto& module : m_modules)
598 ANA_CHECK (module->onInitialize (*this));
600 }
601
602 if (m_newInputFile)
603 {
604 m_newInputFile = false;
605 for (auto& module : m_modules)
606 ANA_CHECK (module->onNewInputFile (*this));
607 }
608
609 if (eventRange.m_beginEvent == 0)
610 {
611 for (auto& module : m_modules)
612 ANA_CHECK (module->onFileExecute (*this));
613 }
614
615 ANA_MSG_INFO ("Processing events " << eventRange.m_beginEvent << "-" << eventRange.m_endEvent << " in file " << eventRange.m_url);
616
617 for (uint64_t event = eventRange.m_beginEvent;
618 event != uint64_t (eventRange.m_endEvent);
619 ++ event)
620 {
622 for (auto& module : m_modules)
623 {
624 if (module->onExecute (*this).isFailure())
625 {
626 ANA_MSG_ERROR ("processing event " << treeEntry() << " on file " << inputFileName());
627 return ::StatusCode::FAILURE;
628 }
629 }
630 if (m_firstEvent)
631 {
632 m_firstEvent = false;
633 for (auto& module : m_modules)
634 ANA_CHECK (module->postFirstEvent (*this));
635 }
637 if (m_eventsProcessed % 10000 == 0)
638 ANA_MSG_INFO ("Processed " << m_eventsProcessed << " events");
639 }
640 return ::StatusCode::SUCCESS;
641 }
Long64_t treeEntry() const override
description: the entry in the tree we are reading guarantee: no-fail
Definition Worker.cxx:220
std::string inputFileName() const override
the name of the file we are reading the current tree from, without the path component
Definition Worker.cxx:245
Long64_t inputFileNumEntries() const override
the number of events in the input file
Definition Worker.cxx:794
bool m_firstEvent
whether we are still to process the first event
Definition Worker.h:452
static constexpr Long64_t eof
the special value to indicate that the range includes all events until the end of the file
Definition EventRange.h:34

◆ processInputs()

StatusCode EL::Worker::processInputs ( )
protected

process all the inputs

This method ought to be called after initialize and before finalize. It will rely on the defined modules to steer it to the files and events it ought to process.

Definition at line 499 of file Worker.cxx.

501 {
502 using namespace msgEventLoop;
503
505
506 for (auto& module : m_modules)
507 ANA_CHECK (module->processInputs (*this, *this));
508
509 return ::StatusCode::SUCCESS;
510 }

◆ setFilterPassed()

void EL::Worker::setFilterPassed ( bool val_filterPassed)
finaloverridevirtualnoexcept

set the value of filterPassed

Guarantee
no-fail

Implements EL::IFilterWorker.

Definition at line 323 of file Worker.cxx.

325 {
327 m_skipEvent = !val_filterPassed;
328 }

◆ setJobConfig()

void EL::Worker::setJobConfig ( JobConfig && jobConfig)
protected

set the JobConfig

This takes care of adding the algorithms, etc. (only algorithms for now, 03 Feb 17).

Note the rvalue calling convention here: Algorithms are objects that get modified, so if you use them more than once you need to copy/clone them. However, in practice no driver should need that (though many do for now, 03 Feb 17), as drivers generally stream the JobConfig in for one-time use.

Guarantee
basic
Failures
job configuration/streaming errors

Definition at line 373 of file Worker.cxx.

375 {
377 for (auto& alg : jobConfig.extractAlgorithms())
378 {
379 m_algs.push_back (std::move (alg));
380 }
381 }

◆ setMetaData()

void EL::Worker::setMetaData ( const SH::MetaObject * val_metaData)
protected

set the metaData

Guarantee
no-fail

Definition at line 342 of file Worker.cxx.

344 {
346 RCU_REQUIRE (val_metaData != 0);
347
348 m_metaData = val_metaData;
349 }

◆ setOutputHist()

void EL::Worker::setOutputHist ( const std::string & val_outputTarget)
protected

set the histogram output list

Guarantee
no-fail

Definition at line 353 of file Worker.cxx.

355 {
357
358 m_outputTarget = val_outputTarget;
359 }

◆ setSegmentName()

void EL::Worker::setSegmentName ( const std::string & val_segmentName)
protected

set the segment name

Guarantee
no-fail

Definition at line 363 of file Worker.cxx.

365 {
367
368 m_segmentName = val_segmentName;
369 }

◆ skipEvent()

void EL::Worker::skipEvent ( )
overridevirtual

effects: skip the current event, i.e.

skip the rest of the algorithms for this event guarantee: no-fail rationale: if you have an analysis strategy in which you divide work into multiple algorithms you may want to have dedicated algorithms for event selection that then skip later algorithms that fill histograms

Implements EL::IWorker.

Definition at line 305 of file Worker.cxx.

307 {
309 m_skipEvent = true;
310 }

◆ testInvariant()

void EL::Worker::testInvariant ( ) const

effects: test the invariant of this object guarantee: no-fail

Definition at line 69 of file Worker.cxx.

71 {
72 RCU_INVARIANT (this != nullptr);
73 for (std::size_t iter = 0, end = m_algs.size(); iter != end; ++ iter)
74 {
75 RCU_INVARIANT (m_algs[iter].m_algorithm != nullptr);
76 }
77 }
#define RCU_INVARIANT(x)
Definition Assert.h:201

◆ tree()

TTree * EL::Worker::tree ( ) const
overridevirtual

description: the tree we are running on guarantee: no-fail

Implements EL::IWorker.

Definition at line 210 of file Worker.cxx.

212 {
213 RCU_READ_INVARIANT (this);
214 return m_inputTree;
215 }

◆ treeEntry()

Long64_t EL::Worker::treeEntry ( ) const
overridevirtual

description: the entry in the tree we are reading guarantee: no-fail

Implements EL::IWorker.

Definition at line 219 of file Worker.cxx.

221 {
222 RCU_READ_INVARIANT (this);
223 return m_inputEntry;
224 }

◆ triggerConfig()

TTree * EL::Worker::triggerConfig ( ) const
overridevirtual

description: the trigger config tree from the input file, or NULL if we did not find it guarantee: strong failures: i/o errors

Implements EL::IWorker.

Definition at line 258 of file Worker.cxx.

260 {
261 RCU_READ_INVARIANT (this);
262 return dynamic_cast<TTree*>(inputFile()->Get("physicsMeta/TrigConfTree"));
263 }

◆ xaodEvent()

xAOD::Event * EL::Worker::xaodEvent ( ) const
overridevirtual

description: the xAOD event and store guarantee: strong failures: out of memory I failures: EventSvc not configured postcondition: result != 0

Implements EL::IWorker.

Definition at line 267 of file Worker.cxx.

269 {
270 RCU_READ_INVARIANT (this);
271
272 if (m_event == nullptr)
273 RCU_THROW_MSG ("Job not configured for xAOD support");
274 return m_event;
275 }

◆ xaodStore()

xAOD::TStore * EL::Worker::xaodStore ( ) const
overridevirtual

Implements EL::IWorker.

Definition at line 279 of file Worker.cxx.

281 {
282 RCU_READ_INVARIANT (this);
283
284 if (m_tstore == nullptr)
285 RCU_THROW_MSG ("Job not configured for xAOD support");
286 return m_tstore;
287 }
xAOD::TStore * m_tstore
the TStore structure, if we use one
Definition ModuleData.h:104

Member Data Documentation

◆ m_algorithmsInitialized

bool EL::Worker::m_algorithmsInitialized {false}
private

whether the algorithms are initialized

Definition at line 447 of file Worker.h.

447{false};

◆ m_algs

std::vector<Detail::AlgorithmData> EL::Detail::ModuleData::m_algs
inherited

the list of algorithms

Definition at line 67 of file ModuleData.h.

◆ m_batchJob

BatchJob* EL::Detail::ModuleData::m_batchJob = nullptr
inherited

the BatchJob configuration (if used)

Definition at line 116 of file ModuleData.h.

◆ m_event

xAOD::Event* EL::Detail::ModuleData::m_event {nullptr}
inherited

the Event object, if we use one

Definition at line 101 of file ModuleData.h.

101{nullptr};

◆ m_eventsProcessed

uint64_t EL::Detail::ModuleData::m_eventsProcessed {0}
inherited

the number of events that have been processed

Definition at line 92 of file ModuleData.h.

92{0};

◆ m_evtStore

asg::SgEvent* EL::Detail::ModuleData::m_evtStore {nullptr}
inherited

the SgEvent structure, if we use one

Definition at line 107 of file ModuleData.h.

107{nullptr};

◆ m_firstEvent

bool EL::Worker::m_firstEvent {true}
private

whether we are still to process the first event

Definition at line 452 of file Worker.h.

452{true};

◆ m_firstInputFile

bool EL::Worker::m_firstInputFile {true}
private

whether this is the first input file

Definition at line 426 of file Worker.h.

426{true};

◆ m_hasInputEvents

bool EL::Detail::ModuleData::m_hasInputEvents = false
inherited

flag whether the most recently opened input file has events or not

Definition at line 83 of file ModuleData.h.

◆ m_histOutput

OutputStreamData* EL::Detail::ModuleData::m_histOutput {nullptr}
inherited

the histogram output stream

Definition at line 95 of file ModuleData.h.

95{nullptr};

◆ m_inputEntry

uint64_t EL::Detail::ModuleData::m_inputEntry {0}
inherited

the entry in the input tree we are currently looking at

Definition at line 80 of file ModuleData.h.

80{0};

◆ m_inputFile

std::unique_ptr<TFile> EL::Detail::ModuleData::m_inputFile
inherited

the input file pointer of the currently opened filed

Definition at line 73 of file ModuleData.h.

◆ m_inputFileUrl

std::string EL::Detail::ModuleData::m_inputFileUrl
inherited

the input file url of the currently opened file

Definition at line 70 of file ModuleData.h.

◆ m_inputTree

TTree* EL::Detail::ModuleData::m_inputTree {nullptr}
inherited

the (main) tree in the input file

Definition at line 76 of file ModuleData.h.

76{nullptr};

◆ m_jobStats

std::unique_ptr<TTree> EL::Detail::ModuleData::m_jobStats
inherited

Tree saving per-job statistics information.

Definition at line 98 of file ModuleData.h.

◆ m_metaData

const SH::MetaObject* EL::Detail::ModuleData::m_metaData {nullptr}
inherited

the meta-data we use

Definition at line 89 of file ModuleData.h.

89{nullptr};

◆ m_moduleConfig

std::vector<asg::AsgComponentConfig> EL::Worker::m_moduleConfig
private

the module configurations we use

Definition at line 457 of file Worker.h.

◆ m_modules

std::vector<std::unique_ptr<Detail::Module> > EL::Worker::m_modules
private

the list of modules we hold

Definition at line 421 of file Worker.h.

◆ m_newInputFile

bool EL::Worker::m_newInputFile {false}
private

whether this is a new input file (i.e.

one that has not yet been connected to the algorithms)

Definition at line 432 of file Worker.h.

432{false};

◆ m_outputHistMap

std::map<std::string,TH1*> EL::Worker::m_outputHistMap
private

Definition at line 409 of file Worker.h.

◆ m_outputs

std::map<std::string,std::shared_ptr<Detail::OutputStreamData> > EL::Detail::ModuleData::m_outputs
inherited

the list of output files

Definition at line 113 of file ModuleData.h.

◆ m_outputTarget

std::string EL::Worker::m_outputTarget
private

the target file to which we will write the histogram output

Definition at line 437 of file Worker.h.

◆ m_outputTreeMap

std::map<std::pair<std::string,std::string>,TTree*> EL::Worker::m_outputTreeMap
private

Definition at line 416 of file Worker.h.

◆ m_segmentName

std::string EL::Worker::m_segmentName
private

the name of the segment we are processing

Definition at line 442 of file Worker.h.

◆ m_skipEvent

bool EL::Detail::ModuleData::m_skipEvent = false
inherited

whether we are skipping the current event

Definition at line 86 of file ModuleData.h.

◆ m_tstore

xAOD::TStore* EL::Detail::ModuleData::m_tstore {nullptr}
inherited

the TStore structure, if we use one

Definition at line 104 of file ModuleData.h.

104{nullptr};

◆ m_worker

Worker* EL::Detail::ModuleData::m_worker {nullptr}
inherited

the worker (to pass on to the algorithms)

Definition at line 110 of file ModuleData.h.

110{nullptr};

The documentation for this class was generated from the following files: