Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:36

0001 #ifndef FWCore_Common_EventBase_h
0002 #define FWCore_Common_EventBase_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Common
0006 // Class  :     EventBase
0007 //
0008 /**\class EventBase EventBase.h FWCore/Common/interface/EventBase.h
0009 
0010  Description: Base class for Events in both the full and light framework
0011 
0012  Usage:
0013     One can use this class for code which needs to work in both the full and the
0014  light (i.e. FWLite) frameworks.  Data can be accessed using the same getByLabel
0015  interface which is available in the full framework.
0016 
0017 */
0018 //
0019 // Original Author:  Chris Jones
0020 //         Created:  Thu Aug 27 11:01:06 CDT 2009
0021 //
0022 
0023 // user include files
0024 #include "DataFormats/Common/interface/BasicHandle.h"
0025 
0026 #include "DataFormats/Provenance/interface/EventAuxiliary.h"
0027 #include "DataFormats/Provenance/interface/EventID.h"
0028 #include "DataFormats/Provenance/interface/Timestamp.h"
0029 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0030 #include "DataFormats/Common/interface/ConvertHandle.h"
0031 #include "DataFormats/Common/interface/Handle.h"
0032 #include "FWCore/Common/interface/TriggerResultsByName.h"
0033 #include "FWCore/Utilities/interface/InputTag.h"
0034 
0035 // system include files
0036 #include <typeinfo>
0037 
0038 namespace edm {
0039 
0040   class ProcessHistory;
0041   class ProductID;
0042   class TriggerResults;
0043   class TriggerNames;
0044   class ParameterSet;
0045 
0046   class EventBase {
0047   public:
0048     EventBase();
0049     virtual ~EventBase();
0050 
0051     // ---------- const member functions ---------------------
0052     template <typename T>
0053     bool getByLabel(InputTag const&, Handle<T>&) const;
0054 
0055     template <typename T>
0056     bool get(ProductID const&, Handle<T>&) const;
0057 
0058     // AUX functions.
0059     edm::EventID id() const { return eventAuxiliary().id(); }
0060     edm::Timestamp time() const { return eventAuxiliary().time(); }
0061     edm::LuminosityBlockNumber_t luminosityBlock() const { return eventAuxiliary().luminosityBlock(); }
0062     bool isRealData() const { return eventAuxiliary().isRealData(); }
0063     edm::EventAuxiliary::ExperimentType experimentType() const { return eventAuxiliary().experimentType(); }
0064     int bunchCrossing() const { return eventAuxiliary().bunchCrossing(); }
0065     int orbitNumber() const { return eventAuxiliary().orbitNumber(); }
0066     virtual edm::EventAuxiliary const& eventAuxiliary() const = 0;
0067 
0068     virtual TriggerNames const& triggerNames(edm::TriggerResults const& triggerResults) const = 0;
0069     virtual TriggerResultsByName triggerResultsByName(edm::TriggerResults const& triggerResults) const = 0;
0070     virtual ProcessHistory const& processHistory() const = 0;
0071 
0072     virtual edm::ParameterSet const* parameterSet(edm::ParameterSetID const& psID) const = 0;
0073 
0074   protected:
0075     static TriggerNames const* triggerNames_(edm::TriggerResults const& triggerResults);
0076 
0077     static edm::ParameterSet const* parameterSetForID_(edm::ParameterSetID const& psID);
0078 
0079   private:
0080     //EventBase(EventBase const&); // allow default
0081 
0082     //EventBase const& operator=(EventBase const&); // allow default
0083 
0084     virtual BasicHandle getByLabelImpl(std::type_info const& iWrapperType,
0085                                        std::type_info const& iProductType,
0086                                        InputTag const& iTag) const = 0;
0087     virtual BasicHandle getImpl(std::type_info const& iProductType, ProductID const& iTag) const = 0;
0088     // ---------- member data --------------------------------
0089   };
0090 
0091   template <typename T>
0092   bool EventBase::getByLabel(InputTag const& tag, Handle<T>& result) const {
0093     result.clear();
0094     BasicHandle bh = this->getByLabelImpl(typeid(edm::Wrapper<T>), typeid(T), tag);
0095     result = convert_handle<T>(std::move(bh));
0096     if (result.failedToGet()) {
0097       return false;
0098     }
0099     return true;
0100   }
0101 
0102   template <typename T>
0103   bool EventBase::get(ProductID const& pid, Handle<T>& result) const {
0104     result.clear();
0105     BasicHandle bh = this->getImpl(typeid(T), pid);
0106     result = convert_handle_check_type<T>(std::move(bh));
0107     if (result.failedToGet()) {
0108       return false;
0109     }
0110     return true;
0111   }
0112 
0113 }  // namespace edm
0114 
0115 #endif