Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-06-05 22:16:07

0001 #ifndef Mu_MuBaseFlatTableProducer_h
0002 #define Mu_MuBaseFlatTableProducer_h
0003 
0004 /** \class MuBaseFlatTableProducer MuBaseFlatTableProducer.h DPGAnalysis/MuonTools/src/MuBaseFlatTableProducer.h
0005  *  
0006  * Helper class defining the generic interface of a FlatTableProducer
0007  *
0008  * \author C. Battilana (INFN BO)
0009  *
0010  *
0011  */
0012 
0013 #include "DPGAnalysis/MuonTools/interface/MuNtupleUtils.h"
0014 
0015 #include "FWCore/Framework/interface/stream/EDProducer.h"
0016 #include "FWCore/Framework/interface/ConsumesCollector.h"
0017 
0018 #include "DataFormats/NanoAOD/interface/FlatTable.h"
0019 
0020 #include <string>
0021 
0022 class MuBaseFlatTableProducer : public edm::stream::EDProducer<> {
0023 public:
0024   /// Constructor
0025   explicit MuBaseFlatTableProducer(const edm::ParameterSet &);
0026 
0027   /// Configure event setup for each run
0028   void beginRun(const edm::Run &run, const edm::EventSetup &config) final;
0029 
0030   /// Fill ntuples event by event
0031   void produce(edm::Event &, const edm::EventSetup &) final;
0032 
0033   /// Empty, needed by interface
0034   void endRun(const edm::Run &, const edm::EventSetup &) final {}
0035 
0036 protected:
0037   /// The label name of the FlatTableProducer
0038   std::string m_name;
0039 
0040   /// Get info from the ES by run
0041   virtual void getFromES(const edm::Run &run, const edm::EventSetup &environment) {}
0042 
0043   /// Get info from the ES for a given event
0044   virtual void getFromES(const edm::EventSetup &environment) {}
0045 
0046   /// Fill ntuple
0047   virtual void fillTable(edm::Event &ev) = 0;
0048 
0049   /// Definition of default values for int variables
0050   static constexpr int DEFAULT_INT_VAL{-999};
0051 
0052   /// Definition of default values for int8 variables
0053   static constexpr int8_t DEFAULT_INT8_VAL{-99};
0054 
0055   /// Definition of default values for positive int variables
0056   static constexpr int DEFAULT_INT_VAL_POS{-1};
0057 
0058   /// Definition of default values for float variables
0059   static constexpr double DEFAULT_DOUBLE_VAL{-999.0};
0060 
0061   /// Definition of default values for positive float variables
0062   static constexpr double DEFAULT_DOUBLE_VAL_POS{-1.0};
0063 
0064   template <typename T>
0065   void addColumn(std::unique_ptr<nanoaod::FlatTable> &table,
0066                  const std::string name,
0067                  const std::vector<T> &vec,
0068                  const std::string descr) {
0069     table->template addColumn<T, std::vector<T>>(name, vec, descr);
0070   }
0071 };
0072 
0073 #endif