00001 #include<iostream>
00002 #include <fstream>
00003 #include <string>
00004 #include <sstream>
00005 #include <xercesc/dom/DOMNode.hpp>
00006 #include <xercesc/dom/DOM.hpp>
00007 #include <xercesc/parsers/XercesDOMParser.hpp>
00008 #include <xercesc/util/PlatformUtils.hpp>
00009 #include <xercesc/util/XMLString.hpp>
00010 #include <xercesc/sax/SAXException.hpp>
00011 #include <xercesc/framework/LocalFileFormatTarget.hpp>
00012
00013 #include "CondTools/Ecal/interface/EcalSRPHandler.h"
00014 #include "CondTools/Ecal/interface/EcalCondHeader.h"
00015 #include "CondTools/Ecal/interface/DOMHelperFunctions.h"
00016 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00017 #include "CondFormats/EcalObjects/interface/EcalSRSettings.h"
00018
00019 #include "OnlineDB/EcalCondDB/interface/RunConfigDat.h"
00020 #include "OnlineDB/EcalCondDB/interface/ODRunConfigInfo.h"
00021 #include "OnlineDB/EcalCondDB/interface/ODRunConfigSeqInfo.h"
00022
00023 #include "OnlineDB/EcalCondDB/interface/FEConfigMainInfo.h"
00024 #include "OnlineDB/EcalCondDB/interface/FEConfigBadTTInfo.h"
00025
00026 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00027
00028 #include "SimCalorimetry/EcalSelectiveReadoutProducers/interface/EcalSRCondTools.h"
00029
00030 using namespace XERCES_CPP_NAMESPACE;
00031 using namespace xuti;
00032
00033 popcon::EcalSRPHandler::EcalSRPHandler(const edm::ParameterSet & ps)
00034 : m_name(ps.getUntrackedParameter<std::string>("name","EcalSRPHandler")) {
00035
00036 m_firstRun =(unsigned long)atoi( ps.getParameter<std::string>("firstRun").c_str());
00037 m_lastRun =(unsigned long)atoi( ps.getParameter<std::string>("lastRun").c_str());
00038 m_sid = ps.getParameter<std::string>("OnlineDBSID");
00039 m_user = ps.getParameter<std::string>("OnlineDBUser");
00040 m_pass = ps.getParameter<std::string>("OnlineDBPassword");
00041 m_location = ps.getParameter<std::string>("location");
00042 m_runtype = ps.getParameter<std::string>("runtype");
00043 m_gentag = ps.getParameter<std::string>("gentag");
00044 m_i_tag = "";
00045 m_debug = ps.getParameter<bool>("debug");
00046 m_i_version= 0;
00047
00048 }
00049
00050 popcon::EcalSRPHandler::~EcalSRPHandler() {}
00051
00052 void popcon::EcalSRPHandler::getNewObjects() {
00053
00054 std::ostringstream ss;
00055 ss<<"ECAL ";
00056
00057 unsigned long long max_since = 1;
00058
00059
00060 max_since = tagInfo().lastInterval.first;
00061
00062
00063 Ref srp_db = lastPayload();
00064 if(m_debug)
00065 std::cout << " max_since : " << max_since
00066 << "\n retrieved last payload " << std::endl;
00067
00068
00069 EcalSRSettings* sref = new EcalSRSettings();
00070 sref->deltaEta_ = srp_db->deltaEta_;
00071 sref->deltaPhi_ = srp_db->deltaPhi_;
00072 sref->ecalDccZs1stSample_ = srp_db->ecalDccZs1stSample_;
00073 sref->ebDccAdcToGeV_ = srp_db->ebDccAdcToGeV_;
00074 sref->eeDccAdcToGeV_ = srp_db->eeDccAdcToGeV_;
00075 sref->dccNormalizedWeights_ = srp_db->dccNormalizedWeights_;
00076 sref->symetricZS_ = srp_db->symetricZS_;
00077 sref->srpLowInterestChannelZS_ = srp_db->srpLowInterestChannelZS_;
00078 sref->srpHighInterestChannelZS_ = srp_db->srpHighInterestChannelZS_;
00079 sref->actions_ = srp_db->actions_;
00080 sref->tccMasksFromConfig_ = srp_db->tccMasksFromConfig_;
00081 sref->srpMasksFromConfig_ = srp_db->srpMasksFromConfig_;
00082 sref->dccMasks_ = srp_db->dccMasks_;
00083 sref->srfMasks_ = srp_db->srfMasks_;
00084 sref->substitutionSrfs_= srp_db->substitutionSrfs_;
00085 sref->testerTccEmuSrpIds_ = srp_db->testerTccEmuSrpIds_;
00086 sref->testerSrpEmuSrpIds_ = srp_db->testerSrpEmuSrpIds_;
00087 sref->testerDccTestSrpIds_ = srp_db->testerDccTestSrpIds_;
00088 sref->testerSrpTestSrpIds_ = srp_db->testerSrpTestSrpIds_;
00089 sref->bxOffsets_ = srp_db->bxOffsets_;
00090 sref->bxGlobalOffset_ = srp_db->bxGlobalOffset_;
00091 sref->automaticMasks_ = srp_db->automaticMasks_;
00092 sref->automaticSrpSelect_ = srp_db->automaticSrpSelect_;
00093
00094
00095
00096 std::cout << "Retrieving DAQ status from OMDS DB ... " << std::endl;
00097 econn = new EcalCondDBInterface( m_sid, m_user, m_pass );
00098 std::cout << "Connection done" << std::endl;
00099
00100 if (!econn) {
00101 std::cout << " Problem with OMDS: connection parameters " << m_sid << "/" << m_user << std::endl;
00102 throw cms::Exception("OMDS not available");
00103 }
00104
00105 LocationDef my_locdef;
00106 my_locdef.setLocation(m_location);
00107
00108 RunTypeDef my_rundef;
00109 my_rundef.setRunType(m_runtype);
00110
00111 RunTag my_runtag;
00112 my_runtag.setLocationDef( my_locdef );
00113 my_runtag.setRunTypeDef( my_rundef );
00114 my_runtag.setGeneralTag(m_gentag);
00115
00116
00117 int min_run = 0;
00118 if(m_firstRun <= (unsigned long)max_since) {
00119 min_run= (int)max_since+1;
00120 }
00121 else { min_run=(int)m_firstRun; }
00122
00123 int max_run=(int)m_lastRun;
00124 if(m_debug)
00125 std::cout << "min_run " << min_run << " max_run " << max_run << std::endl;
00126
00127 std::ofstream fout;
00128 if(m_debug) {
00129 char outfile[800];
00130 sprintf(outfile,"SRP_run%d.txt",min_run);
00131 fout.open(outfile, std::fstream::out);
00132 fout << " ORCOFF last run max_since : " << max_since << std::endl;
00133 PrintPayload(*sref, fout);
00134 }
00135
00136 RunList my_list;
00137 my_list = econn->fetchRunListByLocation(my_runtag, min_run, max_run, my_locdef);
00138
00139 std::vector<RunIOV> run_vec = my_list.getRuns();
00140 int num_runs = run_vec.size();
00141
00142 if(m_debug) {
00143 fout << " number of runs is : " << num_runs << std::endl;
00144 }
00145 unsigned long irun = 0;
00146 if(num_runs > 0){
00147 int fe_conf_id_old = 0;
00148
00149
00150 for(int kr = 0; kr < num_runs; kr++) {
00151 irun = (unsigned long) run_vec[kr].getRunNumber();
00152 std::string geneTag = run_vec[kr].getRunTag().getGeneralTag();
00153 if(geneTag != "GLOBAL") {
00154 if(m_debug)
00155 fout << "\n New run " << irun << " with tag " << geneTag << " giving up " << std::endl;
00156 continue;
00157 }
00158 if(m_debug)
00159 fout << "\n New run " << irun << " geneTag " << geneTag << std::endl;
00160
00161
00162 std::map<EcalLogicID, RunConfigDat> dataset;
00163 econn->fetchDataSet(&dataset, &run_vec[kr]);
00164 std::string myconfig_tag = "";
00165 int myconfig_version = 0;
00166 std::map< EcalLogicID, RunConfigDat>::const_iterator it;
00167 int cycle_id_old = 0;
00168 int srp_id_old = 0;
00169 int dcc_id_old = 0;
00170 if(dataset.size() != 1) {
00171 std::cout << "\n\n run " << irun << " strange number of dataset "
00172 << dataset.size() << std::endl;
00173 if(m_debug)
00174 fout << "\n\n run " << irun << " strange number of dataset "
00175 << dataset.size() << " giving up " << std::endl;
00176 continue;
00177 }
00178
00179 it = dataset.begin();
00180 RunConfigDat dat = it->second;
00181 myconfig_tag = dat.getConfigTag();
00182 if(myconfig_tag.substr(0,15) == "ZeroSuppression") {
00183 if(m_debug)
00184 fout << " run " << irun << " tag " << myconfig_tag << " giving up " << std::endl;
00185 continue;
00186 }
00187
00188
00189 typedef std::map<EcalLogicID, RunFEConfigDat>::const_iterator feConfIter;
00190 std::map<EcalLogicID, RunFEConfigDat> feconfig;
00191 econn->fetchDataSet(&feconfig, &run_vec[kr]);
00192 if(feconfig.size() != 1) {
00193 if(m_debug)
00194 fout << "\n\n run " << irun << " strange number of FE config "
00195 << feconfig.size() << " giving up " << std::endl;
00196 continue;
00197 }
00198 RunFEConfigDat rd_fe;
00199 int fe_conf_id = 0;
00200 feConfIter p=feconfig.begin();
00201 rd_fe = p->second;
00202 fe_conf_id = rd_fe.getConfigId();
00203
00204 myconfig_version = dat.getConfigVersion();
00205 if(m_debug)
00206 fout << " run " << irun << " tag " << myconfig_tag
00207 << " version " << myconfig_version
00208 << " Fe config " << fe_conf_id << std::endl;
00209
00210 if(myconfig_tag != m_i_tag || myconfig_version != m_i_version || fe_conf_id != fe_conf_id_old) {
00211 if(m_debug)
00212 fout << " run= " << irun
00213 << " different tag ... retrieving last config set from DB" << std::endl;
00214
00215 bool FromCLOB = false;
00216 EcalSRSettings* sr = new EcalSRSettings;
00217 sr->ebDccAdcToGeV_ = 0.035;
00218 sr->eeDccAdcToGeV_ = 0.060;
00219 sr->symetricZS_.push_back(0);
00220
00221 ODRunConfigInfo od_run_info;
00222 od_run_info.setTag(myconfig_tag);
00223 od_run_info.setVersion(myconfig_version);
00224
00225 try {
00226 econn-> fetchConfigSet(&od_run_info);
00227 int config_id = od_run_info.getId();
00228
00229 ODRunConfigSeqInfo seq;
00230 seq.setEcalConfigId(config_id);
00231 seq.setSequenceNumber(0);
00232 econn-> fetchConfigSet(&seq);
00233 int sequenceid = seq.getSequenceId();
00234
00235 ODEcalCycle ecal_cycle;
00236 ecal_cycle.setSequenceId(sequenceid);
00237 econn-> fetchConfigSet(&ecal_cycle);
00238 int cycle_id = ecal_cycle.getId();
00239 int srp_id = ecal_cycle.getSRPId();
00240 if(srp_id == 0) {
00241 if(m_debug)
00242 fout << " no SRP config for this run, give up " << std::endl;
00243 delete sr;
00244 continue;
00245 }
00246 int dcc_id = ecal_cycle.getDCCId();
00247 if(m_debug)
00248 fout << " cycleid " << cycle_id << " SRP id " << srp_id << " DCC id " << dcc_id << std::endl;
00249 cycle_id_old = cycle_id;
00250 srp_id_old = srp_id;
00251 dcc_id_old = dcc_id;
00252
00253
00254
00255 ODSRPConfig srp;
00256 srp.setId(srp_id);
00257 econn-> fetchConfigSet(&srp);
00258
00259 unsigned char* cbuffer = srp.getSRPClob();
00260 unsigned int SRPClobSize = srp.getSRPClobSize();
00261 std::string srpstr((char*)cbuffer, SRPClobSize);
00262 std::string SRPClob = srpstr;
00263 std::fstream myfile;
00264 myfile.open ("srp.txt", std::fstream::out);
00265 for (std::string::iterator it = SRPClob.begin() ; it < SRPClob.end(); it++ )
00266 myfile << *it;
00267 myfile.close();
00268 std::ifstream f("srp.txt");
00269 if(!f.good()){
00270 throw cms::Exception("EcalSRPHandler") << " Failed to open file srp.txt";
00271 if(m_debug)
00272 fout << " Failed to open file srp.txt" << std::endl;
00273 }
00274 EcalSRCondTools::importSrpConfigFile(*sr, f, m_debug);
00275 f.close();
00276 int rv = system("rm srp.txt");
00277 if(m_debug && rv != 0) fout << "rm srp.txt result code: " << rv << "\n";
00278
00279 sr->bxGlobalOffset_ = srp.getSRP0BunchAdjustPosition();
00280 sr->automaticMasks_ = srp.getAutomaticMasks();
00281 sr->automaticSrpSelect_ = srp.getAutomaticSrpSelect();
00282
00283
00284
00285 ODDCCConfig dcc;
00286 dcc.setId(dcc_id);
00287 econn-> fetchConfigSet(&dcc);
00288 std::string weightsMode = dcc.getDCCWeightsMode();
00289 if(m_debug)
00290 fout << " DCC weightsMode " << weightsMode << std::endl
00291 << " weight size beg " << sr->dccNormalizedWeights_.size() << std::endl;
00292 if(weightsMode == "CLOB") {
00293 FromCLOB = true;
00294 if(m_debug)
00295 fout << " will read weights from DCC CLOB " << std::endl;
00296 }
00297 cbuffer = dcc.getDCCClob();
00298 unsigned int DCCClobSize = dcc.getDCCClobSize();
00299 std::string dccstr((char*)cbuffer, DCCClobSize);
00300 std::string DCCClob = dccstr;
00301 std::ostringstream osd;
00302 osd << "dcc.txt";
00303 std::string fname = osd.str();
00304 myfile.open (fname.c_str(), std::fstream::out);
00305 for (std::string::iterator it = DCCClob.begin() ; it < DCCClob.end(); it++ )
00306 myfile << *it;
00307 myfile.close();
00308 importDccConfigFile(*sr, fname, FromCLOB);
00309 if(m_debug)
00310 fout << " weight size after CLOB " << sr->dccNormalizedWeights_.size() << std::endl;
00311 rv = system("rm dcc.txt");
00312 if(m_debug && rv != 0) fout << "rm dcc.txt result code: " << rv << "\n";
00313 }
00314 catch (std::exception &e) {
00315
00316 std::cout << "ERROR: This config does not exist: tag " << myconfig_tag
00317 <<" version "<< myconfig_version<< std::endl;
00318 if(m_debug)
00319 fout << "ERROR: This config does not exist: tag " << myconfig_tag
00320 <<" version "<< myconfig_version<< std::endl;
00321
00322 }
00323 if(m_debug)
00324 fout << " FromCLOB " << FromCLOB << std::endl;
00325 if(!FromCLOB) {
00326
00327 ODFEDAQConfig myconfig;
00328 myconfig.setId(fe_conf_id);
00329 econn->fetchConfigSet(&myconfig);
00330
00331
00332 int mywei = myconfig.getWeightId();
00333 if(m_debug)
00334 fout << " WEI_ID " << mywei << std::endl;
00335
00336 if(mywei != 0) {
00337 ODWeightsSamplesDat samp;
00338 samp.setId(mywei);
00339 econn->fetchConfigSet(&samp);
00340 int mySample = samp.getSampleId();
00341 if(m_debug)
00342 fout << " SAMPLE_ID " << mySample << std::endl;
00343 sr->ecalDccZs1stSample_.push_back(mySample);
00344
00345 ODWeightsDat weights;
00346 weights.setId(mywei);
00347 econn->fetchConfigSet(&weights);
00348
00349 std::vector<std::vector<float> > my_dccw = weights.getWeight();
00350 int imax = my_dccw.size();
00351 if(m_debug)
00352 fout << " weight size before check " << imax << std::endl;
00353 if(imax == 75848) {
00354 bool WeightsChange = false, WeightsChangeEB = false, WeightsChangeEE = false;
00355 for (int i = 1; i < 61200 ; i++)
00356 for (int ich = 0; ich < 6 ; ich++)
00357 if(my_dccw[i][ich] != my_dccw[0][ich]) WeightsChangeEB = true;
00358 if(m_debug)
00359 fout << " WeightsChangeEB " << WeightsChangeEB << std::endl;
00360 for(int i = 61201; i < 75848 ; i++)
00361 for (int ich = 0; ich < 6 ; ich++)
00362 if(my_dccw[i][ich] != my_dccw[61200][ich]) WeightsChangeEE = true;
00363 if(m_debug)
00364 fout << " WeightsChangeEE " << WeightsChangeEE << std::endl;
00365 for(int ich = 0; ich < 6 ; ich++)
00366 if(my_dccw[0][ich] != my_dccw[61200][ich]) WeightsChange = true;
00367 if(m_debug)
00368 fout << " WeightsChange " << WeightsChange << std::endl;
00369
00370 if(WeightsChangeEB || WeightsChangeEE)
00371 sr->dccNormalizedWeights_ = my_dccw;
00372 else if (WeightsChange) {
00373 std::vector<float> dccwRowEB, dccwRowEE;
00374 for (int ich = 0; ich < 6 ; ich++) {
00375 dccwRowEB.push_back(my_dccw[0][ich]);
00376 dccwRowEE.push_back(my_dccw[61200][ich]);
00377 }
00378 sr->dccNormalizedWeights_.push_back(dccwRowEB);
00379 sr->dccNormalizedWeights_.push_back(dccwRowEE);
00380 }
00381 else {
00382 std::vector<float> dccwRow;
00383 for (int ich = 0; ich < 6 ; ich++) {
00384 dccwRow.push_back(my_dccw[0][ich]);
00385 }
00386 sr->dccNormalizedWeights_.push_back(dccwRow);
00387 if(m_debug) {
00388 fout << " weight ";
00389 for(int ich = 0; ich < 6 ; ich++)
00390 fout << " ch " << ich << " " << sr->dccNormalizedWeights_[0][ich] ;
00391 fout << std::endl;
00392 }
00393 }
00394 }
00395 else {
00396 sr->dccNormalizedWeights_ = my_dccw;
00397 }
00398 if(m_debug)
00399 fout << " weight size after DB " << sr->dccNormalizedWeights_.size() << std::endl;
00400 }
00401 }
00402
00403
00404 if(sr->dccNormalizedWeights_.size() == 0) {
00405
00406 float def[] = {-1215, 20, 297, 356, 308, 232};
00407 std::vector<float> dccw(def,def+6);
00408 if(m_debug)
00409 fout << " default weights " ;
00410 for(int i = 0; i < 6; i++) {
00411 if(m_debug)
00412 fout << " i " << i << " def " << def [i] << " dccw " << dccw[i] << " \n";
00413 }
00414 sr->dccNormalizedWeights_.push_back(dccw);
00415 }
00416
00417 int imax = sr->dccNormalizedWeights_.size();
00418 if(m_debug)
00419 fout << " weight size " << imax << " normalized weights : "<< std::endl;
00420 for(int i = 0; i < imax ; i++)
00421 for(int ich = 0; ich < 6 ; ich++) {
00422 sr->dccNormalizedWeights_[i][ich] /= 1024.;
00423 if (m_debug && i == 0)
00424 fout << " ch " << ich << " weight " << sr->dccNormalizedWeights_[i][ich] << std::endl;
00425 }
00426
00427
00428
00429
00430 if(m_debug)
00431 fout << " checking for change " << std::endl;
00432 bool nochange = true;
00433 int imaxref, imaxnew;
00434
00435 if(sref->deltaEta_ != sr->deltaEta_) {
00436 nochange = false;
00437 if(m_debug) {
00438 imaxref = sref->deltaEta_.size();
00439 imaxnew = sr->deltaEta_.size();
00440 if(imaxref != imaxnew) {
00441 fout << " deltaEta_ size ref " << imaxref << " now " << imaxnew << std::endl;
00442 }
00443 else {
00444 for(int i = 0; i < imaxref ; i++) {
00445 if(sref->deltaEta_[i] != sr->deltaEta_[i]) {
00446 fout << " deltaEta_[" << i << "] ref "<< sref->deltaEta_[i]
00447 << " now " <<sr->deltaEta_[i] << std::endl;
00448 }
00449 }
00450 }
00451 }
00452 }
00453
00454 if(sref->deltaPhi_ != sr->deltaPhi_) {
00455 nochange = false;
00456 if(m_debug) {
00457 imaxref = sref->deltaPhi_.size();
00458 imaxnew = sr->deltaPhi_.size();
00459 if(imaxref != imaxnew) {
00460 fout << " deltaPhi size ref " << imaxref << " now " << imaxnew << std::endl;
00461 }
00462 else {
00463 for(int i = 0; i < imaxref ; i++) {
00464 if(sref->deltaPhi_[i] != sr->deltaPhi_[i]) {
00465 fout << " deltaPhi[" << i << "] ref "<< sref->deltaPhi_[i]
00466 << " now " <<sr->deltaPhi_[i] << std::endl;
00467 }
00468 }
00469 }
00470 }
00471 }
00472
00473 if(sref->ecalDccZs1stSample_ != sr->ecalDccZs1stSample_) {
00474 nochange = false;
00475 if(m_debug) {
00476 imaxref = sref->ecalDccZs1stSample_.size();
00477 imaxnew = sr->ecalDccZs1stSample_.size();
00478 if(imaxref != imaxnew) {
00479 fout << " ecalDccZs1stSample size ref " << imaxref << " now " << imaxnew << std::endl;
00480 }
00481 else {
00482 for(int i = 0; i < imaxref ; i++) {
00483 if(sref->ecalDccZs1stSample_[i] != sr->ecalDccZs1stSample_[i]) {
00484 fout << " ecalDccZs1stSample_[" << i << "] ref "<< sref->ecalDccZs1stSample_[i]
00485 << " now " <<sr->ecalDccZs1stSample_[i] << std::endl;
00486 }
00487 }
00488 }
00489 }
00490 }
00491
00492 if(sref->ebDccAdcToGeV_ != sr->ebDccAdcToGeV_ || sref->eeDccAdcToGeV_ != sr->eeDccAdcToGeV_) {
00493 nochange = false;
00494 if(m_debug)
00495 fout << " ebDccAdcToGeV ref " << sref->ebDccAdcToGeV_ << " ee " << sref->eeDccAdcToGeV_
00496 << " now " << sr->ebDccAdcToGeV_ << " ee " << sr->eeDccAdcToGeV_ << std::endl;
00497 }
00498
00499 if(sref->dccNormalizedWeights_ != sr->dccNormalizedWeights_) {
00500 nochange = false;
00501 if(m_debug) {
00502 imaxref = sref->dccNormalizedWeights_.size();
00503 imaxnew = sr->dccNormalizedWeights_.size();
00504 if(imaxref != imaxnew) {
00505 fout << " dccNormalizedWeights size ref " << imaxref << " now " << imaxnew << std::endl;
00506 }
00507 else {
00508 int i = 0;
00509 for(int ich = 0; ich < 6 ; ich++) {
00510 if(sref->dccNormalizedWeights_[i][ich] != sr->dccNormalizedWeights_[i][ich]) {
00511 fout << " dccNormalizedWeights_[" << i << "][" << ich << "] ref "
00512 << sref->dccNormalizedWeights_[i][ich]
00513 << " now " << sr->dccNormalizedWeights_[i][ich] << std::endl;
00514 }
00515 }
00516 }
00517 }
00518 }
00519
00520 if(sref->symetricZS_ != sr->symetricZS_) {
00521 nochange = false;
00522 if(m_debug) {
00523 imaxref = sref->symetricZS_.size();
00524 imaxnew = sr->symetricZS_.size();
00525 if(imaxref != imaxnew) {
00526 fout << " symetricZS size ref " << imaxref << " now " << imaxnew << std::endl;
00527 }
00528 else {
00529 for(int i = 0; i < imaxref ; i++) {
00530 if(sref->symetricZS_[i] != sr->symetricZS_[i]) {
00531 fout << " symetricZS[" << i << "] ref "<< sref->symetricZS_[i]
00532 << " now " <<sr->symetricZS_[i] << std::endl;
00533 }
00534 }
00535 }
00536 }
00537 }
00538
00539 if(sref->srpLowInterestChannelZS_ != sr->srpLowInterestChannelZS_) {
00540 nochange = false;
00541 if(m_debug) {
00542 imaxref = sref->srpLowInterestChannelZS_.size();
00543 imaxnew = sr->srpLowInterestChannelZS_.size();
00544 if(imaxref != imaxnew) {
00545 fout << " srpLowInterestChannelZS size ref " << imaxref << " now " << imaxnew << std::endl;
00546 }
00547 else {
00548 for(int i = 0; i < imaxref ; i++) {
00549 if(sref->srpLowInterestChannelZS_[i] != sr->srpLowInterestChannelZS_[i]) {
00550 fout << " srpLowInterestChannelZS[" << i << "] ref "<< sref->srpLowInterestChannelZS_[i]
00551 << " now " <<sr->srpLowInterestChannelZS_[i] << std::endl;
00552 }
00553 }
00554 }
00555 }
00556 }
00557
00558 if(sref->srpHighInterestChannelZS_ != sr->srpHighInterestChannelZS_) {
00559 nochange = false;
00560 if(m_debug) {
00561 imaxref = sref->srpHighInterestChannelZS_.size();
00562 imaxnew = sr->srpHighInterestChannelZS_.size();
00563 if(imaxref != imaxnew) {
00564 fout << " srpHighInterestChannelZS size ref " << imaxref << " now " << imaxnew << std::endl;
00565 }
00566 else {
00567 for(int i = 0; i < imaxref ; i++) {
00568 if(sref->srpHighInterestChannelZS_[i] != sr->srpHighInterestChannelZS_[i]) {
00569 fout << " srpHighInterestChannelZS[" << i << "] ref "<< sref->srpHighInterestChannelZS_[i]
00570 << " now " <<sr->srpHighInterestChannelZS_[i] << std::endl;
00571 }
00572 }
00573 }
00574 }
00575 }
00576
00577 if(sref->actions_ != sr->actions_) {
00578 nochange = false;
00579 if(m_debug) {
00580 for(int i = 0; i < 4; i++) {
00581 if(sref->actions_[i] != sr->actions_[i]) {
00582 fout << " actions " << i <<" ref " << sref->actions_[i]
00583 << " now " << sr->actions_[i] << std::endl;
00584 }
00585 }
00586 }
00587 }
00588
00589 if(sref->tccMasksFromConfig_ != sr->tccMasksFromConfig_) {
00590 nochange = false;
00591 if(m_debug) {
00592 for(int i = 0; i < 108; i++) {
00593 if(sref->tccMasksFromConfig_[i] != sr->tccMasksFromConfig_[i]) {
00594 fout << " tccMasks " << i << " ref " << sref->tccMasksFromConfig_[i]
00595 << " now " << sr->tccMasksFromConfig_[i] << std::endl;
00596 }
00597 }
00598 }
00599 }
00600
00601 if(sref->srpMasksFromConfig_ != sr->srpMasksFromConfig_) {
00602 nochange = false;
00603 if(m_debug) {
00604 for(int i = 0; i < 12; i++) {
00605 for(int ich = 0; ich < 8; ich++) {
00606 if(sref->srpMasksFromConfig_[i][ich] != sr->srpMasksFromConfig_[i][ich]) {
00607 fout << " srpMasks " << i << " " << ich << " ref " << sref->srpMasksFromConfig_[i][ich]
00608 << " now " << sr->srpMasksFromConfig_[i][ich] << std::endl;
00609 }
00610 }
00611 }
00612 }
00613 }
00614
00615 if(sref->dccMasks_ != sr->dccMasks_) {
00616 nochange = false;
00617 if(m_debug) {
00618 for(int i = 0; i < 54; i++) {
00619 if(sref->dccMasks_[i] != sr->dccMasks_[i]) {
00620 fout << " dccMasks " << i << " ref " << sref->dccMasks_[i]
00621 << " now " << sr->dccMasks_[i] << std::endl;
00622 }
00623 }
00624 }
00625 }
00626
00627 if(sref->srfMasks_ != sr->srfMasks_) {
00628 nochange = false;
00629 if(m_debug) {
00630 for(int i = 0; i < 12; i++) {
00631 if(sref->srfMasks_[i] != sr->srfMasks_[i]) {
00632 fout << " srfMasks " << i << " ref " << sref->srfMasks_[i]
00633 << " now " << sr->srfMasks_[i] << std::endl;
00634 }
00635 }
00636 }
00637 }
00638
00639 if(sref->substitutionSrfs_ != sr->substitutionSrfs_) {
00640 nochange = false;
00641 if(m_debug) {
00642 for(int i = 0; i < 12; i++) {
00643 for(int ich = 0; ich < 68; ich++) {
00644 if(sref->substitutionSrfs_[i][ich] != sr->substitutionSrfs_[i][ich]) {
00645 fout << " substitutionSrfs " << i << " " << ich << " ref " << sref->substitutionSrfs_[i][ich]
00646 << " now " << sr->substitutionSrfs_[i][ich] << std::endl;
00647 }
00648 }
00649 }
00650 }
00651 }
00652
00653 if(sref->testerTccEmuSrpIds_ != sr->testerTccEmuSrpIds_) {
00654 nochange = false;
00655 if(m_debug) {
00656 for(int i = 0; i < 12; i++) {
00657 fout << " testerTccEmuSrpIds " << i << " ref " << sref->testerTccEmuSrpIds_[i]
00658 << " now " << sr->testerTccEmuSrpIds_[i] << std::endl;
00659 }
00660 }
00661 }
00662
00663 if(sref->testerSrpEmuSrpIds_ != sr->testerSrpEmuSrpIds_) {
00664 nochange = false;
00665 if(m_debug)
00666 for(int i = 0; i < 12; i++) {
00667 fout << " testerSrpEmuSrpIds " << i << " ref " << sref->testerSrpEmuSrpIds_[i]
00668 << " now " << sr->testerSrpEmuSrpIds_[i] << std::endl;
00669 }
00670 }
00671
00672 if(sref->testerDccTestSrpIds_ != sr->testerDccTestSrpIds_) {
00673 nochange = false;
00674 if(m_debug)
00675 for(int i = 0; i < 12; i++) {
00676 fout << " testerDccTestSrpIds " << i << " ref " << sref->testerDccTestSrpIds_[i]
00677 << " now " << sr->testerDccTestSrpIds_[i] << std::endl;
00678 }
00679 }
00680
00681 if(sref->testerSrpTestSrpIds_ != sr->testerSrpTestSrpIds_) {
00682 nochange = false;
00683 if(m_debug)
00684 for(int i = 0; i < 12; i++) {
00685 fout << " testerSrpTestSrpIds " << i << " ref " << sref->testerSrpTestSrpIds_[i]
00686 << " now " << sr->testerSrpTestSrpIds_[i] << std::endl;
00687 }
00688 }
00689
00690 if(sref->bxOffsets_ != sr->bxOffsets_) {
00691 nochange = false;
00692 if(m_debug)
00693 for(int i = 0; i < 12; i++) {
00694 fout << " bxOffsets " << i << " ref " << sref->bxOffsets_[i]
00695 << " now " << sr->bxOffsets_[i] << std::endl;
00696 }
00697 }
00698
00699 if(sref->bxGlobalOffset_ != sr->bxGlobalOffset_) {
00700 nochange = false;
00701 if(m_debug)
00702 fout << " bxGlobalOffset ref " << sr->bxGlobalOffset_
00703 << " now " << sr->bxGlobalOffset_ << std::endl;
00704 }
00705
00706 if(sref->automaticMasks_ != sr->automaticMasks_) {
00707 nochange = false;
00708 if(m_debug)
00709 fout << " automaticMasks ref " << sref->automaticMasks_
00710 << " now " << sr->automaticMasks_ << std::endl;
00711 }
00712
00713 if(sref->automaticSrpSelect_ != sref->automaticSrpSelect_) {
00714 nochange = false;
00715 if(m_debug)
00716 fout << " automaticSrpSelect ref " << sref->automaticSrpSelect_
00717 << " now " << sr->automaticSrpSelect_ << std::endl;
00718 }
00719
00720 if(nochange) {
00721 if(m_debug)
00722 fout << " no change has been found " << std::endl;
00723 std::ostringstream ss;
00724 ss << "Run=" << irun << "_SRPunchanged_"<<std::endl;
00725 m_userTextLog = ss.str()+";";
00726 }
00727 else {
00728 if(m_debug) {
00729 fout << " Change has been found !\n New payload :" << std::endl;
00730 PrintPayload(*sr, fout);
00731 }
00732 ChangePayload(*sref, *sr);
00733
00734 EcalSRSettings* srp_pop = new EcalSRSettings();
00735 ChangePayload(*srp_pop, *sr);
00736 m_to_transfer.push_back(std::make_pair(srp_pop, irun));
00737
00738 std::ostringstream ss;
00739 ss << "Run=" << irun << "_SRPchanged_"<<std::endl;
00740 m_userTextLog = ss.str()+";";
00741
00742 if(m_to_transfer.size() >= 20 ) break;
00743 }
00744 delete sr;
00745 m_i_tag = myconfig_tag;
00746 m_i_version = myconfig_version;
00747 fe_conf_id_old = fe_conf_id;
00748 }
00749 }
00750 }
00751
00752
00753 delete econn;
00754 fout.close();
00755
00756 }
00757
00758 void popcon::EcalSRPHandler::importDccConfigFile(EcalSRSettings& sr, const std::string& filename, bool useCLOB){
00759 XMLPlatformUtils::Initialize();
00760
00761 XercesDOMParser* parser = new XercesDOMParser;
00762 parser->setValidationScheme( XercesDOMParser::Val_Never );
00763 parser->setDoNamespaces( false );
00764 parser->setDoSchema( false );
00765
00766 parser->parse(filename.c_str());
00767
00768 DOMDocument* xmlDoc = parser->getDocument();
00769 if (!xmlDoc) {
00770 std::cout << "importDccConfigFile Error parsing document" << std::endl;
00771 }
00772
00773 DOMElement* element = xmlDoc->getDocumentElement();
00774 std::string type = toNative(element->getTagName());
00775
00776
00777 int EBEE = -1;
00778 int L1ZS[2] = {0, 0}, L2ZS[2] = {0, 0};
00779 for (DOMNode* childNode = element->getFirstChild();
00780 childNode; childNode = childNode->getNextSibling()) {
00781 if (childNode->getNodeType() == DOMNode::ELEMENT_NODE) {
00782 const std::string foundName = toNative(childNode->getNodeName());
00783 DOMElement *child = static_cast<DOMElement *>(childNode);
00784 DOMNamedNodeMap *attributes = child->getAttributes();
00785 unsigned int numAttributes = attributes->getLength();
00786 for (unsigned int j = 0; j < numAttributes; ++j) {
00787 DOMNode *attributeNode = attributes->item(j);
00788 DOMAttr *attribute = static_cast<DOMAttr *>(attributeNode);
00789 const std::string info = toNative(attribute->getName());
00790 const std::string scope = toNative(attribute->getValue());
00791 if(info == "_scope") {
00792 if(scope.substr(0,2) == "EE") EBEE = 1;
00793 else EBEE = 0;
00794 }
00795 }
00796
00797 for (DOMNode* subchildNode = childNode->getFirstChild();
00798 subchildNode; subchildNode = subchildNode->getNextSibling()) {
00799 if (subchildNode->getNodeType() == DOMNode::ELEMENT_NODE) {
00800 const std::string subName = toNative(subchildNode->getNodeName());
00801
00802 for (DOMNode* subsubchildNode = subchildNode->getFirstChild();
00803 subsubchildNode; subsubchildNode = subsubchildNode->getNextSibling()) {
00804 if (subsubchildNode->getNodeType() == DOMNode::ELEMENT_NODE) {
00805 const std::string subName = toNative(subsubchildNode->getNodeName());
00806 if(subName == "L1ZSUPPRESSION")
00807 GetNodeData(subsubchildNode,L1ZS[EBEE]);
00808 if(subName == "L2ZSUPPRESSION")
00809 GetNodeData(subsubchildNode,L2ZS[EBEE]);
00810 if(subName == "FIRSTZSSAMPLE") {
00811 int ZS;
00812 GetNodeData(subsubchildNode,ZS);
00813 if(useCLOB) sr.ecalDccZs1stSample_.push_back(ZS);
00814 }
00815 if(subName == "CXTALWEIGHTS") {
00816 std::vector<float> dcc(6);
00817 float w;
00818 for(int iw = 0; iw < 6; iw++) {
00819 GetNodeData(subsubchildNode,w);
00820 dcc.push_back( w );
00821 }
00822 if(useCLOB) sr.dccNormalizedWeights_.push_back(dcc);
00823 }
00824 }
00825 }
00826 }
00827 }
00828 }
00829 }
00830 sr.srpLowInterestChannelZS_.push_back(L1ZS[0]*0.035/4);
00831 sr.srpLowInterestChannelZS_.push_back(L1ZS[1]*0.060/4);
00832 sr.srpHighInterestChannelZS_.push_back(L2ZS[0]*0.035/4);
00833 sr.srpHighInterestChannelZS_.push_back(L2ZS[1]*0.060/4);
00834 delete parser;
00835 XMLPlatformUtils::Terminate();
00836 }
00837
00838 void popcon::EcalSRPHandler::PrintPayload(EcalSRSettings& sr, std::ofstream& fout){
00839 int imax = sr.deltaEta_.size();
00840 fout << " deltaEta[" << imax << "] ";
00841 for(int i = 0; i < imax ; i++) {
00842 fout << sr.deltaEta_[i] << " ";
00843 }
00844 fout << std::endl;
00845
00846 imax = sr.deltaPhi_.size();
00847 fout << " deltaPhi[" << imax << "] ";
00848 for(int i = 0; i < imax ; i++) {
00849 fout << sr.deltaPhi_[i] << " ";
00850 }
00851 fout << std::endl;
00852
00853 imax = sr.ecalDccZs1stSample_.size();
00854 fout << " ecalDccZs1stSample[" << imax << "] ";
00855 for(int i = 0; i < imax ; i++) {
00856 fout << sr.ecalDccZs1stSample_[i] << " ";
00857 }
00858 fout << std::endl;
00859
00860 fout << " ebDccAdcToGeV " << sr.ebDccAdcToGeV_ << std::endl;
00861
00862 fout << " eeDccAdcToGeV " << sr.eeDccAdcToGeV_ << std::endl;
00863
00864 fout << " dccNormalizedWeights" << std::endl;
00865 for(int i = 0; i < (int)sr.dccNormalizedWeights_.size(); ++i){
00866 fout << " Channel " << i;
00867 for(int j = 0; j < (int)sr.dccNormalizedWeights_[i].size(); ++j)
00868 fout << " " << sr.dccNormalizedWeights_[i][j];
00869 fout << std::endl;
00870 }
00871
00872 imax = sr.symetricZS_.size();
00873 fout << " symetricZS["<< imax << "] ";
00874 for(int i = 0; i < imax ; i++) {
00875 fout << sr.symetricZS_[i] << " ";
00876 }
00877 fout << std::endl;
00878
00879 imax = sr.srpLowInterestChannelZS_.size();
00880 fout << " srpLowInterestChannelZS["<< imax << "] ";
00881 for(int i = 0; i < imax ; i++) {
00882 fout << sr.srpLowInterestChannelZS_[i] << " ";
00883 }
00884 fout << std::endl;
00885
00886 imax = sr.srpHighInterestChannelZS_.size();
00887 fout << " srpHighInterestChannelZS["<< imax << "] ";
00888 for(int i = 0; i < imax ; i++) {
00889 fout << sr.srpHighInterestChannelZS_[i] << " ";
00890 }
00891 fout << std::endl;
00892
00893 imax = sr.actions_.size();
00894 fout << " actions["<< imax << "] ";
00895 for(int i = 0; i < imax ; i++) {
00896 fout << sr.actions_[i] << " ";
00897 }
00898 fout << std::endl;
00899
00900 imax = sr.tccMasksFromConfig_.size();
00901 fout << " tccMasksFromConfig["<< imax << "] ";
00902 for(int i = 0; i < imax ; i++) {
00903 fout << sr.tccMasksFromConfig_[i] << " ";
00904 }
00905 fout << std::endl;
00906
00907 fout << " srpMasksFromConfig" << std::endl;
00908 for(int i = 0; i < (int)sr.srpMasksFromConfig_.size(); ++i){
00909 for(int j = 0; j < (int)sr.srpMasksFromConfig_[i].size(); ++j)
00910 fout << sr.srpMasksFromConfig_[i][j] << " ";
00911 fout << std::endl;
00912 }
00913
00914 imax = sr.dccMasks_.size();
00915 fout << " dccMasks[" << imax << "] ";
00916 for(int i = 0; i < imax ; i++) {
00917 fout << sr.dccMasks_[i] << " ";
00918 }
00919 fout << std::endl;
00920
00921 imax = sr.srfMasks_.size();
00922 fout << " srfMasks[" << imax << "] ";
00923 for(int i = 0; i < imax ; i++) {
00924 fout << sr.srfMasks_[i] << " ";
00925 }
00926 fout << std::endl;
00927
00928 fout << "substitutionSrfs" << std::endl;
00929 for(int i = 0; i < (int)sr.substitutionSrfs_.size(); ++i){
00930 for(int j = 0; j < (int)sr.substitutionSrfs_[i].size(); ++j)
00931 fout << sr.substitutionSrfs_[i][j] << " ";
00932 fout << std::endl;
00933 }
00934
00935 imax = sr.testerTccEmuSrpIds_.size();
00936 fout << " testerTccEmuSrpIds[" << imax << "] ";
00937 for(int i = 0; i < imax ; i++) {
00938 fout << sr.testerTccEmuSrpIds_[i] << " ";
00939 }
00940 fout << std::endl;
00941
00942 imax = sr.testerSrpEmuSrpIds_.size();
00943 fout << " testerSrpEmuSrpIds[" << imax << "] ";
00944 for(int i = 0; i < imax ; i++) {
00945 fout << sr.testerSrpEmuSrpIds_[i] << " ";
00946 }
00947 fout << std::endl;
00948
00949 imax = sr.testerDccTestSrpIds_.size();
00950 fout << " testerDccTestSrpIds[" << imax << "] ";
00951 for(int i = 0; i < imax ; i++) {
00952 fout << sr.testerDccTestSrpIds_[i] << " ";
00953 }
00954 fout << std::endl;
00955
00956 imax = sr. testerSrpTestSrpIds_.size();
00957 fout << " testerSrpTestSrpIds[" << imax << "] ";
00958 for(int i = 0; i < imax ; i++) {
00959 fout << sr.testerSrpTestSrpIds_[i] << " ";
00960 }
00961 fout << std::endl;
00962
00963 imax = sr.bxOffsets_.size();
00964 fout << " bxOffsets[" << imax << "] ";
00965 for(int i = 0; i < imax ; i++) {
00966 fout << sr.bxOffsets_[i] << " ";
00967 }
00968 fout << std::endl;
00969
00970 fout << " bxGlobalOffset " << sr.bxGlobalOffset_ << std::endl;
00971 fout << " automaticMasks " << sr.automaticMasks_ << std::endl;
00972 fout << " automaticSrpSelect " << sr.automaticSrpSelect_ << std::endl;
00973 }
00974
00975 void popcon::EcalSRPHandler::ChangePayload(EcalSRSettings& sref, EcalSRSettings& sr ){
00976 sref.deltaEta_ = sr.deltaEta_;
00977 sref.deltaPhi_ = sr.deltaPhi_;
00978 sref.ecalDccZs1stSample_ = sr.ecalDccZs1stSample_;
00979 sref.ebDccAdcToGeV_ = sr.ebDccAdcToGeV_;
00980 sref.eeDccAdcToGeV_ = sr.eeDccAdcToGeV_;
00981 sref.dccNormalizedWeights_ = sr.dccNormalizedWeights_;
00982 sref.symetricZS_ = sr.symetricZS_;
00983 sref.srpLowInterestChannelZS_ = sr.srpLowInterestChannelZS_;
00984 sref.srpHighInterestChannelZS_ = sr.srpHighInterestChannelZS_;
00985 sref.actions_ = sr.actions_;
00986 sref.tccMasksFromConfig_ = sr.tccMasksFromConfig_;
00987 sref.srpMasksFromConfig_ = sr.srpMasksFromConfig_;
00988 sref.dccMasks_ = sr.dccMasks_;
00989 sref.srfMasks_ = sr.srfMasks_;
00990 sref.substitutionSrfs_ = sr.substitutionSrfs_;
00991 sref.testerTccEmuSrpIds_ = sr.testerTccEmuSrpIds_;
00992 sref.testerSrpEmuSrpIds_ = sr.testerSrpEmuSrpIds_;
00993 sref.testerDccTestSrpIds_ = sr.testerDccTestSrpIds_;
00994 sref.testerSrpTestSrpIds_ = sr.testerSrpTestSrpIds_;
00995 sref.bxOffsets_ = sr.bxOffsets_;
00996 sref.bxGlobalOffset_ = sr.bxGlobalOffset_;
00997 sref.automaticMasks_ = sr.automaticMasks_;
00998 sref.automaticSrpSelect_ = sr.automaticSrpSelect_;
00999 }