Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:22

0001 // -*- C++ -*-
0002 
0003 #if !defined(EventContainer_H)
0004 #define EventContainer_H
0005 
0006 #include <map>
0007 #include <string>
0008 #include <typeinfo>
0009 
0010 #include "TH1.h"
0011 #include "TFile.h"
0012 
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 #include "DataFormats/Common/interface/Handle.h"
0015 #include "PhysicsTools/FWLite/interface/CommandLineParser.h"
0016 #include "DataFormats/FWLite/interface/EventBase.h"
0017 #include "PhysicsTools/FWLite/interface/TH1Store.h"
0018 
0019 namespace fwlite {
0020 
0021   class EventContainer : public EventBase {
0022   public:
0023     //////////////////////
0024     // Public Constants //
0025     //////////////////////
0026 
0027     typedef std::map<std::string, std::string> SSMap;
0028     typedef void (*FuncPtr)(std::string&);
0029 
0030     /////////////
0031     // friends //
0032     /////////////
0033     // tells particle data how to print itself out
0034     friend std::ostream& operator<<(std::ostream& o_stream, const EventContainer& rhs);
0035 
0036     //////////////////////////
0037     //            _         //
0038     // |\/|      |_         //
0039     // |  |EMBER | UNCTIONS //
0040     //                      //
0041     //////////////////////////
0042 
0043     /////////////////////////////////
0044     // Constructors and Destructor //
0045     /////////////////////////////////
0046     EventContainer(optutl::CommandLineParser& parser, FuncPtr funcPtr = nullptr);
0047     ~EventContainer() override;
0048 
0049     ////////////////
0050     // One Liners //
0051     ////////////////
0052 
0053     // return number of events seen
0054     int eventsSeen() const { return m_eventsSeen; }
0055 
0056     //////////////////////////////
0057     // Regular Member Functions //
0058     //////////////////////////////
0059 
0060     // adds a histogram pointer to the map.  You can specify a
0061     // directory as well if you wish.
0062     void add(TH1* histPtr, const std::string& directory = "");
0063 
0064     // given a string, returns corresponding histogram pointer
0065     TH1* hist(const std::string& name);
0066     TH1* hist(const char* name) { return hist((const std::string)name); }
0067     TH1* hist(const TString& name) { return hist((const char*)name); }
0068 
0069     // return this containers parser
0070     optutl::CommandLineParser& parser();
0071 
0072     ///////////////////////////////////////////////////////////////////
0073     // Implement the two functions needed to make this an EventBase. //
0074     ///////////////////////////////////////////////////////////////////
0075     bool getByLabel(const std::type_info& iInfo,
0076                     const char* iModuleLabel,
0077                     const char* iProductInstanceLabel,
0078                     const char* iProcessLabel,
0079                     void* oData) const override;
0080 
0081     const std::string getBranchNameFor(const std::type_info& iInfo,
0082                                        const char* iModuleLabel,
0083                                        const char* iProductInstanceLabel,
0084                                        const char* iProcessLabel) const override;
0085 
0086     const EventContainer& operator++() override;
0087 
0088     const EventContainer& toBegin() override;
0089 
0090     bool atEnd() const override;
0091 
0092     edm::TriggerNames const& triggerNames(edm::TriggerResults const& triggerResults) const override {
0093       return m_eventBasePtr->triggerNames(triggerResults);
0094     }
0095 
0096     edm::TriggerResultsByName triggerResultsByName(edm::TriggerResults const& triggerResults) const override {
0097       return m_eventBasePtr->triggerResultsByName(triggerResults);
0098     }
0099 
0100     Long64_t fileIndex() const override { return m_eventBasePtr->fileIndex(); }
0101     Long64_t secondaryFileIndex() const override { return m_eventBasePtr->secondaryFileIndex(); }
0102 
0103     edm::EventAuxiliary const& eventAuxiliary() const override { return m_eventBasePtr->eventAuxiliary(); }
0104 
0105     template <class T>
0106     bool getByLabel(const edm::InputTag& tag, edm::Handle<T>& handle) const {
0107       return m_eventBasePtr->getByLabel(tag, handle);
0108     }
0109     /////////////////////////////
0110     // Static Member Functions //
0111     /////////////////////////////
0112 
0113   private:
0114     //////////////////////////////
0115     // Private Member Functions //
0116     //////////////////////////////
0117 
0118     // stop the copy constructor
0119     EventContainer(const EventContainer& rhs) {}
0120 
0121     /////////////////////////
0122     // Private Member Data //
0123     /////////////////////////
0124 
0125     fwlite::EventBase* m_eventBasePtr;
0126     TH1Store m_histStore;
0127     std::string m_outputName;
0128     int m_eventsSeen;
0129     int m_maxWanted;
0130     int m_outputEvery;
0131     optutl::CommandLineParser* m_parserPtr;
0132 
0133     ////////////////////////////////
0134     // Private Static Member Data //
0135     ////////////////////////////////
0136 
0137     static bool sm_autoloaderCalled;
0138   };
0139 }  // namespace fwlite
0140 
0141 #endif  // EventContainer_H