Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
art::RootInputFileSequence Class Reference

#include <RootInputFileSequence.h>

Classes

struct  Config
 

Public Types

using RootInputFileSharedPtr = std::shared_ptr< RootInputFile >
 
using EntryNumber = input::EntryNumber
 

Public Member Functions

 RootInputFileSequence (RootInputFileSequence const &)=delete
 
RootInputFileSequenceoperator= (RootInputFileSequence const &)=delete
 
 RootInputFileSequence (fhicl::TableFragment< Config > const &, InputFileCatalog &, FastCloningInfoProvider const &, InputSource::ProcessingMode, UpdateOutputCallbacks &, ProcessConfiguration const &)
 
void endJob ()
 
std::unique_ptr< FileBlockreadFile_ ()
 
std::unique_ptr< RootInputFileopenSecondaryFile (std::string const &name, cet::exempt_ptr< RootInputFile > primaryFile)
 
void closeFile_ ()
 
void skip (int offset)
 
void rewind_ ()
 
EventID seekToEvent (EventID const &, bool exact=false)
 
EventID seekToEvent (off_t offset, bool exact=false)
 
input::ItemType getNextItemType ()
 
void readIt (RunID const &)
 
std::unique_ptr< RunPrincipalreadRun_ ()
 
void readIt (SubRunID const &)
 
std::unique_ptr< SubRunPrincipalreadSubRun_ (cet::exempt_ptr< RunPrincipal const >)
 
void readIt (EventID const &, bool exact=false)
 
std::unique_ptr< EventPrincipalreadEvent_ ()
 
RootInputFileSharedPtr rootFileForLastReadEvent () const
 
RootInputFileSharedPtr rootFile () const
 
std::unique_ptr< RangeSetHandlerrunRangeSetHandler ()
 
std::unique_ptr< RangeSetHandlersubRunRangeSetHandler ()
 
std::vector< std::vector< std::string > > const & secondaryFileNames () const
 
EventID origEventID () const
 
EventNumber_t eventsToSkip () const
 
FastCloningInfoProvider const & fastCloningInfo () const
 
unsigned int treeCacheSize () const
 
int64_t treeMaxVirtualSize () const
 
int64_t saveMemoryObjectThreshold () const
 
bool delayedReadEventProducts () const
 
bool delayedReadSubRunProducts () const
 
bool delayedReadRunProducts () const
 
InputSource::ProcessingMode const & processingMode ()
 
void finish ()
 

Private Member Functions

void initFile (bool skipBadFiles)
 
bool nextFile ()
 
bool previousFile ()
 
void rewindFile ()
 
std::vector< FileCatalogItem > const & fileCatalogItems () const
 
ProcessConfiguration const & processConfiguration () const
 
bool primary () const
 

Private Attributes

InputFileCatalogcatalog_
 
bool firstFile_ {true}
 
bool seekingFile_ {false}
 
RootInputFileSharedPtr rootFile_ {nullptr}
 
std::vector< std::shared_ptr< FileIndex > > fileIndexes_
 
EventID origEventID_ {}
 
EventNumber_t eventsToSkip_
 
bool const compactSubRunRanges_
 
bool const noEventSort_
 
bool const skipBadFiles_
 
unsigned int const treeCacheSize_
 
int64_t const treeMaxVirtualSize_
 
int64_t const saveMemoryObjectThreshold_
 
bool const delayedReadEventProducts_
 
bool const delayedReadSubRunProducts_
 
bool const delayedReadRunProducts_
 
int forcedRunOffset_ {}
 
RunNumber_t setRun_ {}
 
GroupSelectorRules groupSelectorRules_
 
std::shared_ptr< DuplicateCheckerduplicateChecker_ {nullptr}
 
bool const dropDescendants_
 
bool const readParameterSets_
 
RootInputFileSharedPtr rootFileForLastReadEvent_
 
FastCloningInfoProvider fastCloningInfo_
 
InputSource::ProcessingMode processingMode_
 
ProcessConfiguration const & processConfiguration_
 
std::vector< std::vector< std::string > > secondaryFileNames_ {}
 
UpdateOutputCallbacksoutputCallbacks_
 
bool pendingClose_ {false}
 

Detailed Description

Definition at line 36 of file RootInputFileSequence.h.

Member Typedef Documentation

Definition at line 40 of file RootInputFileSequence.h.

Definition at line 39 of file RootInputFileSequence.h.

Constructor & Destructor Documentation

art::RootInputFileSequence::RootInputFileSequence ( RootInputFileSequence const &  )
delete
art::RootInputFileSequence::RootInputFileSequence ( fhicl::TableFragment< Config > const &  config,
InputFileCatalog catalog,
FastCloningInfoProvider const &  fcip,
InputSource::ProcessingMode  pMode,
UpdateOutputCallbacks outputCallbacks,
ProcessConfiguration const &  processConfig 
)

Definition at line 30 of file RootInputFileSequence.cc.

