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