CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends
edm::IndexIntoFile Class Reference

#include <IndexIntoFile.h>

Classes

class  EventEntry
 
class  EventFinder
 
class  IndexIntoFileItr
 
class  IndexIntoFileItrEntryOrder
 
class  IndexIntoFileItrImpl
 
class  IndexIntoFileItrNoSort
 
class  IndexIntoFileItrSorted
 
class  IndexRunKey
 
class  IndexRunLumiEventKey
 
class  IndexRunLumiKey
 
class  RunOrLumiEntry
 
class  RunOrLumiIndexes
 
class  SortedRunOrLumiItr
 
struct  Transients
 

Public Types

using EntryNumber_t = long long
 
enum  EntryType { kRun, kLumi, kEvent, kEnd }
 
enum  SortOrder { numericalOrder, firstAppearanceOrder, entryOrder }
 

Public Member Functions

void addEntry (ProcessHistoryID const &processHistoryID, RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, EntryNumber_t entry)
 
void addLumi (int index, RunNumber_t run, LuminosityBlockNumber_t lumi, EntryNumber_t entry)
 
IndexIntoFileItr begin (SortOrder sortOrder) const
 
SortedRunOrLumiItr beginRunOrLumi () const
 
void checkForMissingRunOrLumiEntry () const
 Run this check just after sorting. More...
 
bool containsDuplicateEvents () const
 Returns true if the IndexIntoFile contains 2 events with the same ProcessHistoryID index, run number, lumi number and event number. More...
 
