File indexing completed on 2024-04-06 12:05:02
0001 #ifndef DataFormats_Provenance_IndexIntoFile_h
0002 #define DataFormats_Provenance_IndexIntoFile_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227 #include "DataFormats/Provenance/interface/EventID.h"
0228 #include "DataFormats/Provenance/interface/ProcessHistoryID.h"
0229 #include "DataFormats/Provenance/interface/RunID.h"
0230 #include "DataFormats/Provenance/interface/RunLumiEventNumber.h"
0231 #include "FWCore/Utilities/interface/propagate_const.h"
0232 #include "FWCore/Utilities/interface/value_ptr.h"
0233 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0234
0235 #include <memory>
0236
0237 #include <cassert>
0238 #include <iosfwd>
0239 #include <map>
0240 #include <set>
0241 #include <vector>
0242
0243 class TestIndexIntoFile;
0244 class TestIndexIntoFile1;
0245 class TestIndexIntoFile2;
0246 class TestIndexIntoFile3;
0247 class TestIndexIntoFile4;
0248 class TestIndexIntoFile5;
0249
0250 namespace edm {
0251
0252 class ProcessHistoryRegistry;
0253 class RootFile;
0254
0255 class IndexIntoFile {
0256 public:
0257 class IndexIntoFileItr;
0258 class SortedRunOrLumiItr;
0259 class IndexRunLumiEventKey;
0260
0261 using EntryNumber_t = long long;
0262 static constexpr int invalidIndex = -1;
0263 static constexpr RunNumber_t invalidRun = 0U;
0264 static constexpr LuminosityBlockNumber_t invalidLumi = 0U;
0265 static constexpr EventNumber_t invalidEvent = 0U;
0266 static constexpr EntryNumber_t invalidEntry = -1LL;
0267
0268 enum EntryType { kRun, kLumi, kEvent, kEnd };
0269
0270 IndexIntoFile();
0271 ~IndexIntoFile();
0272
0273 ProcessHistoryID const& processHistoryID(int i) const;
0274 std::vector<ProcessHistoryID> const& processHistoryIDs() const;
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333 enum SortOrder { numericalOrder, firstAppearanceOrder, entryOrder };
0334
0335
0336
0337 IndexIntoFileItr begin(SortOrder sortOrder) const;
0338
0339
0340 IndexIntoFileItr end(SortOrder sortOrder) const;
0341
0342
0343 bool iterationWillBeInEntryOrder(SortOrder sortOrder) const;
0344
0345
0346 bool empty() const;
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369 IndexIntoFileItr findPosition(RunNumber_t run, LuminosityBlockNumber_t lumi = 0U, EventNumber_t event = 0U) const;
0370
0371 IndexIntoFileItr findPosition(SortOrder sortOrder,
0372 RunNumber_t run,
0373 LuminosityBlockNumber_t lumi = 0U,
0374 EventNumber_t event = 0U) const;
0375
0376
0377
0378 IndexIntoFileItr findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const;
0379
0380
0381
0382 IndexIntoFileItr findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const;
0383
0384
0385 IndexIntoFileItr findRunPosition(RunNumber_t run) const;
0386
0387 bool containsItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const;
0388 bool containsEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const;
0389 bool containsLumi(RunNumber_t run, LuminosityBlockNumber_t lumi) const;
0390 bool containsRun(RunNumber_t run) const;
0391
0392 SortedRunOrLumiItr beginRunOrLumi() const;
0393 SortedRunOrLumiItr endRunOrLumi() const;
0394
0395
0396
0397 void set_intersection(IndexIntoFile const& indexIntoFile, std::set<IndexRunLumiEventKey>& intersection) const;
0398
0399
0400 bool containsDuplicateEvents() const;
0401
0402
0403
0404
0405 class RunOrLumiEntry {
0406 public:
0407 RunOrLumiEntry();
0408
0409 RunOrLumiEntry(EntryNumber_t orderPHIDRun,
0410 EntryNumber_t orderPHIDRunLumi,
0411 EntryNumber_t entry,
0412 int processHistoryIDIndex,
0413 RunNumber_t run,
0414 LuminosityBlockNumber_t lumi,
0415 EntryNumber_t beginEvents,
0416 EntryNumber_t Event);
0417
0418 EntryNumber_t orderPHIDRun() const { return orderPHIDRun_; }
0419 EntryNumber_t orderPHIDRunLumi() const { return orderPHIDRunLumi_; }
0420 EntryNumber_t entry() const { return entry_; }
0421 int processHistoryIDIndex() const { return processHistoryIDIndex_; }
0422 RunNumber_t run() const { return run_; }
0423 LuminosityBlockNumber_t lumi() const { return lumi_; }
0424 EntryNumber_t beginEvents() const { return beginEvents_; }
0425 EntryNumber_t endEvents() const { return endEvents_; }
0426
0427 bool isRun() const { return lumi() == invalidLumi; }
0428
0429 void setOrderPHIDRun(EntryNumber_t v) { orderPHIDRun_ = v; }
0430 void setOrderPHIDRunLumi(EntryNumber_t v) { orderPHIDRunLumi_ = v; }
0431 void setProcessHistoryIDIndex(int v) { processHistoryIDIndex_ = v; }
0432
0433 bool operator<(RunOrLumiEntry const& right) const {
0434 if (orderPHIDRun_ == right.orderPHIDRun()) {
0435 if (orderPHIDRunLumi_ == right.orderPHIDRunLumi()) {
0436 return entry_ < right.entry();
0437 }
0438 return orderPHIDRunLumi_ < right.orderPHIDRunLumi();
0439 }
0440 return orderPHIDRun_ < right.orderPHIDRun();
0441 }
0442
0443 private:
0444
0445
0446
0447
0448 EntryNumber_t orderPHIDRun_;
0449
0450
0451
0452
0453
0454
0455 EntryNumber_t orderPHIDRunLumi_;
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466 EntryNumber_t entry_;
0467
0468 int processHistoryIDIndex_;
0469 RunNumber_t run_;
0470 LuminosityBlockNumber_t lumi_;
0471
0472
0473
0474
0475 EntryNumber_t beginEvents_;
0476 EntryNumber_t endEvents_;
0477 };
0478
0479
0480
0481
0482 class RunOrLumiIndexes {
0483 public:
0484 RunOrLumiIndexes(int processHistoryIDIndex, RunNumber_t run, LuminosityBlockNumber_t lumi, int indexToGetEntry);
0485
0486 int processHistoryIDIndex() const { return processHistoryIDIndex_; }
0487 RunNumber_t run() const { return run_; }
0488 LuminosityBlockNumber_t lumi() const { return lumi_; }
0489 int indexToGetEntry() const { return indexToGetEntry_; }
0490 long long beginEventNumbers() const { return beginEventNumbers_; }
0491 long long endEventNumbers() const { return endEventNumbers_; }
0492
0493 bool isRun() const { return lumi() == invalidLumi; }
0494
0495 void setBeginEventNumbers(long long v) { beginEventNumbers_ = v; }
0496 void setEndEventNumbers(long long v) { endEventNumbers_ = v; }
0497
0498 bool operator<(RunOrLumiIndexes const& right) const {
0499 if (processHistoryIDIndex_ == right.processHistoryIDIndex()) {
0500 if (run_ == right.run()) {
0501 return lumi_ < right.lumi();
0502 }
0503 return run_ < right.run();
0504 }
0505 return processHistoryIDIndex_ < right.processHistoryIDIndex();
0506 }
0507
0508 private:
0509 int processHistoryIDIndex_;
0510 RunNumber_t run_;
0511 LuminosityBlockNumber_t lumi_;
0512 int indexToGetEntry_;
0513
0514
0515
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526 long long beginEventNumbers_;
0527 long long endEventNumbers_;
0528 };
0529
0530
0531
0532
0533 class EventEntry {
0534 public:
0535 EventEntry() : event_(invalidEvent), entry_(invalidEntry) {}
0536 EventEntry(EventNumber_t event, EntryNumber_t entry) : event_(event), entry_(entry) {}
0537
0538 EventNumber_t event() const { return event_; }
0539 EntryNumber_t entry() const { return entry_; }
0540
0541 bool operator<(EventEntry const& right) const { return event() < right.event(); }
0542
0543 bool operator==(EventEntry const& right) const { return event() == right.event(); }
0544
0545 private:
0546 EventNumber_t event_;
0547 EntryNumber_t entry_;
0548 };
0549
0550
0551
0552
0553 class SortedRunOrLumiItr {
0554 public:
0555 SortedRunOrLumiItr(IndexIntoFile const* indexIntoFile, unsigned runOrLumi);
0556
0557 IndexIntoFile const* indexIntoFile() const { return indexIntoFile_; }
0558 unsigned runOrLumi() const { return runOrLumi_; }
0559
0560 bool operator==(SortedRunOrLumiItr const& right) const;
0561 bool operator!=(SortedRunOrLumiItr const& right) const;
0562 SortedRunOrLumiItr& operator++();
0563
0564 bool isRun();
0565
0566 void getRange(long long& beginEventNumbers,
0567 long long& endEventNumbers,
0568 EntryNumber_t& beginEventEntry,
0569 EntryNumber_t& endEventEntry);
0570
0571 RunOrLumiIndexes const& runOrLumiIndexes() const;
0572
0573 private:
0574 IndexIntoFile const* indexIntoFile_;
0575
0576
0577
0578 unsigned runOrLumi_;
0579 };
0580
0581
0582
0583
0584 class IndexIntoFileItrImpl {
0585 public:
0586 IndexIntoFileItrImpl(IndexIntoFile const* indexIntoFile,
0587 EntryType entryType,
0588 int indexToRun,
0589 int indexToLumi,
0590 int indexToEventRange,
0591 long long indexToEvent,
0592 long long nEvents);
0593 virtual ~IndexIntoFileItrImpl();
0594
0595 virtual IndexIntoFileItrImpl* clone() const = 0;
0596
0597 EntryType getEntryType() const { return type_; }
0598
0599 void next();
0600
0601 void skipEventForward(int& phIndexOfSkippedEvent,
0602 RunNumber_t& runOfSkippedEvent,
0603 LuminosityBlockNumber_t& lumiOfSkippedEvent,
0604 EntryNumber_t& skippedEventEntry);
0605
0606 void skipEventBackward(int& phIndexOfEvent,
0607 RunNumber_t& runOfEvent,
0608 LuminosityBlockNumber_t& lumiOfEvent,
0609 EntryNumber_t& eventEntry);
0610
0611 virtual int processHistoryIDIndex() const = 0;
0612 virtual RunNumber_t run() const = 0;
0613 virtual LuminosityBlockNumber_t lumi() const = 0;
0614 virtual EntryNumber_t entry() const = 0;
0615 virtual bool shouldProcessLumi() const = 0;
0616 virtual bool shouldProcessRun() const = 0;
0617 virtual LuminosityBlockNumber_t peekAheadAtLumi() const = 0;
0618 virtual EntryNumber_t peekAheadAtEventEntry() const = 0;
0619 EntryNumber_t firstEventEntryThisRun();
0620 EntryNumber_t firstEventEntryThisLumi();
0621 virtual bool skipLumiInRun() = 0;
0622 virtual bool lumiIterationStartingIndex(int index) const = 0;
0623
0624 void advanceToNextRun();
0625 void advanceToNextLumiOrRun();
0626 bool skipToNextEventInLumi();
0627 void initializeRun();
0628
0629 void initializeLumi();
0630
0631 bool operator==(IndexIntoFileItrImpl const& right) const;
0632
0633 IndexIntoFile const* indexIntoFile() const { return indexIntoFile_; }
0634
0635
0636
0637
0638
0639
0640
0641
0642
0643
0644 int size() const { return size_; }
0645 virtual int indexedSize() const;
0646
0647 EntryType type() const { return type_; }
0648 int indexToRun() const { return indexToRun_; }
0649
0650 int indexToLumi() const { return indexToLumi_; }
0651 int indexToEventRange() const { return indexToEventRange_; }
0652 long long indexToEvent() const { return indexToEvent_; }
0653 long long nEvents() const { return nEvents_; }
0654
0655 void copyPosition(IndexIntoFileItrImpl const& position);
0656
0657 void getLumisInRun(std::vector<LuminosityBlockNumber_t>& lumis) const;
0658
0659 protected:
0660 void setInvalid();
0661
0662 void setIndexToLumi(int value) { indexToLumi_ = value; }
0663 void setIndexToEventRange(int value) { indexToEventRange_ = value; }
0664 void setIndexToEvent(long long value) { indexToEvent_ = value; }
0665 void setNEvents(long long value) { nEvents_ = value; }
0666
0667 private:
0668 virtual void initializeLumi_() = 0;
0669 virtual bool nextEventRange() = 0;
0670 virtual bool previousEventRange() = 0;
0671 bool previousLumiWithEvents();
0672 virtual bool setToLastEventInRange(int index) = 0;
0673 virtual EntryType getRunOrLumiEntryType(int index) const = 0;
0674 virtual bool isSameLumi(int index1, int index2) const = 0;
0675 virtual bool isSameRun(int index1, int index2) const = 0;
0676 virtual LuminosityBlockNumber_t lumi(int index) const = 0;
0677
0678 IndexIntoFile const* indexIntoFile_;
0679 int size_;
0680
0681 EntryType type_;
0682 int indexToRun_;
0683 int indexToLumi_;
0684 int indexToEventRange_;
0685 long long indexToEvent_;
0686 long long nEvents_;
0687 };
0688
0689
0690
0691
0692 class IndexIntoFileItrNoSort : public IndexIntoFileItrImpl {
0693 public:
0694 IndexIntoFileItrNoSort(IndexIntoFile const* indexIntoFile,
0695 EntryType entryType,
0696 int indexToRun,
0697 int indexToLumi,
0698 int indexToEventRange,
0699 long long indexToEvent,
0700 long long nEvents);
0701
0702 IndexIntoFileItrImpl* clone() const override;
0703
0704 int processHistoryIDIndex() const override;
0705 RunNumber_t run() const override;
0706 LuminosityBlockNumber_t lumi() const override;
0707 EntryNumber_t entry() const override;
0708 bool shouldProcessLumi() const final { return true; }
0709 bool shouldProcessRun() const final { return true; }
0710 LuminosityBlockNumber_t peekAheadAtLumi() const override;
0711 EntryNumber_t peekAheadAtEventEntry() const override;
0712 bool skipLumiInRun() override;
0713 bool lumiIterationStartingIndex(int index) const override;
0714
0715 private:
0716 void initializeLumi_() override;
0717 bool nextEventRange() override;
0718 bool previousEventRange() override;
0719 bool setToLastEventInRange(int index) override;
0720 EntryType getRunOrLumiEntryType(int index) const override;
0721 bool isSameLumi(int index1, int index2) const override;
0722 bool isSameRun(int index1, int index2) const override;
0723 LuminosityBlockNumber_t lumi(int index) const override;
0724 };
0725
0726
0727
0728
0729 class IndexIntoFileItrSorted : public IndexIntoFileItrImpl {
0730 public:
0731 IndexIntoFileItrSorted(IndexIntoFile const* indexIntoFile,
0732 EntryType entryType,
0733 int indexToRun,
0734 int indexToLumi,
0735 int indexToEventRange,
0736 long long indexToEvent,
0737 long long nEvents);
0738
0739 IndexIntoFileItrImpl* clone() const override;
0740 int processHistoryIDIndex() const override;
0741 RunNumber_t run() const override;
0742 LuminosityBlockNumber_t lumi() const override;
0743 EntryNumber_t entry() const override;
0744 bool shouldProcessLumi() const final { return true; }
0745 bool shouldProcessRun() const final { return true; }
0746 LuminosityBlockNumber_t peekAheadAtLumi() const override;
0747 EntryNumber_t peekAheadAtEventEntry() const override;
0748 bool skipLumiInRun() override;
0749 bool lumiIterationStartingIndex(int index) const override;
0750
0751 private:
0752 void initializeLumi_() override;
0753 bool nextEventRange() override;
0754 bool previousEventRange() override;
0755 bool setToLastEventInRange(int index) override;
0756 EntryType getRunOrLumiEntryType(int index) const override;
0757 bool isSameLumi(int index1, int index2) const override;
0758 bool isSameRun(int index1, int index2) const override;
0759 LuminosityBlockNumber_t lumi(int index) const override;
0760 };
0761
0762
0763
0764
0765 class IndexIntoFileItrEntryOrder : public IndexIntoFileItrImpl {
0766 public:
0767 IndexIntoFileItrEntryOrder(IndexIntoFile const* indexIntoFile,
0768 EntryType entryType,
0769 int indexToRun,
0770 int indexToLumi,
0771 int indexToEventRange,
0772 long long indexToEvent,
0773 long long nEvents);
0774
0775 IndexIntoFileItrImpl* clone() const override;
0776 int processHistoryIDIndex() const override;
0777 RunNumber_t run() const override;
0778 LuminosityBlockNumber_t lumi() const override;
0779 EntryNumber_t entry() const override;
0780 bool shouldProcessLumi() const final;
0781 bool shouldProcessRun() const final;
0782 LuminosityBlockNumber_t peekAheadAtLumi() const override;
0783 EntryNumber_t peekAheadAtEventEntry() const override;
0784 bool skipLumiInRun() override;
0785 bool lumiIterationStartingIndex(int index) const override;
0786 int indexedSize() const override { return indexedSize_; }
0787
0788 private:
0789
0790
0791
0792
0793
0794
0795
0796
0797 RunOrLumiEntry const& runOrLumisEntry(EntryNumber_t iEntry) const {
0798 return indexIntoFile()->runOrLumiEntries()[fileOrderRunOrLumiEntry_[iEntry]];
0799 }
0800 bool shouldProcessRunOrLumi(EntryNumber_t iEntry) const { return shouldProcessRunOrLumi_[iEntry]; }
0801 bool shouldProcessEvents(EntryNumber_t iEntry) const { return shouldProcessEvents_[iEntry]; }
0802 void initializeLumi_() override;
0803 bool nextEventRange() override;
0804 bool previousEventRange() override;
0805 bool setToLastEventInRange(int index) override;
0806 EntryType getRunOrLumiEntryType(int index) const override;
0807 bool isSameLumi(int index1, int index2) const override;
0808 bool isSameRun(int index1, int index2) const override;
0809 LuminosityBlockNumber_t lumi(int index) const override;
0810
0811 struct TTreeEntryAndIndex {
0812 IndexIntoFile::EntryNumber_t ttreeEntry_;
0813 int runOrLumiIndex_;
0814 };
0815
0816 class EntryOrderInitializationInfo {
0817 public:
0818 void resizeVectors(std::vector<RunOrLumiEntry> const&);
0819 void gatherNeededInfo(std::vector<RunOrLumiEntry> const&);
0820 void fillIndexesSortedByEventEntry(std::vector<RunOrLumiEntry> const&);
0821 void fillIndexesToLastContiguousEvents(std::vector<RunOrLumiEntry> const&);
0822
0823
0824 std::vector<int> firstIndexOfRun_;
0825 std::vector<int> firstIndexOfLumi_;
0826 std::vector<int> startOfLastContiguousEventsInRun_;
0827 std::vector<int> startOfLastContiguousEventsInLumi_;
0828
0829
0830
0831 std::vector<TTreeEntryAndIndex> indexesSortedByEventEntry_;
0832 std::vector<TTreeEntryAndIndex>::const_iterator iEventSequence_;
0833 std::vector<TTreeEntryAndIndex>::const_iterator iEventSequenceEnd_;
0834 int eventSequenceIndex_ = 0;
0835 RunOrLumiEntry const* eventSequenceRunOrLumiEntry_ = nullptr;
0836
0837 void nextEventSequence(std::vector<RunOrLumiEntry> const& runOrLumiEntries) {
0838 ++iEventSequence_;
0839 if (iEventSequence_ < iEventSequenceEnd_) {
0840 eventSequenceIndex_ = iEventSequence_->runOrLumiIndex_;
0841 eventSequenceRunOrLumiEntry_ = &runOrLumiEntries[eventSequenceIndex_];
0842 }
0843 }
0844
0845
0846
0847 std::vector<TTreeEntryAndIndex> runsWithNoEvents_;
0848 std::vector<TTreeEntryAndIndex>::const_iterator nextRunWithNoEvents_;
0849 std::vector<TTreeEntryAndIndex>::const_iterator endRunsWithNoEvents_;
0850 };
0851
0852 void addRunsWithNoEvents(EntryOrderInitializationInfo&, EntryNumber_t maxRunTTreeEntry = invalidEntry);
0853 void fillLumisWithNoRemainingEvents(std::vector<TTreeEntryAndIndex>& lumisWithNoRemainingEvents,
0854 int startingIndex,
0855 EntryNumber_t currentRun,
0856 RunOrLumiEntry const* eventSequenceRunOrLumiEntry) const;
0857 void reserveSpaceInVectors(std::vector<EntryNumber_t>::size_type);
0858 void addToFileOrder(int index, bool processRunOrLumi, bool processEvents);
0859 void handleToEndOfContiguousEventsInRun(EntryOrderInitializationInfo& info, EntryNumber_t currentRun);
0860 void handleToEndOfContiguousEventsInLumis(EntryOrderInitializationInfo& info,
0861 EntryNumber_t currentRun,
0862 int endOfRunEntries);
0863 EntryNumber_t lowestInLumi(EntryOrderInitializationInfo& info, int currentLumi) const;
0864 void handleLumisWithNoEvents(std::vector<TTreeEntryAndIndex>::const_iterator& nextLumiWithNoEvents,
0865 std::vector<TTreeEntryAndIndex>::const_iterator& endLumisWithNoEvents,
0866 EntryNumber_t lumiTTreeEntryNumber,
0867 bool completeAll = false);
0868 void handleLumiWithEvents(EntryOrderInitializationInfo& info,
0869 int currentLumi,
0870 EntryNumber_t firstBeginEventsContiguousLumi);
0871 void handleLumiEntriesNoRemainingEvents(EntryOrderInitializationInfo& info,
0872 int& iLumiIndex,
0873 int currentLumi,
0874 EntryNumber_t firstBeginEventsContiguousLumi,
0875 bool completeAll = false);
0876
0877 int indexedSize_ = 0;
0878 std::vector<EntryNumber_t> fileOrderRunOrLumiEntry_;
0879 std::vector<bool> shouldProcessRunOrLumi_;
0880 std::vector<bool> shouldProcessEvents_;
0881 };
0882
0883
0884
0885
0886 class IndexIntoFileItr {
0887 public:
0888
0889
0890
0891
0892
0893
0894
0895
0896 IndexIntoFileItr(IndexIntoFile const* indexIntoFile,
0897 SortOrder sortOrder,
0898 EntryType entryType,
0899 int indexToRun,
0900 int indexToLumi,
0901 int indexToEventRange,
0902 long long indexToEvent,
0903 long long nEvents);
0904
0905 EntryType getEntryType() const { return impl_->getEntryType(); }
0906 int processHistoryIDIndex() const { return impl_->processHistoryIDIndex(); }
0907 RunNumber_t run() const { return impl_->run(); }
0908 LuminosityBlockNumber_t lumi() const { return impl_->lumi(); }
0909 EntryNumber_t entry() const { return impl_->entry(); }
0910 bool shouldProcessLumi() const { return impl_->shouldProcessLumi(); }
0911 bool shouldProcessRun() const { return impl_->shouldProcessRun(); }
0912 bool lumiIterationStartingIndex(int index) const { return impl_->lumiIterationStartingIndex(index); }
0913
0914
0915
0916 LuminosityBlockNumber_t peekAheadAtLumi() const { return impl_->peekAheadAtLumi(); }
0917
0918
0919
0920
0921
0922 EntryNumber_t peekAheadAtEventEntry() const { return impl_->peekAheadAtEventEntry(); }
0923
0924
0925
0926
0927 EntryNumber_t firstEventEntryThisRun() { return impl_->firstEventEntryThisRun(); }
0928 EntryNumber_t firstEventEntryThisLumi() { return impl_->firstEventEntryThisLumi(); }
0929
0930
0931
0932
0933
0934
0935
0936
0937
0938
0939
0940
0941
0942
0943 IndexIntoFileItr& operator++() {
0944 impl_->next();
0945 return *this;
0946 }
0947
0948
0949
0950
0951
0952
0953 void skipEventForward(int& phIndexOfSkippedEvent,
0954 RunNumber_t& runOfSkippedEvent,
0955 LuminosityBlockNumber_t& lumiOfSkippedEvent,
0956 EntryNumber_t& skippedEventEntry) {
0957 impl_->skipEventForward(phIndexOfSkippedEvent, runOfSkippedEvent, lumiOfSkippedEvent, skippedEventEntry);
0958 }
0959
0960
0961
0962
0963
0964
0965
0966
0967 void skipEventBackward(int& phIndexOfEvent,
0968 RunNumber_t& runOfEvent,
0969 LuminosityBlockNumber_t& lumiOfEvent,
0970 EntryNumber_t& eventEntry) {
0971 impl_->skipEventBackward(phIndexOfEvent, runOfEvent, lumiOfEvent, eventEntry);
0972 }
0973
0974
0975
0976 bool skipLumiInRun() { return impl_->skipLumiInRun(); }
0977
0978
0979
0980 bool skipToNextEventInLumi() { return impl_->skipToNextEventInLumi(); }
0981
0982 void advanceToNextRun() { impl_->advanceToNextRun(); }
0983 void advanceToNextLumiOrRun() { impl_->advanceToNextLumiOrRun(); }
0984
0985 void advanceToEvent();
0986 void advanceToLumi();
0987
0988 bool operator==(IndexIntoFileItr const& right) const { return *impl_ == *right.impl_; }
0989
0990 bool operator!=(IndexIntoFileItr const& right) const { return !(*this == right); }
0991
0992
0993 void initializeRun() { impl_->initializeRun(); }
0994
0995
0996 void initializeLumi() { impl_->initializeLumi(); }
0997
0998
0999 void copyPosition(IndexIntoFileItr const& position);
1000
1001 void getLumisInRun(std::vector<LuminosityBlockNumber_t>& lumis) const { impl_->getLumisInRun(lumis); }
1002
1003 private:
1004
1005 friend class ::TestIndexIntoFile;
1006 friend class ::TestIndexIntoFile2;
1007 friend class ::TestIndexIntoFile3;
1008 friend class ::TestIndexIntoFile4;
1009 friend class ::TestIndexIntoFile5;
1010
1011
1012
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
1023 value_ptr<IndexIntoFileItrImpl> impl_;
1024 };
1025
1026
1027
1028
1029 class IndexRunKey {
1030 public:
1031 IndexRunKey(int index, RunNumber_t run) : processHistoryIDIndex_(index), run_(run) {}
1032
1033 int processHistoryIDIndex() const { return processHistoryIDIndex_; }
1034 RunNumber_t run() const { return run_; }
1035
1036 bool operator<(IndexRunKey const& right) const {
1037 if (processHistoryIDIndex_ == right.processHistoryIDIndex()) {
1038 return run_ < right.run();
1039 }
1040 return processHistoryIDIndex_ < right.processHistoryIDIndex();
1041 }
1042
1043 private:
1044 int processHistoryIDIndex_;
1045 RunNumber_t run_;
1046 };
1047
1048
1049
1050
1051 class IndexRunLumiKey {
1052 public:
1053 IndexRunLumiKey(int index, RunNumber_t run, LuminosityBlockNumber_t lumi)
1054 : processHistoryIDIndex_(index), run_(run), lumi_(lumi) {}
1055
1056 int processHistoryIDIndex() const { return processHistoryIDIndex_; }
1057 RunNumber_t run() const { return run_; }
1058 LuminosityBlockNumber_t lumi() const { return lumi_; }
1059
1060 bool operator<(IndexRunLumiKey const& right) const {
1061 if (processHistoryIDIndex_ == right.processHistoryIDIndex()) {
1062 if (run_ == right.run()) {
1063 return lumi_ < right.lumi();
1064 }
1065 return run_ < right.run();
1066 }
1067 return processHistoryIDIndex_ < right.processHistoryIDIndex();
1068 }
1069
1070 private:
1071 int processHistoryIDIndex_;
1072 RunNumber_t run_;
1073 LuminosityBlockNumber_t lumi_;
1074 };
1075
1076
1077
1078
1079 class IndexRunLumiEventKey {
1080 public:
1081 IndexRunLumiEventKey(int index, RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
1082 : processHistoryIDIndex_(index), run_(run), lumi_(lumi), event_(event) {}
1083
1084 int processHistoryIDIndex() const { return processHistoryIDIndex_; }
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 {
1090 if (processHistoryIDIndex_ == right.processHistoryIDIndex()) {
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 }
1099 return processHistoryIDIndex_ < right.processHistoryIDIndex();
1100 }
1101
1102 private:
1103 int processHistoryIDIndex_;
1104 RunNumber_t run_;
1105 LuminosityBlockNumber_t lumi_;
1106 EventNumber_t event_;
1107 };
1108
1109
1110
1111
1112 class EventFinder {
1113 public:
1114 virtual ~EventFinder() {}
1115 virtual EventNumber_t getEventNumberOfEntry(EntryNumber_t entry) const = 0;
1116 };
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126 void addEntry(ProcessHistoryID const& processHistoryID,
1127 RunNumber_t run,
1128 LuminosityBlockNumber_t lumi,
1129 EventNumber_t event,
1130 EntryNumber_t entry);
1131
1132
1133
1134
1135
1136 void sortVector_Run_Or_Lumi_Entries();
1137
1138
1139 void checkForMissingRunOrLumiEntry() const;
1140
1141
1142 void addLumi(int index, RunNumber_t run, LuminosityBlockNumber_t lumi, EntryNumber_t entry);
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154 void fixIndexes(std::vector<ProcessHistoryID>& processHistoryIDs);
1155
1156
1157
1158 void setNumberOfEvents(EntryNumber_t nevents) { transient_.numberOfEvents_ = nevents; }
1159
1160
1161
1162
1163
1164
1165 void setEventFinder(std::shared_ptr<EventFinder> ptr) { transient_.eventFinder_ = ptr; }
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180 void fillEventNumbers() const;
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195 void fillEventEntries() const;
1196
1197
1198
1199
1200
1201
1202 void fillEventNumbersOrEntries(bool needEventNumbers, bool needEventEntries) const;
1203
1204
1205
1206
1207 std::vector<EventNumber_t>& unsortedEventNumbers() { return transient_.unsortedEventNumbers_; }
1208 std::vector<EventNumber_t> const& unsortedEventNumbers() const { return transient_.unsortedEventNumbers_; }
1209
1210
1211
1212 void inputFileClosed();
1213
1214
1215 void doneFileInitialization();
1216
1217
1218
1219
1220 std::vector<RunOrLumiEntry>& setRunOrLumiEntries() { return runOrLumiEntries_; }
1221
1222
1223
1224
1225 std::vector<ProcessHistoryID>& setProcessHistoryIDs() { return processHistoryIDs_; }
1226
1227
1228
1229
1230 void reduceProcessHistoryIDs(ProcessHistoryRegistry const& processHistoryRegistry);
1231
1232
1233
1234
1235
1236 std::vector<RunOrLumiEntry> const& runOrLumiEntries() const { return runOrLumiEntries_; }
1237
1238
1239
1240
1241 void initializeTransients() { transient_.reset(); }
1242
1243 struct Transients {
1244 Transients();
1245 void reset();
1246 int previousAddedIndex_;
1247 std::map<IndexRunKey, EntryNumber_t> runToOrder_;
1248 std::map<IndexRunLumiKey, EntryNumber_t> lumiToOrder_;
1249 EntryNumber_t beginEvents_;
1250 EntryNumber_t endEvents_;
1251 int currentIndex_;
1252 RunNumber_t currentRun_;
1253 LuminosityBlockNumber_t currentLumi_;
1254 EntryNumber_t numberOfEvents_;
1255 edm::propagate_const<std::shared_ptr<EventFinder>> eventFinder_;
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
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
1271
1272
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; }
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;
1282 int& previousAddedIndex() const { return transient_.previousAddedIndex_; }
1283 std::map<IndexRunKey, EntryNumber_t>& runToOrder() const { return transient_.runToOrder_; }
1284 std::map<IndexRunLumiKey, EntryNumber_t>& lumiToOrder() const { return transient_.lumiToOrder_; }
1285 EntryNumber_t& beginEvents() const { return transient_.beginEvents_; }
1286 EntryNumber_t& endEvents() const { return transient_.endEvents_; }
1287 int& currentIndex() const { return transient_.currentIndex_; }
1288 RunNumber_t& currentRun() const { return transient_.currentRun_; }
1289 LuminosityBlockNumber_t& currentLumi() const { return transient_.currentLumi_; }
1290 std::vector<RunOrLumiIndexes>& runOrLumiIndexes() const { return transient_.runOrLumiIndexes_; }
1291 size_t numberOfEvents() const { return transient_.numberOfEvents_; }
1292 EventNumber_t getEventNumberOfEntry(EntryNumber_t entry) const {
1293 return transient_.eventFinder_->getEventNumberOfEntry(entry);
1294 }
1295
1296
1297 CMS_SA_ALLOW mutable Transients transient_;
1298
1299 std::vector<ProcessHistoryID> processHistoryIDs_;
1300 std::vector<RunOrLumiEntry> runOrLumiEntries_;
1301 };
1302
1303 template <>
1304 struct value_ptr_traits<IndexIntoFile::IndexIntoFileItrImpl> {
1305 static IndexIntoFile::IndexIntoFileItrImpl* clone(IndexIntoFile::IndexIntoFileItrImpl const* p) {
1306 return p->clone();
1307 }
1308 static void destroy(IndexIntoFile::IndexIntoFileItrImpl* p) { delete p; }
1309 };
1310
1311 class Compare_Index_Run {
1312 public:
1313 bool operator()(IndexIntoFile::RunOrLumiIndexes const& lh, IndexIntoFile::RunOrLumiIndexes const& rh);
1314 };
1315
1316 class Compare_Index {
1317 public:
1318 bool operator()(IndexIntoFile::RunOrLumiIndexes const& lh, IndexIntoFile::RunOrLumiIndexes const& rh);
1319 };
1320
1321
1322 class IndexIntoFileItrHolder {
1323 public:
1324 IndexIntoFileItrHolder(IndexIntoFile::IndexIntoFileItr const& iIter) : iter_(iIter) {}
1325 void getLumisInRun(std::vector<LuminosityBlockNumber_t>& lumis) const { iter_.getLumisInRun(lumis); }
1326
1327 private:
1328 IndexIntoFile::IndexIntoFileItr const& iter_;
1329 };
1330 }
1331
1332 #endif