LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
art::EmptyEvent Class Referencefinal
Inheritance diagram for art::EmptyEvent:
art::InputSource

Classes

struct  Config
 

Public Types

using Parameters = fhicl::WrappedTable< Config, Config::KeysToIgnore >
 
enum  ProcessingMode { Runs, RunsAndSubRuns, RunsSubRunsAndEvents }
 

Public Member Functions

 EmptyEvent (Parameters const &config, InputSourceDescription &desc)
 
 EmptyEvent (EmptyEvent const &)=delete
 
 EmptyEvent (EmptyEvent &&)=delete
 
EmptyEventoperator= (EmptyEvent const &)=delete
 
EmptyEventoperator= (EmptyEvent &&)=delete
 
ModuleDescription const & moduleDescription () const
 
ProcessConfiguration const & processConfiguration () const
 

Static Public Member Functions

static ProcessingMode mode (std::string const &modeString)
 

Private Member Functions

unique_ptr< RangeSetHandlerrunRangeSetHandler () override
 
unique_ptr< RangeSetHandlersubRunRangeSetHandler () override
 
void doBeginJob () override
 
void doEndJob () override
 
void skipEvents (int offset) override
 
unique_ptr< FileBlockreadFile () override
 
void closeFile () override
 
unique_ptr< RunPrincipalreadRun () override
 
input::ItemType nextItemType () override
 
unique_ptr< SubRunPrincipalreadSubRun (cet::exempt_ptr< RunPrincipal const >) override
 
unique_ptr< EventPrincipalreadEvent (cet::exempt_ptr< SubRunPrincipal const >) override
 
input::ItemType nextItemType_ ()
 
unique_ptr< EmptyEventTimestampPluginmakePlugin_ (OptionalDelegatedParameter const &maybeConfig)
 

Private Attributes

ProcessingLimits limits_
 
unsigned const numberEventsInRun_
 
unsigned const numberEventsInSubRun_
 
steady_clock::time_point const beginTime_ {steady_clock::now()}
 
std::chrono::seconds const maxTime_
 
std::chrono::microseconds const eventCreationDelay_
 
unsigned numberEventsInThisRun_ {}
 
unsigned numberEventsInThisSubRun_ {}
 
EventID origEventID_ {}
 
EventID eventID_ {}
 
bool firstTime_ {true}
 
bool newFile_ {true}
 
bool newRun_ {true}
 
bool newSubRun_ {true}
 
bool const resetEventOnSubRun_
 
cet::BasicPluginFactory pluginFactory_ {}
 
unique_ptr< EmptyEventTimestampPluginplugin_
 

Detailed Description

Definition at line 44 of file EmptyEvent_source.cc.

Member Typedef Documentation

Member Enumeration Documentation

Enumerator
Runs 
RunsAndSubRuns 
RunsSubRunsAndEvents 

Definition at line 61 of file InputSource.h.

Constructor & Destructor Documentation

art::EmptyEvent::EmptyEvent ( Parameters const &  config,
InputSourceDescription desc 
)

Definition at line 146 of file EmptyEvent_source.cc.

References art::errors::Configuration, eventCreationDelay_, eventID_, art::EventID::firstEvent(), art::RunID::firstRun(), art::SubRunID::firstSubRun(), limits_, makePlugin_(), maxTime_, art::InputSourceDescription::moduleDescription, nextItemType_(), numberEventsInRun_, numberEventsInSubRun_, origEventID_, plugin_, resetEventOnSubRun_, art::RunID::run(), art::SubRunID::run(), and art::SubRunID::subRun().

