CMS 3D CMS Logo

EcalTPGPhysicsConstHandler.cc
Go to the documentation of this file.
2 
11 
12 #include <iostream>
13 
15  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalTPGPhysicsConstHandler")) {
16  edm::LogInfo("EcalTPGPhysicsConstHandler") << "EcalTPGPhysicsConst Source handler constructor.";
17  m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
18  m_lastRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("lastRun").c_str()));
19  m_sid = ps.getParameter<std::string>("OnlineDBSID");
20  m_user = ps.getParameter<std::string>("OnlineDBUser");
21  m_pass = ps.getParameter<std::string>("OnlineDBPassword");
22  m_locationsource = ps.getParameter<std::string>("LocationSource");
23  m_location = ps.getParameter<std::string>("Location");
24  m_gentag = ps.getParameter<std::string>("GenTag");
25  m_runtype = ps.getParameter<std::string>("RunType");
26 
27  edm::LogInfo("EcalTPGPhysicsConstHandler") << m_sid << "/" << m_user << "/" << m_location << "/" << m_gentag;
28 }
29 
31 
33  edm::LogInfo("EcalTPGPhysicsConstHandler") << "Started GetNewObjects!!!";
34 
35  //check whats already inside of database
36  if (tagInfo().size) {
37  //check whats already inside of database
38  std::cout << "got offlineInfo = " << std::endl;
39  std::cout << "tag name = " << tagInfo().name << std::endl;
40  std::cout << "size = " << tagInfo().size << std::endl;
41  } else {
42  std::cout << " First object for this tag " << std::endl;
43  }
44 
45  unsigned int max_since = 0;
46  max_since = static_cast<unsigned int>(tagInfo().lastInterval.since);
47  edm::LogInfo("EcalTPGPhysicsConstHandler") << "max_since : " << max_since;
48  Ref physC_db = lastPayload();
49 
50  edm::LogInfo("EcalTPGPhysicsConstHandler") << "retrieved last payload ";
51 
52  // here we retrieve all the runs after the last from online DB
53  edm::LogInfo("EcalTPGPhysicsConstHandler") << "Retrieving run list from ONLINE DB ... ";
54 
55  edm::LogInfo("EcalTPGPhysicsConstHandler") << "Making connection...";
56  econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
57  edm::LogInfo("EcalTPGPhysicsConstHandler") << "Done.";
58 
59  if (!econn) {
60  std::cout << " connection parameters " << m_sid << "/" << m_user << std::endl;
61  // cerr << e.what() << std::endl;
62  throw cms::Exception("OMDS not available");
63  }
64 
66  my_locdef.setLocation(m_location);
67 
69  my_rundef.setRunType(m_runtype);
70 
71  RunTag my_runtag;
72  my_runtag.setLocationDef(my_locdef);
73  my_runtag.setRunTypeDef(my_rundef);
74  my_runtag.setGeneralTag(m_gentag);
75 
76  readFromFile("last_tpg_physC_settings.txt");
77 
78  unsigned int min_run;
79 
80  if (m_firstRun < m_i_run_number) {
81  min_run = m_i_run_number + 1;
82  } else {
83  min_run = m_firstRun;
84  }
85 
86  std::cout << "m_i_run_number" << m_i_run_number << "m_firstRun " << m_firstRun << "max_since " << max_since
87  << std::endl;
88 
89  if (min_run < max_since) {
90  min_run = max_since + 1; // we have to add 1 to the last transferred one
91  }
92 
93  unsigned int max_run = m_lastRun;
94  edm::LogInfo("EcalTPGPhysicsConstHandler") << "min_run= " << min_run << "max_run= " << max_run;
95 
96  RunList my_list;
97  my_list = econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run, my_locdef);
98  // my_list=econn->fetchRunListByLocation(my_runtag,min_run,max_run,my_locdef);
99 
100  std::vector<RunIOV> run_vec = my_list.getRuns();
101  size_t num_runs = run_vec.size();
102 
103  std::cout << "number of runs is : " << num_runs << std::endl;
104 
105  unsigned int irun;
106  if (num_runs > 0) {
107  for (size_t kr = 0; kr < run_vec.size(); kr++) {
108  irun = static_cast<unsigned int>(run_vec[kr].getRunNumber());
109 
110  std::cout << " **************** " << std::endl;
111  std::cout << " **************** " << std::endl;
112  std::cout << " run= " << irun << std::endl;
113 
114  // retrieve the data :
115  std::map<EcalLogicID, RunTPGConfigDat> dataset;
116  econn->fetchDataSet(&dataset, &run_vec[kr]);
117 
118  std::string the_config_tag = "";
119  int the_config_version = 0;
120 
121  std::map<EcalLogicID, RunTPGConfigDat>::const_iterator it;
122 
123  int nr = 0;
124  for (it = dataset.begin(); it != dataset.end(); it++) {
125  ++nr;
126  //EcalLogicID ecalid = it->first;
127  RunTPGConfigDat dat = it->second;
128  the_config_tag = dat.getConfigTag();
129  the_config_version = dat.getVersion();
130  }
131 
132  // it is all the same for all SM... get the last one
133 
134  std::cout << " run= " << irun << " tag " << the_config_tag << " version=" << the_config_version << std::endl;
135 
136  // here we should check if it is the same as previous run.
137 
138  if ((the_config_tag != m_i_tag || the_config_version != m_i_version) && nr > 0) {
139  std::cout << "the tag is different from last transferred run ... retrieving last config set from DB"
140  << std::endl;
141 
142  FEConfigMainInfo fe_main_info;
143  fe_main_info.setConfigTag(the_config_tag);
144  fe_main_info.setVersion(the_config_version);
145 
146  try {
147  std::cout << " before fetch config set" << std::endl;
148  econn->fetchConfigSet(&fe_main_info);
149  std::cout << " after fetch config set" << std::endl;
150 
151  // now get TPGPhysicsConst
152  int linId = fe_main_info.getLinId();
153  int fgrId = fe_main_info.getFgrId();
154  int lutId = fe_main_info.getLUTId();
155 
156  if ((linId != m_i_physClin) || (fgrId != m_i_physCfgr) || (lutId != m_i_physClut)) {
157  std::cout << "one of the parameters: linId, LutId or fgrId is different from" << std::endl;
158  std::cout << "last transferred run ..." << std::endl;
159 
160  FEConfigLinInfo fe_physLin_info;
161  FEConfigFgrInfo fe_physFgr_info;
162  FEConfigLUTInfo fe_physLut_info;
163  fe_physLin_info.setId(linId);
164  fe_physFgr_info.setId(fgrId);
165  fe_physLut_info.setId(lutId);
166 
167  econn->fetchConfigSet(&fe_physLin_info);
168  econn->fetchConfigSet(&fe_physFgr_info);
169  econn->fetchConfigSet(&fe_physLut_info);
170  std::map<EcalLogicID, FEConfigLinParamDat> dataset_TpgPhysicsLin;
171  std::map<EcalLogicID, FEConfigLUTParamDat> dataset_TpgPhysicsLut;
172  std::map<EcalLogicID, FEConfigFgrParamDat> dataset_TpgPhysicsFgr;
173 
174  econn->fetchDataSet(&dataset_TpgPhysicsLin, &fe_physLin_info);
175  econn->fetchDataSet(&dataset_TpgPhysicsLut, &fe_physLut_info);
176  econn->fetchDataSet(&dataset_TpgPhysicsFgr, &fe_physFgr_info);
177 
179  typedef std::map<EcalLogicID, FEConfigLinParamDat>::const_iterator CIfeLin;
180  typedef std::map<EcalLogicID, FEConfigLUTParamDat>::const_iterator CIfeLUT;
181  typedef std::map<EcalLogicID, FEConfigFgrParamDat>::const_iterator CIfeFgr;
182 
183  EcalLogicID ecidLin_xt;
184  EcalLogicID ecidLut_xt;
185  EcalLogicID ecidFgr_xt;
186  FEConfigLinParamDat rd_physLin;
187  FEConfigLUTParamDat rd_physLut;
188  FEConfigFgrParamDat rd_physFgr;
189 
190  std::map<int, float> EtSatLinEB;
191  std::map<int, float> EtSatLinEE;
192  typedef std::map<int, float>::const_iterator itEtSat;
193 
194  std::map<int, EcalTPGPhysicsConst::Item> temporaryMapEB;
195  std::map<int, EcalTPGPhysicsConst::Item> temporaryMapEE;
196  typedef std::map<int, EcalTPGPhysicsConst::Item>::iterator iterEB;
197  typedef std::map<int, EcalTPGPhysicsConst::Item>::iterator iterEE;
198 
199  for (CIfeLin p0 = dataset_TpgPhysicsLin.begin(); p0 != dataset_TpgPhysicsLin.end(); p0++) {
200  ecidLin_xt = p0->first;
201  rd_physLin = p0->second;
202 
203  std::string ecid_nameLin = ecidLin_xt.getName();
204 
205  if (ecid_nameLin == "EB") {
207  EtSatLinEB.insert(std::make_pair(eb.rawId(), rd_physLin.getETSat()));
208  } else if (ecid_nameLin == "EE") {
210  EtSatLinEE.insert(std::make_pair(ee.rawId(), rd_physLin.getETSat()));
211  }
212  }
213 
214  for (CIfeLUT p1 = dataset_TpgPhysicsLut.begin(); p1 != dataset_TpgPhysicsLut.end(); p1++) {
215  ecidLut_xt = p1->first;
216  rd_physLut = p1->second;
217 
218  std::string ecid_nameLut = ecidLut_xt.getName();
219 
220  // Ecal barrel detector
221  if (ecid_nameLut == "EB") {
223 
224  for (itEtSat it1 = EtSatLinEB.begin(); it1 != EtSatLinEB.end(); it1++) {
225  if (it1->first == (int)eb.rawId()) {
226  float ETSatLin = it1->second;
227 
228  if (rd_physLut.getETSat() == ETSatLin) {
230  item.EtSat = rd_physLut.getETSat();
231  item.ttf_threshold_Low = rd_physLut.getTTThreshlow();
232  item.ttf_threshold_High = rd_physLut.getTTThreshhigh();
233  item.FG_lowThreshold = 0;
234  item.FG_highThreshold = 0;
235  item.FG_lowRatio = 0;
236  item.FG_highRatio = 0;
237  temporaryMapEB.insert(std::make_pair(eb.rawId(), item));
238  } else
239  throw cms::Exception("The values of the ETSatLin and ETSatLut are different.");
240  }
241  }
242 
243  } else if (ecid_nameLut == "EE") {
244  // Ecal endcap detector
245 
247 
248  for (itEtSat it2 = EtSatLinEE.begin(); it2 != EtSatLinEE.end(); it2++) {
249  if (it2->first == (int)ee.rawId()) {
250  float ETSatLin = it2->second;
251 
252  if (rd_physLut.getETSat() == ETSatLin) {
254  item.EtSat = rd_physLut.getETSat();
255  item.ttf_threshold_Low = rd_physLut.getTTThreshlow();
256  item.ttf_threshold_High = rd_physLut.getTTThreshhigh();
257  item.FG_lowThreshold = 0;
258  item.FG_highThreshold = 0;
259  item.FG_lowRatio = 0;
260  item.FG_highRatio = 0;
261  temporaryMapEE.insert(std::make_pair(ee.rawId(), item));
262  } else
263  throw cms::Exception("The values of the ETSatLin and ETSatLut are different.");
264  }
265  }
266  }
267  }
268 
269  for (CIfeFgr p2 = dataset_TpgPhysicsFgr.begin(); p2 != dataset_TpgPhysicsFgr.end(); p2++) {
270  ecidFgr_xt = p2->first;
271  rd_physFgr = p2->second;
272 
273  std::string ecid_nameFgr = ecidFgr_xt.getName();
274 
275  // Ecal barrel detector
276  if (ecid_nameFgr == "EB") {
278 
279  for (iterEB itt = temporaryMapEB.begin(); itt != temporaryMapEB.end(); itt++) {
280  if (itt->first == (int)eb.rawId()) {
281  (itt->second).FG_lowThreshold = rd_physFgr.getFGlowthresh();
282  (itt->second).FG_highThreshold = rd_physFgr.getFGhighthresh();
283  (itt->second).FG_lowRatio = rd_physFgr.getFGlowratio();
284  (itt->second).FG_highRatio = rd_physFgr.getFGhighratio();
285 
286  physC->setValue(eb.rawId(), itt->second);
287  }
288  }
289 
290  } else if (ecid_nameFgr == "EE") {
291  // Ecal endcap detector
292 
294 
295  for (iterEE itEE = temporaryMapEE.begin(); itEE != temporaryMapEE.end(); itEE++) {
296  if (itEE->first == (int)ee.rawId()) {
297  (itEE->second).FG_lowThreshold = rd_physFgr.getFGlowthresh();
298  (itEE->second).FG_highThreshold = rd_physFgr.getFGhighthresh();
299  // the last two is empty for the EE
300  (itEE->second).FG_lowRatio = rd_physFgr.getFGlowratio();
301  (itEE->second).FG_highRatio = rd_physFgr.getFGhighratio();
302 
303  physC->setValue(ee.rawId(), itEE->second);
304  }
305  }
306  }
307  }
308 
309  Time_t snc = (Time_t)irun;
310 
311  m_to_transfer.push_back(std::make_pair((EcalTPGPhysicsConst*)physC, snc));
312 
313  m_i_run_number = irun;
314  m_i_tag = the_config_tag;
315  m_i_version = the_config_version;
316  m_i_physClin = linId;
317  m_i_physClut = lutId;
318  m_i_physCfgr = fgrId;
319 
320  writeFile("last_tpg_physC_settings.txt");
321 
322  } else {
323  m_i_run_number = irun;
324  m_i_tag = the_config_tag;
325  m_i_version = the_config_version;
326 
327  writeFile("last_tpg_physC_settings.txt");
328 
329  std::cout << " even if the tag/version is not the same, the physics constants id is the same -> no "
330  "transfer needed "
331  << std::endl;
332  }
333 
334  }
335 
336  catch (std::exception& e) {
337  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" << the_config_tag << " version=" << the_config_version
338  << std::endl;
339  std::cout << e.what() << std::endl;
340  m_i_run_number = irun;
341  }
342  std::cout << " **************** " << std::endl;
343 
344  } else if (nr == 0) {
345  m_i_run_number = irun;
346  std::cout << " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed " << std::endl;
347  std::cout << " **************** " << std::endl;
348  } else {
349  m_i_run_number = irun;
350  m_i_tag = the_config_tag;
351  m_i_version = the_config_version;
352  std::cout << " the tag/version is the same -> no transfer needed " << std::endl;
353  std::cout << " **************** " << std::endl;
354  writeFile("last_tpg_physC_settings.txt");
355  }
356  }
357  }
358 
359  delete econn;
360  edm::LogInfo("EcalTPGPhysicsConstHandler") << "Ecal - > end of getNewObjects -----------";
361 }
362 
364  //-------------------------------------------------------------
365 
366  m_i_tag = "";
367  m_i_version = 0;
368  m_i_run_number = 0;
369  m_i_physClin = 0;
370  m_i_physClut = 0;
371  m_i_physCfgr = 0;
372 
373  FILE* inpFile; // input file
374  inpFile = fopen(inputFile, "r");
375  if (!inpFile) {
376  edm::LogError("EcalTPGPhysicsConstHandler") << "*** Can not open file: " << inputFile;
377  return;
378  }
379 
380  char line[256];
381 
382  std::ostringstream str;
383 
384  fgets(line, 255, inpFile);
385  m_i_tag = to_string(line);
386  str << "gen tag " << m_i_tag << std::endl; // should I use this?
387 
388  fgets(line, 255, inpFile);
389  m_i_version = atoi(line);
390  str << "version= " << m_i_version << std::endl;
391 
392  fgets(line, 255, inpFile);
393  m_i_run_number = atoi(line);
394  str << "run_number= " << m_i_run_number << std::endl;
395 
396  fgets(line, 255, inpFile);
397  m_i_physClin = atoi(line);
398  str << "physClin_config= " << m_i_physClin << std::endl;
399 
400  fgets(line, 255, inpFile);
401  m_i_physClut = atoi(line);
402  str << "physClut_config= " << m_i_physClut << std::endl;
403 
404  fgets(line, 255, inpFile);
405  m_i_physCfgr = atoi(line);
406  str << "physCfgr_config= " << m_i_physCfgr << std::endl;
407 
408  fclose(inpFile); // close inp. file
409 }
410 
412  //-------------------------------------------------------------
413 
414  std::ofstream myfile;
415  myfile.open(inputFile);
416  myfile << m_i_tag << std::endl;
417  myfile << m_i_version << std::endl;
418  myfile << m_i_run_number << std::endl;
419  myfile << m_i_physClin << std::endl;
420  myfile << m_i_physClut << std::endl;
421  myfile << m_i_physCfgr << std::endl;
422 
423  myfile.close();
424 }
size
Write out results.
void setValue(const uint32_t &id, const Item &value)
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:42
std::vector< RunIOV > getRuns()
Definition: RunList.cc:25
int getFgrId() const
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
float getTTThreshlow() const
std::string getName() const
Definition: EcalLogicID.cc:26
float getTTThreshhigh() const
Definition: RunTag.h:13
EcalTPGPhysicsConstHandler(edm::ParameterSet const &)
int getVersion() const
Log< level::Error, false > LogError
void setVersion(int id)
static std::string to_string(const XMLCh *ch)
void setId(int id)
float getFGhighratio() const
int getLinId() const
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:33
void setId(int id)
Log< level::Info, false > LogInfo
Definition: DetId.h:17
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::string getConfigTag() const
cond::Time_t Time_t
Definition: Time.h:18
std::unique_ptr< EcalTPGPhysicsConst > Ref
void setConfigTag(std::string x)
Definition: IODConfig.h:29
float getFGlowthresh() const
int getLUTId() const
void setGeneralTag(std::string tag)
Definition: RunTag.cc:24
#define str(s)
float getFGlowratio() const
float getFGhighthresh() const
void setId(int id)