CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EcalADCToGeVHandler.cc
Go to the documentation of this file.
5 
6 #include <iostream>
7 
9  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalADCToGeVHandler")) {
10  std::cout << "EcalADCToGeV Source handler constructor\n" << std::endl;
11  m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
12  m_lastRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("lastRun").c_str()));
13  m_sid = ps.getParameter<std::string>("OnlineDBSID");
14  m_user = ps.getParameter<std::string>("OnlineDBUser");
15  m_pass = ps.getParameter<std::string>("OnlineDBPassword");
16  m_locationsource = ps.getParameter<std::string>("LocationSource");
17  m_location = ps.getParameter<std::string>("Location");
18  m_gentag = ps.getParameter<std::string>("GenTag");
19  m_file_lowfield = ps.getParameter<std::string>("FileLowField");
20  m_file_highfield = ps.getParameter<std::string>("FileHighField");
21 
22  std::cout << m_sid << "/" << m_user << "/" << m_location << "/" << m_gentag << std::endl;
23 }
24 
26 
28  std::cout << "------- Ecal - > getNewObjects\n";
29 
30  std::ostringstream ss;
31  ss << "ECAL ";
32 
33  unsigned int max_since = 0;
34  max_since = static_cast<unsigned int>(tagInfo().lastInterval.since);
35  std::cout << "max_since : " << max_since << std::endl;
36  bool magnet_high = false;
37  bool something_to_transfer = false;
38  if (tagInfo().size) {
39  Ref ped_db = lastPayload();
40 
41  // we parse the last record in the DB and check if it is low or high field
42 
43  std::cout << "retrieved last payload " << std::endl;
44 
45  EcalADCToGeVConstant the_cal;
46 
47  //unused float adc_eb=ped_db->getEBValue();
48  float adc_ee = ped_db->getEEValue();
49 
50  // float the_value_high_eb=0.03894;
51  // float the_value_high_ee=0.06285;
52  // float the_value_high_eb=0.03894;
53  // float the_value_high_ee=0.06378;
54 
55  // bool magnet_high=true;
56  // if(adc_eb!= the_value_high_eb || adc_ee!= the_value_high_ee ) magnet_high=false;
57 
58  //unused float the_value_low_eb=0.03894;
59  // Run 1 : float the_value_low_ee=0.05678;
60  float the_value_low_ee = 0.0590975;
61  if (adc_ee > the_value_low_ee)
62  magnet_high = true;
63  } // check if there is already a payload
64  else
65  something_to_transfer = true;
66 
67  // here we connect to the online DB to check the value of the magnetic field
68  std::cout << "Connecting to ONLINE DB ... " << std::endl;
69  econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
70  std::cout << "Connection done" << std::endl;
71 
72  std::cout << "Retrieving last run from ONLINE DB ... " << std::endl;
73  std::map<EcalLogicID, RunDat> rundat;
74  RunIOV rp;
75  run_t runmax = 10000000;
76  std::string location_p5 = "P5_Co";
77  econn->fetchValidDataSet(&rundat, &rp, location_p5, runmax);
78 
79  unsigned long long irun = (unsigned long long)rp.getRunNumber();
80 
81  std::cout << "retrieved run number " << irun << std::endl;
82 
83  if (irun > max_since) {
84  // retrieve from last value data record
85  // always call this method at first run
86 
87  std::map<EcalLogicID, RunDCSMagnetDat> dataset;
88 
89  econn->fetchDataSet(&dataset, &rp);
90 
91  if (dataset.empty()) {
92  throw(std::runtime_error("Zero rows read back"));
93  } else {
94  std::cout << "retrieved magnet current" << std::endl;
95  }
96 
97  float mag_cur = 0;
98 
99  std::map<EcalLogicID, RunDCSMagnetDat>::iterator it;
100  for (it = dataset.begin(); it != dataset.end(); ++it) {
101  RunDCSMagnetDat a_mag = (*it).second;
102  mag_cur = a_mag.getMagnetCurrent();
103  }
104 
105  std::string file_ = m_file_highfield;
106  if (tagInfo().size) {
107  if (mag_cur > 7000. && magnet_high) {
108  std::cout << " the magnet is ON and the constants are for magnet ON " << std::endl;
109 
110  } else if (mag_cur > 7000. && !magnet_high) {
111  something_to_transfer = true;
112  std::cout << " the magnet is ON and the constants are for magnet OFF " << std::endl;
113  std::cout << " I transfer the ON constants " << std::endl;
114  file_ = m_file_highfield;
115 
116  } else if (mag_cur < 6000. && magnet_high) {
117  something_to_transfer = true;
118  std::cout << " the magnet is OFF and the constants are for magnet ON " << std::endl;
119  std::cout << " I transfer the OFF constants " << std::endl;
120  file_ = m_file_lowfield;
121 
122  } else if (mag_cur < 6000. && !magnet_high) {
123  std::cout << " the magnet is OFF and the constants are for magnet OFF " << std::endl;
124  file_ = m_file_lowfield;
125 
126  } else {
127  std::cout << " the magnet is in a strange situation I do nothing ... just be patient " << std::endl;
128  }
129  } else {
130  if (mag_cur > 7000.)
131  std::cout << " first payload, the magnet is ON " << std::endl;
132  else if (mag_cur < 6000.) {
133  std::cout << " first payload, the magnet is OFF " << std::endl;
134  file_ = m_file_lowfield;
135  } else
136  std::cout << " the magnet is in a strange situation I do nothing ... just be patient " << std::endl;
137  }
138 
139  if (something_to_transfer) {
140  std::cout << "Generating popcon record for run " << irun << " going to open file " << file_ << "\n"
141  << std::flush;
143  // EcalCondHeader header; // DBv1
144  // EcalADCToGeVXMLTranslator::readXML(file_,header,*payload); // DBv1
145  // DBv2 poor xml file :-(
146  std::ifstream fxml;
147  fxml.open(file_.c_str());
148  std::string line, bid, bid2;
149  float val;
150  for (int il = 0; il < 4; il++) {
151  std::getline(fxml, line);
152  // std::cout << line << "\n";
153  }
154  for (int iPart = 0; iPart < 2; iPart++) { // EB, EE
155  fxml >> bid;
156  std::size_t begin = bid.find_first_of('>');
157  std::size_t end = bid.find_last_of('<');
158  begin++;
159  std::string str2 = bid.substr(begin, end - begin);
160  std::size_t endmantissa = str2.find('e');
161  std::string mantissa = str2.substr(0, endmantissa);
162  std::size_t string_size = str2.size();
163  std::string exponent = str2.substr(endmantissa + 1, string_size);
164  std::istringstream is(mantissa);
165  is >> val;
166  float mult;
167  std::istringstream ise(exponent);
168  ise >> mult;
169  val = val * pow(10, mult);
170  std::cout << " Partition " << iPart << " ADCToGeV " << val << "\n";
171  if (iPart < 1)
172  payload->setEBValue(val);
173  else
174  payload->setEEValue(val);
175  }
176  // end change for DBv2
177 
178  Time_t snc = (Time_t)irun;
179  popcon::PopConSourceHandler<EcalADCToGeVConstant>::m_to_transfer.push_back(std::make_pair(payload, snc));
180  ss << "Run=" << irun << "_Magnet_changed_" << std::endl;
181  m_userTextLog = ss.str() + ";";
182  } else {
183  std::cout << "Run " << irun << " nothing sent to the DB" << std::endl;
184  ss << "Run=" << irun << "_Magnet_NOT_changed_" << std::endl;
185  m_userTextLog = ss.str() + ";";
186  }
187 
188  delete econn;
189  } // irun > max_since
190  else {
191  std::cout << "Run " << irun << " nothing sent to the DB" << std::endl;
192  ss << "Run=" << irun << "_no_new_runs_" << std::endl;
193  m_userTextLog = ss.str() + ";";
194  }
195  std::cout << "Ecal - > end of getNewObjects -----------\n";
196 }
int run_t
Definition: CaliIOV.h:11
void setEEValue(const float &value)
float getMagnetCurrent() const
void setEBValue(const float &value)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
run_t getRunNumber() const
Definition: RunIOV.cc:31
cond::Time_t Time_t
Definition: Time.h:18
std::unique_ptr< EcalADCToGeVConstant > Ref
string end
Definition: dataset.py:937
EcalADCToGeVHandler(edm::ParameterSet const &)
tuple cout
Definition: gather_cfg.py:144
Definition: RunIOV.h:13
tuple size
Write out results.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29