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 
29  debug_ = pset.getUntrackedParameter<bool>("debug", false);
30  inputFileName_ = pset.getUntrackedParameter<string>("inputFile");
31  // Create the object to be written to DB
32  phaseMap_ = new DTTPGParameters();
33 
34  if (debug_)
35  cout << "[DTTPGParamsWriter]Constructor called!" << endl;
36 }
37 
38 // Destructor
40 
41  if (debug_)
42  cout << "[DTTPGParamsWriter]Destructor called!" << endl;
43 }
44 
45 // Do the job
47  const EventSetup &eventSetup) {
48 
49  if (debug_)
50  cout << "[DTTPGParamsWriter]Reading data from file." << endl;
51 
52  std::ifstream inputFile_(inputFileName_.c_str());
53  int nLines = 0;
55 
56  while (std::getline(inputFile_, line)) {
57  DTChamberId chId;
58  float fine = 0.;
59  int coarse = 0;
60  pharseLine(line, chId, fine, coarse);
61  phaseMap_->set(chId, coarse, fine, DTTimeUnits::ns);
62  if (debug_) {
63  float fineDB = 0.;
64  int coarseDB = 0;
65  phaseMap_->get(chId, coarseDB, fineDB, DTTimeUnits::ns);
66  std::cout << "[DTTPGParamsWriter] Read data for chamber " << chId
67  << ". File params -> fine: " << fine << " coarse: " << coarse
68  << ". DB params -> fine: " << fineDB << " coarse: " << coarseDB
69  << std::endl;
70  }
71  nLines++;
72  }
73  if (debug_) {
74  std::cout << "[DTTPGParamsWriter] # of entries written the the DB: "
75  << nLines << std::endl;
76  }
77  if (nLines != 250) {
78  std::cout
79  << "[DTTPGParamsWriter] # of DB entries != 250. Check you input file!"
80  << std::endl;
81  }
82 
83  inputFile_.close();
84 }
85 
87  float &fine, int &coarse) {
88 
89  std::vector<std::string> elements;
91  elements, line,
92  boost::algorithm::is_any_of(
93  string(" \t\n"))); // making string conversion explicit (needed to
94  // cope with -Warray-bounds in slc5_ia32_gcc434
95  if (elements.size() != 5) {
96  std::cout << "[DTTPGParamsWriter] wrong number of entries in line : "
97  << line << " pleas check your input file syntax!" << std::endl;
98  } else {
99  chId = DTChamberId(atoi(elements[0].c_str()), atoi(elements[1].c_str()),
100  atoi(elements[2].c_str()));
101  fine = atof(elements[3].c_str());
102  coarse = atoi(elements[4].c_str());
103  }
104 }
105 
106 // Write objects to DB
108  if (debug_)
109  cout << "[DTTPGParamsWriter] Writing ttrig object to DB!" << endl;
110 
111  string delayRecord = "DTTPGParametersRcd";
112  DTCalibDBUtils::writeToDB(delayRecord, phaseMap_);
113 }
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)
double split
Definition: MVATrainer.cc:139
Definition: event.py:1
DTTPGParamsWriter(const edm::ParameterSet &pset)
Constructor.