CMS 3D CMS Logo

IndexIntoFile.h
Go to the documentation of this file.
1 #ifndef DataFormats_Provenance_IndexIntoFile_h
2 #define DataFormats_Provenance_IndexIntoFile_h
3 
234 
235 #include <memory>
236 
237 #include <cassert>
238 #include <iosfwd>
239 #include <map>
240 #include <set>
241 #include <vector>
242 
243 class TestIndexIntoFile;
244 class TestIndexIntoFile1;
245 class TestIndexIntoFile2;
246 class TestIndexIntoFile3;
247 class TestIndexIntoFile4;
248 class TestIndexIntoFile5;
249 
250 namespace edm {
251 
252  class ProcessHistoryRegistry;
253  class RootFile;
254 
256  public:
257  class IndexIntoFileItr;
258  class SortedRunOrLumiItr;
259  class IndexRunLumiEventKey;
260 
261  using EntryNumber_t = long long;
262  static constexpr int invalidIndex = -1;
267 
269 
270  IndexIntoFile();
271  ~IndexIntoFile();
272 
273  ProcessHistoryID const& processHistoryID(int i) const;
274  std::vector<ProcessHistoryID> const& processHistoryIDs() const;
275 
332 
334 
337  IndexIntoFileItr begin(SortOrder sortOrder) const;
338 
340  IndexIntoFileItr end(SortOrder sortOrder) const;
341 
343  bool iterationWillBeInEntryOrder(SortOrder sortOrder) const;
344 
346  bool empty() const;
347 
370 
371  IndexIntoFileItr findPosition(SortOrder sortOrder,
374  EventNumber_t event = 0U) const;
375 
379 
383 
385  IndexIntoFileItr findRunPosition(RunNumber_t run) const;
386 
390  bool containsRun(RunNumber_t run) const;
391 
392  SortedRunOrLumiItr beginRunOrLumi() const;
393  SortedRunOrLumiItr endRunOrLumi() const;
394 
397  void set_intersection(IndexIntoFile const& indexIntoFile, std::set<IndexRunLumiEventKey>& intersection) const;
398 
400  bool containsDuplicateEvents() const;
401 
402  //*****************************************************************************
403  //*****************************************************************************
404 
406  public:
407  RunOrLumiEntry();
408 
417 
420  EntryNumber_t entry() const { return entry_; }
422  RunNumber_t run() const { return run_; }
423  LuminosityBlockNumber_t lumi() const { return lumi_; }
425  EntryNumber_t endEvents() const { return endEvents_; }
426 
427  bool isRun() const { return lumi() == invalidLumi; }
428 
432 
433  bool operator<(RunOrLumiEntry const& right) const {
434  if (orderPHIDRun_ == right.orderPHIDRun()) {
435  if (orderPHIDRunLumi_ == right.orderPHIDRunLumi()) {
436  return entry_ < right.entry();
437  }
438  return orderPHIDRunLumi_ < right.orderPHIDRunLumi();
439  }
440  return orderPHIDRun_ < right.orderPHIDRun();
441  }
442 
443  private:
444  // All Runs, Lumis, and Events associated with the same
445  // ProcessHistory and Run in the same input file are processed
446  // contiguously. This parameter establishes the default order
447  // of processing of these contiguous subsets of data.
449 
450  // All Lumis and Events associated with the same
451  // ProcessHistory, Run, and Lumi in the same input file are
452  // processed contiguously. This parameter establishes the
453  // default order of processing of these contiguous subsets
454  // of data.
456 
457  // TTree entry number of Run or Lumi
458  // Always will be valid except when the IndexIntoFile was
459  // created while processing more than 1 luminosity block
460  // at a time (multiple concurrent lumis). In that case
461  // there can be multiple contiguous event ranges associated
462  // with the same lumi TTree entry. Exactly one of those will
463  // have a valid entry_ number and the rest will be set
464  // to the invalid value (-1). For a particular lumi, the
465  // invalid ones sort before the valid ones.
467 
470  LuminosityBlockNumber_t lumi_; // 0 indicates this is a run entry
471 
472  // These are entry numbers in the Events TTree
473  // Each RunOrLumiEntry is associated with one contiguous range of events.
474  // This is disjoint from the ranges associated with all other RunOrLumiEntry's
475  EntryNumber_t beginEvents_; // -1 if a run or a lumi with no events
476  EntryNumber_t endEvents_; // -1 if a run or a lumi with no events
477  };
478 
479  //*****************************************************************************
480  //*****************************************************************************
481 
483  public:
485 
487  RunNumber_t run() const { return run_; }
488  LuminosityBlockNumber_t lumi() const { return lumi_; }
489  int indexToGetEntry() const { return indexToGetEntry_; }
490  long long beginEventNumbers() const { return beginEventNumbers_; }
491  long long endEventNumbers() const { return endEventNumbers_; }
492 
493  bool isRun() const { return lumi() == invalidLumi; }
494 
496  void setEndEventNumbers(long long v) { endEventNumbers_ = v; }
497 
498  bool operator<(RunOrLumiIndexes const& right) const {
500  if (run_ == right.run()) {
501  return lumi_ < right.lumi();
502  }
503  return run_ < right.run();
504  }
506  }
507 
508  private:
511  LuminosityBlockNumber_t lumi_; // 0 indicates this is a run entry
513 
514  // The next two data members are indexes into the vectors eventNumbers_ and
515  // eventEntries_ (which both have the same number of entries in the same order,
516  // the only difference being that one contains only events numbers and is
517  // smaller in memory).
518 
519  // If there are no events, then the next two are equal (and the value is the
520  // index where the first event would have gone if there had been one)
521 
522  // Note that there can be many RunOrLumiIndexes objects where these two values are
523  // the same if there are many noncontiguous ranges of events associated with the same
524  // PHID-Run-Lumi (this one range in eventNumbers_ corresponds to the union of
525  // all the noncontiguous ranges in the Events TTree).
526  long long beginEventNumbers_; // first event this PHID-Run-Lumi (-1 if a run or not set)
527  long long endEventNumbers_; // one past last event this PHID-Run-Lumi (-1 if a run or not set)
528  };
529 
530  //*****************************************************************************
531  //*****************************************************************************
532 
533  class EventEntry {
534  public:
537 
538  EventNumber_t event() const { return event_; }
539  EntryNumber_t entry() const { return entry_; }
540 
541  bool operator<(EventEntry const& right) const { return event() < right.event(); }
542 
543  bool operator==(EventEntry const& right) const { return event() == right.event(); }
544 
545  private:
548  };
549 
550  //*****************************************************************************
551  //*****************************************************************************
552 
554  public:
556 
557  IndexIntoFile const* indexIntoFile() const { return indexIntoFile_; }
558  unsigned runOrLumi() const { return runOrLumi_; }
559 
560  bool operator==(SortedRunOrLumiItr const& right) const;
561  bool operator!=(SortedRunOrLumiItr const& right) const;
563 
564  bool isRun();
565 
566  void getRange(long long& beginEventNumbers,
567  long long& endEventNumbers,
568  EntryNumber_t& beginEventEntry,
569  EntryNumber_t& endEventEntry);
570 
571  RunOrLumiIndexes const& runOrLumiIndexes() const;
572 
573  private:
575 
576  // This is an index into runOrLumiIndexes_
577  // which gives the current position of the iteration
578  unsigned runOrLumi_;
579  };
580 
581  //*****************************************************************************
582  //*****************************************************************************
583 
585  public:
587  EntryType entryType,
588  int indexToRun,
589  int indexToLumi,
590  int indexToEventRange,
591  long long indexToEvent,
592  long long nEvents);
593  virtual ~IndexIntoFileItrImpl();
594 
595  virtual IndexIntoFileItrImpl* clone() const = 0;
596 
597  EntryType getEntryType() const { return type_; }
598 
599  void next();
600 
601  void skipEventForward(int& phIndexOfSkippedEvent,
602  RunNumber_t& runOfSkippedEvent,
603  LuminosityBlockNumber_t& lumiOfSkippedEvent,
604  EntryNumber_t& skippedEventEntry);
605 
606  void skipEventBackward(int& phIndexOfEvent,
607  RunNumber_t& runOfEvent,
608  LuminosityBlockNumber_t& lumiOfEvent,
609  EntryNumber_t& eventEntry);
610 
611  virtual int processHistoryIDIndex() const = 0;
612  virtual RunNumber_t run() const = 0;
613  virtual LuminosityBlockNumber_t lumi() const = 0;
614  virtual EntryNumber_t entry() const = 0;
615  virtual bool shouldProcessLumi() const = 0;
616  virtual bool shouldProcessRun() const = 0;
617  virtual LuminosityBlockNumber_t peekAheadAtLumi() const = 0;
618  virtual EntryNumber_t peekAheadAtEventEntry() const = 0;
621  virtual bool skipLumiInRun() = 0;
622  virtual bool lumiIterationStartingIndex(int index) const = 0;
623 
624  void advanceToNextRun();
625  void advanceToNextLumiOrRun();
626  bool skipToNextEventInLumi();
627  void initializeRun();
628 
629  void initializeLumi();
630 
631  bool operator==(IndexIntoFileItrImpl const& right) const;
632 
633  IndexIntoFile const* indexIntoFile() const { return indexIntoFile_; }
634 
635  // runOrLumiEntries_ and runOrLumiIndexes_ have the same size. It
636  // is returned by the function size(). There are iterator data members
637  // that are indexes into a container. The iterators also need the size of that
638  // container and the function indexedSize() returns it. For the NoSort and
639  // Sorted derived iterator classes, those indexes point directly into
640  // runOrLumiEntries_ or runOrLumiIndexes_ and therefore return the same
641  // value as size(). The indexes in the EntryOrder iterator class point into
642  // a larger container and indexedSize() is overridden to give the size of
643  // that container.
644  int size() const { return size_; }
645  virtual int indexedSize() const;
646 
647  EntryType type() const { return type_; }
648  int indexToRun() const { return indexToRun_; }
649 
650  int indexToLumi() const { return indexToLumi_; }
651  int indexToEventRange() const { return indexToEventRange_; }
652  long long indexToEvent() const { return indexToEvent_; }
653  long long nEvents() const { return nEvents_; }
654 
656 
657  void getLumisInRun(std::vector<LuminosityBlockNumber_t>& lumis) const;
658 
659  protected:
660  void setInvalid();
661 
664  void setIndexToEvent(long long value) { indexToEvent_ = value; }
665  void setNEvents(long long value) { nEvents_ = value; }
666 
667  private:
668  virtual void initializeLumi_() = 0;
669  virtual bool nextEventRange() = 0;
670  virtual bool previousEventRange() = 0;
671  bool previousLumiWithEvents();
672  virtual bool setToLastEventInRange(int index) = 0;
673  virtual EntryType getRunOrLumiEntryType(int index) const = 0;
674  virtual bool isSameLumi(int index1, int index2) const = 0;
675  virtual bool isSameRun(int index1, int index2) const = 0;
676  virtual LuminosityBlockNumber_t lumi(int index) const = 0;
677 
679  int size_;
680 
685  long long indexToEvent_;
686  long long nEvents_;
687  };
688 
689  //*****************************************************************************
690  //*****************************************************************************
691 
693  public:
695  EntryType entryType,
696  int indexToRun,
697  int indexToLumi,
698  int indexToEventRange,
699  long long indexToEvent,
700  long long nEvents);
701 
702  IndexIntoFileItrImpl* clone() const override;
703 
704  int processHistoryIDIndex() const override;
705  RunNumber_t run() const override;
706  LuminosityBlockNumber_t lumi() const override;
707  EntryNumber_t entry() const override;
708  bool shouldProcessLumi() const final { return true; }
709  bool shouldProcessRun() const final { return true; }
710  LuminosityBlockNumber_t peekAheadAtLumi() const override;
711  EntryNumber_t peekAheadAtEventEntry() const override;
712  bool skipLumiInRun() override;
713  bool lumiIterationStartingIndex(int index) const override;
714 
715  private:
716  void initializeLumi_() override;
717  bool nextEventRange() override;
718  bool previousEventRange() override;
719  bool setToLastEventInRange(int index) override;
720  EntryType getRunOrLumiEntryType(int index) const override;
721  bool isSameLumi(int index1, int index2) const override;
722  bool isSameRun(int index1, int index2) const override;
723  LuminosityBlockNumber_t lumi(int index) const override;
724  };
725 
726  //*****************************************************************************
727  //*****************************************************************************
728 
730  public:
732  EntryType entryType,
733  int indexToRun,
734  int indexToLumi,
735  int indexToEventRange,
736  long long indexToEvent,
737  long long nEvents);
738 
739  IndexIntoFileItrImpl* clone() const override;
740  int processHistoryIDIndex() const override;
741  RunNumber_t run() const override;
742  LuminosityBlockNumber_t lumi() const override;
743  EntryNumber_t entry() const override;
744  bool shouldProcessLumi() const final { return true; }
745  bool shouldProcessRun() const final { return true; }
746  LuminosityBlockNumber_t peekAheadAtLumi() const override;
747  EntryNumber_t peekAheadAtEventEntry() const override;
748  bool skipLumiInRun() override;
749  bool lumiIterationStartingIndex(int index) const override;
750 
751  private:
752  void initializeLumi_() override;
753  bool nextEventRange() override;
754  bool previousEventRange() override;
755  bool setToLastEventInRange(int index) override;
756  EntryType getRunOrLumiEntryType(int index) const override;
757  bool isSameLumi(int index1, int index2) const override;
758  bool isSameRun(int index1, int index2) const override;
759  LuminosityBlockNumber_t lumi(int index) const override;
760  };
761 
762  //*****************************************************************************
763  //*****************************************************************************
764 
766  public:
768  EntryType entryType,
769  int indexToRun,
770  int indexToLumi,
771  int indexToEventRange,
772  long long indexToEvent,
773  long long nEvents);
774 
775  IndexIntoFileItrImpl* clone() const override;
776  int processHistoryIDIndex() const override;
777  RunNumber_t run() const override;
778  LuminosityBlockNumber_t lumi() const override;
779  EntryNumber_t entry() const override;
780  bool shouldProcessLumi() const final;
781  bool shouldProcessRun() const final;
782  LuminosityBlockNumber_t peekAheadAtLumi() const override;
783  EntryNumber_t peekAheadAtEventEntry() const override;
784  bool skipLumiInRun() override;
785  bool lumiIterationStartingIndex(int index) const override;
786  int indexedSize() const override { return indexedSize_; }
787 
788  private:
789  // Note the argument to the function runOrLumisEntry is NOT a
790  // direct index into the vector in IndexIntoFile! It returns a
791  // reference to an object from that vector. However, the argument
792  // to runOrLumisEntry is an index into fileOrderRunOrLumiEntry_
793  // which reorders the elements so the iteration is in event TTree
794  // entry order. It also adds in dummy entries to insert
795  // the extra run and lumi transitions required for that ordering.
796 
799  }
800  bool shouldProcessRunOrLumi(EntryNumber_t iEntry) const { return shouldProcessRunOrLumi_[iEntry]; }
801  bool shouldProcessEvents(EntryNumber_t iEntry) const { return shouldProcessEvents_[iEntry]; }
802  void initializeLumi_() override;
803  bool nextEventRange() override;
804  bool previousEventRange() override;
805  bool setToLastEventInRange(int index) override;
806  EntryType getRunOrLumiEntryType(int index) const override;
807  bool isSameLumi(int index1, int index2) const override;
808  bool isSameRun(int index1, int index2) const override;
809  LuminosityBlockNumber_t lumi(int index) const override;
810 
814  };
815 
817  public:
818  void resizeVectors(std::vector<RunOrLumiEntry> const&);
819  void gatherNeededInfo(std::vector<RunOrLumiEntry> const&);
820  void fillIndexesSortedByEventEntry(std::vector<RunOrLumiEntry> const&);
821  void fillIndexesToLastContiguousEvents(std::vector<RunOrLumiEntry> const&);
822 
823  // Contains information only needed in the constructor of IndexIntoFileItrEntryOrder
824  std::vector<int> firstIndexOfRun_;
825  std::vector<int> firstIndexOfLumi_;
828 
829  // Will contain indexes of lumi entries with events and will be
830  // sorted by first Event TTree entry number.
831  std::vector<TTreeEntryAndIndex> indexesSortedByEventEntry_;
832  std::vector<TTreeEntryAndIndex>::const_iterator iEventSequence_;
833  std::vector<TTreeEntryAndIndex>::const_iterator iEventSequenceEnd_;
836 
837  void nextEventSequence(std::vector<RunOrLumiEntry> const& runOrLumiEntries) {
838  ++iEventSequence_;
840  eventSequenceIndex_ = iEventSequence_->runOrLumiIndex_;
842  }
843  }
844 
845  // Holds the index to the first entry associated with each run with no events
846  // Sorted by the first run TTree entry number
847  std::vector<TTreeEntryAndIndex> runsWithNoEvents_;
848  std::vector<TTreeEntryAndIndex>::const_iterator nextRunWithNoEvents_;
849  std::vector<TTreeEntryAndIndex>::const_iterator endRunsWithNoEvents_;
850  };
851 
853  void fillLumisWithNoRemainingEvents(std::vector<TTreeEntryAndIndex>& lumisWithNoRemainingEvents,
854  int startingIndex,
856  RunOrLumiEntry const* eventSequenceRunOrLumiEntry) const;
858  void addToFileOrder(int index, bool processRunOrLumi, bool processEvents);
862  int endOfRunEntries);
864  void handleLumisWithNoEvents(std::vector<TTreeEntryAndIndex>::const_iterator& nextLumiWithNoEvents,
865  std::vector<TTreeEntryAndIndex>::const_iterator& endLumisWithNoEvents,
866  EntryNumber_t lumiTTreeEntryNumber,
867  bool completeAll = false);
869  int currentLumi,
870  EntryNumber_t firstBeginEventsContiguousLumi);
872  int& iLumiIndex,
873  int currentLumi,
874  EntryNumber_t firstBeginEventsContiguousLumi,
875  bool completeAll = false);
876 
877  int indexedSize_ = 0;
878  std::vector<EntryNumber_t> fileOrderRunOrLumiEntry_;
879  std::vector<bool> shouldProcessRunOrLumi_;
880  std::vector<bool> shouldProcessEvents_;
881  };
882 
883  //*****************************************************************************
884  //*****************************************************************************
885 
887  public:
897  SortOrder sortOrder,
898  EntryType entryType,
899  int indexToRun,
900  int indexToLumi,
901  int indexToEventRange,
902  long long indexToEvent,
903  long long nEvents);
904 
905  EntryType getEntryType() const { return impl_->getEntryType(); }
906  int processHistoryIDIndex() const { return impl_->processHistoryIDIndex(); }
907  RunNumber_t run() const { return impl_->run(); }
908  LuminosityBlockNumber_t lumi() const { return impl_->lumi(); }
909  EntryNumber_t entry() const { return impl_->entry(); }
910  bool shouldProcessLumi() const { return impl_->shouldProcessLumi(); }
911  bool shouldProcessRun() const { return impl_->shouldProcessRun(); }
912  bool lumiIterationStartingIndex(int index) const { return impl_->lumiIterationStartingIndex(index); }
913 
916  LuminosityBlockNumber_t peekAheadAtLumi() const { return impl_->peekAheadAtLumi(); }
917 
922  EntryNumber_t peekAheadAtEventEntry() const { return impl_->peekAheadAtEventEntry(); }
923 
927  EntryNumber_t firstEventEntryThisRun() { return impl_->firstEventEntryThisRun(); }
928  EntryNumber_t firstEventEntryThisLumi() { return impl_->firstEventEntryThisLumi(); }
929 
930  // This is intentionally not implemented.
931  // It would be difficult to implement for the no sort mode,
932  // either slow or using extra memory.
933  // It would be easy to implement for the sorted iteration,
934  // but I did not implement it so both cases would offer a
935  // consistent interface.
936  // It looks like in all cases where this would be needed
937  // it would not be difficult to get the event number
938  // directly from the event auxiliary.
939  // We may need to revisit this decision in the future.
940  // EventNumber_t event() const;
941 
944  impl_->next();
945  return *this;
946  }
947 
953  void skipEventForward(int& phIndexOfSkippedEvent,
954  RunNumber_t& runOfSkippedEvent,
955  LuminosityBlockNumber_t& lumiOfSkippedEvent,
956  EntryNumber_t& skippedEventEntry) {
957  impl_->skipEventForward(phIndexOfSkippedEvent, runOfSkippedEvent, lumiOfSkippedEvent, skippedEventEntry);
958  }
959 
967  void skipEventBackward(int& phIndexOfEvent,
968  RunNumber_t& runOfEvent,
969  LuminosityBlockNumber_t& lumiOfEvent,
970  EntryNumber_t& eventEntry) {
971  impl_->skipEventBackward(phIndexOfEvent, runOfEvent, lumiOfEvent, eventEntry);
972  }
973 
976  bool skipLumiInRun() { return impl_->skipLumiInRun(); }
977 
980  bool skipToNextEventInLumi() { return impl_->skipToNextEventInLumi(); }
981 
982  void advanceToNextRun() { impl_->advanceToNextRun(); }
983  void advanceToNextLumiOrRun() { impl_->advanceToNextLumiOrRun(); }
984 
985  void advanceToEvent();
986  void advanceToLumi();
987 
988  bool operator==(IndexIntoFileItr const& right) const { return *impl_ == *right.impl_; }
989 
990  bool operator!=(IndexIntoFileItr const& right) const { return !(*this == right); }
991 
993  void initializeRun() { impl_->initializeRun(); }
994 
996  void initializeLumi() { impl_->initializeLumi(); }
997 
1000 
1001  void getLumisInRun(std::vector<LuminosityBlockNumber_t>& lumis) const { impl_->getLumisInRun(lumis); }
1002 
1003  private:
1004  //for testing
1005  friend class ::TestIndexIntoFile;
1006  friend class ::TestIndexIntoFile2;
1007  friend class ::TestIndexIntoFile3;
1008  friend class ::TestIndexIntoFile4;
1009  friend class ::TestIndexIntoFile5;
1010 
1011  // The rest of these are intended to be used only by code which tests
1012  // this class.
1013  IndexIntoFile const* indexIntoFile() const { return impl_->indexIntoFile(); }
1014  int size() const { return impl_->size(); }
1015  int indexedSize() const { return impl_->indexedSize(); }
1016  EntryType type() const { return impl_->type(); }
1017  int indexToRun() const { return impl_->indexToRun(); }
1018  int indexToLumi() const { return impl_->indexToLumi(); }
1019  int indexToEventRange() const { return impl_->indexToEventRange(); }
1020  long long indexToEvent() const { return impl_->indexToEvent(); }
1021  long long nEvents() const { return impl_->nEvents(); }
1022 
1024  };
1025 
1026  //*****************************************************************************
1027  //*****************************************************************************
1028 
1029  class IndexRunKey {
1030  public:
1032 
1034  RunNumber_t run() const { return run_; }
1035 
1036  bool operator<(IndexRunKey const& right) const {
1038  return run_ < right.run();
1039  }
1041  }
1042 
1043  private:
1046  };
1047 
1048  //*****************************************************************************
1049  //*****************************************************************************
1050 
1052  public:
1055 
1057  RunNumber_t run() const { return run_; }
1058  LuminosityBlockNumber_t lumi() const { return lumi_; }
1059 
1060  bool operator<(IndexRunLumiKey const& right) const {
1062  if (run_ == right.run()) {
1063  return lumi_ < right.lumi();
1064  }
1065  return run_ < right.run();
1066  }
1068  }
1069 
1070  private:
1074  };
1075 
1076  //*****************************************************************************
1077  //*****************************************************************************
1078 
1080  public:
1083 
1085  RunNumber_t run() const { return run_; }
1086  LuminosityBlockNumber_t lumi() const { return lumi_; }
1087  EventNumber_t event() const { return event_; }
1088 
1089  bool operator<(IndexRunLumiEventKey const& right) const {
1091  if (run_ == right.run()) {
1092  if (lumi_ == right.lumi()) {
1093  return event_ < right.event();
1094  }
1095  return lumi_ < right.lumi();
1096  }
1097  return run_ < right.run();
1098  }
1100  }
1101 
1102  private:
1107  };
1108 
1109  //*****************************************************************************
1110  //*****************************************************************************
1111 
1112  class EventFinder {
1113  public:
1114  virtual ~EventFinder() {}
1116  };
1117 
1118  //*****************************************************************************
1119  //*****************************************************************************
1120 
1121  // The next two functions are used by the output module to fill the
1122  // persistent data members.
1123 
1127  RunNumber_t run,
1131 
1137 
1139  void checkForMissingRunOrLumiEntry() const;
1140 
1141  //used internally by addEntry
1143  //*****************************************************************************
1144  //*****************************************************************************
1145 
1146  // The next group of functions is used by the PoolSource (or other
1147  // input related code) to fill the IndexIntoFile.
1148 
1154  void fixIndexes(std::vector<ProcessHistoryID>& processHistoryIDs);
1155 
1159 
1165  void setEventFinder(std::shared_ptr<EventFinder> ptr) { transient_.eventFinder_ = ptr; }
1166 
1180  void fillEventNumbers() const;
1181 
1195  void fillEventEntries() const;
1196 
1202  void fillEventNumbersOrEntries(bool needEventNumbers, bool needEventEntries) const;
1203 
1207  std::vector<EventNumber_t>& unsortedEventNumbers() { return transient_.unsortedEventNumbers_; }
1208  std::vector<EventNumber_t> const& unsortedEventNumbers() const { return transient_.unsortedEventNumbers_; }
1209 
1212  void inputFileClosed();
1213 
1215  void doneFileInitialization();
1216 
1220  std::vector<RunOrLumiEntry>& setRunOrLumiEntries() { return runOrLumiEntries_; }
1221 
1225  std::vector<ProcessHistoryID>& setProcessHistoryIDs() { return processHistoryIDs_; }
1226 
1230  void reduceProcessHistoryIDs(ProcessHistoryRegistry const& processHistoryRegistry);
1231 
1232  //*****************************************************************************
1233  //*****************************************************************************
1234 
1236  std::vector<RunOrLumiEntry> const& runOrLumiEntries() const { return runOrLumiEntries_; }
1237 
1238  //*****************************************************************************
1239  //*****************************************************************************
1240 
1242 
1243  struct Transients {
1244  Transients();
1245  void reset();
1247  std::map<IndexRunKey, EntryNumber_t> runToOrder_;
1248  std::map<IndexRunLumiKey, EntryNumber_t> lumiToOrder_;
1256  std::vector<RunOrLumiIndexes> runOrLumiIndexes_;
1257  std::vector<EventNumber_t> eventNumbers_;
1258  std::vector<EventEntry> eventEntries_;
1259  std::vector<EventNumber_t> unsortedEventNumbers_;
1260  };
1261 
1262  private:
1263  //for testing
1264  friend class ::TestIndexIntoFile;
1265  friend class ::TestIndexIntoFile1;
1266  friend class ::TestIndexIntoFile2;
1267  friend class ::TestIndexIntoFile3;
1268  friend class ::TestIndexIntoFile4;
1269  friend class ::TestIndexIntoFile5;
1270 
1273  void fillRunOrLumiIndexes() const;
1274 
1275  std::vector<EventNumber_t>& unsortedEventNumbersMutable() const { return transient_.unsortedEventNumbers_; }
1276  void fillUnsortedEventNumbers() const;
1277  void resetEventFinder() const { transient_.eventFinder_ = nullptr; } // propagate_const<T> has no reset() function
1278  std::vector<EventEntry>& eventEntries() const { return transient_.eventEntries_; }
1279  std::vector<EventNumber_t>& eventNumbers() const { return transient_.eventNumbers_; }
1280  void sortEvents() const;
1281  void sortEventEntries() const;
1283  std::map<IndexRunKey, EntryNumber_t>& runToOrder() const { return transient_.runToOrder_; }
1284  std::map<IndexRunLumiKey, EntryNumber_t>& lumiToOrder() const { return transient_.lumiToOrder_; }
1287  int& currentIndex() const { return transient_.currentIndex_; }
1290  std::vector<RunOrLumiIndexes>& runOrLumiIndexes() const { return transient_.runOrLumiIndexes_; }
1291  size_t numberOfEvents() const { return transient_.numberOfEvents_; }
1293  return transient_.eventFinder_->getEventNumberOfEntry(entry);
1294  }
1295 
1296  //This class is used only by one thread at a time within the source serialized code
1298 
1299  std::vector<ProcessHistoryID> processHistoryIDs_; // of reduced process histories
1300  std::vector<RunOrLumiEntry> runOrLumiEntries_;
1301  };
1302 
1303  template <>
1304  struct value_ptr_traits<IndexIntoFile::IndexIntoFileItrImpl> {
1306  return p->clone();
1307  }
1309  };
1310 
1312  public:
1314  };
1315 
1317  public:
1319  };
1320 
1321  // This class exists only to allow forward declarations of IndexIntoFile::IndexIntoFileItr
1323  public:
1325  void getLumisInRun(std::vector<LuminosityBlockNumber_t>& lumis) const { iter_.getLumisInRun(lumis); }
1326 
1327  private:
1329  };
1330 } // namespace edm
1331 
1332 #endif
void initializeRun()
Should only be used internally and for tests.
IndexIntoFileItr end(SortOrder sortOrder) const
Used to end an iteration over the Runs, Lumis, and Events in a file.
LuminosityBlockNumber_t peekAheadAtLumi() const override
IndexIntoFileItr begin(SortOrder sortOrder) const
EntryType getRunOrLumiEntryType(int index) const override
bool shouldProcessEvents(EntryNumber_t iEntry) const
bool lumiIterationStartingIndex(int index) const override
void handleToEndOfContiguousEventsInRun(EntryOrderInitializationInfo &info, EntryNumber_t currentRun)
std::vector< RunOrLumiIndexes > & runOrLumiIndexes() const
IndexIntoFileItr findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const
std::map< IndexRunLumiKey, EntryNumber_t > & lumiToOrder() const
static const TGPicture * info(bool iBackgroundIsBlack)
void fillLumisWithNoRemainingEvents(std::vector< TTreeEntryAndIndex > &lumisWithNoRemainingEvents, int startingIndex, EntryNumber_t currentRun, RunOrLumiEntry const *eventSequenceRunOrLumiEntry) const
std::vector< EventNumber_t > const & unsortedEventNumbers() const
IndexRunLumiKey(int index, RunNumber_t run, LuminosityBlockNumber_t lumi)
#define CMS_SA_ALLOW
static constexpr int invalidIndex
EntryNumber_t entry() const override
int & previousAddedIndex() const
bool isSameLumi(int index1, int index2) const override
LuminosityBlockNumber_t currentLumi_
static void destroy(IndexIntoFile::IndexIntoFileItrImpl *p)
bool operator==(SortedRunOrLumiItr const &right) const
EntryNumber_t endEvents() const
void handleToEndOfContiguousEventsInLumis(EntryOrderInitializationInfo &info, EntryNumber_t currentRun, int endOfRunEntries)
IndexIntoFileItrEntryOrder(IndexIntoFile const *indexIntoFile, EntryType entryType, int indexToRun, int indexToLumi, int indexToEventRange, long long indexToEvent, long long nEvents)
void fillEventNumbers() const
void handleLumisWithNoEvents(std::vector< TTreeEntryAndIndex >::const_iterator &nextLumiWithNoEvents, std::vector< TTreeEntryAndIndex >::const_iterator &endLumisWithNoEvents, EntryNumber_t lumiTTreeEntryNumber, bool completeAll=false)
void addToFileOrder(int index, bool processRunOrLumi, bool processEvents)
void addLumi(int index, RunNumber_t run, LuminosityBlockNumber_t lumi, EntryNumber_t entry)
void addRunsWithNoEvents(EntryOrderInitializationInfo &, EntryNumber_t maxRunTTreeEntry=invalidEntry)
bool containsEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
EntryNumber_t orderPHIDRunLumi() const
IndexIntoFileItrImpl * clone() const override
std::vector< TTreeEntryAndIndex >::const_iterator iEventSequence_
std::vector< EventNumber_t > eventNumbers_
virtual int processHistoryIDIndex() const =0
bool operator!=(SortedRunOrLumiItr const &right) const
virtual bool setToLastEventInRange(int index)=0
bool operator<(IndexRunLumiKey const &right) const
void sortEventEntries() const
EventEntry(EventNumber_t event, EntryNumber_t entry)
IndexIntoFile const * indexIntoFile() const
static IndexIntoFile::IndexIntoFileItrImpl * clone(IndexIntoFile::IndexIntoFileItrImpl const *p)
unsigned long long EventNumber_t
virtual LuminosityBlockNumber_t peekAheadAtLumi() const =0
EntryNumber_t & endEvents() const
EntryType getRunOrLumiEntryType(int index) const override
IndexIntoFile::IndexIntoFileItr const & iter_
void fillEventEntries() const
bool operator==(EventEntry const &right) const
void nextEventSequence(std::vector< RunOrLumiEntry > const &runOrLumiEntries)
RunNumber_t & currentRun() const
std::vector< EventEntry > & eventEntries() const
bool int lh
Definition: SIMDVec.h:20
IndexIntoFileItrHolder(IndexIntoFile::IndexIntoFileItr const &iIter)
std::vector< EventNumber_t > unsortedEventNumbers_
virtual bool isSameLumi(int index1, int index2) const =0
LuminosityBlockNumber_t lumi() const
bool shouldProcessRunOrLumi(EntryNumber_t iEntry) const
IndexRunLumiEventKey(int index, RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
uint16_t size_type
unsigned int LuminosityBlockNumber_t
IndexIntoFileItr findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
std::vector< TTreeEntryAndIndex >::const_iterator iEventSequenceEnd_
bool iterationWillBeInEntryOrder(SortOrder sortOrder) const
Used to determine whether or not to disable fast cloning.
static constexpr EventNumber_t invalidEvent
virtual EntryNumber_t peekAheadAtEventEntry() const =0
EntryNumber_t peekAheadAtEventEntry() const
EventNumber_t getEventNumberOfEntry(EntryNumber_t entry) const
std::map< IndexRunLumiKey, EntryNumber_t > lumiToOrder_
bool operator==(IndexIntoFileItrImpl const &right) const
void sortVector_Run_Or_Lumi_Entries()
IndexIntoFileItrImpl * clone() const override
void fillUnsortedEventNumbers() const
bool containsItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
LuminosityBlockNumber_t lumi() const override
bool operator!=(IndexIntoFileItr const &right) const
std::vector< TTreeEntryAndIndex >::const_iterator nextRunWithNoEvents_
EntryNumber_t lowestInLumi(EntryOrderInitializationInfo &info, int currentLumi) const
void setNumberOfEvents(EntryNumber_t nevents)
void reduceProcessHistoryIDs(ProcessHistoryRegistry const &processHistoryRegistry)
LuminosityBlockNumber_t lumi() const
int & currentIndex() const
long long EntryNumber_t
bool setToLastEventInRange(int index) override
EntryNumber_t entry() const
IndexIntoFileItrImpl * clone() const override
void checkForMissingRunOrLumiEntry() const
Run this check just after sorting.
bool operator<(RunOrLumiEntry const &right) const
virtual LuminosityBlockNumber_t lumi() const =0
virtual bool lumiIterationStartingIndex(int index) const =0
RunOrLumiIndexes(int processHistoryIDIndex, RunNumber_t run, LuminosityBlockNumber_t lumi, int indexToGetEntry)
std::vector< ProcessHistoryID > & setProcessHistoryIDs()
void reserveSpaceInVectors(std::vector< EntryNumber_t >::size_type)
void setOrderPHIDRun(EntryNumber_t v)
virtual EntryType getRunOrLumiEntryType(int index) const =0
static constexpr RunNumber_t invalidRun
bool lumiIterationStartingIndex(int index) const
LuminosityBlockNumber_t peekAheadAtLumi() const override
virtual EventNumber_t getEventNumberOfEntry(EntryNumber_t entry) const =0
void skipEventBackward(int &phIndexOfEvent, RunNumber_t &runOfEvent, LuminosityBlockNumber_t &lumiOfEvent, EntryNumber_t &eventEntry)
virtual IndexIntoFileItrImpl * clone() const =0
std::vector< RunOrLumiEntry > runOrLumiEntries_
std::map< IndexRunKey, EntryNumber_t > runToOrder_
LuminosityBlockNumber_t lumi() const override
void copyPosition(IndexIntoFileItr const &position)
Copy the position without modifying the pointer to the IndexIntoFile or size.
void handleLumiWithEvents(EntryOrderInitializationInfo &info, int currentLumi, EntryNumber_t firstBeginEventsContiguousLumi)
void skipEventForward(int &phIndexOfSkippedEvent, RunNumber_t &runOfSkippedEvent, LuminosityBlockNumber_t &lumiOfSkippedEvent, EntryNumber_t &skippedEventEntry)
std::vector< ProcessHistoryID > processHistoryIDs_
void skipEventBackward(int &phIndexOfEvent, RunNumber_t &runOfEvent, LuminosityBlockNumber_t &lumiOfEvent, EntryNumber_t &eventEntry)
LuminosityBlockNumber_t lumi_
virtual bool isSameRun(int index1, int index2) const =0
SortedRunOrLumiItr endRunOrLumi() const
void setOrderPHIDRunLumi(EntryNumber_t v)
IndexIntoFileItrImpl(IndexIntoFile const *indexIntoFile, EntryType entryType, int indexToRun, int indexToLumi, int indexToEventRange, long long indexToEvent, long long nEvents)
LuminosityBlockNumber_t peekAheadAtLumi() const override
bool operator<(EventEntry const &right) const
bool empty() const
True if no runs, lumis, or events are in the file.
virtual EntryNumber_t entry() const =0
bool isSameRun(int index1, int index2) const override
ProcessHistoryID const & processHistoryID(int i) const
IndexIntoFileItr & operator++()
Move to next event to be processed.
EventNumber_t event() const
EntryNumber_t peekAheadAtEventEntry() const override
Definition: value.py:1
std::vector< TTreeEntryAndIndex >::const_iterator endRunsWithNoEvents_
bool operator<(RunOrLumiIndexes const &right) const
bool operator<(IndexRunKey const &right) const
std::vector< EventNumber_t > & unsortedEventNumbersMutable() const
bool isSameRun(int index1, int index2) const override
std::vector< EntryNumber_t > fileOrderRunOrLumiEntry_
bool operator()(IndexIntoFile::RunOrLumiIndexes const &lh, IndexIntoFile::RunOrLumiIndexes const &rh)
void getLumisInRun(std::vector< LuminosityBlockNumber_t > &lumis) const
void handleLumiEntriesNoRemainingEvents(EntryOrderInitializationInfo &info, int &iLumiIndex, int currentLumi, EntryNumber_t firstBeginEventsContiguousLumi, bool completeAll=false)
void addEntry(ProcessHistoryID const &processHistoryID, RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, EntryNumber_t entry)
EntryNumber_t beginEvents() const
bool operator==(IndexIntoFileItr const &right) const
SortedRunOrLumiItr(IndexIntoFile const *indexIntoFile, unsigned runOrLumi)
virtual bool shouldProcessRun() const =0
LuminosityBlockNumber_t lumi() const
bool lumiIterationStartingIndex(int index) const override
bool containsLumi(RunNumber_t run, LuminosityBlockNumber_t lumi) const
bool lumiIterationStartingIndex(int index) const override
IndexRunKey(int index, RunNumber_t run)
IndexIntoFile const * indexIntoFile() const
void fillIndexesToLastContiguousEvents(std::vector< RunOrLumiEntry > const &)
LuminosityBlockNumber_t lumi() const
size_t numberOfEvents() const
void fixIndexes(std::vector< ProcessHistoryID > &processHistoryIDs)
EntryNumber_t peekAheadAtEventEntry() const override
std::vector< EventNumber_t > & eventNumbers() const
std::vector< RunOrLumiEntry > & setRunOrLumiEntries()
bool setToLastEventInRange(int index) override
IndexIntoFile const * indexIntoFile() const
static constexpr EntryNumber_t invalidEntry
LuminosityBlockNumber_t peekAheadAtLumi() const
IndexIntoFileItrSorted(IndexIntoFile const *indexIntoFile, EntryType entryType, int indexToRun, int indexToLumi, int indexToEventRange, long long indexToEvent, long long nEvents)
std::vector< EventNumber_t > & unsortedEventNumbers()
static constexpr LuminosityBlockNumber_t invalidLumi
void getLumisInRun(std::vector< LuminosityBlockNumber_t > &lumis) const
void initializeLumi()
Should only be used internally and for tests.
bool operator<(IndexRunLumiEventKey const &right) const
void fillRunOrLumiIndexes() const
std::vector< ProcessHistoryID > const & processHistoryIDs() const
LuminosityBlockNumber_t lumi() const
void copyPosition(IndexIntoFileItrImpl const &position)
void getLumisInRun(std::vector< LuminosityBlockNumber_t > &lumis) const
LuminosityBlockNumber_t lumi() const override
std::vector< RunOrLumiEntry > const & runOrLumiEntries() const
Used internally and for test purposes.
std::vector< EventEntry > eventEntries_
EntryNumber_t orderPHIDRun() const
void doneFileInitialization()
Clears the temporary vector of event numbers to reduce memory usage.
LuminosityBlockNumber_t & currentLumi() const
EntryType getRunOrLumiEntryType(int index) const override
bool containsRun(RunNumber_t run) const
bool containsDuplicateEvents() const
Returns true if the IndexIntoFile contains 2 events with the same ProcessHistoryID index...
HLT enums.
static int position[264][3]
Definition: ReadPGInfo.cc:289
bool isSameLumi(int index1, int index2) const override
bool isSameRun(int index1, int index2) const override
IndexIntoFileItr findRunPosition(RunNumber_t run) const
Same as findPosition.
bool isSameLumi(int index1, int index2) const override
RunOrLumiEntry const & runOrLumisEntry(EntryNumber_t iEntry) const
std::vector< RunOrLumiIndexes > runOrLumiIndexes_
IndexIntoFileItr findPosition(RunNumber_t run, LuminosityBlockNumber_t lumi=0U, EventNumber_t event=0U) const
SortedRunOrLumiItr beginRunOrLumi() const
IndexIntoFileItr(IndexIntoFile const *indexIntoFile, SortOrder sortOrder, EntryType entryType, int indexToRun, int indexToLumi, int indexToEventRange, long long indexToEvent, long long nEvents)
unsigned int RunNumber_t
virtual bool shouldProcessLumi() const =0
void sortEvents() const
bool operator()(IndexIntoFile::RunOrLumiIndexes const &lh, IndexIntoFile::RunOrLumiIndexes const &rh)
EntryNumber_t entry() const override
void setEventFinder(std::shared_ptr< EventFinder > ptr)
void getRange(long long &beginEventNumbers, long long &endEventNumbers, EntryNumber_t &beginEventEntry, EntryNumber_t &endEventEntry)
RunOrLumiIndexes const & runOrLumiIndexes() const
virtual RunNumber_t run() const =0
void fillEventNumbersOrEntries(bool needEventNumbers, bool needEventEntries) const
void set_intersection(IndexIntoFile const &indexIntoFile, std::set< IndexRunLumiEventKey > &intersection) const
EntryNumber_t & beginEvents() const
value_ptr< IndexIntoFileItrImpl > impl_
std::map< IndexRunKey, EntryNumber_t > & runToOrder() const
void skipEventForward(int &phIndexOfSkippedEvent, RunNumber_t &runOfSkippedEvent, LuminosityBlockNumber_t &lumiOfSkippedEvent, EntryNumber_t &skippedEventEntry)
IndexIntoFileItrNoSort(IndexIntoFile const *indexIntoFile, EntryType entryType, int indexToRun, int indexToLumi, int indexToEventRange, long long indexToEvent, long long nEvents)
void resetEventFinder() const
Definition: event.py:1
EntryNumber_t peekAheadAtEventEntry() const override
edm::propagate_const< std::shared_ptr< EventFinder > > eventFinder_