CMS 3D CMS Logo

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