148  : InputSource{desc.moduleDescription}
149  , limits_{config().limitsConfig(), [this] { return nextItemType_(); }}
150  , numberEventsInRun_{static_cast<uint32_t>(config().numberEventsInRun())}
151  , numberEventsInSubRun_{static_cast<uint32_t>(
152  config().numberEventsInSubRun())}
153  , maxTime_{config().maxTime()}
154  , eventCreationDelay_{config().eventCreationDelay()}
155  , resetEventOnSubRun_{config().resetEventOnSubRun()}
156  , plugin_{makePlugin_(config().timestampPlugin)}
157 {
158  // Additional configuration checking which is cumbersome to do with
159  // the FHiCL validation system.
160  auto const& pset = config.get_PSet();
161  if (pset.has_key("maxTime") &&
162  (pset.has_key("maxEvents") || pset.has_key("maxSubRuns"))) {
163  throw Exception{
165  "An error occurred while configuring the EmptyEvent source.\n"}
166  << "The 'maxTime' parameter cannot be used with the 'maxEvents' or "
167  "'maxSubRuns' parameters.\n"
168  "Type 'art --print-description EmptyEvent' for the allowed "
169  "configuration.\n";
170  }
171 
172  RunNumber_t firstRun{};
173  bool haveFirstRun = config().firstRun(firstRun);
174  SubRunNumber_t firstSubRun{};
175  bool haveFirstSubRun = config().firstSubRun(firstSubRun);
176  EventNumber_t firstEvent{};
177  bool haveFirstEvent = config().firstEvent(firstEvent);
178  RunID firstRunID = haveFirstRun ? RunID(firstRun) : RunID::firstRun();
179  SubRunID firstSubRunID = haveFirstSubRun ?
180  SubRunID(firstRunID.run(), firstSubRun) :
181  SubRunID::firstSubRun(firstRunID);
182  origEventID_ =
183  haveFirstEvent ?
184  EventID(firstSubRunID.run(), firstSubRunID.subRun(), firstEvent) :
185  EventID::firstEvent(firstSubRunID);
187 }
InputSource(ModuleDescription const &)
Definition: InputSource.cc:27
std::chrono::microseconds const eventCreationDelay_
unique_ptr< EmptyEventTimestampPlugin > makePlugin_(OptionalDelegatedParameter const &maybeConfig)
unsigned const numberEventsInRun_
unsigned const numberEventsInSubRun_
std::chrono::seconds const maxTime_
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:119
unique_ptr< EmptyEventTimestampPlugin > plugin_
static SubRunID firstSubRun()
Definition: SubRunID.h:153
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
bool const resetEventOnSubRun_
static EventID firstEvent()
Definition: EventID.h:190
ProcessingLimits limits_
input::ItemType nextItemType_()
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120
art::EmptyEvent::EmptyEvent ( EmptyEvent const &  )
delete
art::EmptyEvent::EmptyEvent ( EmptyEvent &&  )
delete

Member Function Documentation

void art::EmptyEvent::closeFile ( )
overrideprivatevirtual

Implements art::InputSource.

Definition at line 291 of file EmptyEvent_source.cc.

292 {}
void art::EmptyEvent::doBeginJob ( )
overrideprivatevirtual

Reimplemented from art::InputSource.

Definition at line 358 of file EmptyEvent_source.cc.

References plugin_.

359 {
360  if (plugin_) {
361  plugin_->doBeginJob();
362  }
363 }
unique_ptr< EmptyEventTimestampPlugin > plugin_
void art::EmptyEvent::doEndJob ( )
overrideprivatevirtual

Reimplemented from art::InputSource.

Definition at line 366 of file EmptyEvent_source.cc.

References plugin_.

367 {
368  if (plugin_) {
369  plugin_->doEndJob();
370  }
371 }
unique_ptr< EmptyEventTimestampPlugin > plugin_
std::unique_ptr< art::EmptyEventTimestampPlugin > art::EmptyEvent::makePlugin_ ( OptionalDelegatedParameter const &  maybeConfig)
private

Definition at line 374 of file EmptyEvent_source.cc.

References art::errors::Configuration, e, fhicl::ParameterSet::get(), fhicl::OptionalDelegatedParameter::get_if_present(), pluginFactory_, and value.

Referenced by EmptyEvent().

