CMS 3D CMS Logo

MultiChainEvent.h
Go to the documentation of this file.
1 #ifndef DataFormats_FWLite_MultiChainEvent_h
2 #define DataFormats_FWLite_MultiChainEvent_h
3 // -*- C++ -*-
4 //
5 // Package: FWLite
6 // Class : MultiChainEvent
7 //
16 //
17 // Original Author: Salvatore Rappoccio
18 // Created: Thu Jul 9 22:05:56 CDT 2009
19 //
20 // system include files
21 #include <memory>
22 #include <string>
23 #include <typeinfo>
24 #include <vector>
25 
26 // user include files
30 
31 // forward declarations
32 namespace edm {
33  class WrapperBase;
34  class ProductRegistry;
35  class ProcessHistory;
36  class BranchDescription;
37  class EDProductGetter;
38  class EventAux;
39  class TriggerResults;
40  class TriggerNames;
42 } // namespace edm
43 
44 namespace fwlite {
45 
46  namespace internal {
47  class MultiProductGetter;
48  }
49 
50  class MultiChainEvent : public EventBase {
51  public:
52  typedef std::map<edm::EventID, Long64_t> sec_file_index_map;
53  typedef std::pair<edm::EventID, edm::EventID> event_id_range;
54  typedef std::map<event_id_range, Long64_t> sec_file_range_index_map;
55 
56  MultiChainEvent(std::vector<std::string> const& iFileNames1,
57  std::vector<std::string> const& iFileNames2,
58  bool useSecFileMapSorted = false);
59  ~MultiChainEvent() override;
60 
61  const MultiChainEvent& operator++() override;
62 
64  bool to(Long64_t iIndex);
65 
66  //If lumi is non-zero, Go to event by Run, Lumi, and Event number
67  //If lumi is zero, Go to event by Run and Event number
68  bool to(edm::EventID id);
71 
72  // Go to the very first Event.
73  const MultiChainEvent& toBegin() override;
74 
75  // ---------- const member functions ---------------------
76  std::string const getBranchNameFor(std::type_info const&, char const*, char const*, char const*) const override;
77  template <typename T>
79  auto t = event1_->consumes<T>(iTag);
80  if (t) {
81  return t;
82  }
83  return event2_->consumes<T>(iTag);
84  }
85 
87 
89  bool getByLabel(std::type_info const&, char const*, char const*, char const*, void*) const override;
90  //void getByBranchName(std::type_info const&, char const*, void*&) const;
91 
92  bool isValid() const;
93  operator bool() const;
94  bool atEnd() const override;
95 
96  Long64_t size() const;
97 
98  edm::EventAuxiliary const& eventAuxiliary() const override;
99 
100  std::vector<edm::BranchDescription> const& getBranchDescriptions() const;
101  std::vector<std::string> const& getProcessHistory() const;
102  edm::ProcessHistory const& processHistory() const override;
103  TFile* getTFile() const { return event1_->getTFile(); }
104  TFile* getTFileSec() const { return event2_->getTFile(); }
105 
106  Long64_t eventIndex() const { return event1_->eventIndex(); }
107  Long64_t eventIndexSec() const { return event2_->eventIndex(); }
108 
109  fwlite::LuminosityBlock const& getLuminosityBlock() { return event1_->getLuminosityBlock(); }
110 
111  fwlite::Run const& getRun() { return event1_->getRun(); }
112 
113  Long64_t fileIndex() const override { return event1_->eventIndex(); }
114  Long64_t secondaryFileIndex() const override { return event2_->eventIndex(); }
115 
118 
119  edm::ParameterSet const* parameterSet(edm::ParameterSetID const& psID) const override;
120 
121  // ---------- static member functions --------------------
122  static void throwProductNotFoundException(std::type_info const&, char const*, char const*, char const*);
123 
124  // return the two chain events
125  ChainEvent const* primary() const { return &*event1_; }
126  ChainEvent const* secondary() const { return &*event2_; }
127 
128  // ---------- member functions ---------------------------
129 
130  edm::WrapperBase const* getByProductID(edm::ProductID const&) const override;
131 
132  std::optional<std::tuple<edm::WrapperBase const*, unsigned int>> getThinnedProduct(edm::ProductID const& pid,
133  unsigned int key) const;
134 
135  void getThinnedProducts(edm::ProductID const& pid,
136  std::vector<edm::WrapperBase const*>& foundContainers,
137  std::vector<unsigned int>& keys) const;
138 
140  unsigned int key,
141  edm::ProductID const& thinned) const;
142 
143  private:
144  bool getByTokenImp(edm::EDGetToken, edm::WrapperBase const*&) const override;
145 
146  MultiChainEvent(Event const&); // stop default
147 
148  const MultiChainEvent& operator=(Event const&); // stop default
149 
151  bool toSec(Long64_t iIndex);
152 
153  //Go to event from secondary files by Run, Lumi (if non-zero), and Event number
154  bool toSec(const edm::EventID& id);
157 
158  // ---------- member data --------------------------------
159 
160  std::shared_ptr<ChainEvent> event1_; // primary files
161  std::shared_ptr<ChainEvent> event2_; // secondary files
162  std::shared_ptr<internal::MultiProductGetter const> getter_;
163 
164  // speed up secondary file access with a (run range)_1 ---> index_2 map,
165  // when the files are sorted by run,event within the file.
166  // in this case, it is sufficient to store only a run-range to index mapping.
167  // with this, the solution becomes more performant.
170  };
171 
172 } // namespace fwlite
173 #endif
std::optional< std::tuple< edm::WrapperBase const *, unsigned int > > getThinnedProduct(edm::ProductID const &pid, unsigned int key) const
const MultiChainEvent & toBegin() override
ChainEvent const * secondary() const
edm::ParameterSet const * parameterSet(edm::ParameterSetID const &psID) const override
std::string const getBranchNameFor(std::type_info const &, char const *, char const *, char const *) const override
std::variant< unsigned int, detail::GetThinnedKeyFromExceptionFactory, std::monostate > OptionalThinnedKey
bool getByTokenImp(edm::EDGetToken, edm::WrapperBase const *&) const override
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
edm::EDGetTokenT< T > consumes(edm::InputTag const &iTag) const
unsigned long long EventNumber_t
Long64_t secondaryFileIndex() const override
edm::EventAuxiliary const & eventAuxiliary() const override
edm::ProcessHistory const & processHistory() const override
fwlite::Run const & getRun()
virtual bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *) const =0
unsigned int LuminosityBlockNumber_t
bool to(Long64_t iIndex)
Go to the event at index iIndex.
bool toSec(Long64_t iIndex)
Go to the event from secondary files at index iIndex.
edm::WrapperBase const * getByProductID(edm::ProductID const &) const override
edm::OptionalThinnedKey getThinnedKeyFrom(edm::ProductID const &parent, unsigned int key, edm::ProductID const &thinned) const
bool atEnd() const override
std::map< edm::EventID, Long64_t > sec_file_index_map
Long64_t fileIndex() const override
std::vector< edm::BranchDescription > const & getBranchDescriptions() const
key
prepare the HTCondor submission files and eventually submit them
void getThinnedProducts(edm::ProductID const &pid, std::vector< edm::WrapperBase const *> &foundContainers, std::vector< unsigned int > &keys) const
static void throwProductNotFoundException(std::type_info const &, char const *, char const *, char const *)
static std::string const triggerResults
Definition: EdmProvDump.cc:47
edm::TriggerResultsByName triggerResultsByName(edm::TriggerResults const &triggerResults) const override
std::map< event_id_range, Long64_t > sec_file_range_index_map
TFile * getTFile() const
sec_file_range_index_map secFileMapSorted_
ChainEvent const * primary() const
std::shared_ptr< internal::MultiProductGetter const > getter_
bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *) const override
MultiChainEvent(std::vector< std::string > const &iFileNames1, std::vector< std::string > const &iFileNames2, bool useSecFileMapSorted=false)
std::pair< edm::EventID, edm::EventID > event_id_range
std::vector< std::string > const & getProcessHistory() const
HLT enums.
const MultiChainEvent & operator=(Event const &)
Long64_t eventIndexSec() const
std::shared_ptr< ChainEvent > event2_
unsigned int RunNumber_t
const MultiChainEvent & operator++() override
Long64_t eventIndex() const
fwlite::LuminosityBlock const & getLuminosityBlock()
long double T
TFile * getTFileSec() const
Definition: event.py:1
std::shared_ptr< ChainEvent > event1_