37  : catalog_{catalog}
38  , firstFile_{true}
39  , seekingFile_{false}
40  , fileIndexes_(fileCatalogItems().size())
41  , eventsToSkip_{config().skipEvents()}
42  , compactSubRunRanges_{config().compactSubRunRanges()}
43  , noEventSort_{config().noEventSort()}
44  , skipBadFiles_{config().skipBadFiles()}
45  , treeCacheSize_{config().cacheSize()}
46  , treeMaxVirtualSize_{config().treeMaxVirtualSize()}
47  , saveMemoryObjectThreshold_{config().saveMemoryObjectThreshold()}
48  , delayedReadEventProducts_{config().delayedReadEventProducts()}
49  , delayedReadSubRunProducts_{config().delayedReadSubRunProducts()}
50  , delayedReadRunProducts_{config().delayedReadRunProducts()}
51  , groupSelectorRules_{config().inputCommands(),
52  "inputCommands",
53  "InputSource"}
54  , dropDescendants_{config().dropDescendantsOfDroppedBranches()}
55  , readParameterSets_{config().readParameterSets()}
56  , fastCloningInfo_{fcip}
57  , processingMode_{pMode}
58  , processConfiguration_{processConfig}
59  , outputCallbacks_{outputCallbacks}
60  {
61  auto const& primaryFileNames = catalog_.fileSources();
62 
63  map<string const, vector<string> const> secondaryFilesMap;
64 
65  std::vector<Config::SecondaryFile> secondaryFiles;
66  if (config().secondaryFileNames(secondaryFiles)) {
67  // Until we can find a way to atomically update the
68  // 'selectedProducts' list for output modules, secondary input
69  // files can be used only in single-threaded, single-schedule
70  // execution.
71  auto const& globals = *Globals::instance();
72  if (globals.nthreads() != 1 && globals.nschedules() != 1) {
73  throw Exception{
75  "An error occurred while creating the RootInput source.\n"}
76  << "This art process is using " << globals.nthreads()
77  << " thread(s) and " << globals.nschedules() << " schedule(s).\n"
78  << "Secondary file names can be used only when 1 thread and 1 "
79  "schedule are specified.\n"
80  << "This is done by specifying '-j=1' at the command line.\n";
81  }
82 
83  for (auto const& val : secondaryFiles) {
84  auto const a = val.a();
85  auto const b = val.b();
86  if (a.empty()) {
88  << "Empty filename found as value of an \"a\" parameter!\n";
89  }
90  for (auto const& name : b) {
91  if (name.empty()) {
93  << "Empty secondary filename found as value of an \"b\" "
94  "parameter!\n";
95  }
96  }
97  secondaryFilesMap.emplace(a, b);
98  }
99  }
100 
102  stk;
103  for (auto const& primaryFileName : primaryFileNames) {
104  vector<string> secondaries;
105  auto SFMI = secondaryFilesMap.find(primaryFileName);
106  if (SFMI == secondaryFilesMap.end()) {
107  // This primary has no secondaries.
108  secondaryFileNames_.push_back(std::move(secondaries));
109  continue;
110  }
111  if (!SFMI->second.size()) {
112  // Has an empty secondary list.
113  secondaryFileNames_.push_back(std::move(secondaries));
114  continue;
115  }
116  stk.emplace_back(SFMI->second.cbegin(), SFMI->second.cend());
117  while (stk.size()) {
118  auto val = stk.back();
119  stk.pop_back();
120  if (val.first == val.second) {
121  // Reached end of this filename list.
122  continue;
123  }
124  auto const& fn = *val.first;
125  ++val.first;
126  secondaries.push_back(fn);
127  auto SI = secondaryFilesMap.find(fn);
128  if (SI == secondaryFilesMap.end()) {
129  // Has no secondary list.
130  if (val.first == val.second) {
131  // Reached end of this filename list.
132  continue;
133  }
134  stk.emplace_back(val.first, val.second);
135  continue;
136  }
137  if (!SI->second.size()) {
138  // Has an empty secondary list.
139  if (val.first == val.second) {
140  // Reached end of this filename list.
141  continue;
142  }
143  stk.emplace_back(val.first, val.second);
144  continue;
145  }
146  stk.emplace_back(val.first, val.second);
147  stk.emplace_back(SI->second.cbegin(), SI->second.cend());
148  }
149  secondaryFileNames_.push_back(std::move(secondaries));
150  }
151  RunNumber_t firstRun{};
152  bool const haveFirstRun{config().hasFirstRun(firstRun)};
153  SubRunNumber_t firstSubRun{};
154  bool const haveFirstSubRun{config().hasFirstSubRun(firstSubRun)};
155  EventNumber_t firstEvent{};
156  bool const haveFirstEvent{config().hasFirstEvent(firstEvent)};
157 
158  RunID const firstRunID{haveFirstRun ? RunID{firstRun} : RunID::firstRun()};
159  SubRunID const firstSubRunID{haveFirstSubRun ?
160  SubRunID{firstRunID.run(), firstSubRun} :
161  SubRunID::firstSubRun(firstRunID)};
162 
163  origEventID_ = haveFirstEvent ? EventID{firstSubRunID, firstEvent} :
164  EventID::firstEvent(firstSubRunID);
165 
166  if (noEventSort_ && haveFirstEvent) {
168  << "Illegal configuration options passed to RootInput\n"
169  << "You cannot request \"noEventSort\" and also set \"firstEvent\".\n";
170  }
171  if (primary()) {
172  duplicateChecker_ = std::make_shared<DuplicateChecker>(config().dc);
173  }
174  if (pendingClose_) {
176  << "RootInputFileSequence looking for next file with a pending close!";
177  }
178 
179  while (catalog_.getNextFile()) {
181  if (rootFile_) {
182  // We found one, good, stop now.
183  break;
184  }
185  }
186 
187  if (!rootFile_) {
188  // We could not open any input files, stop.
189  return;
190  }
191  if (config().setRunNumber(setRun_)) {
192  try {
193  forcedRunOffset_ = rootFile_->setForcedRunOffset(setRun_);
194  }
195  catch (art::Exception& e) {
196  if (e.categoryCode() == errors::InvalidNumber) {
198  << "setRunNumber " << setRun_
199  << " does not correspond to a valid run number in ["
200  << RunID::firstRun().run() << ", " << RunID::maxRun().run()
201  << "]\n";
202  } else {
203  throw; // Rethrow.
204  }
205  }
206  if (forcedRunOffset_ < 0) {
208  << "The value of the 'setRunNumber' parameter must not be\n"
209  << "less than the first run number in the first input file.\n"
210  << "'setRunNumber' was " << setRun_ << ", while the first run was "
211  << setRun_ - forcedRunOffset_ << ".\n";
212  }
213  }
214  if (!readParameterSets_) {
215  mf::LogWarning("PROVENANCE")
216  << "Source parameter readParameterSets was set to false: parameter set "
217  "provenance\n"
218  << "will NOT be available in this or subsequent jobs using output from "
219  "this job.\n"
220  << "Check your experiment's policy on this issue to avoid future "
221  "problems\n"
222  << "with analysis reproducibility.\n";
223  }
224  if (compactSubRunRanges_) {
225  mf::LogWarning("PROVENANCE")
226  << "Source parameter compactEventRanges was set to true: enabling "
227  "compact event ranges\n"
228  << "creates a history that can cause file concatenation problems if a "
229  "given SubRun spans\n"
230  << "multiple input files. Use with care.\n";
231  }
232  }
std::vector< std::shared_ptr< FileIndex > > fileIndexes_
ProcessConfiguration const & processConfiguration_
std::vector< FileCatalogItem > const & fileCatalogItems() const
bool getNextFile(int attempts=5)
std::shared_ptr< DuplicateChecker > duplicateChecker_
RunNumber_t run() const
Definition: RunID.h:65
std::vector< std::vector< std::string > > const & secondaryFileNames() const
const double e
intermediate_table::const_iterator const_iterator
GroupSelectorRules groupSelectorRules_
static RunID maxRun()
Definition: RunID.h:111
const double a
FastCloningInfoProvider fastCloningInfo_
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:119
RootInputFileSharedPtr rootFile_
static SubRunID firstSubRun()
Definition: SubRunID.h:152
std::vector< std::vector< std::string > > secondaryFileNames_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
InputSource::ProcessingMode processingMode_
void initFile(bool skipBadFiles)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
static RunID firstRun()
Definition: RunID.h:117
static Globals * instance()
Definition: Globals.cc:26
std::vector< std::string > const & fileSources() const
static EventID firstEvent()
Definition: EventID.h:191
UpdateOutputCallbacks & outputCallbacks_
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120