375 {
376  auto pset = maybeConfig.get_if_present<ParameterSet>();
377  if (!pset) {
378  return nullptr;
379  }
380 
381  try {
382  auto const libspec = pset->get<std::string>("plugin_type");
383  auto const pluginType = pluginFactory_.pluginType(libspec);
384  if (pluginType ==
386  return pluginFactory_
387  .makePlugin<std::unique_ptr<EmptyEventTimestampPlugin>>(libspec, *pset);
388  }
389  throw Exception(errors::Configuration, "EmptyEvent: ")
390  << "unrecognized plugin type " << pluginType << "for plugin " << libspec
391  << ".\n";
392  }
393  catch (cet::exception& e) {
394  throw Exception(errors::Configuration, "EmptyEvent: ", e)
395  << "Exception caught while processing plugin spec.\n";
396  }
397 }
T get(std::string const &key) const
Definition: ParameterSet.h:314
cet::BasicPluginFactory pluginFactory_
double value
Definition: spectrum.C:18
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Float_t e
Definition: plot.C:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
InputSource::ProcessingMode art::InputSource::mode ( std::string const &  modeString)
staticinherited

Definition at line 9 of file InputSource.cc.

References art::errors::Configuration, art::InputSource::Runs, art::InputSource::RunsAndSubRuns, and art::InputSource::RunsSubRunsAndEvents.

Referenced by art::ProcessingLimits::ProcessingLimits().

10  {
11  if (modeString == "Runs") {
12  return Runs;
13  }
14  if (modeString == "RunsAndSubRuns") {
15  return RunsAndSubRuns;
16  }
17  if (modeString == "RunsSubRunsAndEvents") {
18  return RunsSubRunsAndEvents;
19  }
21  << "The 'processingMode' parameter for sources has an illegal value '"
22  << modeString << "'\n"
23  << "Legal values are 'Runs', 'RunsAndSubRuns', or "
24  "'RunsSubRunsAndEvents'.\n";
25  }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
ModuleDescription const & art::InputSource::moduleDescription ( ) const
inherited

Definition at line 31 of file InputSource.cc.

References art::InputSource::moduleDescription_.

Referenced by readRun(), and readSubRun().

32  {
33  return moduleDescription_;
34  }
ModuleDescription moduleDescription_
Definition: InputSource.h:106
art::input::ItemType art::EmptyEvent::nextItemType ( )
overrideprivatevirtual

Implements art::InputSource.

Definition at line 190 of file EmptyEvent_source.cc.

References limits_, and art::ProcessingLimits::nextItemType().

191 {
192  return limits_.nextItemType();
193 }
input::ItemType nextItemType()
ProcessingLimits limits_
art::input::ItemType art::EmptyEvent::nextItemType_ ( )
private

Definition at line 196 of file EmptyEvent_source.cc.

References beginTime_, art::EventID::event(), eventCreationDelay_, eventID_, firstTime_, art::input::IsEvent, art::input::IsFile, art::input::IsRun, art::input::IsStop, art::input::IsSubRun, art::RunID::isValid(), art::SubRunID::isValid(), art::EventID::isValid(), maxTime_, newFile_, newRun_, newSubRun_, art::EventID::next(), art::EventID::nextRun(), art::EventID::nextSubRun(), numberEventsInRun_, numberEventsInSubRun_, numberEventsInThisRun_, numberEventsInThisSubRun_, origEventID_, resetEventOnSubRun_, art::EventID::run(), art::EventID::runID(), art::EventID::subRun(), and art::EventID::subRunID().

Referenced by EmptyEvent().

