test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RootPrimaryFileSequence.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 ----------------------------------------------------------------------*/
3 #include "DuplicateChecker.h"
4 #include "InputFile.h"
5 #include "PoolSource.h"
6 #include "RootFile.h"
8 #include "RootTree.h"
9 
19 
20 namespace edm {
22  ParameterSet const& pset,
24  InputFileCatalog const& catalog) :
25  RootInputFileSequence(pset, catalog),
26  input_(input),
27  firstFile_(true),
28  branchesMustMatch_(BranchDescription::Permissive),
29  orderedProcessHistoryIDs_(),
30  eventSkipperByID_(EventSkipperByID::create(pset).release()),
31  initialNumberOfEventsToSkip_(pset.getUntrackedParameter<unsigned int>("skipEvents")),
32  noEventSort_(pset.getUntrackedParameter<bool>("noEventSort")),
33  treeCacheSize_(noEventSort_ ? pset.getUntrackedParameter<unsigned int>("cacheSize") : 0U),
34  duplicateChecker_(new DuplicateChecker(pset)),
35  usingGoToEvent_(false),
36  enablePrefetching_(false) {
37 
38  // The SiteLocalConfig controls the TTreeCache size and the prefetching settings.
40  if(pSLC.isAvailable()) {
41  if(treeCacheSize_ != 0U && pSLC->sourceTTreeCacheSize()) {
42  treeCacheSize_ = *(pSLC->sourceTTreeCacheSize());
43  }
44  enablePrefetching_ = pSLC->enablePrefetching();
45  }
46 
47  std::string branchesMustMatch = pset.getUntrackedParameter<std::string>("branchesMustMatch", std::string("permissive"));
48  if(branchesMustMatch == std::string("strict")) branchesMustMatch_ = BranchDescription::Strict;
49 
50  // Prestage the files
53  }
54  // Open the first file.
57  if(rootFile()) break;
58  }
59  if(rootFile()) {
60  input_.productRegistryUpdate().updateFromInput(rootFile()->productRegistry()->productList());
63  }
64  }
65  }
66 
68  }
69 
70  void
72  closeFile_();
73  }
74 
75  std::unique_ptr<FileBlock>
77  if(firstFile_) {
78  // The first input file has already been opened.
79  firstFile_ = false;
80  if(!rootFile()) {
82  }
83  } else {
84  if(!nextFile()) {
85  assert(0);
86  }
87  }
88  if(!rootFile()) {
89  return std::unique_ptr<FileBlock>(new FileBlock);
90  }
91  return rootFile()->createFileBlock();
92  }
93 
94  void
96  // close the currently open file, if any, and delete the RootFile object.
97  if(rootFile()) {
98  std::unique_ptr<InputSource::FileCloseSentry>
100  rootFile()->close();
101  if(duplicateChecker_) duplicateChecker_->inputFileClosed();
102  rootFile().reset();
103  }
104  }
105 
106  void
108  // If we are not duplicate checking across files and we are not using random access to find events,
109  // then we can delete the IndexIntoFile for the file we are closing.
110  // If we can't delete all of it, then we can delete the parts we do not need.
111  bool deleteIndexIntoFile = !usingGoToEvent_ && !(duplicateChecker_ && duplicateChecker_->checkingAllFiles() && !duplicateChecker_->checkDisabled());
112  initTheFile(skipBadFiles, deleteIndexIntoFile, &input_, "primaryFiles", InputType::Primary);
113  }
114 
116  RootPrimaryFileSequence::makeRootFile(std::shared_ptr<InputFile> filePtr) {
117  size_t currentIndexIntoFile = sequenceNumberOfFile();
118  return std::make_shared<RootFile>(
119  fileName(),
121  logicalFileName(),
122  filePtr,
125  remainingEvents(),
127  input_.nStreams(),
131  input_.runHelper(),
132  noEventSort_,
137  nullptr, // associationsFromSecondary
142  currentIndexIntoFile,
148  }
149 
151  if(!noMoreFiles()) setAtNextFile();
152  if(noMoreFiles()) {
153  return false;
154  }
155 
157 
158  if(rootFile()) {
159  // make sure the new product registry is compatible with the main one
160  std::string mergeInfo = input_.productRegistryUpdate().merge(*rootFile()->productRegistry(),
161  fileName(),
163  if(!mergeInfo.empty()) {
164  throw Exception(errors::MismatchedInputFiles,"RootPrimaryFileSequence::nextFile()") << mergeInfo;
165  }
166  }
167  return true;
168  }
169 
171  if(atFirstFile()) {
172  return false;
173  }
175 
176  initFile(false);
177 
178  if(rootFile()) {
179  // make sure the new product registry is compatible to the main one
180  std::string mergeInfo = input_.productRegistryUpdate().merge(*rootFile()->productRegistry(),
181  fileName(),
183  if(!mergeInfo.empty()) {
184  throw Exception(errors::MismatchedInputFiles,"RootPrimaryFileSequence::previousEvent()") << mergeInfo;
185  }
186  }
187  if(rootFile()) rootFile()->setToLastEntry();
188  return true;
189  }
190 
193  if(noMoreFiles()) {
194  return InputSource::IsStop;
195  }
196  if(firstFile_) {
197  return InputSource::IsFile;
198  }
199  if(rootFile()) {
200  IndexIntoFile::EntryType entryType = rootFile()->getNextItemType(run, lumi, event);
201  if(entryType == IndexIntoFile::kEvent) {
202  return InputSource::IsEvent;
203  } else if(entryType == IndexIntoFile::kLumi) {
204  return InputSource::IsLumi;
205  } else if(entryType == IndexIntoFile::kRun) {
206  return InputSource::IsRun;
207  }
208  assert(entryType == IndexIntoFile::kEnd);
209  }
210  if(atLastFile()) {
211  return InputSource::IsStop;
212  }
213  return InputSource::IsFile;
214  }
215 
216  // Rewind to before the first event that was read.
217  void
219  if(!atFirstFile()) {
220  closeFile_();
221  setAtFirstFile();
222  }
223  if(!rootFile()) {
224  initFile(false);
225  }
226  rewindFile();
227  firstFile_ = true;
228  if(rootFile()) {
231  }
232  }
233  }
234 
235  // Rewind to the beginning of the current file
236  void
238  if(rootFile()) rootFile()->rewind();
239  }
240 
241  // Advance "offset" events. Offset can be positive or negative (or zero).
242  bool
244  assert(rootFile());
245  while(offset != 0) {
246  bool atEnd = rootFile()->skipEvents(offset);
247  if((offset > 0 || atEnd) && !nextFile()) {
248  return false;
249  }
250  if(offset < 0 && !previousFile()) {
251  setNoMoreFiles();
252  return false;
253  }
254  }
255  return true;
256  }
257 
258  bool
260  usingGoToEvent_ = true;
261  if(rootFile()) {
262  if(rootFile()->goToEvent(eventID)) {
263  return true;
264  }
265  // If only one input file, give up now, to save time.
266  if(rootFile() && indexesIntoFiles().size() == 1) {
267  return false;
268  }
269  // Save the current file and position so that we can restore them
270  // if we fail to restore the desired event
271  bool closedOriginalFile = false;
272  size_t const originalFileSequenceNumber = sequenceNumberOfFile();
273  IndexIntoFile::IndexIntoFileItr originalPosition = rootFile()->indexIntoFileIter();
274 
275  // Look for item (run/lumi/event) in files previously opened without reopening unnecessary files.
276  for(auto it = indexesIntoFiles().begin(), itEnd = indexesIntoFiles().end(); it != itEnd; ++it) {
277  if(*it && (*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
278  // We found it. Close the currently open file, and open the correct one.
280  initFile(false);
281  // Now get the item from the correct file.
282  assert(rootFile());
283  bool found = rootFile()->goToEvent(eventID);
284  assert(found);
285  return true;
286  }
287  }
288  // Look for item in files not yet opened.
289  for(auto it = indexesIntoFiles().begin(), itEnd = indexesIntoFiles().end(); it != itEnd; ++it) {
290  if(!*it) {
292  initFile(false);
293  closedOriginalFile = true;
294  if((*it)->containsItem(eventID.run(), eventID.luminosityBlock(), eventID.event())) {
295  assert(rootFile());
296  if(rootFile()->goToEvent(eventID)) {
297  return true;
298  }
299  }
300  }
301  }
302  if(closedOriginalFile) {
303  setAtFileSequenceNumber(originalFileSequenceNumber);
304  initFile(false);
305  assert(rootFile());
306  rootFile()->setPosition(originalPosition);
307  }
308  }
309  return false;
310  }
311 
312  int
314  return input_.remainingEvents();
315  }
316 
317  int
320  }
321 
322  void
324  desc.addUntracked<unsigned int>("skipEvents", 0U)
325  ->setComment("Skip the first 'skipEvents' events that otherwise would have been processed.");
326  desc.addUntracked<bool>("noEventSort", true)
327  ->setComment("True: Process runs, lumis and events in the order they appear in the file (but see notes 1 and 2).\n"
328  "False: Process runs, lumis and events in each file in numerical order (run#, lumi#, event#) (but see note 3).\n"
329  "Note 1: Events within the same lumi will always be processed contiguously.\n"
330  "Note 2: Lumis within the same run will always be processed contiguously.\n"
331  "Note 3: Any sorting occurs independently in each input file (no sorting across input files).");
332  desc.addUntracked<unsigned int>("cacheSize", roottree::defaultCacheSize)
333  ->setComment("Size of ROOT TTree prefetch cache. Affects performance.");
334  std::string defaultString("permissive");
335  desc.addUntracked<std::string>("branchesMustMatch", defaultString)
336  ->setComment("'strict': Branches in each input file must match those in the first file.\n"
337  "'permissive': Branches in each input file may be any subset of those in the first file.");
338 
341  }
342 
345  if(rootFile()) {
346  if(!rootFile()->wasLastEventJustRead()) {
348  }
349  if(noMoreFiles() || atLastFile()) {
351  } else {
353  }
354  }
356  }
357 
360  if(rootFile()) {
361  if(!rootFile()->wasFirstEventJustRead()) {
363  }
364  if(!atFirstFile()) {
366  }
368  }
370  }
371 
372 }
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
std::string const & logicalFileName() const
void initFile(bool skipBadFiles)
ProductRegistry & productRegistryUpdate()
Definition: InputSource.h:350
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
std::string const & fileName() const
InputSource::ItemType getNextItemType(RunNumber_t &run, LuminosityBlockNumber_t &lumi, EventNumber_t &event)
virtual void closeFile_() override
void setAtFileSequenceNumber(size_t offset)
virtual void initFile_(bool skipBadFiles) override
ProcessingController::ForwardState forwardState() const
tuple lumi
Definition: fjr2json.py:35
assert(m_qm.get())
unsigned long long EventNumber_t
std::vector< std::shared_ptr< IndexIntoFile > > const & indexesIntoFiles() const
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:256
static void fillDescription(ParameterSetDescription &desc)
static void fillDescription(ParameterSetDescription &desc)
std::unique_ptr< FileBlock > readFile_()
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
unsigned int const defaultCacheSize
Definition: RootTree.h:37
unsigned int LuminosityBlockNumber_t
static std::string const input
Definition: EdmProvDump.cc:44
RunHelperBase * runHelper()
Definition: PoolSource.h:47
ProcessingController::ReverseState reverseState() const
std::shared_ptr< RootFile > RootFileSharedPtr
bool goToEvent(EventID const &eventID)
static const StorageFactory * get(void)
int remainingEvents() const
Definition: InputSource.h:200
void stagein(const std::string &url) const
std::string const & lfn() const
virtual RootFileSharedPtr makeRootFile(std::shared_ptr< InputFile > filePtr) override
void initTheFile(bool skipBadFiles, bool deleteIndexIntoFile, InputSource *input, char const *inputTypeName, InputType inputType)
std::vector< ProcessHistoryID > orderedProcessHistoryIDs_
bool isAvailable() const
Definition: Service.h:46
RootPrimaryFileSequence(ParameterSet const &pset, PoolSource &input, InputFileCatalog const &catalog)
std::string merge(ProductRegistry const &other, std::string const &fileName, BranchDescription::MatchMode branchesMustMatch=BranchDescription::Permissive)
unsigned int nStreams() const
Definition: PoolSource.h:44
bool dropDescendants() const
Definition: PoolSource.h:41
bool bypassVersionCheck() const
Definition: PoolSource.h:42
#define end
Definition: vmac.h:37
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::shared_ptr< RootFile const > rootFile() const
int treeMaxVirtualSize() const
Definition: PoolSource.h:45
bool skipBadFiles() const
Definition: PoolSource.h:40
std::shared_ptr< EventSkipperByID const > eventSkipperByID() const
std::shared_ptr< BranchIDListHelper const > branchIDListHelper() const
Accessors for branchIDListHelper.
Definition: InputSource.h:178
bool labelRawDataLikeMC() const
Definition: PoolSource.h:43
edm::propagate_const< std::shared_ptr< DuplicateChecker > > duplicateChecker_
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:351
BranchDescription::MatchMode branchesMustMatch_
tuple skipBadFiles
Definition: example_cfg.py:64
static void fillDescription(ParameterSetDescription &desc)
#define begin
Definition: vmac.h:30
std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper() const
Accessors for thinnedAssociationsHelper.
Definition: InputSource.h:182
void updateFromInput(ProductList const &other)
int remainingLuminosityBlocks() const
Definition: InputSource.h:208
unsigned int RunNumber_t
volatile std::atomic< bool > shutdown_flag false
ProcessConfiguration const & processConfiguration() const
Accessor for Process Configuration.
Definition: InputSource.h:214
std::shared_ptr< DuplicateChecker const > duplicateChecker() const
tuple size
Write out results.
ProductSelectorRules const & productSelectorRules() const
Definition: PoolSource.h:46