LDMX Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
framework::Process Class Reference

Class which represents the process under execution. More...

#include <Process.h>

Public Member Functions

 Process (const framework::config::Parameters &configuration)
 Class constructor.
 
 ~Process ()
 Class Destructor.
 
const std::string & getPassName () const
 Get the processing pass label.
 
int getRunNumber () const
 Get the current run number or the run number to be used when initiating new events from the job.
 
const ldmx::EventHeadergetEventHeader () const
 Get the pointer to the current event header, if defined.
 
const ldmx::RunHeadergetRunHeader () const
 Get the pointer to the current run header, if defined.
 
ConditionsgetConditions ()
 Get a reference to the conditions system.
 
int getLogFrequency () const
 Get the frequency with which the event information is printed.
 
void run ()
 Run the process.
 
void requestFinish ()
 Request that the processing finish with this event.
 
TDirectory * makeHistoDirectory (const std::string &dirName)
 Construct a TDirectory* for the given module.
 
TDirectory * openHistoFile ()
 Open a ROOT TFile to write histograms and TTrees.
 
StorageControlgetStorageController ()
 Access the storage control unit for this process.
 
void setEventHeader (ldmx::EventHeader *h)
 Set the pointer to the current event header, used only for tests.
 

Static Public Member Functions

static Process getDummy ()
 Get a dummy process.
 

Private Member Functions

 Process ()
 Private dummy constructor We hide it here because it shouldn't be used anywhere else.
 
bool process (int n, int n_tries, Event &event) const
 Process the input event through the sequence of processors.
 
void newRun (ldmx::RunHeader &header)
 Run through the processors and let them know that we are starting a new run.
 
void onFileOpen (EventFile &file) const
 File is being opened.
 
void onFileClose (EventFile &file) const
 File is begin closed.
 
 enableLogging ("Process")
 Turn on logging for our process.
 

Private Attributes

framework::config::Parameters config_
 The parameters used to configure this class.
 
std::string passname_
 Processing pass name.
 
int eventLimit_
 Limit on events to process.
 
int totalEvents_
 Number of events we'd like to produce independetly of the number of tries it would take.
 
int logFrequency_
 The frequency with which event info is printed.
 
int maxTries_
 Maximum number of attempts to make before giving up on an event.
 
bool skipCorruptedInputFiles_
 allow the Process to skip input files that are corrupted
 
StorageControl storageController_
 Storage controller.
 
std::vector< EventProcessor * > sequence_
 Ordered list of EventProcessors to execute.
 
Conditions conditions_
 Set of ConditionsProviders.
 
std::vector< std::string > inputFiles_
 List of input files to process.
 
std::vector< std::string > outputFiles_
 List of output file names.
 
int compressionSetting_
 Compression setting to pass to output files.
 
std::vector< std::string > dropKeepRules_
 Set of drop/keep rules.
 
int runForGeneration_ {1}
 Run number to use if generating events.
 
std::string histoFilename_
 Filename for histograms and other user products.
 
const ldmx::EventHeadereventHeader_ {0}
 Pointer to the current EventHeader, used for Conditions information.
 
ldmx::RunHeaderrunHeader_ {0}
 Pointer to the current RunHeader, used for Conditions information.
 
TFile * histoTFile_ {0}
 TFile for histograms and other user products.
 
performance::Trackerperformance_ {0}
 class with calls backs to track performance measurements of software
 

Detailed Description

Class which represents the process under execution.

Definition at line 36 of file Process.h.

Constructor & Destructor Documentation

◆ Process() [1/2]

framework::Process::Process ( const framework::config::Parameters configuration)

Class constructor.

Parameters
configurationParameters to configure process with

Definition at line 23 of file Process.cxx.

