Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:01

0001 #ifndef DataFormats_Provenance_FileIndex_h
0002 #define DataFormats_Provenance_FileIndex_h
0003 
0004 /*----------------------------------------------------------------------
0005 
0006 FileIndex.h
0007 // Obsolete: For Backward compatibility only.
0008 
0009 ----------------------------------------------------------------------*/
0010 
0011 #include "DataFormats/Provenance/interface/RunID.h"
0012 #include "DataFormats/Provenance/interface/EventID.h"
0013 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0014 
0015 #include <cassert>
0016 #include <iosfwd>
0017 #include <vector>
0018 
0019 namespace edm {
0020 
0021   class FileIndex {
0022   public:
0023     typedef long long EntryNumber_t;
0024 
0025     FileIndex();
0026     ~FileIndex() {}
0027 
0028     void addEntry(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, EntryNumber_t entry);
0029 
0030     enum EntryType { kRun, kLumi, kEvent, kEnd };
0031 
0032     class Element {
0033     public:
0034       static EntryNumber_t const invalidEntry = -1LL;
0035       Element() : run_(0U), lumi_(0U), event_(0U), entry_(invalidEntry) {}
0036       Element(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event, long long entry)
0037           : run_(run), lumi_(lumi), event_(event), entry_(entry) {
0038         assert(lumi_ != 0U || event_ == 0U);
0039       }
0040       Element(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event)
0041           : run_(run), lumi_(lumi), event_(event), entry_(invalidEntry) {}
0042       EntryType getEntryType() const { return lumi_ == 0U ? kRun : (event_ == 0U ? kLumi : kEvent); }
0043       RunNumber_t run_;
0044       LuminosityBlockNumber_t lumi_;
0045       EventNumber_t event_;
0046       EntryNumber_t entry_;
0047     };
0048 
0049     typedef std::vector<Element>::const_iterator const_iterator;
0050 
0051     typedef std::vector<Element>::iterator iterator;
0052 
0053     void sortBy_Run_Lumi_Event();
0054     void sortBy_Run_Lumi_EventEntry();
0055 
0056     const_iterator findPosition(RunNumber_t run, LuminosityBlockNumber_t lumi = 0U, EventNumber_t event = 0U) const;
0057 
0058     const_iterator findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const;
0059 
0060     const_iterator findEventEntryPosition(RunNumber_t run,
0061                                           LuminosityBlockNumber_t lumi,
0062                                           EventNumber_t event,
0063                                           EntryNumber_t entry) const;
0064 
0065     const_iterator findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const;
0066 
0067     const_iterator findRunPosition(RunNumber_t run) const;
0068 
0069     const_iterator findLumiOrRunPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const;
0070 
0071     bool containsItem(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const {
0072       return (event != 0) ? containsEvent(run, lumi, event) : (lumi ? containsLumi(run, lumi) : containsRun(run));
0073     }
0074 
0075     bool containsEvent(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const {
0076       return findEventPosition(run, lumi, event) != entries_.end();
0077     }
0078 
0079     bool containsLumi(RunNumber_t run, LuminosityBlockNumber_t lumi) const {
0080       return findLumiPosition(run, lumi) != entries_.end();
0081     }
0082 
0083     bool containsRun(RunNumber_t run) const { return findRunPosition(run) != entries_.end(); }
0084 
0085     const_iterator begin() const { return entries_.begin(); }
0086 
0087     const_iterator end() const { return entries_.end(); }
0088 
0089     iterator begin() { return entries_.begin(); }
0090 
0091     iterator end() { return entries_.end(); }
0092 
0093     iterator erase(iterator pos) { return entries_.erase(pos); }
0094 
0095     iterator erase(iterator begin, iterator end) { return entries_.erase(begin, end); }
0096 
0097     std::vector<Element>::size_type size() const { return entries_.size(); }
0098 
0099     bool empty() const { return entries_.empty(); }
0100 
0101     bool allEventsInEntryOrder() const;
0102 
0103     enum SortState { kNotSorted, kSorted_Run_Lumi_Event, kSorted_Run_Lumi_EventEntry };
0104 
0105     void initializeTransients() const { transient_.reset(); }
0106 
0107     struct Transients {
0108       Transients();
0109       void reset();
0110       bool allInEntryOrder_;
0111       bool resultCached_;
0112       SortState sortState_;
0113     };
0114 
0115   private:
0116     bool& allInEntryOrder() const { return transient_.allInEntryOrder_; }
0117     bool& resultCached() const { return transient_.resultCached_; }
0118     SortState& sortState() const { return transient_.sortState_; }
0119 
0120     std::vector<Element> entries_;
0121     //Only used within source's serial code
0122     CMS_SA_ALLOW mutable Transients transient_;
0123   };
0124 
0125   bool operator<(FileIndex::Element const& lh, FileIndex::Element const& rh);
0126 
0127   inline bool operator>(FileIndex::Element const& lh, FileIndex::Element const& rh) { return rh < lh; }
0128 
0129   inline bool operator>=(FileIndex::Element const& lh, FileIndex::Element const& rh) { return !(lh < rh); }
0130 
0131   inline bool operator<=(FileIndex::Element const& lh, FileIndex::Element const& rh) { return !(rh < lh); }
0132 
0133   inline bool operator==(FileIndex::Element const& lh, FileIndex::Element const& rh) { return !(lh < rh || rh < lh); }
0134 
0135   inline bool operator!=(FileIndex::Element const& lh, FileIndex::Element const& rh) { return lh < rh || rh < lh; }
0136 
0137   class Compare_Run_Lumi_EventEntry {
0138   public:
0139     bool operator()(FileIndex::Element const& lh, FileIndex::Element const& rh);
0140   };
0141 
0142   std::ostream& operator<<(std::ostream& os, FileIndex const& fileIndex);
0143 }  // namespace edm
0144 
0145 #endif