Member Function Documentation

void art::RootInputFileSequence::closeFile_ ( )

Definition at line 356 of file RootInputFileSequence.cc.

357  {
358  if (!rootFile_) {
359  return;
360  }
361  // Account for events skipped in the file.
362  eventsToSkip_ = rootFile_->eventsToSkip();
363  rootFile_->close(primary());
364  detail::logFileAction("Closed input file ", rootFile_->fileName());
365  rootFile_.reset();
366  if (duplicateChecker_.get() != nullptr) {
367  duplicateChecker_->inputFileClosed();
368  }
369  }
void logFileAction(const char *msg, std::string const &file)
Definition: logFileAction.cc:9
std::shared_ptr< DuplicateChecker > duplicateChecker_
RootInputFileSharedPtr rootFile_
bool art::RootInputFileSequence::delayedReadEventProducts ( ) const
inline

Definition at line 207 of file RootInputFileSequence.h.

208  {
210  }
bool art::RootInputFileSequence::delayedReadRunProducts ( ) const
inline

Definition at line 219 of file RootInputFileSequence.h.

220  {
222  }
bool art::RootInputFileSequence::delayedReadSubRunProducts ( ) const
inline

Definition at line 213 of file RootInputFileSequence.h.

214  {
216  }
void art::RootInputFileSequence::endJob ( )

Definition at line 290 of file RootInputFileSequence.cc.

291  {
292  closeFile_();
293  }
EventNumber_t art::RootInputFileSequence::eventsToSkip ( ) const
inline