24 : conditions_{*this} {
25 config_ = configuration;
26
27 passname_ = configuration.getParameter<std::string>("passName", "");
28 histoFilename_ = configuration.getParameter<std::string>("histogramFile", "");
29
30 maxTries_ = configuration.getParameter<int>("maxTriesPerEvent", 1);
31 eventLimit_ = configuration.getParameter<int>("maxEvents", -1);
32 totalEvents_ = configuration.getParameter<int>("totalEvents", -1);
33 logFrequency_ = configuration.getParameter<int>("logFrequency", -1);
35 configuration.getParameter<int>("compressionSetting", 9);
37 configuration.getParameter<bool>("skipCorruptedInputFiles", false);
38
40 configuration.getParameter<std::vector<std::string>>("inputFiles", {});
42 configuration.getParameter<std::vector<std::string>>("outputFiles", {});
44 configuration.getParameter<std::vector<std::string>>("keep", {});
45
46 eventHeader_ = 0;
47
48 // set up the logging for this run
49 logging::open(
50 configuration.getParameter<framework::config::Parameters>("logger", {}));
51
52 auto run{configuration.getParameter<int>("run", -1)};
53 if (run > 0) runForGeneration_ = run;
54
55 auto libs{
56 configuration.getParameter<std::vector<std::string>>("libraries", {})};
57 std::for_each(libs.begin(), libs.end(), [](auto &lib) {
58 PluginFactory::getInstance().loadLibrary(lib);
59 });
60
62 configuration.getParameter<bool>("skimDefaultIsKeep", true));
63 auto skimRules{
64 configuration.getParameter<std::vector<std::string>>("skimRules", {})};
65 for (size_t i = 0; i < skimRules.size(); i += 2) {
66 storageController_.addRule(skimRules[i], skimRules[i + 1]);
67 }
68
69 auto sequence{
70 configuration.getParameter<std::vector<framework::config::Parameters>>(
71 "sequence", {})};
72 if (sequence.empty() &&
73 configuration.getParameter<bool>("testingMode", false)) {
74 EXCEPTION_RAISE(
75 "NoSeq",
76 "No sequence has been defined. What should I be doing?\nUse "
77 "p.sequence to tell me what processors to run.");
78 }
79 for (auto proc : sequence) {
80 auto className{proc.getParameter<std::string>("className")};
81 auto instanceName{proc.getParameter<std::string>("instanceName")};
83 className, instanceName, *this);
84 if (ep == 0) {
85 EXCEPTION_RAISE(
86 "UnableToCreate",
87 "Unable to create instance '" + instanceName + "' of class '" +
88 className +
89 "'. Did you load the library that this class is apart of?");
90 }
91 auto histograms{
92 proc.getParameter<std::vector<framework::config::Parameters>>(
93 "histograms", {})};
94 if (!histograms.empty()) {
95 ep->getHistoDirectory();
96 ep->createHistograms(histograms);
97 }
98 ep->configure(proc);
99 sequence_.push_back(ep);
100 }
101
102 auto conditionsObjectProviders{
103 configuration.getParameter<std::vector<framework::config::Parameters>>(
104 "conditionsObjectProviders", {})};
105 for (auto cop : conditionsObjectProviders) {
106 auto className{cop.getParameter<std::string>("className")};
107 auto objectName{cop.getParameter<std::string>("objectName")};
108 auto tagName{cop.getParameter<std::string>("tagName")};
109
110 conditions_.createConditionsObjectProvider(className, objectName, tagName,
111 cop);
112 }
113
114 bool logPerformance =
115 configuration.getParameter<bool>("logPerformance", false);
116 if (logPerformance) {
117 std::vector<std::string> names{sequence_.size()};
118 for (std::size_t i{0}; i < sequence_.size(); i++) {
119 names[i] = sequence_[i]->getName();
120 }
122 new performance::Tracker(makeHistoDirectory("performance"), names);
123 }
124}
void createConditionsObjectProvider(const std::string &classname, const std::string &instancename, const std::string &tagname, const framework::config::Parameters &params)
Create a ConditionsObjectProvider given the information.
EventProcessor * createEventProcessor(const std::string &classname, const std::string &moduleInstanceName, Process &process)
Make an event processor.
static PluginFactory & getInstance()
Get the factory instance.
std::vector< EventProcessor * > sequence_
Ordered list of EventProcessors to execute.
Definition Process.h:197
std::vector< std::string > outputFiles_
List of output file names.
Definition Process.h:207
bool skipCorruptedInputFiles_
allow the Process to skip input files that are corrupted
Definition Process.h:191
std::vector< std::string > dropKeepRules_
Set of drop/keep rules.
Definition Process.h:219
void run()
Run the process.
Definition Process.cxx:140
std::string histoFilename_
Filename for histograms and other user products.
Definition Process.h:225
StorageControl storageController_
Storage controller.
Definition Process.h:194
int totalEvents_
Number of events we'd like to produce independetly of the number of tries it would take.
Definition Process.h:180
int maxTries_
Maximum number of attempts to make before giving up on an event.
Definition Process.h:186
std::vector< std::string > inputFiles_
List of input files to process.
Definition Process.h:204
TDirectory * makeHistoDirectory(const std::string &dirName)
Construct a TDirectory* for the given module.
Definition Process.cxx:424
std::string passname_
Processing pass name.
Definition Process.h:172
performance::Tracker * performance_
class with calls backs to track performance measurements of software
Definition Process.h:237
const ldmx::EventHeader * eventHeader_
Pointer to the current EventHeader, used for Conditions information.
Definition Process.h:228
int compressionSetting_
Compression setting to pass to output files.
Definition Process.h:216
int logFrequency_
The frequency with which event info is printed.
Definition Process.h:183
int runForGeneration_
Run number to use if generating events.
Definition Process.h:222
Conditions conditions_
Set of ConditionsProviders.
Definition Process.h:200
int eventLimit_
Limit on events to process.
Definition Process.h:175
framework::config::Parameters config_
The parameters used to configure this class.
Definition Process.h:169
void setDefaultKeep(bool keep)
Set the default state.
void addRule(const std::string &processor_pat, const std::string &purpose_pat)
Add a listening rule.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89

