Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:09

0001 #ifndef DataFormats_FWLite_ChainEvent_h
0002 #define DataFormats_FWLite_ChainEvent_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWLite
0006 // Class  :     ChainEvent
0007 //
0008 /**\class ChainEvent ChainEvent.h DataFormats/FWLite/interface/ChainEvent.h
0009 
0010  Description: <one line class summary>
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Tue May  8 15:01:20 EDT 2007
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/Event.h"
0028 #include "DataFormats/FWLite/interface/EventBase.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   class ChainEvent : public EventBase {
0047   public:
0048     ChainEvent(std::vector<std::string> const& iFileNames);
0049     ~ChainEvent() override;
0050 
0051     ChainEvent const& operator++() override;
0052 
0053     ///Go to the event at index iIndex
0054     bool to(Long64_t iIndex);
0055 
0056     // If lumi is non-zero, go to event by Run, Lumi and Event number
0057     // If lumi is 0, go to event by Run and Event number only.
0058     bool to(const edm::EventID& id);
0059     bool to(edm::RunNumber_t run, edm::EventNumber_t event);
0060     bool to(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, edm::EventNumber_t event);
0061 
0062     // Go to the very first Event.
0063     ChainEvent const& toBegin() override;
0064 
0065     // ---------- const member functions ---------------------
0066     std::string const getBranchNameFor(std::type_info const&, char const*, char const*, char const*) const override;
0067     template <typename T>
0068     edm::EDGetTokenT<T> consumes(edm::InputTag const& iTag) const {
0069       return event_->consumes<T>(iTag);
0070     }
0071     using fwlite::EventBase::getByLabel;
0072 
0073     // This function should only be called by fwlite::Handle<>
0074     bool getByLabel(std::type_info const&, char const*, char const*, char const*, void*) const override;
0075     //void getByBranchName(std::type_info const&, char const*, void*&) const;
0076 
0077     bool isValid() const;
0078     operator bool() const;
0079     bool atEnd() const override;
0080 
0081     Long64_t size() const;
0082 
0083     edm::EventAuxiliary const& eventAuxiliary() const override;
0084 
0085     std::vector<edm::BranchDescription> const& getBranchDescriptions() const;
0086     std::vector<std::string> const& getProcessHistory() const;
0087     edm::ProcessHistory const& processHistory() const override;
0088     TFile* getTFile() const { return event_->getTFile(); }
0089 
0090     // These functions return the index of the file that the current event
0091     // resides in. Note that the file index is based on the vector of files
0092     // which were actually opened, not the vector of input files in the
0093     // constructor. These two may differ in the case some input files contain
0094     // 0 events. To get the path of the file where the current event resides
0095     // in, fwlite::ChainEvent::getTFile()->GetPath() is preferred.
0096     Long64_t eventIndex() const { return eventIndex_; }
0097     Long64_t fileIndex() const override { return eventIndex_; }
0098 
0099     void setGetter(std::shared_ptr<edm::EDProductGetter const> getter) { event_->setGetter(getter); }
0100 
0101     Event const* event() const { return &*event_; }
0102 
0103     edm::TriggerNames const& triggerNames(edm::TriggerResults const& triggerResults) const override;
0104     void fillParameterSetRegistry() const;
0105     edm::TriggerResultsByName triggerResultsByName(edm::TriggerResults const& triggerResults) const override;
0106 
0107     edm::ParameterSet const* parameterSet(edm::ParameterSetID const& psID) const override;
0108 
0109     // ---------- static member functions --------------------
0110     static void throwProductNotFoundException(std::type_info const&, char const*, char const*, char const*);
0111 
0112     // ---------- member functions ---------------------------
0113 
0114     edm::WrapperBase const* getByProductID(edm::ProductID const&) const override;
0115     std::optional<std::tuple<edm::WrapperBase const*, unsigned int>> getThinnedProduct(edm::ProductID const& pid,
0116                                                                                        unsigned int key) const;
0117 
0118     void getThinnedProducts(edm::ProductID const& pid,
0119                             std::vector<edm::WrapperBase const*>& foundContainers,
0120                             std::vector<unsigned int>& keys) const;
0121 
0122     edm::OptionalThinnedKey getThinnedKeyFrom(edm::ProductID const& parent,
0123                                               unsigned int key,
0124                                               edm::ProductID const& thinned) const;
0125 
0126     fwlite::LuminosityBlock const& getLuminosityBlock();
0127     fwlite::Run const& getRun();
0128 
0129   private:
0130     bool getByTokenImp(edm::EDGetToken, edm::WrapperBase const*&) const override;
0131 
0132     friend class MultiChainEvent;
0133 
0134     ChainEvent(Event const&);  // stop default
0135 
0136     ChainEvent const& operator=(Event const&);  // stop default
0137 
0138     void findSizes();
0139     void switchToFile(Long64_t);
0140     // ---------- member data --------------------------------
0141     std::vector<std::string> fileNames_;
0142     edm::propagate_const<std::shared_ptr<TFile>> file_;
0143     edm::propagate_const<std::shared_ptr<Event>> event_;
0144     Long64_t eventIndex_;
0145     std::vector<Long64_t> accumulatedSize_;
0146     edm::propagate_const<std::shared_ptr<edm::EDProductGetter>> getter_;
0147   };
0148 
0149 }  // namespace fwlite
0150 #endif