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 
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...";
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 
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  for ( iterEB itt=temporaryMapEB.begin() ; itt != temporaryMapEB.end() ; itt++ ){
317 
318  if (itt->first == (int)eb.rawId()){
319 
320  (itt->second).FG_lowThreshold=rd_physFgr.getFGlowthresh();
321  (itt->second).FG_highThreshold=rd_physFgr.getFGhighthresh();
322  (itt->second).FG_lowRatio=rd_physFgr.getFGlowratio();
323  (itt->second).FG_highRatio= rd_physFgr.getFGhighratio();
324 
325  physC->setValue(eb.rawId(),itt->second);
326 
327  }
328  }
329 
330  ++icellsEB;
331 
332  }
333  else if (ecid_nameFgr=="EE") {
334  // Ecal endcap detector
335 
337 
338  int countEE = 0;
339  for ( iterEE itEE=temporaryMapEE.begin() ; itEE != temporaryMapEE.end() ; itEE++ ){
340 
341  if (itEE->first == (int)ee.rawId()){
342 
343  (itEE->second).FG_lowThreshold=rd_physFgr.getFGlowthresh();
344  (itEE->second).FG_highThreshold=rd_physFgr.getFGhighthresh();
345  // the last two is empty for the EE
346  (itEE->second).FG_lowRatio=rd_physFgr.getFGlowratio();
347  (itEE->second).FG_highRatio= rd_physFgr.getFGhighratio();
348 
349  physC->setValue(ee.rawId(),itEE->second);
350  }
351 
352  countEE++;
353  }
354 
355  ++icellsEE;
356  }
357  }
358 
359 
360  Time_t snc= (Time_t) irun ;
361 
362  m_to_transfer.push_back(std::make_pair((EcalTPGPhysicsConst*)physC,snc));
363 
364 
365  m_i_run_number=irun;
366  m_i_tag=the_config_tag;
367  m_i_version=the_config_version;
368  m_i_physClin=linId;
369  m_i_physClut=lutId;
370  m_i_physCfgr=fgrId;
371 
372  writeFile("last_tpg_physC_settings.txt");
373 
374  } else {
375 
376  m_i_run_number=irun;
377  m_i_tag=the_config_tag;
378  m_i_version=the_config_version;
379 
380  writeFile("last_tpg_physC_settings.txt");
381 
382  std::cout<< " even if the tag/version is not the same, the physics constants id is the same -> no transfer needed "<< std::endl;
383 
384  }
385 
386  }
387 
388 
389 
390  catch (std::exception &e) {
391  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" <<the_config_tag
392  <<" version="<<the_config_version<< std::endl;
393  std::cout << e.what() << std::endl;
394  m_i_run_number=irun;
395 
396  }
397  std::cout<<" **************** "<<std::endl;
398 
399  } else if(nr==0) {
400  m_i_run_number=irun;
401  std::cout<< " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed "<< std::endl;
402  std::cout<<" **************** "<<std::endl;
403  } else {
404  m_i_run_number=irun;
405  m_i_tag=the_config_tag;
406  m_i_version=the_config_version;
407  std::cout<< " the tag/version is the same -> no transfer needed "<< std::endl;
408  std::cout<<" **************** "<<std::endl;
409  writeFile("last_tpg_physC_settings.txt");
410  }
411  }
412  }
413 
414  delete econn;
415  edm::LogInfo("EcalTPGPhysicsConstHandler") << "Ecal - > end of getNewObjects -----------";
416 
417 }
418 
419 
421  //-------------------------------------------------------------
422 
423  m_i_tag="";
424  m_i_version=0;
425  m_i_run_number=0;
426  m_i_physClin=0;
427  m_i_physClut=0;
428  m_i_physCfgr=0;
429 
430  FILE *inpFile; // input file
431  inpFile = fopen(inputFile,"r");
432  if(!inpFile) {
433  edm::LogError("EcalTPGPhysicsConstHandler")<<"*** Can not open file: "<<inputFile;
434  return;
435  }
436 
437  char line[256];
438 
439  std::ostringstream str;
440 
441  fgets(line,255,inpFile);
442  m_i_tag=to_string(line);
443  str << "gen tag " << m_i_tag << std::endl ; // should I use this?
444 
445  fgets(line,255,inpFile);
446  m_i_version=atoi(line);
447  str << "version= " << m_i_version << std::endl ;
448 
449  fgets(line,255,inpFile);
450  m_i_run_number=atoi(line);
451  str << "run_number= " << m_i_run_number << std::endl ;
452 
453  fgets(line,255,inpFile);
454  m_i_physClin=atoi(line);
455  str << "physClin_config= " << m_i_physClin << std::endl ;
456 
457  fgets(line,255,inpFile);
458  m_i_physClut=atoi(line);
459  str << "physClut_config= " << m_i_physClut << std::endl ;
460 
461  fgets(line,255,inpFile);
462  m_i_physCfgr=atoi(line);
463  str << "physCfgr_config= " << m_i_physCfgr << std::endl ;
464 
465  fclose(inpFile); // close inp. file
466 
467 }
468 
470  //-------------------------------------------------------------
471 
472 
473  std::ofstream myfile;
474  myfile.open (inputFile);
475  myfile << m_i_tag <<std::endl;
476  myfile << m_i_version <<std::endl;
477  myfile << m_i_run_number <<std::endl;
478  myfile << m_i_physClin <<std::endl;
479  myfile << m_i_physClut <<std::endl;
480  myfile << m_i_physCfgr <<std::endl;
481 
482  myfile.close();
483 
484 }
485 
size
Write out results.
void setValue(const uint32_t &id, const Item &value)
T getParameter(std::string const &) const
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:70
float getFGlowthresh() const
std::vector< RunIOV > getRuns()
Definition: RunList.cc:35
RunList fetchGlobalRunListByLocation(const RunTag &tag, int min_run, int max_run, const LocationDef &locDef) noexcept(false)
std::string getConfigTag() const
float getFGhighthresh() const
int getVersion() const
Definition: RunTag.h:13
EcalTPGPhysicsConstHandler(edm::ParameterSet const &)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
size_t size
Definition: Types.h:78
float getFGhighratio() const
float getTTThreshhigh() const
void setVersion(int id)
void fetchDataSet(std::map< EcalLogicID, DATT > *fillMap, IOVT *iov) noexcept(false)
std::string name
Definition: Types.h:74
void setId(int id)
cond::ValidityInterval lastInterval
Definition: Types.h:76
std::string getName() const
Definition: EcalLogicID.cc:36
int getLinId() const
float getTTThreshlow() const
double p2[4]
Definition: TauolaWrapper.h:90
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:53
void setId(int id)
Definition: DetId.h:18
int getFgrId() const
void setRunType(std::string runtype)
Definition: RunTypeDef.cc:33
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
int getLUTId() const
void setGeneralTag(std::string tag)
Definition: RunTag.cc:36
#define str(s)
void setId(int id)