Definition at line 177 of file RootInputFileSequence.h.

178  {
179  return eventsToSkip_;
180  }
FastCloningInfoProvider const& art::RootInputFileSequence::fastCloningInfo ( ) const
inline

Definition at line 183 of file RootInputFileSequence.h.

184  {
185  return fastCloningInfo_;
186  }
FastCloningInfoProvider fastCloningInfo_
vector< FileCatalogItem > const & art::RootInputFileSequence::fileCatalogItems ( ) const
private

Definition at line 284 of file RootInputFileSequence.cc.

285  {
286  return catalog_.fileCatalogItems();
287  }
std::vector< FileCatalogItem > const & fileCatalogItems() const
void art::RootInputFileSequence::finish ( )

Definition at line 372 of file RootInputFileSequence.cc.

373  {
374  pendingClose_ = true;
375  }
input::ItemType art::RootInputFileSequence::getNextItemType ( )

Definition at line 693 of file RootInputFileSequence.cc.

694  {
695  if (firstFile_) {
696  return input::IsFile;
697  }
698  if (rootFile_) {
699  auto const entryType = rootFile_->getNextEntryTypeWanted();
700  if (entryType == FileIndex::kEvent) {
701  return input::IsEvent;
702  } else if (entryType == FileIndex::kSubRun) {
703  return input::IsSubRun;
704  } else if (entryType == FileIndex::kRun) {
705  return input::IsRun;
706  }
707  assert(entryType == FileIndex::kEnd);
708  }
709  // now we are either at the end of a root file
710  // or the current file is not a root file
711  if (!catalog_.hasNextFile()) {
712  return input::IsStop;
713  }
714  return input::IsFile;
715  }
bool hasNextFile(int attempts=5)
RootInputFileSharedPtr rootFile_
void art::RootInputFileSequence::initFile ( bool  skipBadFiles)
private

Definition at line 378 of file RootInputFileSequence.cc.