References framework::StorageControl::addRule(), compressionSetting_, conditions_, config_, framework::EventProcessor::configure(), framework::Conditions::createConditionsObjectProvider(), framework::PluginFactory::createEventProcessor(), framework::EventProcessor::createHistograms(), dropKeepRules_, eventHeader_, eventLimit_, framework::EventProcessor::getHistoDirectory(), framework::PluginFactory::getInstance(), framework::config::Parameters::getParameter(), histoFilename_, inputFiles_, logFrequency_, makeHistoDirectory(), maxTries_, outputFiles_, passname_, performance_, run(), runForGeneration_, sequence_, framework::StorageControl::setDefaultKeep(), skipCorruptedInputFiles_, storageController_, and totalEvents_.

◆ ~Process()

framework::Process::~Process ( )

Class Destructor.

Cleans up sequence of EventProcessors. These processors were created by ConfigurePython and should be deleted.

Definition at line 126 of file Process.cxx.

126 {
127 // need to delete the performance object so that it is
128 // written before we close the histogram file below
129 if (performance_) delete performance_;
130 for (EventProcessor *ep : sequence_) {
131 delete ep;
132 }
133 if (histoTFile_) {
134 histoTFile_->Write();
135 delete histoTFile_;
136 histoTFile_ = 0;
137 }
138}
TFile * histoTFile_
TFile for histograms and other user products.
Definition Process.h:234

References histoTFile_, performance_, and sequence_.

◆ Process() [2/2]

framework::Process::Process ( )
inlineprivate

Private dummy constructor We hide it here because it shouldn't be used anywhere else.

Definition at line 133 of file Process.h.

133: conditions_{*this} {}

Referenced by getDummy().

Member Function Documentation

◆ getConditions()

Conditions & framework::Process::getConditions ( )
inline

Get a reference to the conditions system.

Definition at line 78 of file Process.h.

78{ return conditions_; }

References conditions_.

Referenced by framework::EventProcessor::getConditions(), and framework::ConditionsObjectProvider::requestParentCondition().

◆ getDummy()

static Process framework::Process::getDummy ( )
inlinestatic

Get a dummy process.

This function returns an instance of this class without any configuration. This is only helpful in the use case where the user is writing a test for a processor and needs to pass a Process object to the processor's constructor.

Returns
Process without any configuration

Definition at line 126 of file Process.h.

126{ return std::move(Process()); }
Process()
Private dummy constructor We hide it here because it shouldn't be used anywhere else.
Definition Process.h:133

References Process().

◆ getEventHeader()

const ldmx::EventHeader * framework::Process::getEventHeader ( ) const
inline

Get the pointer to the current event header, if defined.

Definition at line 68 of file Process.h.

68{ return eventHeader_; }

References eventHeader_.

Referenced by framework::Conditions::getConditionPtr(), and framework::EventProcessor::getEventHeader().

◆ getLogFrequency()

int framework::Process::getLogFrequency ( ) const
inline

Get the frequency with which the event information is printed.

Returns
integer log frequency (negative if turned off)

Definition at line 84 of file Process.h.

84{ return logFrequency_; }

References logFrequency_.

Referenced by framework::EventProcessor::getLogFrequency().

◆ getPassName()

const std::string & framework::Process::getPassName ( ) const
inline

Get the processing pass label.

Returns
The processing pass label.

Definition at line 56 of file Process.h.

56{ return passname_; }

References passname_.

Referenced by framework::RandomNumberSeedService::onNewRun().

◆ getRunHeader()

const ldmx::RunHeader * framework::Process::getRunHeader ( ) const
inline

Get the pointer to the current run header, if defined.

Definition at line 73 of file Process.h.

73{ return runHeader_; }
ldmx::RunHeader * runHeader_
Pointer to the current RunHeader, used for Conditions information.
Definition Process.h:231

References runHeader_.

◆ getRunNumber()

int framework::Process::getRunNumber ( ) const

Get the current run number or the run number to be used when initiating new events from the job.

Returns
int Run number

Definition at line 420 of file Process.cxx.

420 {
422}
int getRun() const
Return the run number.
Definition EventHeader.h:84

References eventHeader_, ldmx::EventHeader::getRun(), and runForGeneration_.

Referenced by framework::EventProcessor::getRunNumber().

◆ getStorageController()

StorageControl & framework::Process::getStorageController ( )
inline

Access the storage control unit for this process.

Definition at line 109 of file Process.h.

109{ return storageController_; }

References storageController_.

Referenced by framework::EventProcessor::setStorageHint().

◆ makeHistoDirectory()

TDirectory * framework::Process::makeHistoDirectory ( const std::string &  dirName)

Construct a TDirectory* for the given module.

Definition at line 424 of file Process.cxx.

