CMS 3D CMS Logo

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