379  {
380  // close the currently open file, any, and delete the RootInputFile object.
381  closeFile_();
382  std::unique_ptr<TFile> filePtr;
383  try {
384  detail::logFileAction("Initiating request to open input file ",
386  filePtr.reset(TFile::Open(catalog_.currentFile().fileName().c_str()));
387  }
388  catch (cet::exception e) {
389  if (!skipBadFiles) {
391  << e.explain_self()
392  << "\nRootInputFileSequence::initFile(): Input file "
394  << " was not found or could not be opened.\n";
395  }
396  }
397  if (!filePtr || filePtr->IsZombie()) {
398  if (!skipBadFiles) {
400  << "RootInputFileSequence::initFile(): Input file "
402  << " was not found or could not be opened.\n";
403  }
404  mf::LogWarning("")
405  << "Input file: " << catalog_.currentFile().fileName()
406  << " was not found or could not be opened, and will be skipped.\n";
407  return;
408  }
409  detail::logFileAction("Opened input file ",
411  vector<string> empty_vs;
412  rootFile_ = make_shared<RootInputFile>(
414  catalog_.url(),
417  std::move(filePtr),
418  origEventID_,
430  noEventSort_,
435  /*primaryFile*/ exempt_ptr<RootInputFile>{nullptr},
436  secondaryFileNames_.empty() ?
437  empty_vs :
439  this,
441 
443  if (catalog_.currentIndex() + 1 > fileIndexes_.size()) {
444  fileIndexes_.resize(catalog_.currentIndex() + 1);
445  }
446  fileIndexes_[catalog_.currentIndex()] = rootFile_->fileIndexSharedPtr();
447  }
size_t currentIndex() const
std::vector< std::shared_ptr< FileIndex > > fileIndexes_
static constexpr size_t indexEnd
void logFileAction(const char *msg, std::string const &file)
Definition: logFileAction.cc:9
std::string & url()
Definition: FileCatalog.h:98
std::string const & logicalFileName() const
Definition: FileCatalog.h:30
ProcessConfiguration const & processConfiguration() const
std::shared_ptr< DuplicateChecker > duplicateChecker_
FileCatalogItem const & currentFile() const
const double e
GroupSelectorRules groupSelectorRules_
FastCloningInfoProvider fastCloningInfo_
RootInputFileSharedPtr rootFile_
std::vector< std::vector< std::string > > secondaryFileNames_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
InputSource::ProcessingMode processingMode_
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::string const & fileName() const
Definition: FileCatalog.h:25
UpdateOutputCallbacks & outputCallbacks_
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool art::RootInputFileSequence::nextFile ( )
private

Definition at line 501 of file RootInputFileSequence.cc.

502  {
503  if (!catalog_.getNextFile()) {
504  // no more files
505  return false;
506  }
508  return true;
509  }
bool getNextFile(int attempts=5)
void initFile(bool skipBadFiles)
std::unique_ptr< RootInputFile > art::RootInputFileSequence::openSecondaryFile ( std::string const &  name,
cet::exempt_ptr< RootInputFile primaryFile 
)

Definition at line 450 of file RootInputFileSequence.cc.

453  {
454  std::unique_ptr<TFile> filePtr;
455  try {
456  detail::logFileAction("Attempting to open secondary input file ", name);
457  filePtr.reset(TFile::Open(name.c_str()));
458  }
459  catch (cet::exception e) {
461  << e.explain_self()
462  << "\nRootInputFileSequence::openSecondaryFile(): Input file " << name
463  << " was not found or could not be opened.\n";
464  }
465  if (!filePtr || filePtr->IsZombie()) {
467  << "RootInputFileSequence::openSecondaryFile(): Input file " << name
468  << " was not found or could not be opened.\n";
469  }
470  detail::logFileAction("Opened secondary input file ", name);
471  vector<string> empty_secondary_filenames;
472  return std::make_unique<RootInputFile>(name,
473  /*url*/ "",
475  /*logicalFileName*/ "",
476  std::move(filePtr),
477  origEventID_,
489  noEventSort_,
491  /*duplicateChecker_*/ nullptr,
494  primaryFile,
495  empty_secondary_filenames,
496  this,
498  }
void logFileAction(const char *msg, std::string const &file)
Definition: logFileAction.cc:9
ProcessConfiguration const & processConfiguration() const
const double e
GroupSelectorRules groupSelectorRules_
FastCloningInfoProvider fastCloningInfo_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
InputSource::ProcessingMode processingMode_
UpdateOutputCallbacks & outputCallbacks_
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
RootInputFileSequence& art::RootInputFileSequence::operator= ( RootInputFileSequence const &  )
delete
EventID art::RootInputFileSequence::origEventID ( ) const
inline

Definition at line 171 of file RootInputFileSequence.h.

172  {
173  return origEventID_;
174  }
bool art::RootInputFileSequence::previousFile ( )
private

Definition at line 512 of file RootInputFileSequence.cc.

513  {
514  // no going back for non-persistent files
515  if (!catalog_.isSearchable()) {
516  return false;
517  }
518  // no file in the catalog
520  return false;
521  }
522  // first file in the catalog, move to the last file in the list
523  if (catalog_.currentIndex() == 0) {
524  return false;
525  } else {
527  }
528  initFile(/*skipBadFiles=*/false);
529  if (rootFile_) {
530  rootFile_->setToLastEntry();
531  }
532  return true;
533  }
size_t currentIndex() const
static constexpr size_t indexEnd
RootInputFileSharedPtr rootFile_
void rewindTo(size_t index)
void initFile(bool skipBadFiles)
bool art::RootInputFileSequence::primary ( ) const
private

Definition at line 757 of file RootInputFileSequence.cc.

758  {
759  return true;
760  }
ProcessConfiguration const & art::RootInputFileSequence::processConfiguration ( ) const
private

Definition at line 763 of file RootInputFileSequence.cc.

764  {
765  return processConfiguration_;
766  }
ProcessConfiguration const & processConfiguration_
InputSource::ProcessingMode const& art::RootInputFileSequence::processingMode ( )
inline

Definition at line 225 of file RootInputFileSequence.h.

226  {
227  return processingMode_;
228  }
InputSource::ProcessingMode processingMode_
unique_ptr< EventPrincipal > art::RootInputFileSequence::readEvent_ ( )

Definition at line 575 of file RootInputFileSequence.cc.

576  {
577  // Create and setup the EventPrincipal.
578  //
579  // 1. create an EventPrincipal with a unique EventID
580  // 2. For each entry in the provenance, put in one Group,
581  // holding the Provenance for the corresponding EDProduct.
582  // 3. set up the caches in the EventPrincipal to know about this
583  // Group.
584  //
585  // We do *not* create the EDProduct instance (the equivalent of reading
586  // the branch containing this EDProduct. That will be done by the
587  // Delayed Reader when it is asked to do so.
588  //
590  return rootFile_->readEvent();
591  }
RootInputFileSharedPtr rootFile_
RootInputFileSharedPtr rootFileForLastReadEvent_
std::unique_ptr< FileBlock > art::RootInputFileSequence::readFile_ ( )

Definition at line 296 of file RootInputFileSequence.cc.

297  {
298  std::unique_ptr<FileBlock> result;
299  if (firstFile_ && rootFile_) {
300  firstFile_ = false;
301  result = rootFile_->createFileBlock();
302  return result;
303  }
304  if (firstFile_) {
305  // We are at the first file in the sequence of files.
306  firstFile_ = false;
307  while (catalog_.getNextFile()) {
309  if (rootFile_) {
310  // We found one, good, stop now.
311  break;
312  }
313  }
314  if (!rootFile_) {
315  // We could not open any input files, stop.
316  return result;
317  }
318  if (setRun_) {
319  try {
320  forcedRunOffset_ = rootFile_->setForcedRunOffset(setRun_);
321  }
322  catch (art::Exception& e) {
323  if (e.categoryCode() == errors::InvalidNumber) {
325  << "setRunNumber " << setRun_
326  << " does not correspond to a valid run number in ["
327  << RunID::firstRun().run() << ", " << RunID::maxRun().run()
328  << "]\n";
329  } else {
330  throw; // Rethrow.
331  }
332  }
333  if (forcedRunOffset_ < 0) {
335  << "The value of the 'setRunNumber' parameter must not be\n"
336  << "less than the first run number in the first input file.\n"
337  << "'setRunNumber' was " << setRun_ << ", while the first run was "
338  << setRun_ - forcedRunOffset_ << ".\n";
339  }
340  }
341  } else if (seekingFile_) {
342  seekingFile_ = false;
343  initFile(/*skipBadFiles=*/false);
344  } else if (!nextFile()) {
345  // FIXME: Turn this into a throw!
346  assert(false);
347  }
348  if (!rootFile_) {
349  return result;
350  }
351  result = rootFile_->createFileBlock();
352  return result;
353  }
bool getNextFile(int attempts=5)
RunNumber_t run() const
Definition: RunID.h:65
const double e
static RunID maxRun()
Definition: RunID.h:111
RootInputFileSharedPtr rootFile_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void initFile(bool skipBadFiles)
static RunID firstRun()
Definition: RunID.h:117
void art::RootInputFileSequence::readIt ( RunID const &  id)

Definition at line 650 of file RootInputFileSequence.cc.

651  {
652  // Attempt to find run in current file.
653  bool found = rootFile_->setEntry_Run(id);
654  if (found) {
655  // Got it, done.
656  return;
657  }
658  if (!catalog_.isSearchable()) {
659  // Cannot random access files, give up.
660  return;
661  }
662  // Look for the run in the opened files.
663  for (auto B = fileIndexes_.cbegin(), E = fileIndexes_.cend(), I = B; I != E;
664  ++I) {
665  if (*I && (*I)->contains(id, true)) {
666  // We found it, open the file.
667  catalog_.rewindTo(std::distance(B, I));
668  initFile(/*skipBadFiles=*/false);
669  found = rootFile_->setEntry_Run(id);
670  assert(found);
671  return;
672  }
673  }
674  // Look for run in files not yet opened.
675  while (catalog_.getNextFile()) {
676  initFile(/*skipBadFiles=*/false);
677  found = rootFile_->setEntry_Run(id);
678  if (found) {
679  return;
680  }
681  }
682  // Not found.
683  return;
684  }
std::vector< std::shared_ptr< FileIndex > > fileIndexes_
bool getNextFile(int attempts=5)
RootInputFileSharedPtr rootFile_
void rewindTo(size_t index)
void initFile(bool skipBadFiles)
void art::RootInputFileSequence::readIt ( SubRunID const &  id)

Definition at line 606 of file RootInputFileSequence.cc.

607  {
608  // Attempt to find subRun in currently open input file.
609  bool found = rootFile_->setEntry_SubRun(id);
610  if (found) {
611  return;
612  }
613  if (!catalog_.isSearchable()) {
614  return;
615  }
616  // Look for event in cached files
617  for (auto itBegin = fileIndexes_.begin(),
618  itEnd = fileIndexes_.end(),
619  it = itBegin;
620  it != itEnd;
621  ++it) {
622  if (*it && (*it)->contains(id, true)) {
623  // We found it. Close the currently open file, and open the correct one.
624  catalog_.rewindTo(std::distance(itBegin, it));
625  initFile(/*skipBadFiles=*/false);
626  found = rootFile_->setEntry_SubRun(id);
627  assert(found);
628  return;
629  }
630  }
631  // Look for subRun in files not yet opened.
632  while (catalog_.getNextFile()) {
633  initFile(/*skipBadFiles=*/false);
634  found = rootFile_->setEntry_SubRun(id);
635  if (found) {
636  return;
637  }
638  }
639  // not found
640  return;
641  }
std::vector< std::shared_ptr< FileIndex > > fileIndexes_
bool getNextFile(int attempts=5)
RootInputFileSharedPtr rootFile_
void rewindTo(size_t index)
void initFile(bool skipBadFiles)
void art::RootInputFileSequence::readIt ( EventID const &  id,
bool  exact = false 
)

Definition at line 536 of file RootInputFileSequence.cc.

537  {
538  // Attempt to find event in currently open input file.
539  bool found = rootFile_->setEntry_Event(id, exact);
540  if (found) {
542  return;
543  }
544  if (!catalog_.isSearchable()) {
545  return;
546  }
547  // Look for event in cached files
548  for (auto IB = fileIndexes_.cbegin(), IE = fileIndexes_.cend(), I = IB;
549  I != IE;
550  ++I) {
551  if (*I && (*I)->contains(id, exact)) {
552  // We found it. Close the currently open file, and open the correct one.
553  catalog_.rewindTo(std::distance(IB, I));
554  initFile(/*skipBadFiles=*/false);
555  found = rootFile_->setEntry_Event(id, exact);
556  assert(found);
558  return;
559  }
560  }
561  // Look for event in files not yet opened.
562  while (catalog_.getNextFile()) {
563  initFile(/*skipBadFiles=*/false);
564  found = rootFile_->setEntry_Event(id, exact);
565  if (found) {
567  return;
568  }
569  }
570  // Not found
571  return;
572  }
std::vector< std::shared_ptr< FileIndex > > fileIndexes_
bool getNextFile(int attempts=5)
RootInputFileSharedPtr rootFile_
void rewindTo(size_t index)
void initFile(bool skipBadFiles)
RootInputFileSharedPtr rootFileForLastReadEvent_
std::unique_ptr< RunPrincipal > art::RootInputFileSequence::readRun_ ( )

Definition at line 687 of file RootInputFileSequence.cc.

688  {
689  return rootFile_->readRun();
690  }
RootInputFileSharedPtr rootFile_
std::unique_ptr< SubRunPrincipal > art::RootInputFileSequence::readSubRun_ ( cet::exempt_ptr< RunPrincipal const >  rp)

Definition at line 644 of file RootInputFileSequence.cc.

645  {
646  return rootFile_->readSubRun(rp);
647  }
RootInputFileSharedPtr rootFile_
void art::RootInputFileSequence::rewind_ ( )

Definition at line 719 of file RootInputFileSequence.cc.

720  {
721  if (!catalog_.isSearchable()) {
723  << "RootInputFileSequence::rewind_() "
724  << "cannot rollback on non-searchable file catalogs.";
725  }
726  firstFile_ = true;
727  catalog_.rewind();
728  if (duplicateChecker_.get() != nullptr) {
729  duplicateChecker_->rewind();
730  }
731  }
std::shared_ptr< DuplicateChecker > duplicateChecker_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void art::RootInputFileSequence::rewindFile ( )
private

Definition at line 735 of file RootInputFileSequence.cc.

736  {
737  rootFile_->rewind();
738  }
RootInputFileSharedPtr rootFile_
RootInputFileSharedPtr art::RootInputFileSequence::rootFile ( ) const
inline

Definition at line 156 of file RootInputFileSequence.h.

157  {
158  return rootFile_;
159  }
RootInputFileSharedPtr rootFile_
RootInputFileSharedPtr art::RootInputFileSequence::rootFileForLastReadEvent ( ) const
inline

Definition at line 150 of file RootInputFileSequence.h.

151  {
153  }
RootInputFileSharedPtr rootFileForLastReadEvent_
std::unique_ptr< RangeSetHandler > art::RootInputFileSequence::runRangeSetHandler ( )

Definition at line 594 of file RootInputFileSequence.cc.

595  {
596  return rootFile_->runRangeSetHandler();
597  }
RootInputFileSharedPtr rootFile_
int64_t art::RootInputFileSequence::saveMemoryObjectThreshold ( ) const
inline

Definition at line 201 of file RootInputFileSequence.h.

202  {
204  };
std::vector<std::vector<std::string> > const& art::RootInputFileSequence::secondaryFileNames ( ) const
inline

Definition at line 165 of file RootInputFileSequence.h.

166  {
167  return secondaryFileNames_;
168  }
std::vector< std::vector< std::string > > secondaryFileNames_
EventID art::RootInputFileSequence::seekToEvent ( EventID const &  eID,
bool  exact = false 
)

Definition at line 235 of file RootInputFileSequence.cc.

236  {
237  // Attempt to find event in currently open input file.
238  bool found = rootFile_->setEntry_Event(eID, true);
239  // found in the current file
240  if (found) {
241  return rootFile_->eventIDForFileIndexPosition();
242  }
243  // fail if not searchable
244  if (!catalog_.isSearchable()) {
245  return EventID();
246  }
247  // Look for event in files previously opened without reopening unnecessary
248  // files.
249  for (auto itBegin = fileIndexes_.cbegin(),
250  itEnd = fileIndexes_.cend(),
251  it = itBegin;
252  (!found) && it != itEnd;
253  ++it) {
254  if (*it && (*it)->contains(eID, exact)) {
255  // We found it. Close the currently open file, and open the correct one.
256  catalog_.rewindTo(std::distance(itBegin, it));
257  initFile(/*skipBadFiles=*/false);
258  // Now get the event from the correct file.
259  found = rootFile_->setEntry_Event(eID, exact);
260  assert(found);
261  seekingFile_ = true;
262  }
263  }
264  // Look for event in files not yet opened.
265  while (catalog_.getNextFile()) {
266  initFile(/*skipBadFiles=*/false);
267  found = rootFile_->setEntry_Event(eID, exact);
268  if (found) {
269  seekingFile_ = true;
270  return rootFile_->eventIDForFileIndexPosition();
271  }
272  }
273  return EventID();
274  }
std::vector< std::shared_ptr< FileIndex > > fileIndexes_
bool getNextFile(int attempts=5)
RootInputFileSharedPtr rootFile_
void rewindTo(size_t index)
void initFile(bool skipBadFiles)
EventID art::RootInputFileSequence::seekToEvent ( off_t  offset,
bool  exact = false 
)

Definition at line 277 of file RootInputFileSequence.cc.

278  {
279  skip(offset);
280  return rootFile_->eventIDForFileIndexPosition();
281  }
RootInputFileSharedPtr rootFile_
void art::RootInputFileSequence::skip ( int  offset)

Definition at line 742 of file RootInputFileSequence.cc.

743  {
744  while (offset != 0) {
745  offset = rootFile_->skipEvents(offset);
746  if (offset > 0 && !nextFile()) {
747  return;
748  }
749  if (offset < 0 && !previousFile()) {
750  return;
751  }
752  }
753  rootFile_->skipEvents(0);
754  }
RootInputFileSharedPtr rootFile_
std::unique_ptr< RangeSetHandler > art::RootInputFileSequence::subRunRangeSetHandler ( )

Definition at line 600 of file RootInputFileSequence.cc.

601  {
602  return rootFile_->subRunRangeSetHandler();
603  }
RootInputFileSharedPtr rootFile_
unsigned int art::RootInputFileSequence::treeCacheSize ( ) const
inline

Definition at line 189 of file RootInputFileSequence.h.

190  {
191  return treeCacheSize_;
192  }
int64_t art::RootInputFileSequence::treeMaxVirtualSize ( ) const
inline

Definition at line 195 of file RootInputFileSequence.h.

196  {
197  return treeMaxVirtualSize_;
198  }

Member Data Documentation

InputFileCatalog& art::RootInputFileSequence::catalog_
private

Definition at line 248 of file RootInputFileSequence.h.

bool const art::RootInputFileSequence::compactSubRunRanges_
private

Definition at line 255 of file RootInputFileSequence.h.

bool const art::RootInputFileSequence::delayedReadEventProducts_
private

Definition at line 261 of file RootInputFileSequence.h.

bool const art::RootInputFileSequence::delayedReadRunProducts_
private

Definition at line 263 of file RootInputFileSequence.h.

bool const art::RootInputFileSequence::delayedReadSubRunProducts_
private

Definition at line 262 of file RootInputFileSequence.h.

bool const art::RootInputFileSequence::dropDescendants_
private

Definition at line 268 of file RootInputFileSequence.h.

std::shared_ptr<DuplicateChecker> art::RootInputFileSequence::duplicateChecker_ {nullptr}
private

Definition at line 267 of file RootInputFileSequence.h.

EventNumber_t art::RootInputFileSequence::eventsToSkip_
private

Definition at line 254 of file RootInputFileSequence.h.

FastCloningInfoProvider art::RootInputFileSequence::fastCloningInfo_
private

Definition at line 271 of file RootInputFileSequence.h.

std::vector<std::shared_ptr<FileIndex> > art::RootInputFileSequence::fileIndexes_
private

Definition at line 252 of file RootInputFileSequence.h.

bool art::RootInputFileSequence::firstFile_ {true}
private

Definition at line 249 of file RootInputFileSequence.h.

int art::RootInputFileSequence::forcedRunOffset_ {}
private

Definition at line 264 of file RootInputFileSequence.h.

GroupSelectorRules art::RootInputFileSequence::groupSelectorRules_
private

Definition at line 266 of file RootInputFileSequence.h.

bool const art::RootInputFileSequence::noEventSort_
private

Definition at line 256 of file RootInputFileSequence.h.

EventID art::RootInputFileSequence::origEventID_ {}
private

Definition at line 253 of file RootInputFileSequence.h.

UpdateOutputCallbacks& art::RootInputFileSequence::outputCallbacks_
private

Definition at line 275 of file RootInputFileSequence.h.

bool art::RootInputFileSequence::pendingClose_ {false}
private

Definition at line 276 of file RootInputFileSequence.h.

ProcessConfiguration const& art::RootInputFileSequence::processConfiguration_
private

Definition at line 273 of file RootInputFileSequence.h.

InputSource::ProcessingMode art::RootInputFileSequence::processingMode_
private

Definition at line 272 of file RootInputFileSequence.h.

bool const art::RootInputFileSequence::readParameterSets_
private

Definition at line 269 of file RootInputFileSequence.h.

RootInputFileSharedPtr art::RootInputFileSequence::rootFile_ {nullptr}
private

Definition at line 251 of file RootInputFileSequence.h.

RootInputFileSharedPtr art::RootInputFileSequence::rootFileForLastReadEvent_
private

Definition at line 270 of file RootInputFileSequence.h.

int64_t const art::RootInputFileSequence::saveMemoryObjectThreshold_
private

Definition at line 260 of file RootInputFileSequence.h.

std::vector<std::vector<std::string> > art::RootInputFileSequence::secondaryFileNames_ {}
private

Definition at line 274 of file RootInputFileSequence.h.

bool art::RootInputFileSequence::seekingFile_ {false}
private

Definition at line 250 of file RootInputFileSequence.h.

RunNumber_t art::RootInputFileSequence::setRun_ {}
private

Definition at line 265 of file RootInputFileSequence.h.

bool const art::RootInputFileSequence::skipBadFiles_
private

Definition at line 257 of file RootInputFileSequence.h.

unsigned int const art::RootInputFileSequence::treeCacheSize_
private

Definition at line 258 of file RootInputFileSequence.h.

int64_t const art::RootInputFileSequence::treeMaxVirtualSize_
private

Definition at line 259 of file RootInputFileSequence.h.


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