bool containsEvent (RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
 
bool containsItem (RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
 
bool containsLumi (RunNumber_t run, LuminosityBlockNumber_t lumi) const
 
bool containsRun (RunNumber_t run) const
 
void doneFileInitialization ()
 Clears the temporary vector of event numbers to reduce memory usage. More...
 
bool empty () const
 True if no runs, lumis, or events are in the file. More...
 
IndexIntoFileItr end (SortOrder sortOrder) const
 Used to end an iteration over the Runs, Lumis, and Events in a file. More...
 
SortedRunOrLumiItr endRunOrLumi () const
 
void fillEventEntries () const
 
void fillEventNumbers () const
 
void fillEventNumbersOrEntries (bool needEventNumbers, bool needEventEntries) const
 
IndexIntoFileItr findEventPosition (RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
 
IndexIntoFileItr findLumiPosition (RunNumber_t run, LuminosityBlockNumber_t lumi) const
 
IndexIntoFileItr findPosition (RunNumber_t run, LuminosityBlockNumber_t lumi=0U, EventNumber_t event=0U) const
 
IndexIntoFileItr findPosition (SortOrder sortOrder, RunNumber_t run, LuminosityBlockNumber_t lumi=0U, EventNumber_t event=0U) const
 
IndexIntoFileItr findRunPosition (RunNumber_t run) const
 Same as findPosition. More...
 
void fixIndexes (std::vector< ProcessHistoryID > &processHistoryIDs)
 
 IndexIntoFile ()
 
void initializeTransients ()
 
void inputFileClosed ()
 
bool iterationWillBeInEntryOrder (SortOrder sortOrder) const
 Used to determine whether or not to disable fast cloning. More...
 
ProcessHistoryID const & processHistoryID (int i) const
 
std::vector< ProcessHistoryID > const & processHistoryIDs () const
 
void reduceProcessHistoryIDs (ProcessHistoryRegistry const &processHistoryRegistry)
 
std::vector< RunOrLumiEntry > const & runOrLumiEntries () const
 Used internally and for test purposes. More...
 
void set_intersection (IndexIntoFile const &indexIntoFile, std::set< IndexRunLumiEventKey > &intersection) const
 
void setEventFinder (std::shared_ptr< EventFinder > ptr)
 
void setNumberOfEvents (EntryNumber_t nevents)
 
std::vector< ProcessHistoryID > & setProcessHistoryIDs ()
 
std::vector< RunOrLumiEntry > & setRunOrLumiEntries ()
 
void sortVector_Run_Or_Lumi_Entries ()
 
std::vector< EventNumber_t > & unsortedEventNumbers ()
 
std::vector< EventNumber_t > const & unsortedEventNumbers () const
 
 ~IndexIntoFile ()
 

Static Public Attributes

static constexpr EntryNumber_t invalidEntry = -1LL
 
static constexpr EventNumber_t invalidEvent = 0U
 
static constexpr int invalidIndex = -1
 
static constexpr LuminosityBlockNumber_t invalidLumi = 0U
 
static constexpr RunNumber_t invalidRun = 0U
 

Private Member Functions

EntryNumber_tbeginEvents () const
 
int & currentIndex () const
 
LuminosityBlockNumber_tcurrentLumi () const
 
RunNumber_tcurrentRun () const
 
EntryNumber_tendEvents () const
 
std::vector< EventEntry > & eventEntries () const
 
std::vector< EventNumber_t > & eventNumbers () const
 
void fillRunOrLumiIndexes () const
 
void fillUnsortedEventNumbers () const
 
EventNumber_t getEventNumberOfEntry (EntryNumber_t entry) const
 
std::map< IndexRunLumiKey, EntryNumber_t > & lumiToOrder () const
 
size_t numberOfEvents () const
 
int & previousAddedIndex () const
 
void resetEventFinder () const
 
std::vector< RunOrLumiIndexes > & runOrLumiIndexes () const
 
std::map< IndexRunKey, EntryNumber_t > & runToOrder () const
 
void sortEventEntries () const
 
void sortEvents () const
 
std::vector< EventNumber_t > & unsortedEventNumbersMutable () const
 

Private Attributes

std::vector< ProcessHistoryIDprocessHistoryIDs_
 
std::vector< RunOrLumiEntryrunOrLumiEntries_
 
Transients transient_
 

Friends

class ::TestIndexIntoFile
 
class ::TestIndexIntoFile1
 
class ::TestIndexIntoFile2
 
class ::TestIndexIntoFile3
 
class ::TestIndexIntoFile4
 
class ::TestIndexIntoFile5
 

Detailed Description

Used to quickly find the Events, Lumis, and Runs in a single ROOT format data file and step through them in the desired order.

A list of the most important functions that a client would use directly follows. There are detailed comments below with the declaration of each function.

The begin and end functions are used to start and stop an iteration loop. An argument to the iterator constructor determines the order of iteration.

The functions findPosition, findEventPosition, findRunPosition, and findLumiPosition are used to navigate directly to specific runs, lumis, and events.

The functions mentioned above return an object of type IndexIntoFileItr. The IndexIntoFileItr class has member functions which allow one to navigate forward and backward through the runs, lumis, and events in alternative ways. See more comments with the declaration of each public member function in IndexIntoFileItr.

The iterator will know what the current item is (as one would expect). This could be a run, lumi, or event. It knows more than that though, it knows all three as is explained below.

In the run state, IndexIntoFileItr knows which lumi will be processed next after the run and also which event will be processed after the lumi. These may not be the first ones in the run if the skip functions were used.

In the lumi state, the IndexIntoFileItr will always point at the last associated run and the next event to be processed after the lumi. This may not be the first event if the skip function was used.

In the event state, the IndexIntoFileItr will always point at the last corresponding run and also the last corresponding lumi.

There can be multiple run entries in a TTree associated with the same run number and ProcessHistoryID in a file. There can also be multiple lumi entries associated with the same lumi number, run number, and ProcessHistoryID. The sorting orders identified as numericalOrder and firstAppearanceOrder will make these subgroups contiguous, but beyond that is up to the client (normally PoolSource, which passes them up to the EventProcessor) to deal with merging the multiple run (or lumi) entries together.

In entryOrder, the Events are processed in the order they appear in the Events TTree. The event entries associated with a run might not be contiguous. The event entries associated with a lumi might not be contiguous. Even so, the iteration order will always follow the pattern run followed by contained lumis followed by contained events (note it's possible there are no contained events for a lumi or no contained lumis for a run). Because the events are not contiguous, this leads to run or lumi entries appearing more than once in the iteration (once for each contained contiguous sequence of events plus possibly one additional time near the end for the run or lumi to be processed and merged, although this might or might not occur with the last contiguous sequence of events). The iterator is designed to automatically step to each event once, even when it points at the same RunOrLumiEntry with the same events more than once in the iteration. The client does not need to do anything special related to events. On the other hand, the client (usually PoolSource, which passes the value into the Principal) needs to check the iterator functions named shouldProcessLumi or shouldProcessRun to determine whether a lumi or run is being encountered more than once. Those functions will return true only once. At that time, run or lumi products are read, possibly merged, and written to output. When those functions return false, transitions still occur but products are not read, merged or written. If a module attempts to get run or lumi products in those transitions, there will be a "ProductNotFound" exception or invalid Handle. In general, getting run or lumi products from events does not work with the EntryOrder iterator type.

One final comment with regards to IndexIntoFileItr. This is not an STL iterator and it cannot be used with std:: algorithms. The data structures are complex and designed to optimize memory usage. It would be difficult or impossible implement an iterator that is STL compliant.

Here is a summary of the data structures in IndexIntoFile. The persistent data consists of two vectors.

processHistoryIDs_ is a std::vector<ProcessHistoryID> that contains the ProcessHistoryIDs with one element in the vector for each unique ProcessHistoryID. On output they are ordered as they first written out for each output file. On input they are ordered as they are first seen in each process. Note that each ProcessHistoryID is stored once in this separate vector. Everywhere else it is needed it stored as an index into this vector because the ProcessHistoryID itself is large and it would take more memory to store them repeatedly in the other vectors. Note that the ProcessHistoryID's referenced in this class are always the "reduced" ProcessHistoryID's, not the ProcessHistoryID of the full ProcessHistory. You cannot use them to directly access the ProcessHistory from the ProcessHistoryRegistry.

runOrLumiEntries_ is a std::vector<RunOrLumiEntry>. This vector holds one element per entry in the run TTree and one element per entry in the lumi TTree. When sorted, everything associated with a given run and ProcessHistoryID will be contiguous in the vector. These groups of elements will be sorted by an OutputModule in the order they first appear when an Event, Lumi or Run is written to output (close to input order but because of concurrency it might not be exactly the same). Within each of these groups the run entries come first in order, followed by the elements associated with the lumis. The lumis are also contiguous and sorted by first appearance by the output module in a way similar to runs. Within a lumi they are sorted by entry order. And each luminosity element corresponds to one contiguous sequence of Events in the Events TTree. Before we implemented concurrent processing of luminosity blocks that was the full story. After that it became more complicated because the sequence of events written to an output file that were associated with a particular luminosity block TTree entry might no longer be contiguous. Events from another concurrent luminosity block could get mixed in because with multiple events processing simultaneously, there is no longer any guarantee they will finish in the same order that they were read. This is handled by writing additional elements to the runOrLumiEntries_ vector, one for each contiguous block of events associated with a particular luminosity block. Only one of these vector elements will be associated with each entry in the luminosity block TTree and all the others will contain a TTree entry number that is invalid (note the one element with a valid entry might or might not be associated with a contiguous block of events). In the sort of elements related to a particular luminosity block, the entries with invalid entry numbers will come before the valid ones.

There are a number of transient data members also. The 3 most important of these are vectors. To save memory, these are only filled when needed.

runOrLumiIndexes_ is a std::vector<RunOrLumiIndexes>. There is a one to one correspondence between the elements of this vector and the elements of runOrLumiEntries_. The elements of this vector are sorted in numerical order using the ProcessHistoryID index, the run number, and the lumi number. This ordering allows iteration in numerical order and also fast lookup based on run number and lumi number. Each element also has indexes into the eventNumbers_ and eventEntries_ vectors which hold the information giving the event numbers and event entry numbers. Note this vector is initially formed in the identical order as runOrLumiEntries_ and then sorted with a stable sort. The fact that it is a stable sort means that within the subrange associated with a particular luminosity block the elements with an invalid TTree entry number come first and the later come the elements with a valid TTree entry number which are in order of TTree entry number.

eventNumbers_ is a std::vector containing EventNumber_t's. eventEntries_ is a std::vector containing EventEntry's. If filled, both vectors contain the same number of entries with identical event numbers sorted in the same order. The only difference is that one includes the entry numbers and thus takes more memory. Each element of runOrLumiIndexes_ associated with a luminosity block has the indexes necessary to find the range inside eventNumbers_ or eventEntries_ corresponding to its lumi. Within that range the elements are sorted by event number, which is used for the numerical order iteration and to find an event by the event number.

The details of the data structure are a little different when reading files written before release 3_8_0 (backward compatibility, see RootFile::fillIndexIntoFile for the details).

This data structure is optimized for low memory usage when there are large numbers of events. The optimal case would occur when there was was one run in a file, one luminosity block in that run and everything had the same ProcessHistoryID. If duplicate checking were off and the process simply iterated through the file in the default order, then only the persistent vectors would be filled. One vector would contain 2 elements, one for the run and the other for the lumi. The other vector would contain one element, the ProcessHistoryID. Even if there were a billion events, that would be all that would exist and take up memory. The data structure is not the optimal structure for a very sparse skim, but the overheads should be tolerable given the number of runs and luminosity blocks that should occur in CMS data.

Normally only the persistent parts of the data structure are filled in the output module. The output module fills them using two functions designed specifically for that purpose. The functions are addEntry and sortVector_Run_Or_Lumi_Entries.

There are some complexities associated with filling the data structure, mostly revolving around optimizations to minimize the per event memory usage. The client needs to know which parts of the data structure to fill. See the functions below named fixIndexes, setNumberOfEvents, setEventFinder, fillEventNumbers, fillEventEntries, and inputFileClosed.

Note that this class is not intended to be used directly by the average CMS user. PoolSource and PoolOutputModule are the main clients. Other executables that read ROOT format data files, but do not use PoolSource may also need to use it directly (FWLite, Fireworks, edmFileUtil ...). The interface is too complex for general use.

Author
W. David Dagenhart, created 19 May, 2010

Definition at line 255 of file IndexIntoFile.h.

Member Typedef Documentation

◆ EntryNumber_t

Definition at line 261 of file IndexIntoFile.h.

Member Enumeration Documentation

◆ EntryType

◆ SortOrder

This enum is used to specify the order of iteration. In firstAppearanceOrder there are 3 sort criteria, in order of precedence these are:

  1. firstAppearance of the ProcessHistoryID and run number in the Events TTree of the file (in cases where there are no Events in a run it depends on the order of the call to writeRun or writeLumi in the preceding step where the IndexIntoFile was created)
  2. firstAppearance of the ProcessHistoryID, run number and lumi number in the Events TTree of the file (in cases where there are no Events in a lumi it depends on the order of the call to writeRun or writeLumi in the preceding step where the IndexIntoFile was created)
  3. entry number

In numerical order the criteria are in order of precedence are:

  1. processHistoryID index (which are normally in order of appearance in the output module)
  2. run number
  3. lumi number
  4. event number
  5. entry number

In entryOrder the order of iteration is as follows:

  1. Events are processed in the exact order they appear in the input Events TTree. (The main purpose of this order is to allow fast cloning of the input Events TTree to the output Events TTree.)
  2. Runs and Lumis will show up around events so that the pattern run, then contained lumi(s), then contained event(s) is always followed, but because events from a run (or lumi) may not be contiguous a particular run entry or lumi entry may appear multiple times in this ordering. Each Run entry or lumi entry will appear once with the function shouldProcessRun or shouldProcessLumi returning true. The client (usually PoolSource) must notice when these return false and not read or process them multiple times.

All runs and lumis associated with a run should be processed when the last contiguous sequence of events for that run is processed. If a run has no events, then it is interspersed within that sequence of runs according to its run TTree entry number.

  1. Within a run, lumis should be processed when the last contiguous subsequence of events from that lumi is processed. If there are no events from a lumi in the last contiguous sequence of events from the run, then the lumis are interspersed within the sequence of lumis from that run in order of lumi TTree entry number.

Note that the ordering above will allow the client (usually PoolSource) to merge all run entries associated with a single run and merge all lumi entries associated with a single lumi the first time an input file is read. This is the same as in the other two orderings.

Enumerator
numericalOrder 
firstAppearanceOrder 
entryOrder 

Definition at line 333 of file IndexIntoFile.h.

Constructor & Destructor Documentation

◆ IndexIntoFile()

edm::IndexIntoFile::IndexIntoFile ( )

Definition at line 51 of file IndexIntoFile.cc.

std::vector< RunOrLumiEntry > runOrLumiEntries_
std::vector< ProcessHistoryID > processHistoryIDs_

◆ ~IndexIntoFile()

edm::IndexIntoFile::~IndexIntoFile ( )

Definition at line 53 of file IndexIntoFile.cc.

53 {}

Member Function Documentation

◆ addEntry()

void edm::IndexIntoFile::addEntry ( ProcessHistoryID const &  processHistoryID,
RunNumber_t  run,
LuminosityBlockNumber_t  lumi,
EventNumber_t  event,
EntryNumber_t  entry 
)

Used by RootOutputModule to fill the persistent data. This will not work properly if entries are not added in the same order as in RootOutputModule

Definition at line 75 of file IndexIntoFile.cc.

References addLumi(), cms::cuda::assert(), beginEvents(), currentIndex(), currentLumi(), currentRun(), endEvents(), mps_splice::entry, invalidEntry, invalidEvent, invalidIndex, invalidLumi, invalidRun, BXlumiParameters_cfi::lumi, numberOfEvents(), or, previousAddedIndex(), processHistoryID(), processHistoryIDs_, writedatasetfile::run, runOrLumiEntries_, runToOrder(), and setNumberOfEvents().

Referenced by edm::RootOutputFile::writeLuminosityBlock(), edm::RootOutputFile::writeOne(), and edm::RootOutputFile::writeRun().

79  {
80  int index = 0;
81  // First see if the ProcessHistoryID is the same as the previous one.
82  // This is just a performance optimization. We expect to usually get
83  // many in a row that are the same.
86  } else {
87  // If it was not the same as the previous one then search through the
88  // entire vector. If it is not there, it needs to be added at the
89  // end.
90  index = 0;
91  while (index < static_cast<int>(processHistoryIDs_.size()) && processHistoryIDs_[index] != processHistoryID) {
92  ++index;
93  }
94  if (index == static_cast<int>(processHistoryIDs_.size())) {
96  }
97  }
99 
100  if (lumi == invalidLumi) { // adding a run entry
101  std::pair<IndexRunKey, EntryNumber_t> keyAndOrder{IndexRunKey{index, run}, runToOrder().size()};
102  runToOrder().insert(keyAndOrder); // does nothing if this key already was inserted
103  runOrLumiEntries_.emplace_back(
105  } else {
106  if (event == invalidEvent) { // adding a lumi entry
107  if ((currentIndex() != index or currentRun() != run or currentLumi() != lumi) and
108  currentLumi() != invalidLumi) {
109  //we have overlapping lumis so must inject a placeholder
111  }
112  addLumi(index, run, lumi, entry);
116  std::pair<IndexRunKey, EntryNumber_t> keyAndOrder{IndexRunKey{index, run}, runToOrder().size()};
117  runToOrder().insert(keyAndOrder); // does nothing if this key already was inserted
118  } else { // adding an event entry
119  if ((currentIndex() != index or currentRun() != run or currentLumi() != lumi) and
120  currentLumi() != invalidLumi) {
121  //We have overlapping lumis so need to inject a placeholder
123  }
125  if (beginEvents() == invalidEntry) {
126  currentRun() = run;
127  currentIndex() = index;
128  currentLumi() = lumi;
129  beginEvents() = entry;
130  endEvents() = beginEvents() + 1;
131  std::pair<IndexRunKey, EntryNumber_t> keyAndOrder{IndexRunKey{index, run}, runToOrder().size()};
132  runToOrder().insert(keyAndOrder); // does nothing if this key already was inserted
133  } else {
134  assert(currentIndex() == index);
135  assert(currentRun() == run);
136  assert(currentLumi() == lumi);
137  assert(entry == endEvents());
138  ++endEvents();
139  }
140  }
141  }
142  }
static constexpr int invalidIndex
int & previousAddedIndex() const
void addLumi(int index, RunNumber_t run, LuminosityBlockNumber_t lumi, EntryNumber_t entry)
EntryNumber_t & endEvents() const
RunNumber_t & currentRun() const
assert(be >=bs)
static constexpr EventNumber_t invalidEvent
void setNumberOfEvents(EntryNumber_t nevents)
int & currentIndex() const
static constexpr RunNumber_t invalidRun
std::vector< RunOrLumiEntry > runOrLumiEntries_
std::vector< ProcessHistoryID > processHistoryIDs_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
ProcessHistoryID const & processHistoryID(int i) const
size_t numberOfEvents() const
static constexpr EntryNumber_t invalidEntry
static constexpr LuminosityBlockNumber_t invalidLumi
LuminosityBlockNumber_t & currentLumi() const
EntryNumber_t & beginEvents() const
std::map< IndexRunKey, EntryNumber_t > & runToOrder() const
Definition: event.py:1

◆ addLumi()

void edm::IndexIntoFile::addLumi ( int  index,
RunNumber_t  run,
LuminosityBlockNumber_t  lumi,
EntryNumber_t  entry 
)

Definition at line 59 of file IndexIntoFile.cc.

References beginEvents(), endEvents(), mps_splice::entry, invalidEntry, BXlumiParameters_cfi::lumi, lumiToOrder(), writedatasetfile::run, and runOrLumiEntries_.

Referenced by addEntry().

59  {
60  // assign each lumi an order value sequentially when first seen
61  std::pair<IndexRunLumiKey, EntryNumber_t> keyAndOrder{IndexRunLumiKey{index, run, lumi}, lumiToOrder().size()};
62  lumiToOrder().insert(keyAndOrder); // does nothing if this key already was inserted
63  runOrLumiEntries_.emplace_back(invalidEntry,
64  lumiToOrder()[IndexRunLumiKey{index, run, lumi}],
65  entry,
66  index,
67  run,
68  lumi,
69  beginEvents(),
70  endEvents());
73  }
std::map< IndexRunLumiKey, EntryNumber_t > & lumiToOrder() const
EntryNumber_t & endEvents() const
std::vector< RunOrLumiEntry > runOrLumiEntries_
static constexpr EntryNumber_t invalidEntry
EntryNumber_t & beginEvents() const

◆ begin()

IndexIntoFile::IndexIntoFileItr edm::IndexIntoFile::begin ( SortOrder  sortOrder) const

Used to start an iteration over the Runs, Lumis, and Events in a file. Note the argument specifies the order

Definition at line 506 of file IndexIntoFile.cc.

References empty(), end(), edm::IndexIntoFile::IndexIntoFileItr::initializeRun(), invalidIndex, and kRun.

Referenced by containsDuplicateEvents(), findPosition(), iterationWillBeInEntryOrder(), edm::postIndexIntoFilePrintEventLists(), edm::postIndexIntoFilePrintEventsInLumis(), edm::RootFile::RootFile(), set_intersection(), sortEventEntries(), and sortEvents().

506  {
507  if (empty()) {
508  return end(sortOrder);
509  }
510  IndexIntoFileItr iter(this, sortOrder, kRun, 0, invalidIndex, invalidIndex, 0, 0);
511  iter.initializeRun();
512  return iter;
513  }
IndexIntoFileItr end(SortOrder sortOrder) const
Used to end an iteration over the Runs, Lumis, and Events in a file.
static constexpr int invalidIndex
bool empty() const
True if no runs, lumis, or events are in the file.

◆ beginEvents()

EntryNumber_t& edm::IndexIntoFile::beginEvents ( ) const
inlineprivate

◆ beginRunOrLumi()

IndexIntoFile::SortedRunOrLumiItr edm::IndexIntoFile::beginRunOrLumi ( ) const

Definition at line 755 of file IndexIntoFile.cc.

Referenced by containsDuplicateEvents(), fillEventNumbersOrEntries(), and set_intersection().

755 { return SortedRunOrLumiItr(this, 0); }

◆ checkForMissingRunOrLumiEntry()

void edm::IndexIntoFile::checkForMissingRunOrLumiEntry ( ) const

Run this check just after sorting.

Definition at line 405 of file IndexIntoFile.cc.

References currentLumi(), currentRun(), edm::IndexIntoFile::RunOrLumiEntry::entry(), Exception, invalidEntry, B2GTnPMonitor_cfi::item, edm::errors::LogicError, edm::IndexIntoFile::RunOrLumiEntry::lumi(), edm::IndexIntoFile::RunOrLumiEntry::run(), and runOrLumiEntries_.

Referenced by sortVector_Run_Or_Lumi_Entries().

405  {
406  bool shouldThrow = false;
407  bool foundValidLumiEntry = true;
410  EntryNumber_t previousLumi = invalidEntry;
411 
412  RunOrLumiEntry const* lastEntry = nullptr;
413  for (RunOrLumiEntry const& item : runOrLumiEntries_) {
414  if (item.isRun()) {
415  currentRun = item.orderPHIDRun();
416  } else { // Lumi
417  if (item.orderPHIDRun() != currentRun) {
419  << "In IndexIntoFile::sortVector_Run_Or_Lumi_Entries. Missing Run entry.\n"
420  << "If this occurs after an unrelated exception occurs, please ignore this\n"
421  << "exception and fix the primary exception. This is a possible and expected\n"
422  << "side effect. Otherwise, please report to Framework developers.\n"
423  << "This could indicate a bug in the source or Framework\n"
424  << "Run: " << item.run() << " Lumi: " << item.lumi() << " Entry: " << item.entry() << "\n";
425  }
426  currentLumi = item.orderPHIDRunLumi();
427  if (currentLumi != previousLumi) {
428  if (!foundValidLumiEntry) {
429  shouldThrow = true;
430  break;
431  }
432  foundValidLumiEntry = false;
433  previousLumi = currentLumi;
434  }
435  if (item.entry() != invalidEntry) {
436  foundValidLumiEntry = true;
437  }
438  }
439  lastEntry = &item;
440  }
441  if (!foundValidLumiEntry) {
442  shouldThrow = true;
443  }
444 
445  if (shouldThrow) {
447  << "In IndexIntoFile::sortVector_Run_Or_Lumi_Entries. Missing valid Lumi entry.\n"
448  << "If this occurs after an unrelated exception occurs, please ignore this\n"
449  << "exception and fix the primary exception. This is a possible and expected\n"
450  << "side effect. Otherwise, please report to Framework developers.\n"
451  << "This could indicate a bug in the source or Framework\n"
452  << "Run: " << lastEntry->run() << " Lumi: " << lastEntry->lumi() << " Entry: " << lastEntry->entry() << "\n";
453  }
454  }
RunNumber_t & currentRun() const
long long EntryNumber_t
std::vector< RunOrLumiEntry > runOrLumiEntries_
static constexpr EntryNumber_t invalidEntry
LuminosityBlockNumber_t & currentLumi() const

◆ containsDuplicateEvents()

bool edm::IndexIntoFile::containsDuplicateEvents ( ) const

Returns true if the IndexIntoFile contains 2 events with the same ProcessHistoryID index, run number, lumi number and event number.

Definition at line 863 of file IndexIntoFile.cc.

References begin(), edm::IndexIntoFile::RunOrLumiIndexes::beginEventNumbers(), beginRunOrLumi(), empty(), edm::IndexIntoFile::RunOrLumiIndexes::endEventNumbers(), endRunOrLumi(), eventEntries(), eventNumbers(), fillEventNumbers(), edm::IndexIntoFile::RunOrLumiIndexes::isRun(), and dqmdumpme::last.

Referenced by edm::DuplicateChecker::inputFileOpened().

863  {
864  RunOrLumiIndexes const* previousIndexes = nullptr;
865 
866  for (SortedRunOrLumiItr iter = beginRunOrLumi(), iEnd = endRunOrLumi(); iter != iEnd; ++iter) {
867  RunOrLumiIndexes const& indexes = iter.runOrLumiIndexes();
868 
869  // Skip it if it is a run or the same lumi
870  if (indexes.isRun() || (previousIndexes && !(*previousIndexes < indexes))) {
871  continue;
872  }
873  previousIndexes = &indexes;
874 
875  long long beginEventNumbers = indexes.beginEventNumbers();
876  long long endEventNumbers = indexes.endEventNumbers();
877 
878  // there must be more than 1 event in the lumi for there to be any duplicates
879  if (beginEventNumbers + 1 >= endEventNumbers)
880  continue;
881 
882  if (!eventEntries().empty()) {
883  std::vector<EventEntry>::iterator last = eventEntries().begin() + endEventNumbers;
884  if (std::adjacent_find(eventEntries().begin() + beginEventNumbers, last) != last) {
885  return true;
886  }
887  } else {
889  std::vector<EventNumber_t>::iterator last = eventNumbers().begin() + endEventNumbers;
890  if (std::adjacent_find(eventNumbers().begin() + beginEventNumbers, last) != last) {
891  return true;
892  }
893  }
894  }
895  return false;
896  }
IndexIntoFileItr begin(SortOrder sortOrder) const
void fillEventNumbers() const
std::vector< EventEntry > & eventEntries() const
SortedRunOrLumiItr endRunOrLumi() const
bool empty() const
True if no runs, lumis, or events are in the file.
std::vector< EventNumber_t > & eventNumbers() const
SortedRunOrLumiItr beginRunOrLumi() const

◆ containsEvent()

bool edm::IndexIntoFile::containsEvent ( RunNumber_t  run,
LuminosityBlockNumber_t  lumi,
EventNumber_t  event 
) const

Definition at line 745 of file IndexIntoFile.cc.

References findEventPosition(), edm::IndexIntoFile::IndexIntoFileItr::getEntryType(), kEnd, and writedatasetfile::run.

Referenced by containsItem().

745  {
747  }
IndexIntoFileItr findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
Definition: event.py:1

◆ containsItem()

bool edm::IndexIntoFile::containsItem ( RunNumber_t  run,
LuminosityBlockNumber_t  lumi,
EventNumber_t  event 
) const

Definition at line 741 of file IndexIntoFile.cc.

References containsEvent(), containsLumi(), containsRun(), and writedatasetfile::run.

Referenced by edm::RootFile::containsItem().

741  {
742  return (event != 0) ? containsEvent(run, lumi, event) : (lumi ? containsLumi(run, lumi) : containsRun(run));
743  }
bool containsEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
bool containsLumi(RunNumber_t run, LuminosityBlockNumber_t lumi) const
bool containsRun(RunNumber_t run) const
Definition: event.py:1

◆ containsLumi()

bool edm::IndexIntoFile::containsLumi ( RunNumber_t  run,
LuminosityBlockNumber_t  lumi 
) const

Definition at line 749 of file IndexIntoFile.cc.

References findLumiPosition(), edm::IndexIntoFile::IndexIntoFileItr::getEntryType(), kEnd, and writedatasetfile::run.

Referenced by containsItem().

749  {
750  return findLumiPosition(run, lumi).getEntryType() != kEnd;
751  }
IndexIntoFileItr findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const

◆ containsRun()

bool edm::IndexIntoFile::containsRun ( RunNumber_t  run) const

Definition at line 753 of file IndexIntoFile.cc.

References findRunPosition(), edm::IndexIntoFile::IndexIntoFileItr::getEntryType(), kEnd, and writedatasetfile::run.

Referenced by containsItem().

753 { return findRunPosition(run).getEntryType() != kEnd; }
IndexIntoFileItr findRunPosition(RunNumber_t run) const
Same as findPosition.

◆ currentIndex()

int& edm::IndexIntoFile::currentIndex ( ) const
inlineprivate

◆ currentLumi()

LuminosityBlockNumber_t& edm::IndexIntoFile::currentLumi ( ) const
inlineprivate

◆ currentRun()

RunNumber_t& edm::IndexIntoFile::currentRun ( ) const
inlineprivate

◆ doneFileInitialization()

void edm::IndexIntoFile::doneFileInitialization ( )

Clears the temporary vector of event numbers to reduce memory usage.

Definition at line 299 of file IndexIntoFile.cc.

References edm::swap(), and unsortedEventNumbers().

Referenced by edm::RootFile::RootFile().

299 { std::vector<EventNumber_t>().swap(unsortedEventNumbers()); }
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
std::vector< EventNumber_t > & unsortedEventNumbers()

◆ empty()

bool edm::IndexIntoFile::empty ( ) const

True if no runs, lumis, or events are in the file.

Definition at line 532 of file IndexIntoFile.cc.

References runOrLumiEntries().

Referenced by begin(), containsDuplicateEvents(), fwlite::EntryFinder::empty(), fillEventNumbersOrEntries(), fillUnsortedEventNumbers(), fwlite::EntryFinder::findEvent(), fwlite::EntryFinder::findLumi(), findPosition(), fwlite::EntryFinder::findRun(), set_intersection(), and edm::RootFile::validateFile().

532 { return runOrLumiEntries().empty(); }
std::vector< RunOrLumiEntry > const & runOrLumiEntries() const
Used internally and for test purposes.

◆ end()

IndexIntoFile::IndexIntoFileItr edm::IndexIntoFile::end ( SortOrder  sortOrder) const

◆ endEvents()

EntryNumber_t& edm::IndexIntoFile::endEvents ( ) const
inlineprivate

◆ endRunOrLumi()

IndexIntoFile::SortedRunOrLumiItr edm::IndexIntoFile::endRunOrLumi ( ) const

Definition at line 757 of file IndexIntoFile.cc.

References runOrLumiEntries().

Referenced by containsDuplicateEvents(), fillEventNumbersOrEntries(), and set_intersection().

757  {
758  return SortedRunOrLumiItr(this, runOrLumiEntries().size());
759  }
size
Write out results.
std::vector< RunOrLumiEntry > const & runOrLumiEntries() const
Used internally and for test purposes.

◆ eventEntries()

std::vector<EventEntry>& edm::IndexIntoFile::eventEntries ( ) const
inlineprivate

◆ eventNumbers()

std::vector<EventNumber_t>& edm::IndexIntoFile::eventNumbers ( ) const
inlineprivate

◆ fillEventEntries()

void edm::IndexIntoFile::fillEventEntries ( ) const

Fills a vector of objects that contain an event number and the corresponding TTree entry number for the event. Not filling it reduces the memory used by IndexIntoFile. As long as the event finder is still pointing at an open file this will automatically be called on demand (when the event numbers and entries are are needed). It makes sense for the client to fill this explicitly in advance if it is known that it will be needed, because in some cases this will prevent the event numbers vector from being unnecessarily filled (wasting memory). This vector will be needed when iterating over events in numerical order or looking up specific events. The entry numbers are needed if the events are actually read from the input file.

Definition at line 193 of file IndexIntoFile.cc.

References fillEventNumbersOrEntries().

193 { fillEventNumbersOrEntries(false, true); }
void fillEventNumbersOrEntries(bool needEventNumbers, bool needEventEntries) const

◆ fillEventNumbers()

void edm::IndexIntoFile::fillEventNumbers ( ) const

Fills a vector of event numbers. Not filling it reduces the memory used by IndexIntoFile. As long as the event finder is still pointing at an open file this will automatically be called on demand (when the event numbers are are needed). In cases, where the input file may be closed when the need arises, the client code must call this explicitly and fill the vector before the file is closed. In PoolSource, this is necessary when duplicate checking across all files and when doing lookups to see if an event is in a previously opened file. Either this vector or the one that also contains event entry numbers can be used when looking for duplicate events within the same file or looking up events in in the current file without reading them.

Definition at line 191 of file IndexIntoFile.cc.

References fillEventNumbersOrEntries().

Referenced by containsDuplicateEvents(), findPosition(), edm::RootFile::goToEvent(), and set_intersection().

191 { fillEventNumbersOrEntries(true, false); }
void fillEventNumbersOrEntries(bool needEventNumbers, bool needEventEntries) const

◆ fillEventNumbersOrEntries()

void edm::IndexIntoFile::fillEventNumbersOrEntries ( bool  needEventNumbers,
bool  needEventEntries 
) const

If needEventNumbers is true then this function does the same thing as fillEventNumbers. If NeedEventEntries is true, then this function does the same thing as fillEventEntries. If both are true, it fills both within the same loop and it uses less CPU than calling those two functions separately.

Definition at line 195 of file IndexIntoFile.cc.

References cms::cuda::assert(), beginRunOrLumi(), empty(), endRunOrLumi(), mps_splice::entry, edmPickEvents::event, eventEntries(), eventNumbers(), fillUnsortedEventNumbers(), invalidEntry, invalidEvent, L1DTConfigBti_cff::LL, numberOfEvents(), hltrates_dqm_sourceclient-live_cfg::offset, sortEventEntries(), sortEvents(), mitigatedMETSequence_cff::U, and unsortedEventNumbers().

Referenced by fillEventEntries(), fillEventNumbers(), and edm::RootFile::validateFile().

195  {
196  if (numberOfEvents() == 0) {
197  return;
198  }
199 
200  if (needEventNumbers && !eventNumbers().empty()) {
201  needEventNumbers = false;
202  }
203 
204  if (needEventEntries && !eventEntries().empty()) {
205  needEventEntries = false;
206  }
207 
208  if (needEventNumbers && !eventEntries().empty()) {
210  eventNumbers().reserve(eventEntries().size());
212  eventNumbers().push_back(eventEntries()[entry].event());
213  }
214  return;
215  }
216 
217  if (!needEventNumbers && !needEventEntries) {
218  return;
219  }
220 
222 
223  if (needEventNumbers) {
225  }
226  if (needEventEntries) {
227  eventEntries().resize(numberOfEvents());
228  }
229 
230  long long offset = 0;
231  long long previousBeginEventNumbers = -1LL;
232 
233  for (SortedRunOrLumiItr runOrLumi = beginRunOrLumi(), runOrLumiEnd = endRunOrLumi(); runOrLumi != runOrLumiEnd;
234  ++runOrLumi) {
235  if (runOrLumi.isRun())
236  continue;
237 
238  long long beginEventNumbers = 0;
239  long long endEventNumbers = 0;
240  EntryNumber_t beginEventEntry = invalidEntry;
241  EntryNumber_t endEventEntry = invalidEntry;
242  runOrLumi.getRange(beginEventNumbers, endEventNumbers, beginEventEntry, endEventEntry);
243 
244  // This is true each time one hits a new lumi section (except if the previous lumi had
245  // no events, in which case the offset is still 0 anyway)
246  if (beginEventNumbers != previousBeginEventNumbers)
247  offset = 0;
248 
249  for (EntryNumber_t entry = beginEventEntry; entry != endEventEntry; ++entry) {
250  if (needEventNumbers) {
251  eventNumbers().at((entry - beginEventEntry) + offset + beginEventNumbers) = unsortedEventNumbers().at(entry);
252  }
253  if (needEventEntries) {
254  eventEntries().at((entry - beginEventEntry) + offset + beginEventNumbers) =
255  EventEntry(unsortedEventNumbers().at(entry), entry);
256  }
257  }
258 
259  previousBeginEventNumbers = beginEventNumbers;
260  offset += endEventEntry - beginEventEntry;
261  }
262  if (needEventNumbers) {
263  sortEvents();
265  }
266  if (needEventEntries) {
269  }
270  }
size
Write out results.
void sortEventEntries() const
std::vector< EventEntry > & eventEntries() const
assert(be >=bs)
uint16_t size_type
static constexpr EventNumber_t invalidEvent
void fillUnsortedEventNumbers() const
long long EntryNumber_t
SortedRunOrLumiItr endRunOrLumi() const
bool empty() const
True if no runs, lumis, or events are in the file.
size_t numberOfEvents() const
std::vector< EventNumber_t > & eventNumbers() const
static constexpr EntryNumber_t invalidEntry
std::vector< EventNumber_t > & unsortedEventNumbers()
SortedRunOrLumiItr beginRunOrLumi() const
void sortEvents() const

◆ fillRunOrLumiIndexes()

void edm::IndexIntoFile::fillRunOrLumiIndexes ( ) const
private

This function will automatically get called when needed. It depends only on the fact that the persistent data has been filled already.

Definition at line 144 of file IndexIntoFile.cc.

References cms::cuda::assert(), invalidEntry, B2GTnPMonitor_cfi::item, createIOVlist::nEvents, runOrLumiEntries_, runOrLumiIndexes(), and edm::stable_sort_all().

Referenced by findPosition(), edm::IndexIntoFile::IndexIntoFileItrSorted::IndexIntoFileItrSorted(), set_intersection(), edm::IndexIntoFile::SortedRunOrLumiItr::SortedRunOrLumiItr(), sortEventEntries(), and sortEvents().

144  {
145  if (runOrLumiEntries_.empty() || !runOrLumiIndexes().empty()) {
146  return;
147  }
148  runOrLumiIndexes().reserve(runOrLumiEntries_.size());
149 
150  int index = 0;
151  for (RunOrLumiEntry const& item : runOrLumiEntries_) {
152  runOrLumiIndexes().emplace_back(item.processHistoryIDIndex(), item.run(), item.lumi(), index);
153  ++index;
154  }
156 
157  long long beginEventNumbers = 0;
158 
159  std::vector<RunOrLumiIndexes>::iterator beginOfLumi = runOrLumiIndexes().begin();
160  std::vector<RunOrLumiIndexes>::iterator endOfLumi = beginOfLumi;
161  std::vector<RunOrLumiIndexes>::iterator iEnd = runOrLumiIndexes().end();
162  while (true) {
163  while (beginOfLumi != iEnd && beginOfLumi->isRun()) {
164  ++beginOfLumi;
165  }
166  if (beginOfLumi == iEnd)
167  break;
168 
169  endOfLumi = beginOfLumi + 1;
170  while (endOfLumi != iEnd && beginOfLumi->processHistoryIDIndex() == endOfLumi->processHistoryIDIndex() &&
171  beginOfLumi->run() == endOfLumi->run() && beginOfLumi->lumi() == endOfLumi->lumi()) {
172  ++endOfLumi;
173  }
174  int nEvents = 0;
175  for (std::vector<RunOrLumiIndexes>::iterator iter = beginOfLumi; iter != endOfLumi; ++iter) {
176  if (runOrLumiEntries_[iter->indexToGetEntry()].beginEvents() != invalidEntry) {
177  nEvents += runOrLumiEntries_[iter->indexToGetEntry()].endEvents() -
178  runOrLumiEntries_[iter->indexToGetEntry()].beginEvents();
179  }
180  }
181  for (std::vector<RunOrLumiIndexes>::iterator iter = beginOfLumi; iter != endOfLumi; ++iter) {
182  iter->setBeginEventNumbers(beginEventNumbers);
183  iter->setEndEventNumbers(beginEventNumbers + nEvents);
184  }
185  beginEventNumbers += nEvents;
186  beginOfLumi = endOfLumi;
187  }
189  }
size
Write out results.
std::vector< RunOrLumiIndexes > & runOrLumiIndexes() const
void stable_sort_all(RandomAccessSequence &s)
wrappers for std::stable_sort
Definition: Algorithms.h:103
assert(be >=bs)
std::vector< RunOrLumiEntry > runOrLumiEntries_
static constexpr EntryNumber_t invalidEntry

◆ fillUnsortedEventNumbers()

void edm::IndexIntoFile::fillUnsortedEventNumbers ( ) const
private

Definition at line 272 of file IndexIntoFile.cc.

References empty(), mps_splice::entry, getEventNumberOfEntry(), numberOfEvents(), mitigatedMETSequence_cff::U, unsortedEventNumbers(), and unsortedEventNumbersMutable().

Referenced by fillEventNumbersOrEntries().

272  {
273  if (numberOfEvents() == 0 || !unsortedEventNumbers().empty()) {
274  return;
275  }
277 
278  // The main purpose for the existence of the unsortedEventNumbers
279  // vector is that it can easily be filled by reading through
280  // the EventAuxiliary branch in the same order as the TTree
281  // entries. fillEventNumbersOrEntries can then use this information
282  // instead of using getEventNumberOfEntry directly and reading
283  // the branch in a different order.
286  }
287  }
uint16_t size_type
EventNumber_t getEventNumberOfEntry(EntryNumber_t entry) const
bool empty() const
True if no runs, lumis, or events are in the file.
std::vector< EventNumber_t > & unsortedEventNumbersMutable() const
size_t numberOfEvents() const
std::vector< EventNumber_t > & unsortedEventNumbers()

◆ findEventPosition()

IndexIntoFile::IndexIntoFileItr edm::IndexIntoFile::findEventPosition ( RunNumber_t  run,
LuminosityBlockNumber_t  lumi,
EventNumber_t  event 
) const

Same as findPosition,except the entry type of the returned iterator will be kEvent or kEnd and the event argument must be nonzero. This means the next thing to be processed will be the event if it is found.

Definition at line 721 of file IndexIntoFile.cc.

References edm::IndexIntoFile::IndexIntoFileItr::advanceToEvent(), cms::cuda::assert(), findPosition(), invalidEvent, and writedatasetfile::run.

Referenced by containsEvent(), fwlite::EntryFinder::findEvent(), and edm::RootFile::setEntryAtEvent().

723  {
725  IndexIntoFileItr iter = findPosition(run, lumi, event);
726  iter.advanceToEvent();
727  return iter;
728  }
assert(be >=bs)
static constexpr EventNumber_t invalidEvent
IndexIntoFileItr findPosition(RunNumber_t run, LuminosityBlockNumber_t lumi=0U, EventNumber_t event=0U) const
Definition: event.py:1

◆ findLumiPosition()

IndexIntoFile::IndexIntoFileItr edm::IndexIntoFile::findLumiPosition ( RunNumber_t  run,
LuminosityBlockNumber_t  lumi 
) const

Same as findPosition,except the entry type of the returned iterator will be kLumi or kEnd and the lumi argument must be nonzero. This means the next thing to be processed will be the lumi if it is found.

Definition at line 730 of file IndexIntoFile.cc.

References edm::IndexIntoFile::IndexIntoFileItr::advanceToLumi(), cms::cuda::assert(), findPosition(), invalidLumi, writedatasetfile::run, and mitigatedMETSequence_cff::U.

Referenced by containsLumi(), fwlite::EntryFinder::findLumi(), and edm::RootFile::setEntryAtLumi().

730  {
731  assert(lumi != invalidLumi);
732  IndexIntoFileItr iter = findPosition(run, lumi, 0U);
733  iter.advanceToLumi();
734  return iter;
735  }
assert(be >=bs)
static constexpr LuminosityBlockNumber_t invalidLumi
IndexIntoFileItr findPosition(RunNumber_t run, LuminosityBlockNumber_t lumi=0U, EventNumber_t event=0U) const

◆ findPosition() [1/2]

IndexIntoFile::IndexIntoFileItr edm::IndexIntoFile::findPosition ( RunNumber_t  run,
LuminosityBlockNumber_t  lumi = 0U,
EventNumber_t  event = 0U 
) const

Find a run, lumi, or event. Returns an iterator pointing at it. The iterator will always be in numericalOrder mode. If it is not found the entry type of the iterator will be kEnd. If it is found the entry type of the iterator will always be kRun so the next thing to be processed is the run containing the desired lumi or event or if looking for a run, the run itself. If the lumi and event arguments are 0 (invalid), then it will find a run. If only the event argument is 0 (invalid), then it will find a lumi. If will look for an event if all three arguments are nonzero or if only the lumi argument is 0 (invalid). Note that it will find the first match only so if there is more than one match then the others cannot be found with this method. The order of the search is by processHistoryID index, then run number, then lumi number, then event entry. If searching for a lumi the iterator will advance directly to the desired lumi after the run even if it is not the first lumi in the run. If searching for an event, the iterator will advance to the lumi containing the run and then the requested event after run even if there are other lumis earlier in that run and other events earlier in that lumi.

Definition at line 534 of file IndexIntoFile.cc.

References cms::cuda::assert(), begin(), empty(), mps_splice::entry, edmPickEvents::event, eventEntries(), eventNumbers(), fillEventNumbers(), fillRunOrLumiIndexes(), edm::IndexIntoFile::IndexIntoFileItr::initializeLumi(), edm::IndexIntoFile::IndexIntoFileItr::initializeRun(), invalidEntry, invalidEvent, invalidIndex, invalidLumi, kEnd, kRun, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, BXlumiParameters_cfi::lumi, numericalOrder, writedatasetfile::run, runOrLumiEntries_, runOrLumiIndexes(), and pfDeepBoostedJetPreprocessParams_cfi::upper_bound.

Referenced by findEventPosition(), findLumiPosition(), findPosition(), findRunPosition(), and edm::RootFile::goToEvent().

536  {
538 
539  bool lumiMissing = (lumi == 0 && event != 0);
540 
541  std::vector<RunOrLumiIndexes>::const_iterator iEnd = runOrLumiIndexes().end();
542  std::vector<RunOrLumiIndexes>::const_iterator phEnd;
543 
544  // Loop over ranges of entries with the same ProcessHistoryID
545  for (std::vector<RunOrLumiIndexes>::const_iterator phBegin = runOrLumiIndexes().begin(); phBegin != iEnd;
546  phBegin = phEnd) {
547  RunOrLumiIndexes el(phBegin->processHistoryIDIndex(), run, lumi, 0);
548  phEnd = std::upper_bound(phBegin, iEnd, el, Compare_Index());
549 
550  std::vector<RunOrLumiIndexes>::const_iterator iRun = std::lower_bound(phBegin, phEnd, el, Compare_Index_Run());
551 
552  if (iRun == phEnd || iRun->run() != run)
553  continue;
554 
555  if (lumi == invalidLumi && event == invalidEvent) {
556  IndexIntoFileItr indexItr(
558  indexItr.initializeRun();
559  return indexItr;
560  }
561 
562  std::vector<RunOrLumiIndexes>::const_iterator iRunEnd = std::upper_bound(iRun, phEnd, el, Compare_Index_Run());
563  if (!lumiMissing) {
564  std::vector<RunOrLumiIndexes>::const_iterator iLumi = std::lower_bound(iRun, iRunEnd, el);
565  if (iLumi == iRunEnd || iLumi->lumi() != lumi)
566  continue;
567 
568  if (event == invalidEvent) {
569  IndexIntoFileItr indexItr(this,
571  kRun,
572  iRun - runOrLumiIndexes().begin(),
573  iLumi - runOrLumiIndexes().begin(),
574  invalidIndex,
575  0,
576  0);
577  indexItr.initializeLumi();
578  return indexItr;
579  }
580 
581  long long beginEventNumbers = iLumi->beginEventNumbers();
582  long long endEventNumbers = iLumi->endEventNumbers();
583  if (beginEventNumbers >= endEventNumbers)
584  continue;
585 
586  long long indexToEvent = 0;
587  if (!eventEntries().empty()) {
588  std::vector<EventEntry>::const_iterator eventIter =
589  std::lower_bound(eventEntries().begin() + beginEventNumbers,
590  eventEntries().begin() + endEventNumbers,
591  EventEntry(event, invalidEntry));
592  if (eventIter == (eventEntries().begin() + endEventNumbers) || eventIter->event() != event)
593  continue;
594 
595  indexToEvent = eventIter - eventEntries().begin() - beginEventNumbers;
596  } else {
598  std::vector<EventNumber_t>::const_iterator eventIter = std::lower_bound(
599  eventNumbers().begin() + beginEventNumbers, eventNumbers().begin() + endEventNumbers, event);
600  if (eventIter == (eventNumbers().begin() + endEventNumbers) || *eventIter != event)
601  continue;
602 
603  indexToEvent = eventIter - eventNumbers().begin() - beginEventNumbers;
604  }
605 
606  int newIndexToLumi = iLumi - runOrLumiIndexes().begin();
607  while (runOrLumiEntries_[runOrLumiIndexes()[newIndexToLumi].indexToGetEntry()].entry() == invalidEntry) {
608  ++newIndexToLumi;
609  assert(static_cast<unsigned>(newIndexToLumi) < runOrLumiEntries_.size());
610  assert(runOrLumiIndexes()[newIndexToLumi].lumi() == lumi);
611  }
612 
613  return IndexIntoFileItr(this,
615  kRun,
616  iRun - runOrLumiIndexes().begin(),
617  newIndexToLumi,
618  iLumi - runOrLumiIndexes().begin(),
619  indexToEvent,
620  endEventNumbers - beginEventNumbers);
621  }
622  if (lumiMissing) {
623  std::vector<RunOrLumiIndexes>::const_iterator iLumi = iRun;
624  while (iLumi != iRunEnd && iLumi->lumi() == invalidLumi) {
625  ++iLumi;
626  }
627  if (iLumi == iRunEnd)
628  continue;
629 
630  std::vector<RunOrLumiIndexes>::const_iterator lumiEnd;
631  for (; iLumi != iRunEnd; iLumi = lumiEnd) {
632  RunOrLumiIndexes elWithLumi(phBegin->processHistoryIDIndex(), run, iLumi->lumi(), 0);
633  lumiEnd = std::upper_bound(iLumi, iRunEnd, elWithLumi);
634 
635  long long beginEventNumbers = iLumi->beginEventNumbers();
636  long long endEventNumbers = iLumi->endEventNumbers();
637  if (beginEventNumbers >= endEventNumbers)
638  continue;
639 
640  long long indexToEvent = 0;
641  if (!eventEntries().empty()) {
642  std::vector<EventEntry>::const_iterator eventIter =
643  std::lower_bound(eventEntries().begin() + beginEventNumbers,
644  eventEntries().begin() + endEventNumbers,
645  EventEntry(event, invalidEntry));
646  if (eventIter == (eventEntries().begin() + endEventNumbers) || eventIter->event() != event)
647  continue;
648  indexToEvent = eventIter - eventEntries().begin() - beginEventNumbers;
649  } else {
651  std::vector<EventNumber_t>::const_iterator eventIter = std::lower_bound(
652  eventNumbers().begin() + beginEventNumbers, eventNumbers().begin() + endEventNumbers, event);
653  if (eventIter == (eventNumbers().begin() + endEventNumbers) || *eventIter != event)
654  continue;
655  indexToEvent = eventIter - eventNumbers().begin() - beginEventNumbers;
656  }
657 
658  int newIndexToLumi = iLumi - runOrLumiIndexes().begin();
659  while (runOrLumiEntries_[runOrLumiIndexes()[newIndexToLumi].indexToGetEntry()].entry() == invalidEntry) {
660  ++newIndexToLumi;
661  assert(static_cast<unsigned>(newIndexToLumi) < runOrLumiEntries_.size());
662  assert(runOrLumiIndexes()[newIndexToLumi].lumi() == iLumi->lumi());
663  }
664 
665  return IndexIntoFileItr(this,
667  kRun,
668  iRun - runOrLumiIndexes().begin(),
669  newIndexToLumi,
670  iLumi - runOrLumiIndexes().begin(),
671  indexToEvent,
672  endEventNumbers - beginEventNumbers);
673  }
674  }
675  } // Loop over ProcessHistoryIDs
676 
677  return IndexIntoFileItr(this, numericalOrder, kEnd, invalidIndex, invalidIndex, invalidIndex, 0, 0);
678  }
IndexIntoFileItr begin(SortOrder sortOrder) const
std::vector< RunOrLumiIndexes > & runOrLumiIndexes() const
static constexpr int invalidIndex
void fillEventNumbers() const
std::vector< EventEntry > & eventEntries() const
assert(be >=bs)
static constexpr EventNumber_t invalidEvent
std::vector< RunOrLumiEntry > runOrLumiEntries_
bool empty() const
True if no runs, lumis, or events are in the file.
std::vector< EventNumber_t > & eventNumbers() const
static constexpr EntryNumber_t invalidEntry
static constexpr LuminosityBlockNumber_t invalidLumi
void fillRunOrLumiIndexes() const
Definition: event.py:1

◆ findPosition() [2/2]

IndexIntoFile::IndexIntoFileItr edm::IndexIntoFile::findPosition ( SortOrder  sortOrder,
RunNumber_t  run,
LuminosityBlockNumber_t  lumi = 0U,
EventNumber_t  event = 0U 
) const

Definition at line 680 of file IndexIntoFile.cc.

References edm::IndexIntoFile::IndexIntoFileItr::advanceToNextRun(), begin(), end(), findPosition(), getEventNumberOfEntry(), invalidEvent, invalidLumi, BXlumiParameters_cfi::lumi, numericalOrder, edm::IndexIntoFile::IndexIntoFileItr::peekAheadAtEventEntry(), edm::IndexIntoFile::IndexIntoFileItr::peekAheadAtLumi(), writedatasetfile::run, edm::IndexIntoFile::IndexIntoFileItr::run(), edm::IndexIntoFile::IndexIntoFileItr::skipLumiInRun(), and edm::IndexIntoFile::IndexIntoFileItr::skipToNextEventInLumi().

683  {
684  if (sortOrder == IndexIntoFile::numericalOrder) {
685  return findPosition(run, lumi, event); // a faster algorithm
686  }
687  IndexIntoFileItr itr = begin(sortOrder);
688  IndexIntoFileItr itrEnd = end(sortOrder);
689 
690  while (itr != itrEnd) {
691  if (itr.run() != run) {
692  itr.advanceToNextRun();
693  } else {
694  if (lumi == invalidLumi && event == invalidEvent) {
695  return itr;
696  } else if (lumi != invalidLumi && itr.peekAheadAtLumi() != lumi) {
697  if (!itr.skipLumiInRun()) {
698  itr.advanceToNextRun();
699  }
700  } else {
701  if (event == invalidEvent) {
702  return itr;
703  } else {
704  EventNumber_t eventNumber = getEventNumberOfEntry(itr.peekAheadAtEventEntry());
705  if (eventNumber == event) {
706  return itr;
707  } else {
708  if (!itr.skipToNextEventInLumi()) {
709  if (!itr.skipLumiInRun()) {
710  itr.advanceToNextRun();
711  }
712  }
713  }
714  }
715  }
716  }
717  }
718  return itrEnd;
719  }
IndexIntoFileItr end(SortOrder sortOrder) const
Used to end an iteration over the Runs, Lumis, and Events in a file.
IndexIntoFileItr begin(SortOrder sortOrder) const
unsigned long long EventNumber_t
static constexpr EventNumber_t invalidEvent
EventNumber_t getEventNumberOfEntry(EntryNumber_t entry) const
static constexpr LuminosityBlockNumber_t invalidLumi
IndexIntoFileItr findPosition(RunNumber_t run, LuminosityBlockNumber_t lumi=0U, EventNumber_t event=0U) const
Definition: event.py:1

◆ findRunPosition()

IndexIntoFile::IndexIntoFileItr edm::IndexIntoFile::findRunPosition ( RunNumber_t  run) const

Same as findPosition.

Definition at line 737 of file IndexIntoFile.cc.

References findPosition(), writedatasetfile::run, and mitigatedMETSequence_cff::U.

Referenced by containsRun(), fwlite::EntryFinder::findRun(), and edm::RootFile::setEntryAtRun().

737  {
738  return findPosition(run, 0U, 0U);
739  }
IndexIntoFileItr findPosition(RunNumber_t run, LuminosityBlockNumber_t lumi=0U, EventNumber_t event=0U) const

◆ fixIndexes()

void edm::IndexIntoFile::fixIndexes ( std::vector< ProcessHistoryID > &  processHistoryIDs)

Used by PoolSource to force the ProcessHistoryID indexes to be consistent across all input files. Currently this consistency is important when duplicate checking across all input files. It may be important for other reasons in the future. It is important this be called immediately after reading in the object from the input file, before filling the transient data members or using the indexes in any way.

Definition at line 363 of file IndexIntoFile.cc.

References spr::find(), B2GTnPMonitor_cfi::item, processHistoryIDs(), processHistoryIDs_, and runOrLumiEntries_.

Referenced by edm::RootFile::validateFile().

363  {
364  std::map<int, int> oldToNewIndex;
365  for (std::vector<ProcessHistoryID>::const_iterator iter = processHistoryIDs_.begin(),
366  iEnd = processHistoryIDs_.end();
367  iter != iEnd;
368  ++iter) {
369  std::vector<ProcessHistoryID>::const_iterator iterExisting =
370  std::find(processHistoryIDs.begin(), processHistoryIDs.end(), *iter);
371  if (iterExisting == processHistoryIDs.end()) {
372  oldToNewIndex[iter - processHistoryIDs_.begin()] = processHistoryIDs.size();
373  processHistoryIDs.push_back(*iter);
374  } else {
375  oldToNewIndex[iter - processHistoryIDs_.begin()] = iterExisting - processHistoryIDs.begin();
376  }
377  }
379 
380  for (RunOrLumiEntry& item : runOrLumiEntries_) {
381  item.setProcessHistoryIDIndex(oldToNewIndex[item.processHistoryIDIndex()]);
382  }
383  }
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::vector< RunOrLumiEntry > runOrLumiEntries_
std::vector< ProcessHistoryID > processHistoryIDs_
std::vector< ProcessHistoryID > const & processHistoryIDs() const

◆ getEventNumberOfEntry()

EventNumber_t edm::IndexIntoFile::getEventNumberOfEntry ( EntryNumber_t  entry) const
inlineprivate

Definition at line 1292 of file IndexIntoFile.h.

References mps_splice::entry, edm::IndexIntoFile::Transients::eventFinder_, and transient_.

Referenced by fillUnsortedEventNumbers(), and findPosition().

1292  {
1293  return transient_.eventFinder_->getEventNumberOfEntry(entry);
1294  }
edm::propagate_const< std::shared_ptr< EventFinder > > eventFinder_

◆ initializeTransients()

void edm::IndexIntoFile::initializeTransients ( )
inline

◆ inputFileClosed()

void edm::IndexIntoFile::inputFileClosed ( )

Clear some vectors and eventFinder when an input file is closed. This reduces the memory used by IndexIntoFile

Definition at line 292 of file IndexIntoFile.cc.

References eventEntries(), resetEventFinder(), runOrLumiIndexes(), edm::swap(), and unsortedEventNumbers().

292  {
293  std::vector<EventEntry>().swap(eventEntries());
294  std::vector<RunOrLumiIndexes>().swap(runOrLumiIndexes());
295  std::vector<EventNumber_t>().swap(unsortedEventNumbers());
297  }
std::vector< RunOrLumiIndexes > & runOrLumiIndexes() const
std::vector< EventEntry > & eventEntries() const
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
std::vector< EventNumber_t > & unsortedEventNumbers()
void resetEventFinder() const

◆ iterationWillBeInEntryOrder()

bool edm::IndexIntoFile::iterationWillBeInEntryOrder ( SortOrder  sortOrder) const

Used to determine whether or not to disable fast cloning.

Definition at line 519 of file IndexIntoFile.cc.

References begin(), end(), invalidEntry, and kEvent.

Referenced by edm::postIndexIntoFilePrintEventLists(), and edm::RootFile::setIfFastClonable().

519  {
520  EntryNumber_t maxEntry = invalidEntry;
521  for (IndexIntoFileItr it = begin(sortOrder), itEnd = end(sortOrder); it != itEnd; ++it) {
522  if (it.getEntryType() == kEvent) {
523  if (it.entry() < maxEntry) {
524  return false;
525  }
526  maxEntry = it.entry();
527  }
528  }
529  return true;
530  }
IndexIntoFileItr end(SortOrder sortOrder) const
Used to end an iteration over the Runs, Lumis, and Events in a file.
IndexIntoFileItr begin(SortOrder sortOrder) const
long long EntryNumber_t
static constexpr EntryNumber_t invalidEntry

◆ lumiToOrder()

std::map<IndexRunLumiKey, EntryNumber_t>& edm::IndexIntoFile::lumiToOrder ( ) const
inlineprivate

Definition at line 1284 of file IndexIntoFile.h.

References edm::IndexIntoFile::Transients::lumiToOrder_, and transient_.

Referenced by addLumi().

1284 { return transient_.lumiToOrder_; }
std::map< IndexRunLumiKey, EntryNumber_t > lumiToOrder_

◆ numberOfEvents()

size_t edm::IndexIntoFile::numberOfEvents ( ) const
inlineprivate

◆ previousAddedIndex()

int& edm::IndexIntoFile::previousAddedIndex ( ) const
inlineprivate

◆ processHistoryID()

ProcessHistoryID const & edm::IndexIntoFile::processHistoryID ( int  i) const

Definition at line 55 of file IndexIntoFile.cc.

References mps_fire::i, and processHistoryIDs_.

Referenced by addEntry(), and edm::RootFile::readCurrentEvent().

55 { return processHistoryIDs_.at(i); }
std::vector< ProcessHistoryID > processHistoryIDs_

◆ processHistoryIDs()

std::vector< ProcessHistoryID > const & edm::IndexIntoFile::processHistoryIDs ( ) const

Definition at line 57 of file IndexIntoFile.cc.

References processHistoryIDs_.

Referenced by fixIndexes().

57 { return processHistoryIDs_; }
std::vector< ProcessHistoryID > processHistoryIDs_

◆ reduceProcessHistoryIDs()

void edm::IndexIntoFile::reduceProcessHistoryIDs ( ProcessHistoryRegistry const &  processHistoryRegistry)

Used for backward compatibility to convert objects created with releases that used the full ProcessHistoryID in IndexIntoFile to use the reduced ProcessHistoryID.

Definition at line 301 of file IndexIntoFile.cc.

References B2GTnPMonitor_cfi::item, processHistoryIDs_, edm::ProcessHistoryRegistry::reducedProcessHistoryID(), and runOrLumiEntries_.

Referenced by edm::RootFile::validateFile().

301  {
302  std::vector<ProcessHistoryID> reducedPHIDs;
303 
304  std::map<ProcessHistoryID, int> reducedPHIDToIndex;
305  std::pair<ProcessHistoryID, int> mapEntry(ProcessHistoryID(), 0);
306  std::pair<std::map<ProcessHistoryID, int>::iterator, bool> insertResult;
307 
308  std::vector<int> phidIndexConverter;
309  for (auto const& phid : processHistoryIDs_) {
310  ProcessHistoryID const& reducedPHID = processHistoryRegistry.reducedProcessHistoryID(phid);
311  mapEntry.first = reducedPHID;
312  insertResult = reducedPHIDToIndex.insert(mapEntry);
313 
314  if (insertResult.second) {
315  insertResult.first->second = reducedPHIDs.size();
316  reducedPHIDs.push_back(reducedPHID);
317  }
318  phidIndexConverter.push_back(insertResult.first->second);
319  }
320  processHistoryIDs_.swap(reducedPHIDs);
321 
322  // If the size of the vector of IDs does not change
323  // then their indexes and the ordering of the Runs and
324  // and Lumis does not change, so we are done.
325  if (processHistoryIDs_.size() == reducedPHIDs.size()) {
326  return;
327  }
328 
329  std::map<IndexIntoFile::IndexRunKey, int> runOrderMap;
330  std::pair<std::map<IndexIntoFile::IndexRunKey, int>::iterator, bool> runInsertResult;
331 
332  std::map<IndexIntoFile::IndexRunLumiKey, int> lumiOrderMap;
333  std::pair<std::map<IndexIntoFile::IndexRunLumiKey, int>::iterator, bool> lumiInsertResult;
334 
335  // loop over all the RunOrLumiEntry's
336  for (auto& item : runOrLumiEntries_) {
337  // Convert the process history index so it points into the new vector of reduced IDs
338  item.setProcessHistoryIDIndex(phidIndexConverter.at(item.processHistoryIDIndex()));
339 
340  // Convert the phid-run order
341  IndexIntoFile::IndexRunKey runKey(item.processHistoryIDIndex(), item.run());
342  runInsertResult = runOrderMap.insert(std::pair<IndexIntoFile::IndexRunKey, int>(runKey, 0));
343  if (runInsertResult.second) {
344  runInsertResult.first->second = item.orderPHIDRun();
345  } else {
346  item.setOrderPHIDRun(runInsertResult.first->second);
347  }
348 
349  // Convert the phid-run-lumi order for the lumi entries
350  if (item.lumi() != 0) {
351  IndexIntoFile::IndexRunLumiKey lumiKey(item.processHistoryIDIndex(), item.run(), item.lumi());
352  lumiInsertResult = lumiOrderMap.insert(std::pair<IndexIntoFile::IndexRunLumiKey, int>(lumiKey, 0));
353  if (lumiInsertResult.second) {
354  lumiInsertResult.first->second = item.orderPHIDRunLumi();
355  } else {
356  item.setOrderPHIDRunLumi(lumiInsertResult.first->second);
357  }
358  }
359  }
360  std::stable_sort(runOrLumiEntries_.begin(), runOrLumiEntries_.end());
361  }
std::vector< RunOrLumiEntry > runOrLumiEntries_
std::vector< ProcessHistoryID > processHistoryIDs_
Hash< ProcessHistoryType > ProcessHistoryID

◆ resetEventFinder()

void edm::IndexIntoFile::resetEventFinder ( ) const
inlineprivate

Definition at line 1277 of file IndexIntoFile.h.

References edm::IndexIntoFile::Transients::eventFinder_, and transient_.

Referenced by inputFileClosed().

1277 { transient_.eventFinder_ = nullptr; } // propagate_const<T> has no reset() function
edm::propagate_const< std::shared_ptr< EventFinder > > eventFinder_

◆ runOrLumiEntries()

std::vector<RunOrLumiEntry> const& edm::IndexIntoFile::runOrLumiEntries ( ) const
inline

Used internally and for test purposes.

Definition at line 1236 of file IndexIntoFile.h.

References runOrLumiEntries_.

Referenced by edm::IndexIntoFile::IndexIntoFileItrEntryOrder::addRunsWithNoEvents(), empty(), endRunOrLumi(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::EntryOrderInitializationInfo::fillIndexesSortedByEventEntry(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::EntryOrderInitializationInfo::fillIndexesToLastContiguousEvents(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::fillLumisWithNoRemainingEvents(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::EntryOrderInitializationInfo::gatherNeededInfo(), edm::IndexIntoFile::IndexIntoFileItrNoSort::getRunOrLumiEntryType(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::handleLumiEntriesNoRemainingEvents(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::handleLumisWithNoEvents(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::handleLumiWithEvents(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::handleToEndOfContiguousEventsInLumis(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::handleToEndOfContiguousEventsInRun(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::IndexIntoFileItrEntryOrder(), edm::IndexIntoFile::IndexIntoFileItrNoSort::initializeLumi_(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::lowestInLumi(), edm::IndexIntoFile::IndexIntoFileItrNoSort::nextEventRange(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::EntryOrderInitializationInfo::nextEventSequence(), edm::IndexIntoFile::IndexIntoFileItrNoSort::previousEventRange(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::EntryOrderInitializationInfo::resizeVectors(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::runOrLumisEntry(), edm::IndexIntoFile::IndexIntoFileItrNoSort::setToLastEventInRange(), edm::IndexIntoFile::IndexIntoFileItrNoSort::skipLumiInRun(), and edm::IndexIntoFile::SortedRunOrLumiItr::SortedRunOrLumiItr().

1236 { return runOrLumiEntries_; }
std::vector< RunOrLumiEntry > runOrLumiEntries_

◆ runOrLumiIndexes()

std::vector<RunOrLumiIndexes>& edm::IndexIntoFile::runOrLumiIndexes ( ) const
inlineprivate

◆ runToOrder()

std::map<IndexRunKey, EntryNumber_t>& edm::IndexIntoFile::runToOrder ( ) const
inlineprivate

Definition at line 1283 of file IndexIntoFile.h.

References edm::IndexIntoFile::Transients::runToOrder_, and transient_.

Referenced by addEntry(), and sortVector_Run_Or_Lumi_Entries().

1283 { return transient_.runToOrder_; }
std::map< IndexRunKey, EntryNumber_t > runToOrder_

◆ set_intersection()

void edm::IndexIntoFile::set_intersection ( IndexIntoFile const &  indexIntoFile,
std::set< IndexRunLumiEventKey > &  intersection 
) const

The intersection argument will be filled with an entry for each event in both IndexIntoFile objects. To be added the event must have the same ProcessHistoryID index, run number, lumi number and event number.

Definition at line 761 of file IndexIntoFile.cc.

References begin(), edm::IndexIntoFile::RunOrLumiIndexes::beginEventNumbers(), beginRunOrLumi(), empty(), edm::IndexIntoFile::RunOrLumiIndexes::endEventNumbers(), endRunOrLumi(), mps_splice::entry, eventEntries(), eventNumbers(), fillEventNumbers(), fillRunOrLumiIndexes(), reco::helper::VirtualJetProducerHelper::intersection(), edm::IndexIntoFile::RunOrLumiIndexes::isRun(), edm::IndexIntoFile::SortedRunOrLumiItr::isRun(), edm::IndexIntoFile::RunOrLumiIndexes::lumi(), edm::IndexIntoFile::RunOrLumiIndexes::processHistoryIDIndex(), edm::IndexIntoFile::RunOrLumiIndexes::run(), edm::IndexIntoFile::SortedRunOrLumiItr::runOrLumiIndexes(), runOrLumiIndexes(), and DBoxMetadataHelper::set_intersection().

Referenced by edm::DuplicateChecker::inputFileOpened().

762  {
763  if (empty() || indexIntoFile.empty())
764  return;
766  indexIntoFile.fillRunOrLumiIndexes();
767  RunOrLumiIndexes const& back1 = runOrLumiIndexes().back();
768  RunOrLumiIndexes const& back2 = indexIntoFile.runOrLumiIndexes().back();
769 
770  // Very quick decision if the run ranges in the two files do not overlap
771  if (back2 < runOrLumiIndexes().front())
772  return;
773  if (back1 < indexIntoFile.runOrLumiIndexes().front())
774  return;
775 
776  SortedRunOrLumiItr iter1 = beginRunOrLumi();
777  SortedRunOrLumiItr iEnd1 = endRunOrLumi();
778 
779  SortedRunOrLumiItr iter2 = indexIntoFile.beginRunOrLumi();
780  SortedRunOrLumiItr iEnd2 = indexIntoFile.endRunOrLumi();
781 
782  // Quick decision if the lumi ranges in the two files do not overlap
783  while (iter1 != iEnd1 && iter1.isRun())
784  ++iter1;
785  if (iter1 == iEnd1)
786  return;
787  if (back2 < iter1.runOrLumiIndexes())
788  return;
789 
790  while (iter2 != iEnd2 && iter2.isRun())
791  ++iter2;
792  if (iter2 == iEnd2)
793  return;
794  if (back1 < iter2.runOrLumiIndexes())
795  return;
796 
797  RunOrLumiIndexes const* previousIndexes = nullptr;
798 
799  // Loop through the both IndexIntoFile objects and look for matching lumis
800  while (iter1 != iEnd1 && iter2 != iEnd2) {
801  RunOrLumiIndexes const& indexes1 = iter1.runOrLumiIndexes();
802  RunOrLumiIndexes const& indexes2 = iter2.runOrLumiIndexes();
803  if (indexes1 < indexes2) {
804  ++iter1;
805  } else if (indexes2 < indexes1) {
806  ++iter2;
807  } else { // they are equal
808 
809  // Skip them if it is a run or the same lumi
810  if (indexes1.isRun() || (previousIndexes && !(*previousIndexes < indexes1))) {
811  ++iter1;
812  ++iter2;
813  } else {
814  previousIndexes = &indexes1;
815 
816  // Found a matching lumi, now look for matching events
817 
818  long long beginEventNumbers1 = indexes1.beginEventNumbers();
819  long long endEventNumbers1 = indexes1.endEventNumbers();
820 
821  long long beginEventNumbers2 = indexes2.beginEventNumbers();
822  long long endEventNumbers2 = indexes2.endEventNumbers();
823 
824  // there must be at least 1 event in each lumi for there to be any matches
825  if ((beginEventNumbers1 >= endEventNumbers1) || (beginEventNumbers2 >= endEventNumbers2)) {
826  ++iter1;
827  ++iter2;
828  continue;
829  }
830 
831  if (!eventEntries().empty() && !indexIntoFile.eventEntries().empty()) {
832  std::vector<EventEntry> matchingEvents;
833  std::insert_iterator<std::vector<EventEntry> > insertIter(matchingEvents, matchingEvents.begin());
834  std::set_intersection(eventEntries().begin() + beginEventNumbers1,
835  eventEntries().begin() + endEventNumbers1,
836  indexIntoFile.eventEntries().begin() + beginEventNumbers2,
837  indexIntoFile.eventEntries().begin() + endEventNumbers2,
838  insertIter);
839  for (EventEntry const& entry : matchingEvents) {
840  intersection.insert(IndexRunLumiEventKey(
841  indexes1.processHistoryIDIndex(), indexes1.run(), indexes1.lumi(), entry.event()));
842  }
843  } else {
845  indexIntoFile.fillEventNumbers();
846  std::vector<EventNumber_t> matchingEvents;
847  std::insert_iterator<std::vector<EventNumber_t> > insertIter(matchingEvents, matchingEvents.begin());
848  std::set_intersection(eventNumbers().begin() + beginEventNumbers1,
849  eventNumbers().begin() + endEventNumbers1,
850  indexIntoFile.eventNumbers().begin() + beginEventNumbers2,
851  indexIntoFile.eventNumbers().begin() + endEventNumbers2,
852  insertIter);
853  for (EventNumber_t const& eventNumber : matchingEvents) {
854  intersection.insert(
855  IndexRunLumiEventKey(indexes1.processHistoryIDIndex(), indexes1.run(), indexes1.lumi(), eventNumber));
856  }
857  }
858  }
859  }
860  }
861  }
IndexIntoFileItr begin(SortOrder sortOrder) const
std::vector< RunOrLumiIndexes > & runOrLumiIndexes() const
void fillEventNumbers() const
unsigned long long EventNumber_t
std::vector< EventEntry > & eventEntries() const
SortedRunOrLumiItr endRunOrLumi() const
bool empty() const
True if no runs, lumis, or events are in the file.
std::vector< EventNumber_t > & eventNumbers() const
void fillRunOrLumiIndexes() const
SortedRunOrLumiItr beginRunOrLumi() const
std::vector< std::string > set_intersection(std::vector< std::string > const &v1, std::vector< std::string > const &v2)

◆ setEventFinder()

void edm::IndexIntoFile::setEventFinder ( std::shared_ptr< EventFinder ptr)
inline

Calling this enables the functions that fill the event vectors to get the event numbers. It needs to be called before filling the events vectors This implies the client needs to define a class that inherits from EventFinder and then create one. This function is used to pass in a pointer to its base class.

Definition at line 1165 of file IndexIntoFile.h.

References edm::IndexIntoFile::Transients::eventFinder_, and transient_.

Referenced by fwlite::EntryFinder::fillIndex(), and edm::RootFile::validateFile().

1165 { transient_.eventFinder_ = ptr; }
edm::propagate_const< std::shared_ptr< EventFinder > > eventFinder_

◆ setNumberOfEvents()

void edm::IndexIntoFile::setNumberOfEvents ( EntryNumber_t  nevents)
inline

The number of events needs to be set before filling the transient event vectors. It is used to resize them.

Definition at line 1158 of file IndexIntoFile.h.

References createIOVlist::nevents, edm::IndexIntoFile::Transients::numberOfEvents_, and transient_.

Referenced by addEntry(), fwlite::EntryFinder::fillIndex(), and edm::RootFile::validateFile().

◆ setProcessHistoryIDs()

std::vector<ProcessHistoryID>& edm::IndexIntoFile::setProcessHistoryIDs ( )
inline

Used for backward compatibility and tests. RootFile::fillIndexIntoFile uses this to deal with input files created with releases before 3_8_0 which do not contain an IndexIntoFile.

Definition at line 1225 of file IndexIntoFile.h.

References processHistoryIDs_.

Referenced by edm::RootFile::fillIndexIntoFile(), and edm::RootFile::validateFile().

1225 { return processHistoryIDs_; }
std::vector< ProcessHistoryID > processHistoryIDs_

◆ setRunOrLumiEntries()

std::vector<RunOrLumiEntry>& edm::IndexIntoFile::setRunOrLumiEntries ( )
inline

Used for backward compatibility and tests. RootFile::fillIndexIntoFile uses this to deal with input files created with releases before 3_8_0 which do not contain an IndexIntoFile.

Definition at line 1220 of file IndexIntoFile.h.

References runOrLumiEntries_.

Referenced by edm::RootFile::fillIndexIntoFile().

1220 { return runOrLumiEntries_; }
std::vector< RunOrLumiEntry > runOrLumiEntries_

◆ sortEventEntries()

void edm::IndexIntoFile::sortEventEntries ( ) const
private

Definition at line 481 of file IndexIntoFile.cc.

References cms::cuda::assert(), begin(), eventEntries(), fillRunOrLumiIndexes(), runOrLumiIndexes(), and jetUpdater_cfi::sort.

Referenced by fillEventNumbersOrEntries().

481  {
483  std::vector<RunOrLumiIndexes>::iterator beginOfLumi = runOrLumiIndexes().begin();
484  std::vector<RunOrLumiIndexes>::iterator endOfLumi = beginOfLumi;
485  std::vector<RunOrLumiIndexes>::iterator iEnd = runOrLumiIndexes().end();
486  while (true) {
487  while (beginOfLumi != iEnd && beginOfLumi->isRun()) {
488  ++beginOfLumi;
489  }
490  if (beginOfLumi == iEnd)
491  break;
492 
493  endOfLumi = beginOfLumi + 1;
494  while (endOfLumi != iEnd && beginOfLumi->processHistoryIDIndex() == endOfLumi->processHistoryIDIndex() &&
495  beginOfLumi->run() == endOfLumi->run() && beginOfLumi->lumi() == endOfLumi->lumi()) {
496  ++endOfLumi;
497  }
498  assert(beginOfLumi->endEventNumbers() >= 0);
499  assert(beginOfLumi->endEventNumbers() <= static_cast<long long>(eventEntries().size()));
500  std::sort(eventEntries().begin() + beginOfLumi->beginEventNumbers(),
501  eventEntries().begin() + beginOfLumi->endEventNumbers());
502  beginOfLumi = endOfLumi;
503  }
504  }
IndexIntoFileItr begin(SortOrder sortOrder) const
std::vector< RunOrLumiIndexes > & runOrLumiIndexes() const
std::vector< EventEntry > & eventEntries() const
assert(be >=bs)
void fillRunOrLumiIndexes() const

◆ sortEvents()

void edm::IndexIntoFile::sortEvents ( ) const
private

Definition at line 456 of file IndexIntoFile.cc.

References cms::cuda::assert(), begin(), eventNumbers(), fillRunOrLumiIndexes(), runOrLumiIndexes(), and jetUpdater_cfi::sort.

Referenced by fillEventNumbersOrEntries().

456  {
458  std::vector<RunOrLumiIndexes>::iterator beginOfLumi = runOrLumiIndexes().begin();
459  std::vector<RunOrLumiIndexes>::iterator endOfLumi = beginOfLumi;
460  std::vector<RunOrLumiIndexes>::iterator iEnd = runOrLumiIndexes().end();
461  while (true) {
462  while (beginOfLumi != iEnd && beginOfLumi->isRun()) {
463  ++beginOfLumi;
464  }
465  if (beginOfLumi == iEnd)
466  break;
467 
468  endOfLumi = beginOfLumi + 1;
469  while (endOfLumi != iEnd && beginOfLumi->processHistoryIDIndex() == endOfLumi->processHistoryIDIndex() &&
470  beginOfLumi->run() == endOfLumi->run() && beginOfLumi->lumi() == endOfLumi->lumi()) {
471  ++endOfLumi;
472  }
473  assert(beginOfLumi->endEventNumbers() >= 0);
474  assert(beginOfLumi->endEventNumbers() <= static_cast<long long>(eventNumbers().size()));
475  std::sort(eventNumbers().begin() + beginOfLumi->beginEventNumbers(),
476  eventNumbers().begin() + beginOfLumi->endEventNumbers());
477  beginOfLumi = endOfLumi;
478  }
479  }
IndexIntoFileItr begin(SortOrder sortOrder) const
std::vector< RunOrLumiIndexes > & runOrLumiIndexes() const
assert(be >=bs)
std::vector< EventNumber_t > & eventNumbers() const
void fillRunOrLumiIndexes() const

◆ sortVector_Run_Or_Lumi_Entries()

void edm::IndexIntoFile::sortVector_Run_Or_Lumi_Entries ( )

Used by RootOutputModule after all entries have been added. This only works after the correct sequence of addEntry calls, because it makes some corrections before sorting. A std::stable_sort works in cases where those corrections are not needed.

Definition at line 385 of file IndexIntoFile.cc.

References checkForMissingRunOrLumiEntry(), Exception, B2GTnPMonitor_cfi::item, edm::errors::LogicError, runOrLumiEntries_, runToOrder(), and edm::stable_sort_all().

Referenced by edm::RootOutputFile::writeIndexIntoFile().

385  {
386  for (RunOrLumiEntry& item : runOrLumiEntries_) {
387  std::map<IndexRunKey, EntryNumber_t>::const_iterator keyAndOrder =
388  runToOrder().find(IndexRunKey(item.processHistoryIDIndex(), item.run()));
389  if (keyAndOrder == runToOrder().end()) {
391  << "In IndexIntoFile::sortVector_Run_Or_Lumi_Entries. A run entry is missing.\n"
392  << "This means the IndexIntoFile product in the output file will be corrupted.\n"
393  << "The output file will be unusable for most purposes.\n"
394  << "If this occurs after an unrelated exception was thrown in\n"
395  << "endLuminosityBlock or endRun then ignore this exception and fix\n"
396  << "the primary exception. This is an expected side effect.\n"
397  << "Otherwise please report this to the core framework developers\n";
398  }
399  item.setOrderPHIDRun(keyAndOrder->second);
400  }
403  }
void stable_sort_all(RandomAccessSequence &s)
wrappers for std::stable_sort
Definition: Algorithms.h:103
void checkForMissingRunOrLumiEntry() const
Run this check just after sorting.
std::vector< RunOrLumiEntry > runOrLumiEntries_
std::map< IndexRunKey, EntryNumber_t > & runToOrder() const

◆ unsortedEventNumbers() [1/2]

std::vector<EventNumber_t>& edm::IndexIntoFile::unsortedEventNumbers ( )
inline

If something external to IndexIntoFile is reading through the EventAuxiliary then it could use this to fill in the event numbers so that IndexIntoFile will not read through it again.

Definition at line 1207 of file IndexIntoFile.h.

References transient_, and edm::IndexIntoFile::Transients::unsortedEventNumbers_.

Referenced by doneFileInitialization(), fillEventNumbersOrEntries(), edm::RootFile::fillIndexIntoFile(), fillUnsortedEventNumbers(), and inputFileClosed().

std::vector< EventNumber_t > unsortedEventNumbers_

◆ unsortedEventNumbers() [2/2]

std::vector<EventNumber_t> const& edm::IndexIntoFile::unsortedEventNumbers ( ) const
inline

Definition at line 1208 of file IndexIntoFile.h.

References transient_, and edm::IndexIntoFile::Transients::unsortedEventNumbers_.

std::vector< EventNumber_t > unsortedEventNumbers_

◆ unsortedEventNumbersMutable()

std::vector<EventNumber_t>& edm::IndexIntoFile::unsortedEventNumbersMutable ( ) const
inlineprivate

Definition at line 1275 of file IndexIntoFile.h.

References transient_, and edm::IndexIntoFile::Transients::unsortedEventNumbers_.

Referenced by fillUnsortedEventNumbers().

std::vector< EventNumber_t > unsortedEventNumbers_

Friends And Related Function Documentation

◆ ::TestIndexIntoFile

friend class ::TestIndexIntoFile
friend

Definition at line 1264 of file IndexIntoFile.h.

◆ ::TestIndexIntoFile1

friend class ::TestIndexIntoFile1
friend

Definition at line 1265 of file IndexIntoFile.h.

◆ ::TestIndexIntoFile2

friend class ::TestIndexIntoFile2
friend

Definition at line 1266 of file IndexIntoFile.h.

◆ ::TestIndexIntoFile3

friend class ::TestIndexIntoFile3
friend

Definition at line 1267 of file IndexIntoFile.h.

◆ ::TestIndexIntoFile4

friend class ::TestIndexIntoFile4
friend

Definition at line 1268 of file IndexIntoFile.h.

◆ ::TestIndexIntoFile5

friend class ::TestIndexIntoFile5
friend

Definition at line 1269 of file IndexIntoFile.h.

Member Data Documentation

◆ invalidEntry

IndexIntoFile::EntryNumber_t const edm::IndexIntoFile::invalidEntry = -1LL
static

Definition at line 266 of file IndexIntoFile.h.

Referenced by addEntry(), addLumi(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::addRunsWithNoEvents(), checkForMissingRunOrLumiEntry(), edm::IndexIntoFile::IndexIntoFileItrNoSort::entry(), edm::IndexIntoFile::IndexIntoFileItrSorted::entry(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::entry(), fillEventNumbersOrEntries(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::EntryOrderInitializationInfo::fillIndexesSortedByEventEntry(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::EntryOrderInitializationInfo::fillIndexesToLastContiguousEvents(), edm::RootFile::fillIndexIntoFile(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::fillLumisWithNoRemainingEvents(), fillRunOrLumiIndexes(), findPosition(), edm::IndexIntoFile::IndexIntoFileItrImpl::firstEventEntryThisLumi(), edm::IndexIntoFile::IndexIntoFileItrImpl::firstEventEntryThisRun(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::EntryOrderInitializationInfo::gatherNeededInfo(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::handleLumiEntriesNoRemainingEvents(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::handleLumisWithNoEvents(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::handleLumiWithEvents(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::handleToEndOfContiguousEventsInLumis(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::IndexIntoFileItrEntryOrder(), edm::RootFile::initializeDuplicateChecker(), edm::RootFile::initializeFirstProcessBlockEntry(), edm::IndexIntoFile::IndexIntoFileItrNoSort::initializeLumi_(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::initializeLumi_(), iterationWillBeInEntryOrder(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::lowestInLumi(), edm::IndexIntoFile::IndexIntoFileItrNoSort::lumiIterationStartingIndex(), edm::IndexIntoFile::IndexIntoFileItrSorted::lumiIterationStartingIndex(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::lumiIterationStartingIndex(), edm::IndexIntoFile::IndexIntoFileItrNoSort::nextEventRange(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::nextEventRange(), edm::IndexIntoFile::IndexIntoFileItrNoSort::peekAheadAtEventEntry(), edm::IndexIntoFile::IndexIntoFileItrSorted::peekAheadAtEventEntry(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::peekAheadAtEventEntry(), edm::IndexIntoFile::IndexIntoFileItrNoSort::previousEventRange(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::previousEventRange(), edm::RootFile::readLuminosityBlockAuxiliary_(), edm::RootEmbeddedFileSequence::readOneSequential(), edm::RootFile::readRunAuxiliary_(), edm::IndexIntoFile::Transients::reset(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::EntryOrderInitializationInfo::resizeVectors(), edm::RootTree::rewindToInvalid(), edm::RootEmbeddedFileSequence::RootEmbeddedFileSequence(), edm::IndexIntoFile::IndexIntoFileItrNoSort::setToLastEventInRange(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::setToLastEventInRange(), edm::RootEmbeddedFileSequence::skipEntries(), edm::IndexIntoFile::IndexIntoFileItrImpl::skipEventBackward(), edm::IndexIntoFile::IndexIntoFileItrImpl::skipEventForward(), edm::RootFile::skipEvents(), and edm::RootFile::wasFirstEventJustRead().

◆ invalidEvent

EventNumber_t const edm::IndexIntoFile::invalidEvent = 0U
static

◆ invalidIndex

int const edm::IndexIntoFile::invalidIndex = -1
static

Definition at line 262 of file IndexIntoFile.h.

Referenced by addEntry(), edm::IndexIntoFile::IndexIntoFileItrImpl::advanceToNextLumiOrRun(), begin(), end(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::EntryOrderInitializationInfo::fillIndexesSortedByEventEntry(), findPosition(), edm::IndexIntoFile::IndexIntoFileItrImpl::firstEventEntryThisLumi(), edm::IndexIntoFile::IndexIntoFileItrImpl::firstEventEntryThisRun(), edm::IndexIntoFile::IndexIntoFileItrNoSort::initializeLumi_(), edm::IndexIntoFile::IndexIntoFileItrSorted::initializeLumi_(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::initializeLumi_(), edm::IndexIntoFile::IndexIntoFileItrImpl::initializeRun(), edm::IndexIntoFile::IndexIntoFileItrNoSort::nextEventRange(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::nextEventRange(), edm::IndexIntoFile::IndexIntoFileItrNoSort::peekAheadAtEventEntry(), edm::IndexIntoFile::IndexIntoFileItrSorted::peekAheadAtEventEntry(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::peekAheadAtEventEntry(), edm::IndexIntoFile::IndexIntoFileItrNoSort::peekAheadAtLumi(), edm::IndexIntoFile::IndexIntoFileItrSorted::peekAheadAtLumi(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::peekAheadAtLumi(), edm::IndexIntoFile::IndexIntoFileItrNoSort::previousEventRange(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::previousEventRange(), edm::IndexIntoFile::IndexIntoFileItrImpl::previousLumiWithEvents(), edm::IndexIntoFile::IndexIntoFileItrNoSort::processHistoryIDIndex(), edm::IndexIntoFile::IndexIntoFileItrSorted::processHistoryIDIndex(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::processHistoryIDIndex(), edm::IndexIntoFile::Transients::reset(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::EntryOrderInitializationInfo::resizeVectors(), edm::IndexIntoFile::IndexIntoFileItrImpl::setInvalid(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::shouldProcessLumi(), edm::IndexIntoFile::IndexIntoFileItrEntryOrder::shouldProcessRun(), edm::IndexIntoFile::IndexIntoFileItrImpl::skipEventBackward(), edm::IndexIntoFile::IndexIntoFileItrImpl::skipEventForward(), edm::RootFile::skipEvents(), edm::IndexIntoFile::IndexIntoFileItrNoSort::skipLumiInRun(), edm::IndexIntoFile::IndexIntoFileItrSorted::skipLumiInRun(), and edm::IndexIntoFile::IndexIntoFileItrEntryOrder::skipLumiInRun().

◆ invalidLumi

LuminosityBlockNumber_t const edm::IndexIntoFile::invalidLumi = 0U
static

◆ invalidRun

RunNumber_t const edm::IndexIntoFile::invalidRun = 0U
static

◆ processHistoryIDs_

std::vector<ProcessHistoryID> edm::IndexIntoFile::processHistoryIDs_
private

◆ runOrLumiEntries_

std::vector<RunOrLumiEntry> edm::IndexIntoFile::runOrLumiEntries_
private

◆ transient_

Transients edm::IndexIntoFile::transient_
mutableprivate