Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef FWCore_Common_RunBase_h
0002 #define FWCore_Common_RunBase_h
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:     FWCore/Common
0007 // Class  :     RunBase
0008 //
0009 /**\class RunBase RunBase.h FWCore/Common/interface/RunBase.h
0010 
0011  Description: Base class for Runs in both the full and light framework
0012 
0013  Usage:
0014     One can use this class for code which needs to work in both the full and the
0015  light (i.e. FWLite) frameworks.  Data can be accessed using the same getByLabel
0016  interface which is available in the full framework.
0017 
0018 */
0019 //
0020 // Original Author:  Eric Vaandering
0021 //         Created:  Tue Jan 12 15:31:00 CDT 2010
0022 //
0023 
0024 #include "DataFormats/Common/interface/BasicHandle.h"
0025 #include "DataFormats/Common/interface/ConvertHandle.h"
0026 #include "DataFormats/Common/interface/Handle.h"
0027 #include "DataFormats/Provenance/interface/RunAuxiliary.h"
0028 #include "DataFormats/Provenance/interface/RunID.h"
0029 #include "FWCore/Utilities/interface/InputTag.h"
0030 
0031 namespace edm {
0032 
0033   class RunBase {
0034   public:
0035     RunBase();
0036     virtual ~RunBase();
0037 
0038     // AUX functions.
0039     RunID const& id() const { return runAuxiliary().id(); }
0040     RunNumber_t run() const { return runAuxiliary().run(); }
0041     Timestamp const& beginTime() const { return runAuxiliary().beginTime(); }
0042     Timestamp const& endTime() const { return runAuxiliary().endTime(); }
0043 
0044     virtual edm::RunAuxiliary const& runAuxiliary() const = 0;
0045 
0046     /// same as above, but using the InputTag class
0047     template <typename PROD>
0048     bool getByLabel(InputTag const& tag, Handle<PROD>& result) const;
0049 
0050   private:
0051     virtual BasicHandle getByLabelImpl(std::type_info const& iWrapperType,
0052                                        std::type_info const& iProductType,
0053                                        InputTag const& iTag) const = 0;
0054   };
0055 
0056   template <typename T>
0057   bool RunBase::getByLabel(InputTag const& tag, Handle<T>& result) const {
0058     result.clear();
0059     BasicHandle bh = this->getByLabelImpl(typeid(Wrapper<T>), typeid(T), tag);
0060     result = convert_handle<T>(std::move(bh));
0061     if (result.failedToGet()) {
0062       return false;
0063     }
0064     return true;
0065   }
0066 
0067 }  // namespace edm
0068 #endif