CMS 3D CMS Logo

DTTPGParamsWriter.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author C. Battilana CIEMAT
5  */
6 
9 
14 
15 /* C++ Headers */
16 #include <boost/algorithm/string/split.hpp>
17 #include <boost/algorithm/string_regex.hpp>
18 #include <iostream>
19 #include <sstream>
20 #include <string>
21 #include <vector>
22 
23 using namespace std;
24 using namespace edm;
25 
26 // Constructor
28  debug_ = pset.getUntrackedParameter<bool>("debug", false);
29  inputFileName_ = pset.getUntrackedParameter<string>("inputFile");
30  // Create the object to be written to DB
31  phaseMap_ = new DTTPGParameters();
32 
33  if (debug_)
34  cout << "[DTTPGParamsWriter]Constructor called!" << endl;
35 }
36 
37 // Destructor
39  if (debug_)
40  cout << "[DTTPGParamsWriter]Destructor called!" << endl;
41 }
42 
43 // Do the job
44 void DTTPGParamsWriter::analyze(const Event &event, const EventSetup &eventSetup) {
45  if (debug_)
46  cout << "[DTTPGParamsWriter]Reading data from file." << endl;
47 
48  std::ifstream inputFile_(inputFileName_.c_str());
49  int nLines = 0;
51 
52  while (std::getline(inputFile_, line)) {
53  DTChamberId chId;
54  float fine = 0.;
55  int coarse = 0;
56  pharseLine(line, chId, fine, coarse);
57  phaseMap_->set(chId, coarse, fine, DTTimeUnits::ns);
58  if (debug_) {
59  float fineDB = 0.;
60  int coarseDB = 0;
61  phaseMap_->get(chId, coarseDB, fineDB, DTTimeUnits::ns);
62  std::cout << "[DTTPGParamsWriter] Read data for chamber " << chId << ". File params -> fine: " << fine
63  << " coarse: " << coarse << ". DB params -> fine: " << fineDB << " coarse: " << coarseDB << std::endl;
64  }
65  nLines++;
66  }
67  if (debug_) {
68  std::cout << "[DTTPGParamsWriter] # of entries written the the DB: " << nLines << std::endl;
69  }
70  if (nLines != 250) {
71  std::cout << "[DTTPGParamsWriter] # of DB entries != 250. Check you input file!" << std::endl;
72  }
73 
74  inputFile_.close();
75 }
76 
77 void DTTPGParamsWriter::pharseLine(std::string &line, DTChamberId &chId, float &fine, int &coarse) {
78  std::vector<std::string> elements;
80  elements,
81  line,
82  boost::algorithm::is_any_of(string(" \t\n"))); // making string conversion explicit (needed to
83  // cope with -Warray-bounds in slc5_ia32_gcc434
84  if (elements.size() != 5) {
85  std::cout << "[DTTPGParamsWriter] wrong number of entries in line : " << line
86  << " pleas check your input file syntax!" << std::endl;
87  } else {
88  chId = DTChamberId(atoi(elements[0].c_str()), atoi(elements[1].c_str()), atoi(elements[2].c_str()));
89  fine = atof(elements[3].c_str());
90  coarse = atoi(elements[4].c_str());
91  }
92 }
93 
94 // Write objects to DB
96  if (debug_)
97  cout << "[DTTPGParamsWriter] Writing ttrig object to DB!" << endl;
98 
99  string delayRecord = "DTTPGParametersRcd";
100  DTCalibDBUtils::writeToDB(delayRecord, phaseMap_);
101 }
std::vector< std::string_view > split(std::string_view, const char *)
T getUntrackedParameter(std::string const &, T const &) const
void endJob() override
Write ttrig in the DB.
void pharseLine(std::string &line, DTChamberId &chId, float &fine, int &coarse)
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
Compute the ttrig by fiting the TB rising edge.
HLT enums.
~DTTPGParamsWriter() override
Destructor.
static void writeToDB(std::string record, T *payload)
Definition: event.py:1
DTTPGParamsWriter(const edm::ParameterSet &pset)
Constructor.