424 {
425 auto owner{openHistoFile()};
426 TDirectory *child = owner->mkdir((char *)dirName.c_str());
427 if (child) child->cd();
428 return child;
429}
TDirectory * openHistoFile()
Open a ROOT TFile to write histograms and TTrees.
Definition Process.cxx:431

References openHistoFile().

Referenced by framework::EventProcessor::getHistoDirectory(), and Process().

◆ newRun()

void framework::Process::newRun ( ldmx::RunHeader header)
private

Run through the processors and let them know that we are starting a new run.

Parameters
[in]headerRunHeader for the new run

Definition at line 452 of file Process.cxx.

452 {
453 // Producers are allowed to put parameters into
454 // the run header through 'beforeNewRun' method
455 if (performance_) performance_->start(performance::Callback::beforeNewRun, 0);
456 std::size_t i_proc{0};
457 for (auto module : sequence_) {
458 i_proc++;
459 if (dynamic_cast<Producer *>(module)) {
460 if (performance_)
461 performance_->start(performance::Callback::beforeNewRun, i_proc);
462 dynamic_cast<Producer *>(module)->beforeNewRun(header);
463 if (performance_)
464 performance_->stop(performance::Callback::beforeNewRun, i_proc);
465 }
466 }
467 if (performance_) performance_->stop(performance::Callback::beforeNewRun, 0);
468 // now run header has been modified by Producers,
469 // it is valid to read from for everyone else in 'onNewRun'
470 if (performance_) performance_->start(performance::Callback::onNewRun, 0);
471 conditions_.onNewRun(header);
472 i_proc = 0;
473 for (auto module : sequence_) {
474 i_proc++;
475 if (performance_)
476 performance_->start(performance::Callback::onNewRun, i_proc);
477 module->onNewRun(header);
478 if (performance_)
479 performance_->stop(performance::Callback::onNewRun, i_proc);
480 }
481 if (performance_) performance_->stop(performance::Callback::onNewRun, 0);
482}
void onNewRun(ldmx::RunHeader &)
Calls onNewRun for all ConditionsObjectProviders.
void start(Callback cb, std::size_t i_proc)
start the timer for a specific callback and specific processor
Definition Tracker.cxx:90
void stop(Callback cb, std::size_t i_proc)
stop the timer for a specific callback and specific processor
Definition Tracker.cxx:94

References conditions_, framework::Conditions::onNewRun(), performance_, sequence_, framework::performance::Tracker::start(), and framework::performance::Tracker::stop().

Referenced by run().

◆ onFileClose()

void framework::Process::onFileClose ( EventFile file) const
private

File is begin closed.

Definition at line 539 of file Process.cxx.

539 {
540 if (performance_) performance_->start(performance::Callback::onFileClose, 0);
541 std::size_t i_proc{0};
542 for (auto module : sequence_) {
543 i_proc++;
544 if (performance_)
545 performance_->start(performance::Callback::onFileClose, i_proc);
546 module->onFileClose(file);
547 if (performance_)
548 performance_->stop(performance::Callback::onFileClose, i_proc);
549 }
550 if (performance_) performance_->stop(performance::Callback::onFileClose, 0);
551}

References performance_, sequence_, framework::performance::Tracker::start(), and framework::performance::Tracker::stop().

Referenced by run().

◆ onFileOpen()

void framework::Process::onFileOpen ( EventFile file) const
private

File is being opened.

Definition at line 525 of file Process.cxx.

525 {
526 if (performance_) performance_->start(performance::Callback::onFileOpen, 0);
527 std::size_t i_proc{0};
528 for (auto module : sequence_) {
529 i_proc++;
530 if (performance_)
531 performance_->start(performance::Callback::onFileOpen, i_proc);
532 module->onFileOpen(file);
533 if (performance_)
534 performance_->stop(performance::Callback::onFileOpen, i_proc);
535 }
536 if (performance_) performance_->stop(performance::Callback::onFileOpen, 0);
537}

References performance_, sequence_, framework::performance::Tracker::start(), and framework::performance::Tracker::stop().

Referenced by run().

◆ openHistoFile()

TDirectory * framework::Process::openHistoFile ( )

Open a ROOT TFile to write histograms and TTrees.

Definition at line 431 of file Process.cxx.

431 {
432 TDirectory *owner{nullptr};
433
434 if (histoFilename_.empty()) {
435 // trying to write histograms/ntuples but no file defined
436 EXCEPTION_RAISE(
437 "NoHistFileName",
438 "You did not provide the necessary histogram file name to "
439 "put your histograms (or performance data) in.\n Provide this "
440 "name in the python configuration with 'p.histogramFile = "
441 "\"myHistFile.root\"' where p is the Process object.");
442 } else if (histoTFile_ == nullptr) {
443 histoTFile_ = new TFile(histoFilename_.c_str(), "RECREATE");
444 owner = histoTFile_;
445 } else
446 owner = histoTFile_;
447 owner->cd();
448
449 return owner;
450}

