CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EcalSRPHandler.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <string>
4 #include <sstream>
5 #include <xercesc/dom/DOMNode.hpp>
6 #include <xercesc/dom/DOM.hpp>
7 #include <xercesc/parsers/XercesDOMParser.hpp>
9 #include <xercesc/util/XMLString.hpp>
10 #include <xercesc/sax/SAXException.hpp>
11 #include <xercesc/framework/LocalFileFormatTarget.hpp>
12 
18 
22 
25 
27 
29 
30 using namespace XERCES_CPP_NAMESPACE;
31 using namespace xuti;
32 
34  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalSRPHandler")) {
35  m_firstRun = (unsigned long)atoi(ps.getParameter<std::string>("firstRun").c_str());
36  m_lastRun = (unsigned long)atoi(ps.getParameter<std::string>("lastRun").c_str());
37  m_sid = ps.getParameter<std::string>("OnlineDBSID");
38  m_user = ps.getParameter<std::string>("OnlineDBUser");
39  m_pass = ps.getParameter<std::string>("OnlineDBPassword");
40  m_location = ps.getParameter<std::string>("location");
41  m_runtype = ps.getParameter<std::string>("runtype");
42  m_gentag = ps.getParameter<std::string>("gentag");
43  m_i_tag = "";
44  m_debug = ps.getParameter<bool>("debug");
45  m_i_version = 0;
46 }
47 
49 
51  std::ostringstream ss;
52  ss << "ECAL ";
53 
54  unsigned long long max_since = 1;
55 
56  // this is the last inserted run
57  max_since = tagInfo().lastInterval.since;
58 
59  // this is the last object in the DB
60  Ref srp_db = lastPayload();
61  if (m_debug)
62  std::cout << " max_since : " << max_since << "\n retrieved last payload " << std::endl;
63 
64  // we copy the last valid record to a temporary object
65  EcalSRSettings* sref = new EcalSRSettings();
66  sref->deltaEta_ = srp_db->deltaEta_;
67  sref->deltaPhi_ = srp_db->deltaPhi_;
68  sref->ecalDccZs1stSample_ = srp_db->ecalDccZs1stSample_;
69  sref->ebDccAdcToGeV_ = srp_db->ebDccAdcToGeV_;
70  sref->eeDccAdcToGeV_ = srp_db->eeDccAdcToGeV_;
71  sref->dccNormalizedWeights_ = srp_db->dccNormalizedWeights_;
72  sref->symetricZS_ = srp_db->symetricZS_;
73  sref->srpLowInterestChannelZS_ = srp_db->srpLowInterestChannelZS_;
74  sref->srpHighInterestChannelZS_ = srp_db->srpHighInterestChannelZS_;
75  sref->actions_ = srp_db->actions_;
76  sref->tccMasksFromConfig_ = srp_db->tccMasksFromConfig_;
77  sref->srpMasksFromConfig_ = srp_db->srpMasksFromConfig_;
78  sref->dccMasks_ = srp_db->dccMasks_;
79  sref->srfMasks_ = srp_db->srfMasks_;
80  sref->substitutionSrfs_ = srp_db->substitutionSrfs_;
81  sref->testerTccEmuSrpIds_ = srp_db->testerTccEmuSrpIds_;
82  sref->testerSrpEmuSrpIds_ = srp_db->testerSrpEmuSrpIds_;
83  sref->testerDccTestSrpIds_ = srp_db->testerDccTestSrpIds_;
84  sref->testerSrpTestSrpIds_ = srp_db->testerSrpTestSrpIds_;
85  sref->bxOffsets_ = srp_db->bxOffsets_;
86  sref->bxGlobalOffset_ = srp_db->bxGlobalOffset_;
87  sref->automaticMasks_ = srp_db->automaticMasks_;
88  sref->automaticSrpSelect_ = srp_db->automaticSrpSelect_;
89 
90  // now read the actual status from the online DB
91 
92  std::cout << "Retrieving DAQ status from OMDS DB ... " << std::endl;
93  econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
94  std::cout << "Connection done" << std::endl;
95 
96  if (!econn) {
97  std::cout << " Problem with OMDS: connection parameters " << m_sid << "/" << m_user << std::endl;
98  throw cms::Exception("OMDS not available");
99  }
100 
102  my_locdef.setLocation(m_location);
103 
105  my_rundef.setRunType(m_runtype);
106 
107  RunTag my_runtag;
108  my_runtag.setLocationDef(my_locdef);
109  my_runtag.setRunTypeDef(my_rundef);
110  my_runtag.setGeneralTag(m_gentag);
111 
112  // range of validity
113  int min_run = 0;
114  if (m_firstRun <= (unsigned long)max_since) {
115  min_run = (int)max_since + 1; // we have to add 1 to the last transferred one
116  } else {
117  min_run = (int)m_firstRun;
118  }
119 
120  int max_run = (int)m_lastRun;
121  if (m_debug)
122  std::cout << "min_run " << min_run << " max_run " << max_run << std::endl;
123 
124  std::ofstream fout;
125  if (m_debug) {
126  char outfile[800];
127  sprintf(outfile, "SRP_run%d.txt", min_run);
128  fout.open(outfile, std::fstream::out);
129  fout << " ORCOFF last run max_since : " << max_since << std::endl;
130  PrintPayload(*sref, fout);
131  }
132 
133  RunList my_list;
134  my_list = econn->fetchRunListByLocation(my_runtag, min_run, max_run, my_locdef);
135 
136  std::vector<RunIOV> run_vec = my_list.getRuns();
137  int num_runs = run_vec.size();
138 
139  if (m_debug) {
140  fout << " number of runs is : " << num_runs << std::endl;
141  }
142  unsigned long irun = 0;
143  if (num_runs > 0) {
144  int fe_conf_id_old = 0;
145  // int krmax = std::min(num_runs, 100);
146  // for(int kr = 0; kr < krmax; kr++) {
147  for (int kr = 0; kr < num_runs; kr++) { // allow any number of runs, exit on transfert size
148  irun = (unsigned long)run_vec[kr].getRunNumber();
149  std::string geneTag = run_vec[kr].getRunTag().getGeneralTag();
150  if (geneTag != "GLOBAL") {
151  if (m_debug)
152  fout << "\n New run " << irun << " with tag " << geneTag << " giving up " << std::endl;
153  continue;
154  }
155  if (m_debug)
156  fout << "\n New run " << irun << " geneTag " << geneTag << std::endl;
157 
158  // First, RUN_CONFIGURATION
159  std::map<EcalLogicID, RunConfigDat> dataset;
160  econn->fetchDataSet(&dataset, &run_vec[kr]);
161  std::string myconfig_tag = "";
162  int myconfig_version = 0;
163  std::map<EcalLogicID, RunConfigDat>::const_iterator it;
164  if (dataset.size() != 1) {
165  std::cout << "\n\n run " << irun << " strange number of dataset " << dataset.size() << std::endl;
166  if (m_debug)
167  fout << "\n\n run " << irun << " strange number of dataset " << dataset.size() << " giving up " << std::endl;
168  continue;
169  }
170 
171  it = dataset.begin();
172  RunConfigDat dat = it->second;
173  myconfig_tag = dat.getConfigTag();
174  // if (myconfig_tag.substr(0, 15) == "ZeroSuppression") {
175  if (myconfig_tag.substr(0, 15) == "ZeroSuppression" || myconfig_tag.substr(0, 11) == "FullReadout" ||
176  myconfig_tag.substr(0, 11) == "AlmostEmpty") {
177  if (m_debug)
178  fout << " run " << irun << " tag " << myconfig_tag << " giving up " << std::endl;
179  continue;
180  }
181 
182  // Now FE_DAQ_CONFIG
183  typedef std::map<EcalLogicID, RunFEConfigDat>::const_iterator feConfIter;
184  std::map<EcalLogicID, RunFEConfigDat> feconfig;
185  econn->fetchDataSet(&feconfig, &run_vec[kr]);
186  if (feconfig.size() != 1) {
187  if (m_debug)
188  fout << "\n\n run " << irun << " strange number of FE config " << feconfig.size() << " giving up "
189  << std::endl;
190  continue;
191  }
192  RunFEConfigDat rd_fe;
193  int fe_conf_id = 0;
194  feConfIter p = feconfig.begin();
195  rd_fe = p->second;
196  fe_conf_id = rd_fe.getConfigId();
197 
198  myconfig_version = dat.getConfigVersion();
199  if (m_debug)
200  fout << " run " << irun << " tag " << myconfig_tag << " version " << myconfig_version << " Fe config "
201  << fe_conf_id << std::endl;
202  // here we should check if it is the same as previous run.
203  if (myconfig_tag != m_i_tag || myconfig_version != m_i_version || fe_conf_id != fe_conf_id_old) {
204  if (m_debug)
205  fout << " run= " << irun << " different tag ... retrieving last config set from DB" << std::endl;
206 
207  bool FromCLOB = false;
208  EcalSRSettings* sr = new EcalSRSettings;
209  sr->ebDccAdcToGeV_ = 0.035;
210  sr->eeDccAdcToGeV_ = 0.060;
211  sr->symetricZS_.push_back(0);
212 
213  ODRunConfigInfo od_run_info;
214  od_run_info.setTag(myconfig_tag);
215  od_run_info.setVersion(myconfig_version);
216 
217  try {
218  econn->fetchConfigSet(&od_run_info);
219  int config_id = od_run_info.getId();
220 
222  seq.setEcalConfigId(config_id);
223  seq.setSequenceNumber(0);
224  econn->fetchConfigSet(&seq);
225  int sequenceid = seq.getSequenceId();
226 
227  ODEcalCycle ecal_cycle;
228  ecal_cycle.setSequenceId(sequenceid);
229  econn->fetchConfigSet(&ecal_cycle);
230  int cycle_id = ecal_cycle.getId();
231  int srp_id = ecal_cycle.getSRPId();
232  if (srp_id == 0) {
233  if (m_debug)
234  fout << " no SRP config for this run, give up " << std::endl;
235  delete sr;
236  continue; // no SRP config
237  }
238  int dcc_id = ecal_cycle.getDCCId();
239  if (m_debug)
240  fout << " cycleid " << cycle_id << " SRP id " << srp_id << " DCC id " << dcc_id << std::endl;
241  /**************************/
242  /* SRP */
243  /**************************/
244  ODSRPConfig srp;
245  srp.setId(srp_id);
246  econn->fetchConfigSet(&srp);
247 
248  unsigned char* cbuffer = srp.getSRPClob();
249  unsigned int SRPClobSize = srp.getSRPClobSize();
250  std::string srpstr((char*)cbuffer, SRPClobSize);
251  std::string SRPClob = srpstr;
252  std::fstream myfile;
253  myfile.open("srp.txt", std::fstream::out);
254  for (std::string::iterator it = SRPClob.begin(); it < SRPClob.end(); it++)
255  myfile << *it;
256  myfile.close();
257  std::ifstream f("srp.txt");
258  if (!f.good()) {
259  throw cms::Exception("EcalSRPHandler") << " Failed to open file srp.txt";
260  if (m_debug)
261  fout << " Failed to open file srp.txt" << std::endl;
262  }
263  EcalSRCondTools::importSrpConfigFile(*sr, f, m_debug);
264  f.close();
265  int rv = system("rm srp.txt");
266  if (m_debug && rv != 0)
267  fout << "rm srp.txt result code: " << rv << "\n";
268 
272  /**************************/
273  /* DCC */
274  /**************************/
275  ODDCCConfig dcc;
276  dcc.setId(dcc_id);
277  econn->fetchConfigSet(&dcc);
278  std::string weightsMode = dcc.getDCCWeightsMode();
279  if (m_debug)
280  fout << " DCC weightsMode " << weightsMode << std::endl
281  << " weight size beg " << sr->dccNormalizedWeights_.size() << std::endl;
282  if (weightsMode == "CLOB") {
283  FromCLOB = true;
284  if (m_debug)
285  fout << " will read weights from DCC CLOB " << std::endl;
286  }
287  cbuffer = dcc.getDCCClob();
288  unsigned int DCCClobSize = dcc.getDCCClobSize();
289  std::string dccstr((char*)cbuffer, DCCClobSize);
290  std::string DCCClob = dccstr;
291  std::ostringstream osd;
292  osd << "dcc.txt";
293  std::string fname = osd.str();
294  myfile.open(fname.c_str(), std::fstream::out);
295  for (std::string::iterator it = DCCClob.begin(); it < DCCClob.end(); it++)
296  myfile << *it;
297  myfile.close();
298  importDccConfigFile(*sr, fname, FromCLOB);
299  if (m_debug)
300  fout << " weight size after CLOB " << sr->dccNormalizedWeights_.size() << std::endl;
301  rv = system("rm dcc.txt");
302  if (m_debug && rv != 0)
303  fout << "rm dcc.txt result code: " << rv << "\n";
304  } catch (std::exception& e) {
305  // we should not come here...
306  std::cout << "ERROR: This config does not exist: tag " << myconfig_tag << " version " << myconfig_version
307  << std::endl;
308  if (m_debug)
309  fout << "ERROR: This config does not exist: tag " << myconfig_tag << " version " << myconfig_version
310  << std::endl;
311  // m_i_run_number = irun;
312  }
313  if (m_debug)
314  fout << " FromCLOB " << FromCLOB << std::endl;
315  if (!FromCLOB) { // data from FE, we need to get FE_DAQ_CONFIG table
316  // reading this configuration
317  ODFEDAQConfig myconfig;
318  myconfig.setId(fe_conf_id);
319  econn->fetchConfigSet(&myconfig);
320 
321  // list weights
322  int mywei = myconfig.getWeightId();
323  if (m_debug)
324  fout << " WEI_ID " << mywei << std::endl;
325 
326  if (mywei != 0) {
327  ODWeightsSamplesDat samp;
328  samp.setId(mywei);
329  econn->fetchConfigSet(&samp);
330  int mySample = samp.getSampleId();
331  if (m_debug)
332  fout << " SAMPLE_ID " << mySample << std::endl;
333  sr->ecalDccZs1stSample_.push_back(mySample);
334 
336  weights.setId(mywei);
337  econn->fetchConfigSet(&weights);
338 
339  std::vector<std::vector<float> > my_dccw = weights.getWeight();
340  int imax = my_dccw.size();
341  if (m_debug)
342  fout << " weight size before check " << imax << std::endl;
343  if (imax == 75848) { // all the channel present. Check for change
344  bool WeightsChange = false, WeightsChangeEB = false, WeightsChangeEE = false;
345  for (int i = 1; i < 61200; i++) // EB
346  for (int ich = 0; ich < 6; ich++)
347  if (my_dccw[i][ich] != my_dccw[0][ich])
348  WeightsChangeEB = true;
349  if (m_debug)
350  fout << " WeightsChangeEB " << WeightsChangeEB << std::endl;
351  for (int i = 61201; i < 75848; i++) // EE
352  for (int ich = 0; ich < 6; ich++)
353  if (my_dccw[i][ich] != my_dccw[61200][ich])
354  WeightsChangeEE = true;
355  if (m_debug)
356  fout << " WeightsChangeEE " << WeightsChangeEE << std::endl;
357  for (int ich = 0; ich < 6; ich++)
358  if (my_dccw[0][ich] != my_dccw[61200][ich])
359  WeightsChange = true;
360  if (m_debug)
361  fout << " WeightsChange " << WeightsChange << std::endl;
362 
363  if (WeightsChangeEB || WeightsChangeEE) // differences between channels, keep them all
364  sr->dccNormalizedWeights_ = my_dccw;
365  else if (WeightsChange) { // difference between EB and EE, keep only 1 channel from each
366  std::vector<float> dccwRowEB, dccwRowEE;
367  for (int ich = 0; ich < 6; ich++) {
368  dccwRowEB.push_back(my_dccw[0][ich]);
369  dccwRowEE.push_back(my_dccw[61200][ich]);
370  }
371  sr->dccNormalizedWeights_.push_back(dccwRowEB);
372  sr->dccNormalizedWeights_.push_back(dccwRowEE);
373  } else { // no difference keep only one
374  std::vector<float> dccwRow;
375  dccwRow.reserve(6);
376  for (int ich = 0; ich < 6; ich++) {
377  dccwRow.push_back(my_dccw[0][ich]);
378  }
379  sr->dccNormalizedWeights_.push_back(dccwRow);
380  if (m_debug) {
381  fout << " weight ";
382  for (int ich = 0; ich < 6; ich++)
383  fout << " ch " << ich << " " << sr->dccNormalizedWeights_[0][ich];
384  fout << std::endl;
385  }
386  }
387  } // all channels
388  else {
389  sr->dccNormalizedWeights_ = my_dccw;
390  }
391  if (m_debug)
392  fout << " weight size after DB " << sr->dccNormalizedWeights_.size() << std::endl;
393  } // WEI_ID != 0
394  } // weights got from FE
395 
396  // check if we have found the weights
397  if (sr->dccNormalizedWeights_.empty()) { // use the firmware default weights
398  // float opt[] = { -383, -383, -372, 279, 479, 380};
399  float def[] = {-1215, 20, 297, 356, 308, 232};
400  std::vector<float> dccw(def, def + 6);
401  if (m_debug)
402  fout << " default weights ";
403  for (int i = 0; i < 6; i++) {
404  if (m_debug)
405  fout << " i " << i << " def " << def[i] << " dccw " << dccw[i] << " \n";
406  }
407  sr->dccNormalizedWeights_.push_back(dccw); // vector vector
408  }
409  // normalize online weights
410  int imax = sr->dccNormalizedWeights_.size();
411  if (m_debug)
412  fout << " weight size " << imax << " normalized weights : " << std::endl;
413  for (int i = 0; i < imax; i++)
414  for (int ich = 0; ich < 6; ich++) {
415  sr->dccNormalizedWeights_[i][ich] /= 1024.;
416  if (m_debug && i == 0)
417  fout << " ch " << ich << " weight " << sr->dccNormalizedWeights_[i][ich] << std::endl;
418  }
419 
420  /**************************/
421  /* checking for change */
422  /**************************/
423  if (m_debug)
424  fout << " checking for change " << std::endl;
425  bool nochange = true;
426  int imaxref, imaxnew;
427 
428  if (sref->deltaEta_ != sr->deltaEta_) {
429  nochange = false;
430  if (m_debug) {
431  imaxref = sref->deltaEta_.size();
432  imaxnew = sr->deltaEta_.size();
433  if (imaxref != imaxnew) {
434  fout << " deltaEta_ size ref " << imaxref << " now " << imaxnew << std::endl;
435  } else {
436  for (int i = 0; i < imaxref; i++) {
437  if (sref->deltaEta_[i] != sr->deltaEta_[i]) {
438  fout << " deltaEta_[" << i << "] ref " << sref->deltaEta_[i] << " now " << sr->deltaEta_[i]
439  << std::endl;
440  }
441  }
442  }
443  }
444  }
445 
446  if (sref->deltaPhi_ != sr->deltaPhi_) {
447  nochange = false;
448  if (m_debug) {
449  imaxref = sref->deltaPhi_.size();
450  imaxnew = sr->deltaPhi_.size();
451  if (imaxref != imaxnew) {
452  fout << " deltaPhi size ref " << imaxref << " now " << imaxnew << std::endl;
453  } else {
454  for (int i = 0; i < imaxref; i++) {
455  if (sref->deltaPhi_[i] != sr->deltaPhi_[i]) {
456  fout << " deltaPhi[" << i << "] ref " << sref->deltaPhi_[i] << " now " << sr->deltaPhi_[i]
457  << std::endl;
458  }
459  }
460  }
461  }
462  }
463 
464  if (sref->ecalDccZs1stSample_ != sr->ecalDccZs1stSample_) {
465  nochange = false;
466  if (m_debug) {
467  imaxref = sref->ecalDccZs1stSample_.size();
468  imaxnew = sr->ecalDccZs1stSample_.size();
469  if (imaxref != imaxnew) {
470  fout << " ecalDccZs1stSample size ref " << imaxref << " now " << imaxnew << std::endl;
471  } else {
472  for (int i = 0; i < imaxref; i++) {
473  if (sref->ecalDccZs1stSample_[i] != sr->ecalDccZs1stSample_[i]) {
474  fout << " ecalDccZs1stSample_[" << i << "] ref " << sref->ecalDccZs1stSample_[i] << " now "
475  << sr->ecalDccZs1stSample_[i] << std::endl;
476  }
477  }
478  }
479  }
480  }
481 
482  if (sref->ebDccAdcToGeV_ != sr->ebDccAdcToGeV_ || sref->eeDccAdcToGeV_ != sr->eeDccAdcToGeV_) {
483  nochange = false;
484  if (m_debug)
485  fout << " ebDccAdcToGeV ref " << sref->ebDccAdcToGeV_ << " ee " << sref->eeDccAdcToGeV_ << " now "
486  << sr->ebDccAdcToGeV_ << " ee " << sr->eeDccAdcToGeV_ << std::endl;
487  }
488 
489  if (sref->dccNormalizedWeights_ != sr->dccNormalizedWeights_) {
490  nochange = false;
491  if (m_debug) {
492  imaxref = sref->dccNormalizedWeights_.size();
493  imaxnew = sr->dccNormalizedWeights_.size();
494  if (imaxref != imaxnew) {
495  fout << " dccNormalizedWeights size ref " << imaxref << " now " << imaxnew << std::endl;
496  } else {
497  int i = 0;
498  for (int ich = 0; ich < 6; ich++) {
499  if (sref->dccNormalizedWeights_[i][ich] != sr->dccNormalizedWeights_[i][ich]) {
500  fout << " dccNormalizedWeights_[" << i << "][" << ich << "] ref "
501  << sref->dccNormalizedWeights_[i][ich] << " now " << sr->dccNormalizedWeights_[i][ich]
502  << std::endl;
503  }
504  }
505  }
506  }
507  }
508 
509  if (sref->symetricZS_ != sr->symetricZS_) {
510  nochange = false;
511  if (m_debug) {
512  imaxref = sref->symetricZS_.size();
513  imaxnew = sr->symetricZS_.size();
514  if (imaxref != imaxnew) {
515  fout << " symetricZS size ref " << imaxref << " now " << imaxnew << std::endl;
516  } else {
517  for (int i = 0; i < imaxref; i++) {
518  if (sref->symetricZS_[i] != sr->symetricZS_[i]) {
519  fout << " symetricZS[" << i << "] ref " << sref->symetricZS_[i] << " now " << sr->symetricZS_[i]
520  << std::endl;
521  }
522  }
523  }
524  }
525  }
526 
528  nochange = false;
529  if (m_debug) {
530  imaxref = sref->srpLowInterestChannelZS_.size();
531  imaxnew = sr->srpLowInterestChannelZS_.size();
532  if (imaxref != imaxnew) {
533  fout << " srpLowInterestChannelZS size ref " << imaxref << " now " << imaxnew << std::endl;
534  } else {
535  for (int i = 0; i < imaxref; i++) {
537  fout << " srpLowInterestChannelZS[" << i << "] ref " << sref->srpLowInterestChannelZS_[i] << " now "
538  << sr->srpLowInterestChannelZS_[i] << std::endl;
539  }
540  }
541  }
542  }
543  }
544 
546  nochange = false;
547  if (m_debug) {
548  imaxref = sref->srpHighInterestChannelZS_.size();
549  imaxnew = sr->srpHighInterestChannelZS_.size();
550  if (imaxref != imaxnew) {
551  fout << " srpHighInterestChannelZS size ref " << imaxref << " now " << imaxnew << std::endl;
552  } else {
553  for (int i = 0; i < imaxref; i++) {
555  fout << " srpHighInterestChannelZS[" << i << "] ref " << sref->srpHighInterestChannelZS_[i] << " now "
556  << sr->srpHighInterestChannelZS_[i] << std::endl;
557  }
558  }
559  }
560  }
561  }
562 
563  if (sref->actions_ != sr->actions_) {
564  nochange = false;
565  if (m_debug) {
566  for (int i = 0; i < 4; i++) {
567  if (sref->actions_[i] != sr->actions_[i]) {
568  fout << " actions " << i << " ref " << sref->actions_[i] << " now " << sr->actions_[i] << std::endl;
569  }
570  }
571  }
572  }
573 
574  if (sref->tccMasksFromConfig_ != sr->tccMasksFromConfig_) {
575  nochange = false;
576  if (m_debug) {
577  for (int i = 0; i < 108; i++) {
578  if (sref->tccMasksFromConfig_[i] != sr->tccMasksFromConfig_[i]) {
579  fout << " tccMasks " << i << " ref " << sref->tccMasksFromConfig_[i] << " now "
580  << sr->tccMasksFromConfig_[i] << std::endl;
581  }
582  }
583  }
584  }
585 
586  if (sref->srpMasksFromConfig_ != sr->srpMasksFromConfig_) {
587  nochange = false;
588  if (m_debug) {
589  for (int i = 0; i < 12; i++) {
590  for (int ich = 0; ich < 8; ich++) {
591  if (sref->srpMasksFromConfig_[i][ich] != sr->srpMasksFromConfig_[i][ich]) {
592  fout << " srpMasks " << i << " " << ich << " ref " << sref->srpMasksFromConfig_[i][ich] << " now "
593  << sr->srpMasksFromConfig_[i][ich] << std::endl;
594  }
595  }
596  }
597  }
598  }
599 
600  if (sref->dccMasks_ != sr->dccMasks_) {
601  nochange = false;
602  if (m_debug) {
603  for (int i = 0; i < 54; i++) {
604  if (sref->dccMasks_[i] != sr->dccMasks_[i]) {
605  fout << " dccMasks " << i << " ref " << sref->dccMasks_[i] << " now " << sr->dccMasks_[i] << std::endl;
606  }
607  }
608  }
609  }
610 
611  if (sref->srfMasks_ != sr->srfMasks_) {
612  nochange = false;
613  if (m_debug) {
614  for (int i = 0; i < 12; i++) {
615  if (sref->srfMasks_[i] != sr->srfMasks_[i]) {
616  fout << " srfMasks " << i << " ref " << sref->srfMasks_[i] << " now " << sr->srfMasks_[i] << std::endl;
617  }
618  }
619  }
620  }
621 
622  if (sref->substitutionSrfs_ != sr->substitutionSrfs_) {
623  nochange = false;
624  if (m_debug) {
625  for (int i = 0; i < 12; i++) {
626  for (int ich = 0; ich < 68; ich++) {
627  if (sref->substitutionSrfs_[i][ich] != sr->substitutionSrfs_[i][ich]) {
628  fout << " substitutionSrfs " << i << " " << ich << " ref " << sref->substitutionSrfs_[i][ich]
629  << " now " << sr->substitutionSrfs_[i][ich] << std::endl;
630  }
631  }
632  }
633  }
634  }
635 
636  if (sref->testerTccEmuSrpIds_ != sr->testerTccEmuSrpIds_) {
637  nochange = false;
638  if (m_debug) {
639  for (int i = 0; i < 12; i++) {
640  fout << " testerTccEmuSrpIds " << i << " ref " << sref->testerTccEmuSrpIds_[i] << " now "
641  << sr->testerTccEmuSrpIds_[i] << std::endl;
642  }
643  }
644  }
645 
646  if (sref->testerSrpEmuSrpIds_ != sr->testerSrpEmuSrpIds_) {
647  nochange = false;
648  if (m_debug)
649  for (int i = 0; i < 12; i++) {
650  fout << " testerSrpEmuSrpIds " << i << " ref " << sref->testerSrpEmuSrpIds_[i] << " now "
651  << sr->testerSrpEmuSrpIds_[i] << std::endl;
652  }
653  }
654 
655  if (sref->testerDccTestSrpIds_ != sr->testerDccTestSrpIds_) {
656  nochange = false;
657  if (m_debug)
658  for (int i = 0; i < 12; i++) {
659  fout << " testerDccTestSrpIds " << i << " ref " << sref->testerDccTestSrpIds_[i] << " now "
660  << sr->testerDccTestSrpIds_[i] << std::endl;
661  }
662  }
663 
664  if (sref->testerSrpTestSrpIds_ != sr->testerSrpTestSrpIds_) {
665  nochange = false;
666  if (m_debug)
667  for (int i = 0; i < 12; i++) {
668  fout << " testerSrpTestSrpIds " << i << " ref " << sref->testerSrpTestSrpIds_[i] << " now "
669  << sr->testerSrpTestSrpIds_[i] << std::endl;
670  }
671  }
672 
673  if (sref->bxOffsets_ != sr->bxOffsets_) {
674  nochange = false;
675  if (m_debug)
676  for (int i = 0; i < 12; i++) {
677  fout << " bxOffsets " << i << " ref " << sref->bxOffsets_[i] << " now " << sr->bxOffsets_[i] << std::endl;
678  }
679  }
680 
681  if (sref->bxGlobalOffset_ != sr->bxGlobalOffset_) {
682  nochange = false;
683  if (m_debug)
684  fout << " bxGlobalOffset ref " << sr->bxGlobalOffset_ << " now " << sr->bxGlobalOffset_ << std::endl;
685  }
686 
687  if (sref->automaticMasks_ != sr->automaticMasks_) {
688  nochange = false;
689  if (m_debug)
690  fout << " automaticMasks ref " << sref->automaticMasks_ << " now " << sr->automaticMasks_ << std::endl;
691  }
692 
693  if (sref->automaticSrpSelect_ != sr->automaticSrpSelect_) {
694  nochange = false;
695  if (m_debug)
696  fout << " automaticSrpSelect ref " << sref->automaticSrpSelect_ << " now " << sr->automaticSrpSelect_
697  << std::endl;
698  }
699 
700  if (nochange) {
701  if (m_debug)
702  fout << " no change has been found " << std::endl;
703  std::ostringstream ss;
704  ss << "Run=" << irun << "_SRPunchanged_" << std::endl;
705  m_userTextLog = ss.str() + ";";
706  } else {
707  if (m_debug) {
708  fout << " Change has been found !\n New payload :" << std::endl;
709  PrintPayload(*sr, fout);
710  }
711  ChangePayload(*sref, *sr); // new reference
712  // write the new payload to ORCON/ORCOFF
713  EcalSRSettings* srp_pop = new EcalSRSettings();
714  ChangePayload(*srp_pop, *sr); // add this payload to DB
715  m_to_transfer.push_back(std::make_pair(srp_pop, irun));
716 
717  std::ostringstream ss;
718  ss << "Run=" << irun << "_SRPchanged_" << std::endl;
719  m_userTextLog = ss.str() + ";";
720 
721  if (m_to_transfer.size() >= 20)
722  break;
723  }
724  delete sr;
725  m_i_tag = myconfig_tag;
726  m_i_version = myconfig_version;
727  fe_conf_id_old = fe_conf_id;
728  } // different tag or version or fe config
729  } // loop over runs
730  } // test on number of runs
731 
732  // disconnect from DB
733  delete econn;
734  fout.close();
735 }
736 
739 
740  XercesDOMParser* parser = new XercesDOMParser;
741  parser->setValidationScheme(XercesDOMParser::Val_Never);
742  parser->setDoNamespaces(false);
743  parser->setDoSchema(false);
744 
745  parser->parse(filename.c_str());
746 
747  DOMDocument* xmlDoc = parser->getDocument();
748  if (!xmlDoc) {
749  std::cout << "importDccConfigFile Error parsing document" << std::endl;
750  }
751 
752  DOMElement* element = xmlDoc->getDocumentElement();
753  std::string type = cms::xerces::toString(element->getTagName());
754 
755  // 1st level
756  int EBEE = -1;
757  int L1ZS[2] = {0, 0}, L2ZS[2] = {0, 0};
758  for (DOMNode* childNode = element->getFirstChild(); childNode; childNode = childNode->getNextSibling()) {
759  if (childNode->getNodeType() == DOMNode::ELEMENT_NODE) {
760  const std::string foundName = cms::xerces::toString(childNode->getNodeName());
761  DOMElement* child = static_cast<DOMElement*>(childNode);
762  DOMNamedNodeMap* attributes = child->getAttributes();
763  unsigned int numAttributes = attributes->getLength();
764  for (unsigned int j = 0; j < numAttributes; ++j) {
765  DOMNode* attributeNode = attributes->item(j);
766  DOMAttr* attribute = static_cast<DOMAttr*>(attributeNode);
767  const std::string info = cms::xerces::toString(attribute->getName());
768  const std::string scope = cms::xerces::toString(attribute->getValue());
769  if (info == "_scope") {
770  if (scope.substr(0, 2) == "EE")
771  EBEE = 1;
772  else
773  EBEE = 0;
774  }
775  }
776  // 2nd level
777  for (DOMNode* subchildNode = childNode->getFirstChild(); subchildNode;
778  subchildNode = subchildNode->getNextSibling()) {
779  if (subchildNode->getNodeType() == DOMNode::ELEMENT_NODE) {
780  const std::string subName = cms::xerces::toString(subchildNode->getNodeName());
781  // 3rd level
782  for (DOMNode* subsubchildNode = subchildNode->getFirstChild(); subsubchildNode;
783  subsubchildNode = subsubchildNode->getNextSibling()) {
784  if (subsubchildNode->getNodeType() == DOMNode::ELEMENT_NODE) {
785  const std::string subName = cms::xerces::toString(subsubchildNode->getNodeName());
786  if (subName == "L1ZSUPPRESSION")
787  GetNodeData(subsubchildNode, L1ZS[EBEE]);
788  if (subName == "L2ZSUPPRESSION")
789  GetNodeData(subsubchildNode, L2ZS[EBEE]);
790  if (subName == "FIRSTZSSAMPLE") {
791  int ZS;
792  GetNodeData(subsubchildNode, ZS);
793  if (useCLOB)
794  sr.ecalDccZs1stSample_.push_back(ZS);
795  }
796  if (subName == "CXTALWEIGHTS") {
797  std::vector<float> dcc(6);
798  float w;
799  for (int iw = 0; iw < 6; iw++) {
800  GetNodeData(subsubchildNode, w);
801  dcc.push_back(w);
802  }
803  if (useCLOB)
804  sr.dccNormalizedWeights_.push_back(dcc); // vector vector
805  }
806  }
807  } // loop over subsubchild
808  }
809  } // loop over subchild
810  }
811  } // loop over child
812  sr.srpLowInterestChannelZS_.push_back(L1ZS[0] * 0.035 / 4); // EB
813  sr.srpLowInterestChannelZS_.push_back(L1ZS[1] * 0.060 / 4); // EE
814  sr.srpHighInterestChannelZS_.push_back(L2ZS[0] * 0.035 / 4); // EB
815  sr.srpHighInterestChannelZS_.push_back(L2ZS[1] * 0.060 / 4); // EE
816  delete parser;
818 }
819 
821  int imax = sr.deltaEta_.size();
822  fout << " deltaEta[" << imax << "] ";
823  for (int i = 0; i < imax; i++) {
824  fout << sr.deltaEta_[i] << " ";
825  }
826  fout << std::endl;
827 
828  imax = sr.deltaPhi_.size();
829  fout << " deltaPhi[" << imax << "] ";
830  for (int i = 0; i < imax; i++) {
831  fout << sr.deltaPhi_[i] << " ";
832  }
833  fout << std::endl;
834 
835  imax = sr.ecalDccZs1stSample_.size();
836  fout << " ecalDccZs1stSample[" << imax << "] ";
837  for (int i = 0; i < imax; i++) {
838  fout << sr.ecalDccZs1stSample_[i] << " ";
839  }
840  fout << std::endl;
841 
842  fout << " ebDccAdcToGeV " << sr.ebDccAdcToGeV_ << std::endl;
843 
844  fout << " eeDccAdcToGeV " << sr.eeDccAdcToGeV_ << std::endl;
845 
846  fout << " dccNormalizedWeights" << std::endl;
847  for (int i = 0; i < (int)sr.dccNormalizedWeights_.size(); ++i) {
848  fout << " Channel " << i;
849  for (int j = 0; j < (int)sr.dccNormalizedWeights_[i].size(); ++j)
850  fout << " " << sr.dccNormalizedWeights_[i][j];
851  fout << std::endl;
852  }
853 
854  imax = sr.symetricZS_.size();
855  fout << " symetricZS[" << imax << "] ";
856  for (int i = 0; i < imax; i++) {
857  fout << sr.symetricZS_[i] << " ";
858  }
859  fout << std::endl;
860 
861  imax = sr.srpLowInterestChannelZS_.size();
862  fout << " srpLowInterestChannelZS[" << imax << "] ";
863  for (int i = 0; i < imax; i++) {
864  fout << sr.srpLowInterestChannelZS_[i] << " ";
865  }
866  fout << std::endl;
867 
868  imax = sr.srpHighInterestChannelZS_.size();
869  fout << " srpHighInterestChannelZS[" << imax << "] ";
870  for (int i = 0; i < imax; i++) {
871  fout << sr.srpHighInterestChannelZS_[i] << " ";
872  }
873  fout << std::endl;
874 
875  imax = sr.actions_.size();
876  fout << " actions[" << imax << "] ";
877  for (int i = 0; i < imax; i++) {
878  fout << sr.actions_[i] << " ";
879  }
880  fout << std::endl;
881 
882  imax = sr.tccMasksFromConfig_.size();
883  fout << " tccMasksFromConfig[" << imax << "] ";
884  for (int i = 0; i < imax; i++) {
885  fout << sr.tccMasksFromConfig_[i] << " ";
886  }
887  fout << std::endl;
888 
889  fout << " srpMasksFromConfig" << std::endl;
890  for (int i = 0; i < (int)sr.srpMasksFromConfig_.size(); ++i) {
891  for (int j = 0; j < (int)sr.srpMasksFromConfig_[i].size(); ++j)
892  fout << sr.srpMasksFromConfig_[i][j] << " ";
893  fout << std::endl;
894  }
895 
896  imax = sr.dccMasks_.size();
897  fout << " dccMasks[" << imax << "] ";
898  for (int i = 0; i < imax; i++) {
899  fout << sr.dccMasks_[i] << " ";
900  }
901  fout << std::endl;
902 
903  imax = sr.srfMasks_.size();
904  fout << " srfMasks[" << imax << "] ";
905  for (int i = 0; i < imax; i++) {
906  fout << sr.srfMasks_[i] << " ";
907  }
908  fout << std::endl;
909 
910  fout << "substitutionSrfs" << std::endl;
911  for (int i = 0; i < (int)sr.substitutionSrfs_.size(); ++i) {
912  for (int j = 0; j < (int)sr.substitutionSrfs_[i].size(); ++j)
913  fout << sr.substitutionSrfs_[i][j] << " ";
914  fout << std::endl;
915  }
916 
917  imax = sr.testerTccEmuSrpIds_.size();
918  fout << " testerTccEmuSrpIds[" << imax << "] ";
919  for (int i = 0; i < imax; i++) {
920  fout << sr.testerTccEmuSrpIds_[i] << " ";
921  }
922  fout << std::endl;
923 
924  imax = sr.testerSrpEmuSrpIds_.size();
925  fout << " testerSrpEmuSrpIds[" << imax << "] ";
926  for (int i = 0; i < imax; i++) {
927  fout << sr.testerSrpEmuSrpIds_[i] << " ";
928  }
929  fout << std::endl;
930 
931  imax = sr.testerDccTestSrpIds_.size();
932  fout << " testerDccTestSrpIds[" << imax << "] ";
933  for (int i = 0; i < imax; i++) {
934  fout << sr.testerDccTestSrpIds_[i] << " ";
935  }
936  fout << std::endl;
937 
938  imax = sr.testerSrpTestSrpIds_.size();
939  fout << " testerSrpTestSrpIds[" << imax << "] ";
940  for (int i = 0; i < imax; i++) {
941  fout << sr.testerSrpTestSrpIds_[i] << " ";
942  }
943  fout << std::endl;
944 
945  imax = sr.bxOffsets_.size();
946  fout << " bxOffsets[" << imax << "] ";
947  for (int i = 0; i < imax; i++) {
948  fout << sr.bxOffsets_[i] << " ";
949  }
950  fout << std::endl;
951 
952  fout << " bxGlobalOffset " << sr.bxGlobalOffset_ << std::endl;
953  fout << " automaticMasks " << sr.automaticMasks_ << std::endl;
954  fout << " automaticSrpSelect " << sr.automaticSrpSelect_ << std::endl;
955 }
956 
958  sref.deltaEta_ = sr.deltaEta_;
959  sref.deltaPhi_ = sr.deltaPhi_;
961  sref.ebDccAdcToGeV_ = sr.ebDccAdcToGeV_;
962  sref.eeDccAdcToGeV_ = sr.eeDccAdcToGeV_;
964  sref.symetricZS_ = sr.symetricZS_;
967  sref.actions_ = sr.actions_;
970  sref.dccMasks_ = sr.dccMasks_;
971  sref.srfMasks_ = sr.srfMasks_;
977  sref.bxOffsets_ = sr.bxOffsets_;
981 }
unsigned long m_firstRun
void setId(int dac)
Definition: ODWeightsDat.h:21
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:42
void setSequenceId(int x)
Definition: ODEcalCycle.h:28
static void importSrpConfigFile(EcalSRSettings &sr, std::istream &f, bool debug=false)
unsigned int getDCCClobSize() const
Definition: ODDCCConfig.h:43
int def(FILE *, FILE *, int)
std::vector< RunIOV > getRuns()
Definition: RunList.cc:25
static const TGPicture * info(bool iBackgroundIsBlack)
void setId(int id)
Definition: ODFEDAQConfig.h:18
void setSequenceNumber(int x)
void xercesTerminate()
Definition: Xerces.cc:23
Definition: RunTag.h:13
std::vector< short > srfMasks_
EcalSRPHandler(edm::ParameterSet const &)
std::vector< std::vector< float > > dccNormalizedWeights_
std::vector< int > testerSrpEmuSrpIds_
unsigned int getSRPClobSize() const
Definition: ODSRPConfig.h:51
void xercesInitialize()
Definition: Xerces.cc:18
int getDCCId() const
Definition: ODEcalCycle.h:40
std::vector< float > srpHighInterestChannelZS_
int getSequenceId() const
std::vector< int > actions_
int getAutomaticMasks() const
Definition: ODSRPConfig.h:38
std::string toString(XMLCh const *toTranscode)
std::vector< std::vector< short > > substitutionSrfs_
std::vector< int > testerDccTestSrpIds_
unsigned long m_lastRun
void ChangePayload(EcalSRSettings &sref, EcalSRSettings &sr)
int getConfigVersion() const
Definition: RunConfigDat.h:23
std::vector< int > ecalDccZs1stSample_
void setVersion(int x)
int getAutomaticSrpSelect() const
Definition: ODSRPConfig.h:41
std::string getDCCWeightsMode() const
Definition: ODDCCConfig.h:45
int getSRPId() const
Definition: ODEcalCycle.h:64
int getId() const
Definition: ODEcalCycle.h:20
std::vector< short > tccMasksFromConfig_
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:33
std::vector< short > bxOffsets_
int getSRP0BunchAdjustPosition() const
Definition: ODSRPConfig.h:44
std::vector< short > dccMasks_
std::vector< int > deltaPhi_
unsigned char * getDCCClob() const
Definition: ODDCCConfig.h:42
void getNewObjects() override
unsigned char * getSRPClob() const
Definition: ODSRPConfig.h:50
std::vector< std::vector< float > > getWeight() const
Definition: ODWeightsDat.h:52
void GetNodeData(xercesc::DOMNode *node, T &value)
get the node data
std::vector< int > symetricZS_
void setRunType(std::string runtype)
Definition: RunTypeDef.cc:21
int getConfigId() const
int getId() const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
float ebDccAdcToGeV_
ADC to GeV conversion factor used in ZS filter for EB.
void importDccConfigFile(EcalSRSettings &sr, const std::string &filename, bool debug=false)
static std::vector< std::string > checklist dat
std::vector< int > testerTccEmuSrpIds_
void setEcalConfigId(int x)
string fname
main script
std::vector< float > srpLowInterestChannelZS_
std::vector< int > deltaEta_
std::string getConfigTag() const
Definition: RunConfigDat.h:20
std::vector< int > testerSrpTestSrpIds_
void setId(int id)
Definition: ODDCCConfig.h:24
tuple filename
Definition: lut2db_cfg.py:20
void setTag(std::string x)
void setLocation(std::string loc)
Definition: LocationDef.cc:20
tuple cout
Definition: gather_cfg.py:144
int getWeightId() const
Definition: ODFEDAQConfig.h:31
T w() const
void setId(int id)
Definition: ODSRPConfig.h:25
float eeDccAdcToGeV_
ADC to GeV conversion factor used in ZS filter for EE.
void setGeneralTag(std::string tag)
Definition: RunTag.cc:24
void PrintPayload(EcalSRSettings &sr, std::ofstream &fout)
std::vector< std::vector< short > > srpMasksFromConfig_