File indexing completed on 2023-03-17 10:49:50
0001 #ifndef DataFormats_FWLite_MultiChainEvent_h
0002 #define DataFormats_FWLite_MultiChainEvent_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <memory>
0022 #include <string>
0023 #include <typeinfo>
0024 #include <vector>
0025
0026
0027 #include "DataFormats/FWLite/interface/EventBase.h"
0028 #include "DataFormats/FWLite/interface/ChainEvent.h"
0029 #include "FWCore/Utilities/interface/propagate_const.h"
0030
0031
0032 namespace edm {
0033 class WrapperBase;
0034 class ProductRegistry;
0035 class ProcessHistory;
0036 class BranchDescription;
0037 class EDProductGetter;
0038 class EventAux;
0039 class TriggerResults;
0040 class TriggerNames;
0041 class TriggerResultsByName;
0042 }
0043
0044 namespace fwlite {
0045
0046 namespace internal {
0047 class MultiProductGetter;
0048 }
0049
0050 class MultiChainEvent : public EventBase {
0051 public:
0052 typedef std::map<edm::EventID, Long64_t> sec_file_index_map;
0053 typedef std::pair<edm::EventID, edm::EventID> event_id_range;
0054 typedef std::map<event_id_range, Long64_t> sec_file_range_index_map;
0055
0056 MultiChainEvent(std::vector<std::string> const& iFileNames1,
0057 std::vector<std::string> const& iFileNames2,
0058 bool useSecFileMapSorted = false);
0059 ~MultiChainEvent() override;
0060
0061 const MultiChainEvent& operator++() override;
0062
0063
0064 bool to(Long64_t iIndex);
0065
0066
0067
0068 bool to(edm::EventID id);
0069 bool to(edm::RunNumber_t run, edm::EventNumber_t event);
0070 bool to(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, edm::EventNumber_t event);
0071
0072
0073 const MultiChainEvent& toBegin() override;
0074
0075
0076 std::string const getBranchNameFor(std::type_info const&, char const*, char const*, char const*) const override;
0077 template <typename T>
0078 edm::EDGetTokenT<T> consumes(edm::InputTag const& iTag) const {
0079 auto t = event1_->consumes<T>(iTag);
0080 if (t) {
0081 return t;
0082 }
0083 return event2_->consumes<T>(iTag);
0084 }
0085
0086 using fwlite::EventBase::getByLabel;
0087
0088
0089 bool getByLabel(std::type_info const&, char const*, char const*, char const*, void*) const override;
0090
0091
0092 bool isValid() const;
0093 operator bool() const;
0094 bool atEnd() const override;
0095
0096 Long64_t size() const;
0097
0098 edm::EventAuxiliary const& eventAuxiliary() const override;
0099
0100 std::vector<edm::BranchDescription> const& getBranchDescriptions() const;
0101 std::vector<std::string> const& getProcessHistory() const;
0102 edm::ProcessHistory const& processHistory() const override;
0103 TFile* getTFile() const { return event1_->getTFile(); }
0104 TFile* getTFileSec() const { return event2_->getTFile(); }
0105
0106 Long64_t eventIndex() const { return event1_->eventIndex(); }
0107 Long64_t eventIndexSec() const { return event2_->eventIndex(); }
0108
0109 fwlite::LuminosityBlock const& getLuminosityBlock() { return event1_->getLuminosityBlock(); }
0110
0111 fwlite::Run const& getRun() { return event1_->getRun(); }
0112
0113 Long64_t fileIndex() const override { return event1_->eventIndex(); }
0114 Long64_t secondaryFileIndex() const override { return event2_->eventIndex(); }
0115
0116 edm::TriggerNames const& triggerNames(edm::TriggerResults const& triggerResults) const override;
0117 edm::TriggerResultsByName triggerResultsByName(edm::TriggerResults const& triggerResults) const override;
0118
0119 edm::ParameterSet const* parameterSet(edm::ParameterSetID const& psID) const override;
0120
0121
0122 static void throwProductNotFoundException(std::type_info const&, char const*, char const*, char const*);
0123
0124
0125 ChainEvent const* primary() const { return &*event1_; }
0126 ChainEvent const* secondary() const { return &*event2_; }
0127
0128
0129
0130 edm::WrapperBase const* getByProductID(edm::ProductID const&) const override;
0131
0132 std::optional<std::tuple<edm::WrapperBase const*, unsigned int>> getThinnedProduct(edm::ProductID const& pid,
0133 unsigned int key) const;
0134
0135 void getThinnedProducts(edm::ProductID const& pid,
0136 std::vector<edm::WrapperBase const*>& foundContainers,
0137 std::vector<unsigned int>& keys) const;
0138
0139 edm::OptionalThinnedKey getThinnedKeyFrom(edm::ProductID const& parent,
0140 unsigned int key,
0141 edm::ProductID const& thinned) const;
0142
0143 private:
0144 bool getByTokenImp(edm::EDGetToken, edm::WrapperBase const*&) const override;
0145
0146 MultiChainEvent(Event const&);
0147
0148 const MultiChainEvent& operator=(Event const&);
0149
0150
0151 bool toSec(Long64_t iIndex);
0152
0153
0154 bool toSec(const edm::EventID& id);
0155 bool toSec(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, edm::EventNumber_t event);
0156 bool toSec(edm::RunNumber_t run, edm::EventNumber_t event);
0157
0158
0159
0160 std::shared_ptr<ChainEvent> event1_;
0161 std::shared_ptr<ChainEvent> event2_;
0162 std::shared_ptr<internal::MultiProductGetter const> getter_;
0163
0164
0165
0166
0167
0168 bool useSecFileMapSorted_;
0169 sec_file_range_index_map secFileMapSorted_;
0170 };
0171
0172 }
0173 #endif