References histoFilename_, and histoTFile_.

Referenced by makeHistoDirectory().

◆ process()

bool framework::Process::process ( int  n,
int  n_tries,
Event event 
) const
private

Process the input event through the sequence of processors.

The input counters (for events and tries) are only used to print the status.

Parameters
[in]ncounter for number of events processed
[in]n_triescounter for number of tries on current event
[in,out]eventreference to event we are going to process
Returns
true if event was full processed (false if aborted)

Definition at line 484 of file Process.cxx.

484 {
485 if ((logFrequency_ != -1) && ((n + 1) % logFrequency_ == 0) && (n_try < 2)) {
486 // only printout event counter if we've enabled log frequency, the event
487 // matches the frequency and we are on the first try
488 TTimeStamp t;
489 ldmx_log(info) << "Processing " << n + 1 << " Run "
490 << event.getEventHeader().getRun() << " Event "
491 << event.getEventHeader().getEventNumber() << " ("
492 << t.AsString("lc") << ")";
493 }
494
495 if (performance_) performance_->start(performance::Callback::process, 0);
496 std::size_t i_proc{0};
497 try {
498 for (auto module : sequence_) {
499 i_proc++;
500 if (performance_)
501 performance_->start(performance::Callback::process, i_proc);
502 if (dynamic_cast<Producer *>(module)) {
503 (dynamic_cast<Producer *>(module))->produce(event);
504 } else if (dynamic_cast<Analyzer *>(module)) {
505 (dynamic_cast<Analyzer *>(module))->analyze(event);
506 }
507 if (performance_)
508 performance_->stop(performance::Callback::process, i_proc);
509 }
510 } catch (AbortEventException &) {
511 if (performance_) {
512 performance_->stop(performance::Callback::process, i_proc);
513 performance_->stop(performance::Callback::process, 0);
514 performance_->end_event(false);
515 }
516 return false;
517 }
518 if (performance_) {
519 performance_->stop(performance::Callback::process, 0);
520 performance_->end_event(true);
521 }
522 return true;
523}
void end_event(bool completed)
inform us that we finished an event (and whether it was completed or not)
Definition Tracker.cxx:98

References framework::performance::Tracker::end_event(), logFrequency_, performance_, sequence_, framework::performance::Tracker::start(), and framework::performance::Tracker::stop().

Referenced by run().

◆ requestFinish()

void framework::Process::requestFinish ( )
inline

Request that the processing finish with this event.

Definition at line 94 of file Process.h.

94{ eventLimit_ = 0; }

References eventLimit_.

◆ run()

void framework::Process::run ( )

Run the process.

Definition at line 140 of file Process.cxx.

