Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-01 00:02:34

0001 #ifndef DataFormats_Provenance_CompactEventAuxiliaryVector_h
0002 #define DataFormats_Provenance_CompactEventAuxiliaryVector_h
0003 
0004 #include <vector>
0005 #include <unordered_set>
0006 
0007 #include "DataFormats/Provenance/interface/EventAuxiliary.h"
0008 #include "FWCore/Utilities/interface/hash_combine.h"
0009 
0010 namespace edm {
0011   class CompactEventAuxiliaryVector {
0012   public:
0013     using ExperimentType = EventAuxiliary::ExperimentType;
0014     static int const invalidBunchXing = EventAuxiliary::invalidBunchXing;
0015     static int const invalidStoreNumber = EventAuxiliary::invalidStoreNumber;
0016 
0017     // These components of EventAuxiliary change infrequently, so
0018     // they are stored in a std::unordered_set with a reference in
0019     // CompactEventAuxiliary
0020     class CompactEventAuxiliaryExtra {
0021     public:
0022       CompactEventAuxiliaryExtra(bool isReal, ExperimentType eType, int storeNum)
0023           : processHistoryID_(), isRealData_(isReal), experimentType_(eType), storeNumber_(storeNum) {}
0024       CompactEventAuxiliaryExtra(const EventAuxiliary& ea)
0025           : processHistoryID_(ea.processHistoryID()),
0026             isRealData_(ea.isRealData()),
0027             experimentType_(ea.experimentType()),
0028             storeNumber_(ea.storeNumber()) {}
0029 
0030       bool operator==(const CompactEventAuxiliaryExtra& extra) const {
0031         return processHistoryID_ == extra.processHistoryID_ && isRealData_ == extra.isRealData_ &&
0032                experimentType_ == extra.experimentType_ && storeNumber_ == extra.storeNumber_;
0033       }
0034       void write(std::ostream& os) const;
0035 
0036       // Process history ID of the full process history (not the reduced process history)
0037       ProcessHistoryID processHistoryID_;
0038       // Is this real data (i.e. not simulated)
0039       bool isRealData_;
0040       // Something descriptive of the source of the data
0041       ExperimentType experimentType_;
0042       //  The LHC store number
0043       int storeNumber_;
0044     };
0045 
0046     struct ExtraHash {
0047       std::size_t operator()(CompactEventAuxiliaryExtra const& extra) const noexcept {
0048         return hash_value(
0049             extra.processHistoryID_.compactForm(), extra.isRealData_, extra.experimentType_, extra.storeNumber_);
0050       }
0051     };
0052 
0053     using GUIDmemo = std::unordered_set<std::string>;
0054     using extraMemo = std::unordered_set<CompactEventAuxiliaryExtra, ExtraHash>;
0055 
0056     class CompactEventAuxiliary {
0057     public:
0058       CompactEventAuxiliary(EventID const& theId,
0059                             std::string const& processGUID,
0060                             Timestamp const& theTime,
0061                             int bunchXing,
0062                             int orbitNum,
0063                             CompactEventAuxiliaryExtra const& extra,
0064                             GUIDmemo& guidmemo,
0065                             extraMemo& extramemo)
0066           : id_(theId),
0067             processGUID_(memoize(processGUID, guidmemo)),
0068             time_(theTime),
0069             bunchCrossing_(bunchXing),
0070             orbitNumber_(orbitNum),
0071             extra_(memoize(extra, extramemo)) {}
0072       CompactEventAuxiliary(const EventAuxiliary& ea, GUIDmemo& guidmemo, extraMemo& extramemo)
0073           : id_(ea.id()),
0074             processGUID_(memoize(ea.processGUID(), guidmemo)),
0075             time_(ea.time()),
0076             bunchCrossing_(ea.bunchCrossing()),
0077             orbitNumber_(ea.orbitNumber()),
0078             extra_(memoize(CompactEventAuxiliaryExtra(ea), extramemo)) {}
0079 
0080       void write(std::ostream& os) const;
0081 
0082       ProcessHistoryID const& processHistoryID() const { return extra_.processHistoryID_; }
0083       EventID const& id() const { return id_; }
0084       std::string const& processGUID() const { return processGUID_; }
0085       Timestamp const& time() const { return time_; }
0086       LuminosityBlockNumber_t luminosityBlock() const { return id_.luminosityBlock(); }
0087       EventNumber_t event() const { return id_.event(); }
0088       RunNumber_t run() const { return id_.run(); }
0089       bool isRealData() const { return extra_.isRealData_; }
0090       ExperimentType experimentType() const { return extra_.experimentType_; }
0091       int bunchCrossing() const { return bunchCrossing_; }
0092       int orbitNumber() const { return orbitNumber_; }
0093       int storeNumber() const { return extra_.storeNumber_; }
0094 
0095       EventAuxiliary eventAuxiliary() const {
0096         auto ea{EventAuxiliary(id_,
0097                                processGUID_,
0098                                time_,
0099                                extra_.isRealData_,
0100                                extra_.experimentType_,
0101                                bunchCrossing_,
0102                                extra_.storeNumber_,
0103                                orbitNumber_)};
0104         ea.setProcessHistoryID(extra_.processHistoryID_);
0105         return ea;
0106       }
0107 
0108     private:
0109       template <typename T, typename C>
0110       const T& memoize(const T& item, C& memopad) const {
0111         auto it = memopad.insert(item);
0112         return *it.first;
0113       }
0114 
0115       // Event ID
0116       EventID id_;
0117       // Globally unique process ID of process that created event.
0118       const std::string& processGUID_;
0119       // Time from DAQ
0120       Timestamp time_;
0121       //  The bunch crossing number
0122       int bunchCrossing_;
0123       // The orbit number
0124       int orbitNumber_;
0125       // the stuff that changes slowly
0126       const CompactEventAuxiliaryExtra& extra_;
0127     };
0128 
0129     using value_type = CompactEventAuxiliary;
0130     using iterator = std::vector<value_type>::iterator;
0131     using size_type = std::vector<value_type>::size_type;
0132     using const_iterator = std::vector<value_type>::const_iterator;
0133 
0134     size_type size() const { return compactAuxiliaries_.size(); }
0135     void reserve(std::size_t size) { compactAuxiliaries_.reserve(size); }
0136     const_iterator begin() const { return compactAuxiliaries_.begin(); }
0137     const_iterator end() const { return compactAuxiliaries_.end(); }
0138     const_iterator cbegin() const { return compactAuxiliaries_.cbegin(); }
0139     const_iterator cend() const { return compactAuxiliaries_.cend(); }
0140 
0141     size_type extrasSize() const { return extras_.size(); }
0142     size_type guidsSize() const { return processGUIDs_.size(); }
0143 
0144     void push_back(const EventAuxiliary& ea) { compactAuxiliaries_.emplace_back(ea, processGUIDs_, extras_); }
0145 
0146   private:
0147     // Items that change every event
0148     std::vector<CompactEventAuxiliary> compactAuxiliaries_;
0149     // Items that change relatively infrequently
0150     extraMemo extras_;
0151     // Globally unique process IDs of processes that created events.
0152     GUIDmemo processGUIDs_;
0153   };
0154 
0155   inline std::ostream& operator<<(std::ostream& os, const CompactEventAuxiliaryVector::CompactEventAuxiliary& p) {
0156     p.write(os);
0157     return os;
0158   }
0159 
0160   inline std::ostream& operator<<(std::ostream& os, const CompactEventAuxiliaryVector::CompactEventAuxiliaryExtra& p) {
0161     p.write(os);
0162     return os;
0163   }
0164 }  // namespace edm
0165 
0166 #endif