197 {
198  // Called by ProcessingLimits::nextItemType.
199 
200  // Trigger framework stop if max allowed time is exceeded.
201  // N.B. Since the begin time corresponds to source construction and
202  // not the actual event loop, there will be minor differences wrt
203  // the time reported for executing a given job.
204  if (steady_clock::now() - beginTime_ > maxTime_) {
205  return input::IsStop;
206  }
207  // First check for sanity because skip(offset) can be abused and so can the
208  // ctor.
209  if (!eventID_.runID().isValid()) {
210  return input::IsStop;
211  }
212  if (!eventID_.subRunID().isValid()) {
213  return input::IsStop;
214  }
215  if (!eventID_.isValid()) {
216  return input::IsStop;
217  }
218  if (newFile_) {
219  newFile_ = false;
220  return input::IsFile;
221  }
222  if (newRun_) {
223  newRun_ = false;
224  if (eventCreationDelay_ > 0ms) {
225  std::this_thread::sleep_for(eventCreationDelay_);
226  }
227  return input::IsRun;
228  }
229  if (newSubRun_) {
230  newSubRun_ = false;
231  if (eventCreationDelay_ > 0ms) {
232  std::this_thread::sleep_for(eventCreationDelay_);
233  }
234  return input::IsSubRun;
235  }
236  if ((numberEventsInRun_ > 0) &&
238  // Time to switch runs.
239  newRun_ = false;
240  newSubRun_ = true;
243  eventID_ = EventID(
245  firstTime_ = true;
246  if (eventCreationDelay_ > 0ms) {
247  std::this_thread::sleep_for(eventCreationDelay_);
248  }
249  return input::IsRun;
250  }
251  if ((numberEventsInSubRun_ > 0) &&
253  // Time to switch subruns.
254  newRun_ = false;
255  newSubRun_ = false;
257  if (resetEventOnSubRun_) {
259  } else {
261  }
262  firstTime_ = true;
263  if (eventCreationDelay_ > 0ms) {
264  std::this_thread::sleep_for(eventCreationDelay_);
265  }
266  return input::IsSubRun;
267  }
268  // same run and subrun
269  if (!firstTime_) {
270  eventID_ = eventID_.next();
271  if (!eventID_.runID().isValid()) {
272  return input::IsStop;
273  }
274  }
275  firstTime_ = false;
278  if (eventCreationDelay_ > 0ms) {
279  std::this_thread::sleep_for(eventCreationDelay_);
280  }
281  return input::IsEvent;
282 }
bool isValid() const
Definition: EventID.h:122
RunID const & runID() const
Definition: EventID.h:92
SubRunID const & subRunID() const
Definition: EventID.h:104
std::chrono::microseconds const eventCreationDelay_
EventID next() const
Definition: EventID.h:134
unsigned numberEventsInThisRun_
unsigned const numberEventsInRun_
RunNumber_t run() const
Definition: EventID.h:98
bool isValid() const
Definition: SubRunID.h:97
steady_clock::time_point const beginTime_
unsigned const numberEventsInSubRun_
std::chrono::seconds const maxTime_
EventID nextSubRun(EventNumber_t first=IDNumber< Level::Event >::first()) const
Definition: EventID.h:147
bool isValid() const
Definition: RunID.h:70
EventNumber_t event() const
Definition: EventID.h:116
bool const resetEventOnSubRun_
EventID nextRun() const
Definition: EventID.h:153
SubRunNumber_t subRun() const
Definition: EventID.h:110
unsigned numberEventsInThisSubRun_
EmptyEvent& art::EmptyEvent::operator= ( EmptyEvent const &  )
delete
EmptyEvent& art::EmptyEvent::operator= ( EmptyEvent &&  )
delete
ProcessConfiguration const & art::InputSource::processConfiguration ( ) const
inherited

Definition at line 37 of file InputSource.cc.

References art::InputSource::moduleDescription_, and art::ModuleDescription::processConfiguration().

Referenced by readEvent(), readRun(), and readSubRun().

38  {
40  }
ModuleDescription moduleDescription_
Definition: InputSource.h:106
ProcessConfiguration const & processConfiguration() const
unique_ptr< art::EventPrincipal > art::EmptyEvent::readEvent ( cet::exempt_ptr< SubRunPrincipal const >  srp)
overrideprivatevirtual

Implements art::InputSource.

Definition at line 329 of file EmptyEvent_source.cc.

References eventID_, art::Timestamp::invalidTimestamp(), limits_, numberEventsInSubRun_, numberEventsInThisSubRun_, plugin_, art::InputSource::processConfiguration(), and art::ProcessingLimits::update().

330 {
331  auto timestamp = plugin_ ? plugin_->doEventTimestamp(eventID_) :
333  EventAuxiliary const eventAux{eventID_, timestamp, false};
334  auto result = make_unique<EventPrincipal>(eventAux,
336  nullptr,
337  make_unique<NoDelayedReader>(),
340  result->setSubRunPrincipal(srp);
341  limits_.update(result->eventID());
342  return result;
343 }
unsigned const numberEventsInSubRun_
unique_ptr< EmptyEventTimestampPlugin > plugin_
static constexpr Timestamp invalidTimestamp()
Definition: Timestamp.h:82
ProcessConfiguration const & processConfiguration() const
Definition: InputSource.cc:37
ProcessingLimits limits_
void update(EventID const &id)
unsigned numberEventsInThisSubRun_
unique_ptr< art::FileBlock > art::EmptyEvent::readFile ( )
overrideprivatevirtual

Implements art::InputSource.

Definition at line 285 of file EmptyEvent_source.cc.

286 {
287  return make_unique<FileBlock>();
288 }
unique_ptr< art::RunPrincipal > art::EmptyEvent::readRun ( )
overrideprivatevirtual

Implements art::InputSource.

Definition at line 295 of file EmptyEvent_source.cc.

References eventID_, art::Timestamp::invalidTimestamp(), art::InputSource::moduleDescription(), plugin_, art::InputSource::processConfiguration(), and art::EventID::runID().

296 {
297  auto ts = plugin_ ? plugin_->doBeginRunTimestamp(eventID_.runID()) :
299  RunAuxiliary const runAux{
301  auto result =
302  make_unique<RunPrincipal>(runAux, processConfiguration(), nullptr);
303  if (plugin_) {
304  ModuleContext const mc{moduleDescription()};
305  plugin_->doBeginRun(std::as_const(*result).makeRun(mc));
306  }
307  return result;
308 }
RunID const & runID() const
Definition: EventID.h:92
ModuleDescription const & moduleDescription() const
Definition: InputSource.cc:31
unique_ptr< EmptyEventTimestampPlugin > plugin_
static constexpr Timestamp invalidTimestamp()
Definition: Timestamp.h:82
ProcessConfiguration const & processConfiguration() const
Definition: InputSource.cc:37
unique_ptr< art::SubRunPrincipal > art::EmptyEvent::readSubRun ( cet::exempt_ptr< RunPrincipal const >  rp)
overrideprivatevirtual

Implements art::InputSource.

Definition at line 311 of file EmptyEvent_source.cc.

References eventID_, art::Timestamp::invalidTimestamp(), limits_, art::InputSource::moduleDescription(), plugin_, art::InputSource::processConfiguration(), art::EventID::subRunID(), and art::ProcessingLimits::update().

312 {
313  auto ts = plugin_ ? plugin_->doBeginSubRunTimestamp(eventID_.subRunID()) :
315  SubRunAuxiliary const subRunAux{
317  auto result =
318  make_unique<SubRunPrincipal>(subRunAux, processConfiguration(), nullptr);
319  result->setRunPrincipal(rp);
320  if (plugin_) {
321  ModuleContext const mc{moduleDescription()};
322  plugin_->doBeginSubRun(std::as_const(*result).makeSubRun(mc));
323  }
324  limits_.update(result->subRunID());
325  return result;
326 }
SubRunID const & subRunID() const
Definition: EventID.h:104
ModuleDescription const & moduleDescription() const
Definition: InputSource.cc:31
unique_ptr< EmptyEventTimestampPlugin > plugin_
static constexpr Timestamp invalidTimestamp()
Definition: Timestamp.h:82
ProcessConfiguration const & processConfiguration() const
Definition: InputSource.cc:37
ProcessingLimits limits_
void update(EventID const &id)
unique_ptr< art::RangeSetHandler > art::EmptyEvent::runRangeSetHandler ( )
overrideprivatevirtual

Implements art::InputSource.

Definition at line 346 of file EmptyEvent_source.cc.

References eventID_, and art::EventID::run().

347 {
348  return make_unique<OpenRangeSetHandler>(eventID_.run());
349 }
RunNumber_t run() const
Definition: EventID.h:98
void art::EmptyEvent::skipEvents ( int  offset)
overrideprivatevirtual

Reimplemented from art::InputSource.

Definition at line 400 of file EmptyEvent_source.cc.

References DEFINE_ART_INPUT_SOURCE, eventID_, art::EventID::next(), and art::EventID::previous().

401 {
402  for (; offset < 0; ++offset) {
404  }
405  for (; offset > 0; --offset) {
406  eventID_ = eventID_.next();
407  }
408 }
EventID previous() const
Definition: EventID.h:159
EventID next() const
Definition: EventID.h:134
unique_ptr< art::RangeSetHandler > art::EmptyEvent::subRunRangeSetHandler ( )
overrideprivatevirtual

Implements art::InputSource.

Definition at line 352 of file EmptyEvent_source.cc.

References eventID_, and art::EventID::run().

353 {
354  return make_unique<OpenRangeSetHandler>(eventID_.run());
355 }
RunNumber_t run() const
Definition: EventID.h:98

Member Data Documentation

steady_clock::time_point const art::EmptyEvent::beginTime_ {steady_clock::now()}
private

Definition at line 128 of file EmptyEvent_source.cc.

Referenced by nextItemType_().

std::chrono::microseconds const art::EmptyEvent::eventCreationDelay_
private

Definition at line 130 of file EmptyEvent_source.cc.

Referenced by EmptyEvent(), and nextItemType_().

EventID art::EmptyEvent::eventID_ {}
private
bool art::EmptyEvent::firstTime_ {true}
private

Definition at line 135 of file EmptyEvent_source.cc.

Referenced by nextItemType_().

ProcessingLimits art::EmptyEvent::limits_
private

Definition at line 125 of file EmptyEvent_source.cc.

Referenced by EmptyEvent(), nextItemType(), readEvent(), and readSubRun().

std::chrono::seconds const art::EmptyEvent::maxTime_
private

Definition at line 129 of file EmptyEvent_source.cc.

Referenced by EmptyEvent(), and nextItemType_().

bool art::EmptyEvent::newFile_ {true}
private

Definition at line 136 of file EmptyEvent_source.cc.

Referenced by nextItemType_().

bool art::EmptyEvent::newRun_ {true}
private

Definition at line 137 of file EmptyEvent_source.cc.

Referenced by nextItemType_().

bool art::EmptyEvent::newSubRun_ {true}
private

Definition at line 138 of file EmptyEvent_source.cc.

Referenced by nextItemType_().

unsigned const art::EmptyEvent::numberEventsInRun_
private

Definition at line 126 of file EmptyEvent_source.cc.

Referenced by EmptyEvent(), and nextItemType_().

unsigned const art::EmptyEvent::numberEventsInSubRun_
private

Definition at line 127 of file EmptyEvent_source.cc.

Referenced by EmptyEvent(), nextItemType_(), and readEvent().

unsigned art::EmptyEvent::numberEventsInThisRun_ {}
private

Definition at line 131 of file EmptyEvent_source.cc.

Referenced by nextItemType_().

unsigned art::EmptyEvent::numberEventsInThisSubRun_ {}
private

Definition at line 132 of file EmptyEvent_source.cc.

Referenced by nextItemType_(), and readEvent().

EventID art::EmptyEvent::origEventID_ {}
private

Definition at line 133 of file EmptyEvent_source.cc.

Referenced by EmptyEvent(), and nextItemType_().

unique_ptr<EmptyEventTimestampPlugin> art::EmptyEvent::plugin_
private

Definition at line 141 of file EmptyEvent_source.cc.

Referenced by doBeginJob(), doEndJob(), EmptyEvent(), readEvent(), readRun(), and readSubRun().

cet::BasicPluginFactory art::EmptyEvent::pluginFactory_ {}
private

Definition at line 140 of file EmptyEvent_source.cc.

Referenced by makePlugin_().

bool const art::EmptyEvent::resetEventOnSubRun_
private

Definition at line 139 of file EmptyEvent_source.cc.

Referenced by EmptyEvent(), and nextItemType_().


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