140 {
142
143 // Counter to keep track of the number of events that have been
144 // procesed
145 auto n_events_processed{0};
146
147 // make sure the ntuple manager is in a blank state
149
150 // event bus for this process
151 Event theEvent(passname_);
152 // the EventHeader object is created with the event bus as
153 // one of its members, we obtain a pointer for the header
154 // here so we can share it with the conditions system
155 eventHeader_ = theEvent.getEventHeaderPtr();
156 theEvent.getEventHeader().setRun(runForGeneration_);
157
158 // Start by notifying everyone that modules processing is beginning
159 std::size_t i_proc{0};
160 if (performance_)
161 performance_->start(performance::Callback::onProcessStart, 0);
163 for (auto module : sequence_) {
164 i_proc++;
165 if (performance_)
166 performance_->start(performance::Callback::onProcessStart, i_proc);
167 module->onProcessStart();
168 if (performance_)
169 performance_->stop(performance::Callback::onProcessStart, i_proc);
170 }
171 if (performance_)
172 performance_->stop(performance::Callback::onProcessStart, 0);
173
174 // If we have no input files, but do have an event number, run for
175 // that number of events and generate an output file.
176 if (inputFiles_.empty() && eventLimit_ > 0) {
177 if (outputFiles_.empty()) {
178 EXCEPTION_RAISE("InvalidConfig",
179 "No input files or output files were given.");
180 } else if (outputFiles_.size() > 1) {
181 ldmx_log(warn) << "Several output files given with no input files. "
182 << "Only the first output file '" << outputFiles_.at(0)
183 << "' will be used.";
184 }
185 std::string outputFileName = outputFiles_.at(0);
186
187 // Configure the event file to create an output file with no parent. This
188 // requires setting the parameters isOutputFile and isSingleOutput to true.
189 EventFile outFile(config_, outputFileName, nullptr, true, true, false);
190 onFileOpen(outFile);
191 outFile.setupEvent(&theEvent);
192
193 for (auto rule : dropKeepRules_) outFile.addDrop(rule);
194
196 runHeader.setRunStart(std::time(nullptr)); // set run starting
197 runHeader_ = &runHeader; // give handle to run header to process
198 outFile.writeRunHeader(runHeader); // add run header to file
199
200 newRun(runHeader);
201
202 int totalTries = 0; // total number of tries for entire run
203 int numTries = 0; // number of tries for the current event number
204 int event_limit = eventLimit_;
205 if (totalEvents_ > 0) {
206 // Have a warning at the first event
207 if (numTries == 0)
208 ldmx_log(warn) << "The totalEvents was set, so maxEvents and "
209 "maxTriesPerEvent will be ignored!";
210 event_limit = totalEvents_;
211 }
212 while (n_events_processed < event_limit) {
213 totalTries++;
214 numTries++;
215
216 ldmx::EventHeader &eh = theEvent.getEventHeader();
218 eh.setEventNumber(n_events_processed + 1);
219 eh.setTimestamp(TTimeStamp());
220
221 // reset the storage controller state
223 logging::Formatter::set(theEvent.getEventNumber());
224
225 bool completed = process(n_events_processed, numTries, theEvent);
226
227 outFile.nextEvent(storageController_.keepEvent(completed));
228
229 // reset try counter only on successfully completed events
230 if (completed) numTries = 0;
231
232 // we use modulo here insetad of >= because we want to carry
233 // the number of tries across the number of events processed boundary
234 // totalEvents_ is set let's not exit until that's reached
235 if (completed or (totalEvents_ < 0 and numTries % maxTries_ == 0)) {
236 n_events_processed++; // increment events made
237 NtupleManager::getInstance().fill(); // fill ntuples
238 }
239
241 }
242
243 onFileClose(outFile);
244
245 runHeader.setRunEnd(std::time(nullptr));
246 runHeader.setNumTries(totalTries);
247 ldmx_log(info) << runHeader;
248 outFile.writeRunTree();
249
250 // Give a warning that this filter has very low efficiency
251 if (n_events_processed < totalTries / 10000) { // integer division is okay
252 ldmx_log(warn)
253 << "Less than 1 event out of every 10k events tried was accepted!";
254 ldmx_log(warn)
255 << "This could be an issue with your filtering and biasing procedure "
256 "since this is incredibly inefficient.";
257 }
258
259 } else {
260 // there are input files
261
262 EventFile *outFile(0);
263
264 bool singleOutput = false;
265 if (outputFiles_.size() == 1) {
266 singleOutput = true;
267 } else if (!outputFiles_.empty() and
268 outputFiles_.size() != inputFiles_.size()) {
269 EXCEPTION_RAISE("Process",
270 "Unable to handle case of different number of input and "
271 "output files (other than zero/one ouput file).");
272 }
273
274 // next, loop through the files
275 int ifile = 0;
276 int wasRun = -1;
277 for (auto infilename : inputFiles_) {
278 EventFile inFile(config_, infilename);
279 if (inFile.isCorrupted()) {
281 ldmx_log(warn) << "Input file '" << infilename
282 << "' was found to be corrupted. Skipping.";
283 continue;
284 } else {
285 EXCEPTION_RAISE(
286 "BadCode",
287 "We should never get here. "
288 "EventFile is corrupted but we aren't skipping corrupted inputs. "
289 "EventFile should be throwing its own exceptions in this case.");
290 }
291 }
292
293 ldmx_log(info) << "Opening file " << infilename;
294 onFileOpen(inFile);
295
296 // configure event file that will be iterated over
297 EventFile *masterFile;
298 if (!outputFiles_.empty()) {
299 // setup new output file if either
300 // 1) we are not in single output mode
301 // 2) this is the first input file
302 if (!singleOutput or ifile == 0) {
303 // setup new output file
304 outFile = new EventFile(config_, outputFiles_[ifile], &inFile,
305 singleOutput);
306 ifile++;
307
308 // setup theEvent we will iterate over
309 if (outFile) {
310 outFile->setupEvent(&theEvent);
311 masterFile = outFile;
312 } else {
313 EXCEPTION_RAISE("Process", "Unable to construct output file for " +
314 outputFiles_[ifile]);
315 }
316
317 for (auto rule : dropKeepRules_) outFile->addDrop(rule);
318
319 } else {
320 // all other input files
321 outFile->updateParent(&inFile);
322 masterFile = outFile;
323
324 } // check if in singleOutput mode
325
326 } else {
327 // empty output file list, use inputFile as master file
328 inFile.setupEvent(&theEvent);
329 masterFile = &inFile;
330 }
331
332 bool event_completed = true;
333 while (masterFile->nextEvent(
334 storageController_.keepEvent(event_completed)) &&
335 (eventLimit_ < 0 || (n_events_processed) < eventLimit_)) {
336 // clean up for storage control calculation
338 logging::Formatter::set(theEvent.getEventNumber());
339
340 // notify for new run if necessary
341 if (theEvent.getEventHeader().getRun() != wasRun) {
342 wasRun = theEvent.getEventHeader().getRun();
343 ldmx::RunHeader *rh{masterFile->getRunHeaderPtr(wasRun)};
344 if (rh != nullptr) {
345 runHeader_ = rh;
346 ldmx_log(info) << "Got new run header from '"
347 << masterFile->getFileName() << "' ...\n"
348 << *runHeader_;
350 } else {
351 ldmx_log(warn) << "Run header for run " << wasRun
352 << " was not found!";
353 }
354 }
355
356 event_completed = process(n_events_processed, 1, theEvent);
357
358 if (event_completed) NtupleManager::getInstance().fill();
360
361 n_events_processed++;
362 } // loop through events
363
364 bool leave_early{false};
365 if (eventLimit_ > 0 && n_events_processed == eventLimit_) {
366 ldmx_log(info) << "Reached event limit of " << eventLimit_ << " events";
367 leave_early = true;
368 }
369
370 if (eventLimit_ == 0 && n_events_processed > eventLimit_) {
371 ldmx_log(warn) << "Processing interrupted";
372 leave_early = true;
373 }
374
375 ldmx_log(info) << "Closing file " << infilename;
376 onFileClose(inFile);
377
378 // Reset the event in case of multiple input files
379 theEvent.onEndOfFile();
380
381 if (outFile and !singleOutput) {
382 outFile->writeRunTree();
383 delete outFile;
384 outFile = nullptr;
385 }
386
387 if (leave_early) {
388 break;
389 }
390 } // loop through input files
391
392 if (outFile) {
393 // close outFile
394 // outFile would survive to here in single output mode
395 outFile->writeRunTree();
396 delete outFile;
397 outFile = nullptr;
398 }
399
400 } // are there input files? if-else tree
401
402 // finally, notify everyone that we are stopping
403 if (performance_) performance_->start(performance::Callback::onProcessEnd, 0);
404 i_proc = 0;
405 for (auto module : sequence_) {
406 i_proc++;
407 if (performance_)
408 performance_->start(performance::Callback::onProcessEnd, i_proc);
409 module->onProcessEnd();
410 if (performance_)
411 performance_->stop(performance::Callback::onProcessEnd, i_proc);
412 }
413 if (performance_) performance_->stop(performance::Callback::onProcessEnd, 0);
414
415 // we're done so let's close up the logging
416 logging::close();
418}
void onProcessStart()
Calls onProcessStart for all ConditionsObjectProviders.
void clear()
Reset all of the variables to their limits.
static NtupleManager & getInstance()
void reset()
Reset NtupleManager to blank state.
void newRun(ldmx::RunHeader &header)
Run through the processors and let them know that we are starting a new run.
Definition Process.cxx:452
void onFileClose(EventFile &file) const
File is begin closed.
Definition Process.cxx:539
bool process(int n, int n_tries, Event &event) const
Process the input event through the sequence of processors.
Definition Process.cxx:484
void onFileOpen(EventFile &file) const
File is being opened.
Definition Process.cxx:525
bool keepEvent(bool event_completed) const
Determine if the current event should be kept, based on the defined rules.
void resetEventState()
Reset the event-by-event state.
static void set(int n)
set the event number in the current Formatter
Definition Logger.cxx:160
void absolute_start()
literally first line of Process::run
Definition Tracker.cxx:86
void absolute_stop()
literally last line of Process::run (if run compeletes without error)
Definition Tracker.cxx:88
Provides header information an event such as event number and timestamp.
Definition EventHeader.h:44
void setEventNumber(int eventNumber)
Set the event number.
void setRun(int run)
Set the run number.
void setTimestamp(const TTimeStamp &timestamp)
Set the timestamp.
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:54

