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 }
43 
44 namespace fwlite {
45 
46  namespace internal {
47  class MultiProductGetter;
48  }
49 
51 {
52 
53  public:
54 
55  typedef std::map<edm::EventID, Long64_t> sec_file_index_map;
56  typedef std::pair<edm::EventID, edm::EventID> event_id_range;
57  typedef std::map<event_id_range, Long64_t> sec_file_range_index_map;
58 
59  MultiChainEvent(std::vector<std::string> const& iFileNames1,
60  std::vector<std::string> const& iFileNames2,
61  bool useSecFileMapSorted = false);
62  ~MultiChainEvent() override;
63 
64  const MultiChainEvent& operator++() override;
65 
67  bool to(Long64_t iIndex);
68 
69  //If lumi is non-zero, Go to event by Run, Lumi, and Event number
70  //If lumi is zero, Go to event by Run and Event number
71  bool to(edm::EventID id);
74 
75  // Go to the very first Event.
76  const MultiChainEvent& toBegin() override;
77 
78  // ---------- const member functions ---------------------
79  std::string const getBranchNameFor(std::type_info const&,
80  char const*,
81  char const*,
82  char const*) const override;
83 
85 
87  bool getByLabel(std::type_info const&, char const*, char const*, char const*, void*) const override;
88  //void getByBranchName(std::type_info const&, char const*, void*&) const;
89 
90  bool isValid() const;
91  operator bool() const;
92  bool atEnd() const override;
93 
94  Long64_t size() const;
95 
96  edm::EventAuxiliary const& eventAuxiliary() const override;
97 
98  std::vector<edm::BranchDescription> const& getBranchDescriptions() const;
99  std::vector<std::string> const& getProcessHistory() const;
100  edm::ProcessHistory const& processHistory() const override;
101  TFile* getTFile() const {
102  return event1_->getTFile();
103  }
104  TFile* getTFileSec() const {
105  return event2_->getTFile();
106  }
107 
108  Long64_t eventIndex() const { return event1_->eventIndex(); }
109  Long64_t eventIndexSec() const { return event2_->eventIndex(); }
110 
112  return event1_->getLuminosityBlock();
113  }
114 
115  fwlite::Run const& getRun() {
116  return event1_->getRun();
117  }
118 
119 
120  Long64_t fileIndex() const override
121  { return event1_->eventIndex(); }
122  Long64_t secondaryFileIndex() const override
123  { return event2_->eventIndex(); }
124 
125  edm::TriggerNames const& triggerNames(edm::TriggerResults const& triggerResults) const override;
126  edm::TriggerResultsByName triggerResultsByName(edm::TriggerResults const& triggerResults) const override;
127 
128  edm::ParameterSet const* parameterSet(edm::ParameterSetID const& psID) const override;
129 
130  // ---------- static member functions --------------------
131  static void throwProductNotFoundException(std::type_info const&, char const*, char const*, char const*);
132 
133  // return the two chain events
134  ChainEvent const* primary () const { return &*event1_;}
135  ChainEvent const* secondary() const { return &*event2_;}
136 
137  // ---------- member functions ---------------------------
138 
139  edm::WrapperBase const* getByProductID(edm::ProductID const&) const override;
140 
141  edm::WrapperBase const* getThinnedProduct(edm::ProductID const& pid, unsigned int& key) const;
142 
143  void getThinnedProducts(edm::ProductID const& pid,
144  std::vector<edm::WrapperBase const*>& foundContainers,
145  std::vector<unsigned int>& keys) const;
146 
147  private:
148 
149  MultiChainEvent(Event const&); // stop default
150 
151  const MultiChainEvent& operator= (Event const&); // stop default
152 
154  bool toSec(Long64_t iIndex);
155 
156  //Go to event from secondary files by Run, Lumi (if non-zero), and Event number
157  bool toSec(const edm::EventID &id);
159  bool toSec(edm::RunNumber_t run, edm::EventNumber_t event);
160 
161 
162  // ---------- member data --------------------------------
163 
164  std::shared_ptr<ChainEvent> event1_; // primary files
165  std::shared_ptr<ChainEvent> event2_; // secondary files
166  std::shared_ptr<internal::MultiProductGetter const> getter_;
167 
168  // speed up secondary file access with a (run range)_1 ---> index_2 map,
169  // when the files are sorted by run,event within the file.
170  // in this case, it is sufficient to store only a run-range to index mapping.
171  // with this, the solution becomes more performant.
173  sec_file_range_index_map secFileMapSorted_;
174 };
175 
176 }
177 #endif
size
Write out results.
TFile * getTFileSec() const
Long64_t eventIndexSec() const
ChainEvent const * secondary() const
unsigned long long EventNumber_t
Long64_t secondaryFileIndex() const override
fwlite::Run const & getRun()
ChainEvent const * primary() const
unsigned int LuminosityBlockNumber_t
virtual bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *) const =0
T const * getThinnedProduct(RefCore const &ref, unsigned int &thinnedKey, EDProductGetter const *prodGetter)
Definition: RefCoreGet.h:129
std::map< edm::EventID, Long64_t > sec_file_index_map
Long64_t fileIndex() const override
std::map< event_id_range, Long64_t > sec_file_range_index_map
sec_file_range_index_map secFileMapSorted_
static std::string const triggerResults("TriggerResults")
std::shared_ptr< internal::MultiProductGetter const > getter_
std::pair< edm::EventID, edm::EventID > event_id_range
HLT enums.
std::shared_ptr< ChainEvent > event2_
unsigned int RunNumber_t
static void throwProductNotFoundException(char const *where, errors::ErrorCodes error, BranchID const &bid)
Definition: Principal.cc:50
TFile * getTFile() const
Long64_t eventIndex() const
fwlite::LuminosityBlock const & getLuminosityBlock()
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
Definition: event.py:1
std::shared_ptr< ChainEvent > event1_