Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:25

0001 #ifndef DataFormats_FWLite_MultiChainEvent_h
0002 #define DataFormats_FWLite_MultiChainEvent_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWLite
0006 // Class  :     MultiChainEvent
0007 //
0008 /**\class MultiChainEvent MultiChainEvent.h DataFormats/FWLite/interface/MultiChainEvent.h
0009 
0010  Description: FWLite chain event that is aware of two files at once
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Salvatore Rappoccio
0018 //         Created:  Thu Jul  9 22:05:56 CDT 2009
0019 //
0020 // system include files
0021 #include <memory>
0022 #include <string>
0023 #include <typeinfo>
0024 #include <vector>
0025 
0026 // user include files
0027 #include "DataFormats/FWLite/interface/EventBase.h"
0028 #include "DataFormats/FWLite/interface/ChainEvent.h"
0029 #include "FWCore/Utilities/interface/propagate_const.h"
0030 
0031 // forward declarations
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 }  // namespace edm
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     ///Go to the event at index iIndex
0064     bool to(Long64_t iIndex);
0065 
0066     //If lumi is non-zero, Go to event by Run, Lumi, and Event number
0067     //If lumi is zero, Go to event by Run and Event number
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     // Go to the very first Event.
0073     const MultiChainEvent& toBegin() override;
0074 
0075     // ---------- const member functions ---------------------
0076     std::string const getBranchNameFor(std::type_info const&, char const*, char const*, char const*) const override;
0077 
0078     using fwlite::EventBase::getByLabel;
0079 
0080     /** This function should only be called by fwlite::Handle<>*/
0081     bool getByLabel(std::type_info const&, char const*, char const*, char const*, void*) const override;
0082     //void getByBranchName(std::type_info const&, char const*, void*&) const;
0083 
0084     bool isValid() const;
0085     operator bool() const;
0086     bool atEnd() const override;
0087 
0088     Long64_t size() const;
0089 
0090     edm::EventAuxiliary const& eventAuxiliary() const override;
0091 
0092     std::vector<edm::BranchDescription> const& getBranchDescriptions() const;
0093     std::vector<std::string> const& getProcessHistory() const;
0094     edm::ProcessHistory const& processHistory() const override;
0095     TFile* getTFile() const { return event1_->getTFile(); }
0096     TFile* getTFileSec() const { return event2_->getTFile(); }
0097 
0098     Long64_t eventIndex() const { return event1_->eventIndex(); }
0099     Long64_t eventIndexSec() const { return event2_->eventIndex(); }
0100 
0101     fwlite::LuminosityBlock const& getLuminosityBlock() { return event1_->getLuminosityBlock(); }
0102 
0103     fwlite::Run const& getRun() { return event1_->getRun(); }
0104 
0105     Long64_t fileIndex() const override { return event1_->eventIndex(); }
0106     Long64_t secondaryFileIndex() const override { return event2_->eventIndex(); }
0107 
0108     edm::TriggerNames const& triggerNames(edm::TriggerResults const& triggerResults) const override;
0109     edm::TriggerResultsByName triggerResultsByName(edm::TriggerResults const& triggerResults) const override;
0110 
0111     edm::ParameterSet const* parameterSet(edm::ParameterSetID const& psID) const override;
0112 
0113     // ---------- static member functions --------------------
0114     static void throwProductNotFoundException(std::type_info const&, char const*, char const*, char const*);
0115 
0116     // return the two chain events
0117     ChainEvent const* primary() const { return &*event1_; }
0118     ChainEvent const* secondary() const { return &*event2_; }
0119 
0120     // ---------- member functions ---------------------------
0121 
0122     edm::WrapperBase const* getByProductID(edm::ProductID const&) const override;
0123 
0124     std::optional<std::tuple<edm::WrapperBase const*, unsigned int>> getThinnedProduct(edm::ProductID const& pid,
0125                                                                                        unsigned int key) const;
0126 
0127     void getThinnedProducts(edm::ProductID const& pid,
0128                             std::vector<edm::WrapperBase const*>& foundContainers,
0129                             std::vector<unsigned int>& keys) const;
0130 
0131     edm::OptionalThinnedKey getThinnedKeyFrom(edm::ProductID const& parent,
0132                                               unsigned int key,
0133                                               edm::ProductID const& thinned) const;
0134 
0135   private:
0136     MultiChainEvent(Event const&);  // stop default
0137 
0138     const MultiChainEvent& operator=(Event const&);  // stop default
0139 
0140     ///Go to the event from secondary files at index iIndex
0141     bool toSec(Long64_t iIndex);
0142 
0143     //Go to event from secondary files by Run, Lumi (if non-zero), and  Event number
0144     bool toSec(const edm::EventID& id);
0145     bool toSec(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, edm::EventNumber_t event);
0146     bool toSec(edm::RunNumber_t run, edm::EventNumber_t event);
0147 
0148     // ---------- member data --------------------------------
0149 
0150     std::shared_ptr<ChainEvent> event1_;  // primary files
0151     std::shared_ptr<ChainEvent> event2_;  // secondary files
0152     std::shared_ptr<internal::MultiProductGetter const> getter_;
0153 
0154     // speed up secondary file access with a (run range)_1 ---> index_2 map,
0155     // when the files are sorted by run,event within the file.
0156     // in this case, it is sufficient to store only a run-range to index mapping.
0157     // with this, the solution becomes more performant.
0158     bool useSecFileMapSorted_;
0159     sec_file_range_index_map secFileMapSorted_;
0160   };
0161 
0162 }  // namespace fwlite
0163 #endif