References framework::performance::Tracker::absolute_start(), framework::performance::Tracker::absolute_stop(), framework::EventFile::addDrop(), framework::NtupleManager::clear(), conditions_, config_, dropKeepRules_, eventHeader_, eventLimit_, framework::Event::getEventHeader(), framework::Event::getEventHeaderPtr(), framework::Event::getEventNumber(), framework::EventFile::getFileName(), framework::NtupleManager::getInstance(), ldmx::EventHeader::getRun(), framework::EventFile::getRunHeaderPtr(), inputFiles_, framework::EventFile::isCorrupted(), framework::StorageControl::keepEvent(), maxTries_, newRun(), framework::EventFile::nextEvent(), framework::Event::onEndOfFile(), onFileClose(), onFileOpen(), framework::Conditions::onProcessStart(), outputFiles_, passname_, performance_, process(), framework::NtupleManager::reset(), framework::StorageControl::resetEventState(), runForGeneration_, runHeader_, sequence_, framework::logging::Formatter::set(), ldmx::EventHeader::setEventNumber(), ldmx::RunHeader::setNumTries(), ldmx::EventHeader::setRun(), ldmx::RunHeader::setRunEnd(), ldmx::RunHeader::setRunStart(), ldmx::EventHeader::setTimestamp(), framework::EventFile::setupEvent(), skipCorruptedInputFiles_, framework::performance::Tracker::start(), framework::performance::Tracker::stop(), storageController_, totalEvents_, framework::EventFile::updateParent(), framework::EventFile::writeRunHeader(), and framework::EventFile::writeRunTree().

