CMS 3D CMS Logo

DBReader.cc
Go to the documentation of this file.
1 // system include files
2 #include <cstdio>
3 #include <iostream>
4 #include <string>
5 #include <sys/time.h>
6 #include <vector>
7 
8 // user include files
22 
23 class DBReader : public edm::one::EDAnalyzer<> {
24 public:
25  explicit DBReader(const edm::ParameterSet&);
26  ~DBReader() override;
27  void initialize(const edm::EventSetup& iSetup);
28  void analyze(const edm::Event&, const edm::EventSetup&) override;
29 
30 private:
31  template <typename T>
32  void printParameters(const T& functionPtr) {
33  // Looping directly on it does not work, because it is returned by value
34  // and the iterator gets invalidated on the next line. Save it to a temporary object
35  // and iterate on it.
36  std::vector<double> parVecVec(functionPtr->parameters());
37  std::vector<double>::const_iterator parVec = parVecVec.begin();
38  std::vector<int> functionId(functionPtr->identifiers());
39  std::vector<int>::const_iterator id = functionId.begin();
40  edm::LogPrint("DBReader") << "total number of parameters read from database = parVecVec.size() = "
41  << parVecVec.size() << std::endl;
42  int iFunc = 0;
43  for (; id != functionId.end(); ++id, ++iFunc) {
44  int parNum = functionPtr->function(iFunc)->parNum();
45  edm::LogPrint("DBReader") << "For function id = " << *id << ", with " << parNum << " parameters: " << std::endl;
46  for (int par = 0; par < parNum; ++par) {
47  edm::LogPrint("DBReader") << "par[" << par << "] = " << *parVec << std::endl;
48  ++parVec;
49  }
50  }
51  }
52 
53  // uint32_t printdebug_;
56  //std::unique_ptr<BaseFunction> corrector_;
57  std::shared_ptr<MomentumScaleCorrector> corrector_;
58  std::shared_ptr<ResolutionFunction> resolution_;
59  std::shared_ptr<BackgroundFunction> background_;
60 };
61 
63  : muToken_(esConsumes()), type_(iConfig.getUntrackedParameter<std::string>("Type")) {}
64 
66  const MuScleFitDBobject* dbObject = &iSetup.getData(muToken_);
67  edm::LogInfo("DBReader") << "[DBReader::analyze] End Reading MuScleFitDBobjectRcd" << std::endl;
68  edm::LogPrint("DBReader") << "identifiers size from dbObject = " << dbObject->identifiers.size() << std::endl;
69  edm::LogPrint("DBReader") << "parameters size from dbObject = " << dbObject->parameters.size() << std::endl;
70 
71  // This string is one of: scale, resolution, background.
72  // Create the corrector and set the parameters
73  if (type_ == "scale")
74  corrector_.reset(new MomentumScaleCorrector(dbObject));
75  else if (type_ == "resolution")
76  resolution_.reset(new ResolutionFunction(dbObject));
77  else if (type_ == "background")
78  background_.reset(new BackgroundFunction(dbObject));
79  else {
80  edm::LogPrint("DBReader") << "Error: unrecognized type. Use one of those: 'scale', 'resolution', 'background'"
81  << std::endl;
82  exit(1);
83  }
84  // cout << "pointer = " << corrector_.get() << endl;
85 }
86 
87 //: printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug",1)){}
88 
89 DBReader::~DBReader() = default;
90 
91 void DBReader::analyze(const edm::Event& e, const edm::EventSetup& iSetup) {
92  initialize(iSetup);
93  if (type_ == "scale")
95  else if (type_ == "resolution")
97  else if (type_ == "background")
99 }
100 
103 
std::shared_ptr< MomentumScaleCorrector > corrector_
Definition: DBReader.cc:57
std::shared_ptr< BackgroundFunction > background_
Definition: DBReader.cc:59
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: DBReader.cc:91
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const std::string type_
Definition: DBReader.cc:55
void initialize(const edm::EventSetup &iSetup)
Definition: DBReader.cc:65
const edm::ESGetToken< MuScleFitDBobject, MuScleFitDBobjectRcd > muToken_
Definition: DBReader.cc:54
std::vector< int > identifiers
DBReader(const edm::ParameterSet &)
Definition: DBReader.cc:62
bool getData(T &iHolder) const
Definition: EventSetup.h:122
Log< level::Warning, true > LogPrint
void printParameters(const T &functionPtr)
Definition: DBReader.cc:32
std::shared_ptr< ResolutionFunction > resolution_
Definition: DBReader.cc:58
Log< level::Info, false > LogInfo
long double T
~DBReader() override
def exit(msg="")
std::vector< double > parameters