CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DataFormats/FWLite/interface/MultiChainEvent.h

Go to the documentation of this file.
00001 #ifndef DataFormats_FWLite_MultiChainEvent_h
00002 #define DataFormats_FWLite_MultiChainEvent_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     FWLite
00006 // Class  :     MultiChainEvent
00007 //
00016 //
00017 // Original Author:  Salvatore Rappoccio
00018 //         Created:  Thu Jul  9 22:05:56 CDT 2009
00019 //
00020 #if !defined(__CINT__) && !defined(__MAKECINT__)
00021 // system include files
00022 #include <string>
00023 #include <typeinfo>
00024 #include <vector>
00025 #include "boost/shared_ptr.hpp"
00026 
00027 // user include files
00028 #include "DataFormats/FWLite/interface/EventBase.h"
00029 #include "DataFormats/FWLite/interface/ChainEvent.h"
00030 
00031 // forward declarations
00032 namespace edm {
00033   class WrapperHolder;
00034   class ProductRegistry;
00035   class ProcessHistory;
00036   class BranchDescription;
00037   class EDProductGetter;
00038   class EventAux;
00039   class TriggerResults;
00040   class TriggerNames;
00041   class TriggerResultsByName;
00042 }
00043 
00044 namespace fwlite {
00045 
00046   namespace internal {
00047     class MultiProductGetter;
00048   }
00049 
00050 class MultiChainEvent: public EventBase
00051 {
00052 
00053    public:
00054 
00055       typedef std::map<edm::EventID, Long64_t>      sec_file_index_map;
00056       typedef std::pair<edm::EventID, edm::EventID> event_id_range;
00057       typedef std::map<event_id_range, Long64_t>    sec_file_range_index_map;
00058 
00059       MultiChainEvent(std::vector<std::string> const& iFileNames1,
00060                       std::vector<std::string> const& iFileNames2,
00061                       bool useSecFileMapSorted = false);
00062       virtual ~MultiChainEvent();
00063 
00064       const MultiChainEvent& operator++();
00065 
00067       bool to(Long64_t iIndex);
00068 
00069       //If lumi is non-zero, Go to event by Run, Lumi, and Event number
00070       //If lumi is zero, Go to event by Run and Event number
00071       bool to(edm::EventID id);
00072       bool to(edm::RunNumber_t run, edm::EventNumber_t event);
00073       bool to(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, edm::EventNumber_t event);
00074 
00075       // Go to the very first Event.
00076       const MultiChainEvent& toBegin();
00077 
00078       // ---------- const member functions ---------------------
00079       virtual std::string const getBranchNameFor(std::type_info const&,
00080                                                  char const*,
00081                                                  char const*,
00082                                                  char const*) const;
00083 
00085       virtual bool getByLabel(std::type_info const&, char const*, char const*, char const*, void*) const;
00086       virtual bool getByLabel(std::type_info const&, char const*, char const*, char const*, edm::WrapperHolder&) const;
00087       //void getByBranchName(std::type_info const&, char const*, void*&) const;
00088 
00089       bool isValid() const;
00090       operator bool() const;
00091       bool atEnd() const;
00092 
00093       Long64_t size() const;
00094 
00095       virtual edm::EventAuxiliary const& eventAuxiliary() const;
00096 
00097       std::vector<edm::BranchDescription> const& getBranchDescriptions() const;
00098       std::vector<std::string> const& getProcessHistory() const;
00099       edm::ProcessHistory const& processHistory() const;
00100       TFile* getTFile() const {
00101         return event1_->getTFile();
00102       }
00103       TFile* getTFileSec() const {
00104         return event2_->getTFile();
00105       }
00106 
00107       Long64_t eventIndex()    const { return event1_->eventIndex(); }
00108       Long64_t eventIndexSec() const { return event2_->eventIndex(); }
00109 
00110       fwlite::LuminosityBlock const& getLuminosityBlock() {
00111         return event1_->getLuminosityBlock();
00112       }
00113 
00114       fwlite::Run const& getRun() {
00115         return event1_->getRun();
00116       }
00117 
00118 
00119       virtual Long64_t fileIndex()          const
00120       { return event1_->eventIndex(); }
00121       virtual Long64_t secondaryFileIndex() const
00122       { return event2_->eventIndex(); }
00123 
00124       virtual edm::TriggerNames const& triggerNames(edm::TriggerResults const& triggerResults) const;
00125       virtual edm::TriggerResultsByName triggerResultsByName(std::string const& process) const;
00126 
00127       // ---------- static member functions --------------------
00128       static void throwProductNotFoundException(std::type_info const&, char const*, char const*, char const*);
00129 
00130       // return the two chain events
00131       ChainEvent const* primary  () const { return &*event1_;}
00132       ChainEvent const* secondary() const { return &*event2_;}
00133 
00134       // ---------- member functions ---------------------------
00135 
00136       edm::WrapperHolder getByProductID(edm::ProductID const&) const;
00137 
00138 
00139    private:
00140 
00141       MultiChainEvent(Event const&); // stop default
00142 
00143       const MultiChainEvent& operator= (Event const&); // stop default
00144 
00146       bool toSec(Long64_t iIndex);
00147 
00148       //Go to event from secondary files by Run, Lumi (if non-zero), and  Event number
00149       bool toSec(const edm::EventID &id);
00150       bool toSec(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, edm::EventNumber_t event);
00151       bool toSec(edm::RunNumber_t run, edm::EventNumber_t event);
00152 
00153 
00154       // ---------- member data --------------------------------
00155 
00156       boost::shared_ptr<ChainEvent> event1_;  // primary files
00157       boost::shared_ptr<ChainEvent> event2_;  // secondary files
00158       boost::shared_ptr<internal::MultiProductGetter> getter_;
00159 
00160       // speed up secondary file access with a (run range)_1 ---> index_2 map,
00161       // when the files are sorted by run,event within the file.
00162       // in this case, it is sufficient to store only a run-range to index mapping.
00163       // with this, the solution becomes more performant.
00164       bool                     useSecFileMapSorted_;
00165       sec_file_range_index_map secFileMapSorted_;
00166 };
00167 
00168 }
00169 #endif /*__CINT__ */
00170 #endif