Referenced by Process().

◆ setEventHeader()

void framework::Process::setEventHeader ( ldmx::EventHeader h)
inline

Set the pointer to the current event header, used only for tests.

Definition at line 114 of file Process.h.

114{ eventHeader_ = h; }

References eventHeader_.

Member Data Documentation

◆ compressionSetting_

int framework::Process::compressionSetting_
private

Compression setting to pass to output files.

Look at the documentation for the TFile constructor if you want to learn more details. Essentially, setting = 100*algo + level with algo = 0 being the global default.

Definition at line 216 of file Process.h.

Referenced by Process().

◆ conditions_

Conditions framework::Process::conditions_
private

Set of ConditionsProviders.

Definition at line 200 of file Process.h.

Referenced by getConditions(), newRun(), Process(), and run().

◆ config_

framework::config::Parameters framework::Process::config_
private

The parameters used to configure this class.

Definition at line 169 of file Process.h.

Referenced by Process(), and run().

◆ dropKeepRules_

std::vector<std::string> framework::Process::dropKeepRules_
private

Set of drop/keep rules.

Definition at line 219 of file Process.h.

Referenced by Process(), and run().

◆ eventHeader_

const ldmx::EventHeader* framework::Process::eventHeader_ {0}
private

Pointer to the current EventHeader, used for Conditions information.

Definition at line 228 of file Process.h.

228{0};

Referenced by getEventHeader(), getRunNumber(), Process(), run(), and setEventHeader().

◆ eventLimit_

int framework::Process::eventLimit_
private

Limit on events to process.

Definition at line 175 of file Process.h.

Referenced by Process(), requestFinish(), and run().

◆ histoFilename_

std::string framework::Process::histoFilename_
private

Filename for histograms and other user products.

Definition at line 225 of file Process.h.

Referenced by openHistoFile(), and Process().

◆ histoTFile_

TFile* framework::Process::histoTFile_ {0}
private

TFile for histograms and other user products.

Definition at line 234 of file Process.h.

234{0};

Referenced by openHistoFile(), and ~Process().

◆ inputFiles_

std::vector<std::string> framework::Process::inputFiles_
private

List of input files to process.

May be empty if this Process will generate new events.

Definition at line 204 of file Process.h.

Referenced by Process(), and run().

◆ logFrequency_

int framework::Process::logFrequency_
private

The frequency with which event info is printed.

Definition at line 183 of file Process.h.

Referenced by getLogFrequency(), Process(), and process().

◆ maxTries_

int framework::Process::maxTries_
private

Maximum number of attempts to make before giving up on an event.

Definition at line 186 of file Process.h.

Referenced by Process(), and run().

◆ outputFiles_

std::vector<std::string> framework::Process::outputFiles_
private

List of output file names.

If empty, no output file will be created.

Definition at line 207 of file Process.h.

Referenced by Process(), and run().

◆ passname_

std::string framework::Process::passname_
private

Processing pass name.

Definition at line 172 of file Process.h.

Referenced by getPassName(), Process(), and run().

◆ performance_

performance::Tracker* framework::Process::performance_ {0}
private

class with calls backs to track performance measurements of software

Definition at line 237 of file Process.h.

237{0};

Referenced by newRun(), onFileClose(), onFileOpen(), Process(), process(), run(), and ~Process().

◆ runForGeneration_

int framework::Process::runForGeneration_ {1}
private

Run number to use if generating events.

Definition at line 222 of file Process.h.

222{1};

Referenced by getRunNumber(), Process(), and run().

◆ runHeader_

ldmx::RunHeader* framework::Process::runHeader_ {0}
private

Pointer to the current RunHeader, used for Conditions information.

Definition at line 231 of file Process.h.

231{0};

Referenced by getRunHeader(), and run().

◆ sequence_

std::vector<EventProcessor *> framework::Process::sequence_
private

Ordered list of EventProcessors to execute.

Definition at line 197 of file Process.h.

Referenced by newRun(), onFileClose(), onFileOpen(), Process(), process(), run(), and ~Process().

◆ skipCorruptedInputFiles_

bool framework::Process::skipCorruptedInputFiles_
private

allow the Process to skip input files that are corrupted

Definition at line 191 of file Process.h.

Referenced by Process(), and run().

◆ storageController_

StorageControl framework::Process::storageController_
private

Storage controller.

Definition at line 194 of file Process.h.

Referenced by getStorageController(), Process(), and run().

◆ totalEvents_

int framework::Process::totalEvents_
private

Number of events we'd like to produce independetly of the number of tries it would take.

Be warned about infinite loops!

Definition at line 180 of file Process.h.

Referenced by Process(), and run().


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