00001 #include "CondTools/Ecal/plugins/StoreEcalCondition.h"
00002
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "CondCore/DBCommon/interface/Time.h"
00007 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009
00010 #include <fstream>
00011 #include <iostream>
00012 #include <time.h>
00013 #include <unistd.h>
00014
00015 using std::string;
00016
00017 StoreEcalCondition::StoreEcalCondition(const edm::ParameterSet& iConfig) {
00018
00019 prog_name_ = "StoreEcalCondition";
00020
00021 logfile_ = iConfig.getParameter< std::string >("logfile");
00022 sm_slot_ = iConfig.getUntrackedParameter< unsigned int >("smSlot", 1);
00023
00024 typedef std::vector< edm::ParameterSet > Parameters;
00025 Parameters toPut=iConfig.getParameter<Parameters>("toPut");
00026 for(Parameters::iterator itToPut = toPut.begin(); itToPut != toPut.end(); ++itToPut)
00027 {
00028 inpFileName_.push_back(itToPut->getUntrackedParameter<std::string>("inputFile"));
00029 objectName_.push_back(itToPut->getUntrackedParameter<std::string>("conditionType"));
00030
00031 }
00032
00033 sm_constr_ = -1;
00034 }
00035
00036 void StoreEcalCondition::endJob() {
00037 edm::Service<cond::service::PoolDBOutputService> mydbservice;
00038 if( !mydbservice.isAvailable() ){
00039 edm::LogError("StoreEcalCondition")<<"PoolDBOutputService is unavailable"<<std::endl;
00040 return;
00041 }
00042
00043 bool toAppend=false;
00044 for (unsigned int i=0;i<objectName_.size();i++) {
00045 cond::Time_t newTime;
00046
00047 if ( mydbservice->isNewTagRequest( objectName_[i]+std::string("Rcd") ) ) {
00048
00049
00050
00051 newTime = mydbservice->beginOfTime();
00052 } else {
00053
00054
00055
00056 toAppend=true;
00057 newTime = (cond::Time_t)since_[i];
00058 }
00059 edm::LogInfo("StoreEcalCondition") << "Reading " << objectName_[i]
00060 << " from file and writing to DB with newTime " << newTime << endl;
00061
00062 if (objectName_[i] == "EcalWeightXtalGroups") {
00063 EcalWeightXtalGroups* mycali = readEcalWeightXtalGroupsFromFile(inpFileName_[i].c_str());
00064 if(!toAppend){
00065 mydbservice->createNewIOV<EcalWeightXtalGroups>(mycali,newTime,mydbservice->endOfTime(),"EcalWeightXtalGroupsRcd");
00066 }else{
00067 mydbservice->appendSinceTime<EcalWeightXtalGroups>(mycali,newTime,"EcalWeightXtalGroupsRcd");
00068 }
00069 }else if (objectName_[i] =="EcalTBWeights") {
00070 EcalTBWeights* mycali=readEcalTBWeightsFromFile(inpFileName_[i].c_str());
00071 if(!toAppend){
00072 mydbservice->createNewIOV<EcalTBWeights>(mycali,newTime,mydbservice->endOfTime(),"EcalTBWeightsRcd");
00073 }else{
00074 mydbservice->appendSinceTime<EcalTBWeights>(mycali,newTime,"EcalTBWeightsRcd");
00075 }
00076 } else if (objectName_[i] == "EcalADCToGeVConstant") {
00077 EcalADCToGeVConstant* mycali=readEcalADCToGeVConstantFromFile(inpFileName_[i].c_str());
00078 if(!toAppend){
00079 mydbservice->createNewIOV<EcalADCToGeVConstant>(mycali,newTime,mydbservice->endOfTime(),"EcalADCToGeVConstantRcd");
00080 }else{
00081 mydbservice->appendSinceTime<EcalADCToGeVConstant>(mycali,newTime,"EcalADCToGeVConstantRcd");
00082 }
00083 } else if (objectName_[i] == "EcalIntercalibConstants") {
00084 EcalIntercalibConstants* mycali=readEcalIntercalibConstantsFromFile(inpFileName_[i].c_str());
00085 if(!toAppend){
00086 mydbservice->createNewIOV<EcalIntercalibConstants>(mycali,newTime,mydbservice->endOfTime(),"EcalIntercalibConstantsRcd");
00087 }else{
00088 mydbservice->appendSinceTime<EcalIntercalibConstants>(mycali,newTime,"EcalIntercalibConstantsRcd");
00089 }
00090 } else if (objectName_[i] == "EcalGainRatios") {
00091 EcalGainRatios* mycali=readEcalGainRatiosFromFile(inpFileName_[i].c_str());
00092 if(!toAppend){
00093 mydbservice->createNewIOV<EcalGainRatios>(mycali,newTime,mydbservice->endOfTime(),"EcalGainRatiosRcd");
00094 }else{
00095 mydbservice->appendSinceTime<EcalGainRatios>(mycali,newTime,"EcalGainRatiosRcd");
00096 }
00097 } else if (objectName_[i] == "EcalChannelStatus")
00098 {
00099 EcalChannelStatus* mycali=readEcalChannelStatusFromFile(inpFileName_[i].c_str());
00100 if(!toAppend){
00101 mydbservice->createNewIOV<EcalChannelStatus>(mycali,newTime,mydbservice->endOfTime(),"EcalChannelStatusRcd");
00102 }else{
00103 mydbservice->appendSinceTime<EcalChannelStatus>(mycali,newTime,"EcalChannelStatusRcd");
00104 }
00105 } else {
00106 edm::LogError("StoreEcalCondition")<< "Object " << objectName_[i] << " is not supported by this program." << endl;
00107 }
00108
00109
00110
00111 writeToLogFileResults("finished OK\n");
00112 edm::LogInfo("StoreEcalCondition") << "Finished endJob" << endl;
00113 }
00114 }
00115
00116
00117 StoreEcalCondition::~StoreEcalCondition() {
00118
00119 }
00120
00121
00122 void StoreEcalCondition::analyze( const edm::Event& evt, const edm::EventSetup& evtSetup) {
00123
00124
00125 }
00126
00127
00128
00129 void StoreEcalCondition::writeToLogFile(string a, string b, unsigned long long since) {
00130
00131
00132 FILE *outFile;
00133 outFile = fopen(logfile_.c_str(),"a");
00134 if(!outFile) {
00135 edm::LogError("StoreEcalCondition") <<"*** Can not open file: " << logfile_;
00136 return;
00137 }
00138 char header[256];
00139 fillHeader(header);
00140 char appendMode[10];
00141 if (since != 0)
00142 sprintf(appendMode,"append");
00143 else
00144 sprintf(appendMode,"create");
00145
00146 fprintf(outFile, "%s %s condition from file %s written into DB for SM %d (mapped to SM %d) in %s mode (since run %u)\n",
00147 header, a.c_str(),b .c_str(), sm_constr_, sm_slot_, appendMode, (unsigned int)since);
00148
00149 fclose(outFile);
00150
00151 }
00152
00153 void StoreEcalCondition::writeToLogFileResults(char* arg) {
00154
00155
00156 FILE *outFile;
00157 outFile = fopen(logfile_.c_str(),"a");
00158 if(!outFile) {
00159 edm::LogError("StoreEcalCondition")<<"*** Can not open file: " << logfile_;
00160 return;
00161 }
00162 char header[256];
00163 fillHeader(header);
00164 fprintf(outFile, "%s %s\n", header,arg);
00165 fclose(outFile);
00166 }
00167
00168
00169 void StoreEcalCondition::fillHeader(char* header)
00170
00171 {
00172 time_t rawtime;
00173 struct tm * timeinfo;
00174 time ( &rawtime );
00175 timeinfo = localtime ( &rawtime );
00176 char user[50];
00177 sprintf(user,"%s",getlogin());
00178 sprintf(header,"%s %s:",asctime(timeinfo),user);
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 EcalWeightXtalGroups*
00214 StoreEcalCondition::readEcalWeightXtalGroupsFromFile(const char* inputFile) {
00215
00216
00217
00218
00219 EcalWeightXtalGroups* xtalGroups = new EcalWeightXtalGroups();
00220 std::ifstream groupid_in(inputFile);
00221
00222 if(!groupid_in.is_open()) {
00223 edm::LogError("StoreEcalCondition")<< "*** Can not open file: "<< inputFile ;
00224 return 0;
00225 }
00226
00227 int smnumber=-99999;
00228
00229 std::ostringstream str;
00230 groupid_in >> smnumber;
00231 if (smnumber == -99999) {
00232 edm::LogError("StoreEcalCondition") << "ERROR: SM number not found in file" << endl;
00233 return 0;
00234 }
00235 str << "sm= " << smnumber << endl;
00236 sm_constr_ = smnumber;
00237
00238 char temp[256];
00239
00240 for (int i=0;i<=5;i++) {
00241 groupid_in.getline(temp,255);
00242 str << temp << endl;
00243 }
00244
00245
00246 groupid_in.getline(temp, 255);
00247 str << temp << endl;
00248
00249 edm::LogInfo("StoreEcalCondition") << "GROUPID file " << str.str() ;
00250
00251 int xtals = 0;
00252 int xtal, ietaf, iphif, groupID;
00253 while (groupid_in.good()) {
00254 groupid_in >> xtal >> ietaf >> iphif >> groupID;
00255 if (groupid_in.eof()) { break; }
00256
00257 LogDebug("StoreEcalCondition") << "XTAL=" << xtal << " ETA=" << ietaf << " PHI=" << iphif
00258 << " GROUP=" << groupID ;
00259
00260
00261 EBDetId ebid(sm_slot_,xtal,EBDetId::SMCRYSTALMODE);
00262
00263 xtalGroups->setValue(ebid.rawId(), EcalXtalGroupId( groupID ) );
00264 xtals++;
00265 }
00266
00267 if (xtals != 1700) {
00268 edm::LogError("StoreEcalCondition") << "ERROR: GROUPID file did not contain data for 1700 crystals" << endl;
00269 return 0;
00270 }
00271
00272 edm::LogInfo("StoreEcalCondition") << "Groups for " << xtals << " xtals written into DB" ;
00273 sm_constr_ = smnumber;
00274
00275 return xtalGroups;
00276 }
00277
00278
00279 EcalTBWeights*
00280 StoreEcalCondition::readEcalTBWeightsFromFile(const char* inputFile) {
00281
00282
00283
00284
00285 EcalTBWeights* tbwgt = new EcalTBWeights();
00286
00287 std::ifstream WeightsFileTB(inputFile);
00288 if(!WeightsFileTB.is_open()) {
00289 edm::LogError("StoreEcalCondition")<< "*** Can not open file: "<< inputFile ;
00290 return 0;
00291 }
00292
00293 int smnumber=-99999;
00294
00295 std::ostringstream str;
00296 WeightsFileTB >> smnumber;
00297 if (smnumber == -99999)
00298 return 0;
00299
00300 str << "sm= " << smnumber << endl;
00301
00302 char temp[256];
00303
00304 for (int i=0;i<=5;i++)
00305 {
00306 WeightsFileTB.getline(temp,255);
00307 str << temp << endl;
00308 }
00309
00310 edm::LogInfo("StoreEcalCondition") << "Weights file " << str.str() ;
00311
00312 int ngroups=0;
00313 while (WeightsFileTB.good())
00314 {
00315 int igroup_ID = -99999;
00316 int nSamples = -99999;
00317 int nTdcBins = -99999;
00318
00319 WeightsFileTB >> igroup_ID >> nSamples >> nTdcBins;
00320 if (igroup_ID == -99999 || nSamples == -99999 || nTdcBins == -99999)
00321 break;
00322
00323 std::ostringstream str;
00324 str << "Igroup=" << igroup_ID << " Nsamples=" << nSamples << " NTdcBins=" << nTdcBins <<"\n" ;
00325
00326 for (int iTdcBin = 0; iTdcBin < nTdcBins; iTdcBin++) {
00327
00328 EcalWeightSet wgt;
00329 EcalWeightSet::EcalWeightMatrix& wgt1 = wgt.getWeightsBeforeGainSwitch();
00330 EcalWeightSet::EcalWeightMatrix& wgt2 = wgt.getWeightsAfterGainSwitch();
00331 EcalWeightSet::EcalChi2WeightMatrix& chisq1 = wgt.getChi2WeightsBeforeGainSwitch();
00332 EcalWeightSet::EcalChi2WeightMatrix& chisq2 = wgt.getChi2WeightsAfterGainSwitch();
00333
00334
00335
00336
00337
00338
00339 for(int j = 0; j < nSamples; ++j) {
00340 double ww = 0.0; WeightsFileTB >> ww;
00341 wgt1(0,j)=ww;
00342 str << ww << " ";
00343 }
00344 str << std::endl;
00345
00346
00347 for(int j = 0; j < nSamples; ++j) {
00348 double ww = 0.0; WeightsFileTB >> ww;
00349 wgt1(1,j)=ww;
00350 str << ww << " ";
00351 }
00352 str << std::endl;
00353
00354
00355 for(int j = 0; j < nSamples; ++j) {
00356 double ww = 0.0; WeightsFileTB >> ww;
00357 wgt1(2,j)=ww;
00358 str << ww << " ";
00359 }
00360 str << std::endl;
00361
00362 for(int j = 0; j < nSamples; ++j) {
00363
00364
00365 for(int k = 0; k < nSamples; ++k) {
00366 double ww = 0.0; WeightsFileTB >> ww;
00367 chisq1(j,k)=ww;
00368 str << ww << " ";
00369 }
00370 str << std::endl;
00371 }
00372
00373
00374 for(int j = 0; j < nSamples; ++j) {
00375 double ww = 0.0; WeightsFileTB >> ww;
00376 wgt2(0,j)=ww;
00377 str << ww << " ";
00378 }
00379 str << std::endl;
00380
00381
00382 for(int j = 0; j < nSamples; ++j) {
00383 double ww = 0.0; WeightsFileTB >> ww;
00384 wgt2(1,j)=ww;
00385 str << ww << " ";
00386 }
00387 str << std::endl;
00388
00389
00390 for(int j = 0; j < nSamples; ++j) {
00391 double ww = 0.0; WeightsFileTB >> ww;
00392 wgt2(2,j)=ww;
00393 str << ww << " ";
00394 }
00395 str << std::endl;
00396
00397 for(int j = 0; j < nSamples; ++j) {
00398
00399
00400 for(int k = 0; k < nSamples; ++k) {
00401 double ww = 0.0; WeightsFileTB >> ww;
00402 chisq2(j,k)=ww;
00403 str << ww << " ";
00404 }
00405 str << std::endl;
00406 }
00407
00408 LogDebug("StoreEcalCondition") << str.str();
00409
00410
00411 tbwgt->setValue(std::make_pair( igroup_ID , iTdcBin+1 ), wgt);
00412 }
00413 ngroups++;
00414 }
00415
00416 sm_constr_ = smnumber;
00417
00418
00419 edm::LogInfo("StoreEcalCondition") << "Weights for " << ngroups << " groups written into DB" ;
00420 return tbwgt;
00421 }
00422
00423
00424
00425 EcalADCToGeVConstant*
00426 StoreEcalCondition::readEcalADCToGeVConstantFromFile(const char* inputFile) {
00427
00428
00429
00430 FILE *inpFile;
00431 inpFile = fopen(inputFile,"r");
00432 if(!inpFile) {
00433 edm::LogError("StoreEcalCondition")<<"*** Can not open file: "<<inputFile;
00434 return 0;
00435 }
00436
00437 char line[256];
00438
00439 std::ostringstream str;
00440
00441 fgets(line,255,inpFile);
00442 int sm_number=atoi(line);
00443 str << "sm= " << sm_number << endl ;
00444
00445 fgets(line,255,inpFile);
00446
00447
00448 fgets(line,255,inpFile);
00449 string gen_tag=to_string(line);
00450 str << "gen tag " << gen_tag << endl ;
00451
00452 fgets(line,255,inpFile);
00453 string cali_method=to_string(line);
00454 str << "cali method " << cali_method << endl ;
00455
00456 fgets(line,255,inpFile);
00457 string cali_version=to_string(line);
00458 str << "cali version " << cali_version << endl ;
00459
00460 fgets(line,255,inpFile);
00461 string cali_type=to_string(line);
00462 str << "cali type " << cali_type << endl ;
00463
00464 edm::LogInfo("StoreEcalCondition") << "ADCToGeV file " << str.str() ;
00465
00466 fgets(line,255,inpFile);
00467 float adc_to_gev=0;
00468 sscanf(line, "%f", &adc_to_gev );
00469 LogDebug("StoreEcalCondition") <<" calib="<< adc_to_gev ;
00470
00471 fclose(inpFile);
00472
00473 sm_constr_ = sm_number;
00474
00475
00476 EcalADCToGeVConstant* agc = new EcalADCToGeVConstant(adc_to_gev,adc_to_gev );
00477 edm::LogInfo("StoreEcalCondition") << "ADCtoGeV scale written into the DB";
00478 return agc;
00479 }
00480
00481
00482
00483 EcalIntercalibConstants*
00484 StoreEcalCondition::readEcalIntercalibConstantsFromFile(const char* inputFile) {
00485
00486
00487 EcalIntercalibConstants* ical = new EcalIntercalibConstants();
00488
00489
00490 FILE *inpFile;
00491 inpFile = fopen(inputFile,"r");
00492 if(!inpFile) {
00493 edm::LogError("StoreEcalCondition")<<"*** Can not open file: "<<inputFile;
00494 return 0;
00495 }
00496
00497 char line[256];
00498
00499 std::ostringstream str;
00500
00501 fgets(line,255,inpFile);
00502 string sm_or_all=to_string(line);
00503 int sm_number=0;
00504 int nchan=1700;
00505 sm_number=atoi(line);
00506 str << "sm= " << sm_number << endl ;
00507 if(sm_number!=-1){
00508 nchan=1700;
00509 } else {
00510 nchan=61200;
00511 }
00512
00513
00514 fgets(line,255,inpFile);
00515
00516
00517 fgets(line,255,inpFile);
00518 string gen_tag=to_string(line);
00519 str << "gen tag " << gen_tag << endl ;
00520
00521 fgets(line,255,inpFile);
00522 string cali_method=to_string(line);
00523 str << "cali method " << cali_method << endl ;
00524
00525 fgets(line,255,inpFile);
00526 string cali_version=to_string(line);
00527 str << "cali version " << cali_version << endl ;
00528
00529 fgets(line,255,inpFile);
00530 string cali_type=to_string(line);
00531 str << "cali type " << cali_type << endl ;
00532
00533 edm::LogInfo("StoreEcalCondition") << "Intercalibration file " << str.str() ;
00534
00535 int sm_num[61200]={0};
00536 int cry_num[61200]={0};
00537 float calib[61200]={0};
00538 float calib_rms[61200]={0};
00539 int calib_nevents[61200]={0};
00540 int calib_status[61200]={0};
00541
00542 int ii = 0;
00543 if(sm_number!=-1){
00544 while(fgets(line,255,inpFile)) {
00545 sscanf(line, "%d %f %f %d %d", &cry_num[ii], &calib[ii], &calib_rms[ii], &calib_nevents[ii], &calib_status[ii] );
00546
00547
00548
00549 sm_num[ii]=sm_number;
00550 ii++ ;
00551 }
00552 } else {
00553
00554 cout<<"mode ALL BARREL" <<endl;
00555 while(fgets(line,255,inpFile)) {
00556 sscanf(line, "%d %d %f %f %d", &sm_num[ii], &cry_num[ii], &calib[ii], &calib_rms[ii], &calib_status[ii] );
00557 if(ii==0) cout<<"crystal "<<cry_num[ii]<<" of sm "<<sm_num[ii]<<" cali= "<< calib[ii]<<endl;
00558 ii++ ;
00559 }
00560 }
00561
00562
00563 fclose(inpFile);
00564
00565 edm::LogInfo("StoreEcalCondition") << "Read intercalibrations for " << ii << " xtals " ;
00566
00567 cout << " I read the calibrations for "<< ii<< " crystals " << endl;
00568 if(ii!=nchan) edm::LogWarning("StoreEcalCondition") << "Some crystals missing. Missing channels will be set to 0" << endl;
00569
00570
00571
00572 sm_constr_ = sm_number;
00573
00574
00575
00576 for(int i=0; i<nchan; i++){
00577
00578
00579
00580
00581 int slot_num=convertFromConstructionSMToSlot(sm_num[i],-1);
00582 EBDetId ebid(slot_num,cry_num[i],EBDetId::SMCRYSTALMODE);
00583
00584 ical->setValue( ebid.rawId(), calib[i] );
00585
00586 if(i==0) cout<<"crystal "<<cry_num[i]<<" of sm "<<sm_num[i]<< " in slot " <<slot_num<<" calib= "<< calib[i]<<endl;
00587
00588 }
00589
00590 cout<<"loop on channels done" << endl;
00591 return ical;
00592 }
00593
00594
00595 int StoreEcalCondition::convertFromConstructionSMToSlot(int sm_constr,int sm_slot){
00596
00597
00598
00599
00600 int slot_to_constr[37]={-1,12,17,10,1,8,4,27,20,23,25,6,34,35,15,18,30,21,9
00601 ,24,22,13,31,26,16,2,11,5,0,29,28,14,33,32,3,7,19};
00602 int constr_to_slot[36]={28,4,25,34,6,27,11,35,5,18,3,26,1,21,31,14,24,2,15,
00603 36,8,17,20,9,19,10,23,7,30,29,16,22,33,32,12,13 };
00604
00605 int result=0;
00606 if(sm_constr!=-1) {
00607 result=constr_to_slot[sm_constr];
00608 } else if(sm_slot!=-1) {
00609 result=slot_to_constr[sm_slot];
00610 }
00611 return result;
00612 }
00613
00614
00615 EcalGainRatios*
00616 StoreEcalCondition::readEcalGainRatiosFromFile(const char* inputFile) {
00617
00618
00619
00620 EcalGainRatios* gratio = new EcalGainRatios;
00621
00622
00623 FILE *inpFile;
00624 inpFile = fopen(inputFile,"r");
00625 if(!inpFile) {
00626 edm::LogError("StoreEcalCondition")<<"*** Can not open file: "<<inputFile;
00627 return 0;
00628 }
00629
00630 char line[256];
00631 std::ostringstream str;
00632
00633 fgets(line,255,inpFile);
00634 string sm_or_all=to_string(line);
00635 int sm_number=0;
00636 int nchan=1700;
00637 sm_number=atoi(line);
00638 str << "sm= " << sm_number << endl ;
00639 if(sm_number!=-1){
00640 nchan=1700;
00641 } else {
00642 nchan=61200;
00643 }
00644
00645 fgets(line,255,inpFile);
00646
00647
00648 fgets(line,255,inpFile);
00649 string gen_tag=to_string(line);
00650 str << "gen tag " << gen_tag << endl ;
00651
00652 fgets(line,255,inpFile);
00653 string cali_method=to_string(line);
00654 str << "cali method " << cali_method << endl ;
00655
00656 fgets(line,255,inpFile);
00657 string cali_version=to_string(line);
00658 str << "cali version " << cali_version << endl ;
00659
00660
00661 fgets(line,255,inpFile);
00662 string cali_type=to_string(line);
00663
00664 str << "cali type " << cali_type << endl ;
00665
00666 edm::LogInfo("StoreEcalCondition") << "GainRatio file " << str.str() ;
00667
00668
00669
00670 int cry_num[61200]={0};
00671 float g1_g12[61200]={0};
00672 float g6_g12[61200]={0};
00673 int calib_status[61200]={0};
00674 int dummy1=0;
00675 int dummy2=0;
00676 int hash1=0;
00677
00678 int ii = 0;
00679
00680 if(sm_number!=-1){
00681 while(fgets(line,255,inpFile)) {
00682 sscanf(line, "%d %d %d %f %f %d", &dummy1, &dummy2, &cry_num[ii], &g1_g12[ii], &g6_g12[ii], &calib_status[ii] );
00683 ii++ ;
00684 }
00685
00686
00687 fclose(inpFile);
00688
00689
00690
00691 edm::LogInfo("StoreEcalCondition") << "Read gainRatios for " << ii << " xtals " ;
00692 if(ii!=1700) edm::LogWarning("StoreEcalCondition") << " Missing crystals:: missing channels will be set to 0" << endl;
00693
00694
00695 sm_constr_ = sm_number;
00696
00697 for(int i=0; i<1700; i++){
00698
00699
00700 EBDetId ebid(sm_slot_,cry_num[i],EBDetId::SMCRYSTALMODE);
00701
00702 EcalMGPAGainRatio gr;
00703 gr.setGain12Over6( g6_g12[i] );
00704 gr.setGain6Over1(g1_g12[i]/g6_g12[i]);
00705 gratio->setValue( ebid.rawId(), gr );
00706 }
00707
00708
00709
00710
00711
00712
00713 } else {
00714
00715 cout<<"mode ALL BARREL" <<endl;
00716 while(fgets(line,255,inpFile)) {
00717 int eta=0;
00718 int phi=0;
00719 sscanf(line, "%d %d %d %f %f",&hash1, &eta, &phi, &g1_g12[ii], &g6_g12[ii]);
00720 if(ii<20) cout<<"crystal eta/phi="<<eta<<"/"<<phi<<" g1_12/g6_12= "<< g1_g12[ii]<<"/"<<g6_g12[ii]<<endl;
00721
00722 if(g1_g12[ii]<9 || g1_g12[ii]>15 ) g1_g12[ii]=12.0;
00723 if(g6_g12[ii]<1 || g6_g12[ii]>3 ) g6_g12[ii]=2.0;
00724
00725 if(eta<-85|| eta>85 || eta==0) std::cout<<"error!!!"<<endl;
00726 if(phi<1 || phi>360) std::cout<<"error!!!"<<endl;
00727
00728 EBDetId ebid(eta, phi,EBDetId::ETAPHIMODE);
00729 EcalMGPAGainRatio gr;
00730 gr.setGain12Over6( g6_g12[ii] );
00731 gr.setGain6Over1(g1_g12[ii]/g6_g12[ii]);
00732 gratio->setValue( ebid.rawId(), gr );
00733
00734 ii++ ;
00735 }
00736
00737 fclose(inpFile);
00738 if(ii!=61200) edm::LogWarning("StoreEcalCondition") << " Missing crystals !!!!!!!" << endl;
00739
00740 std::cout<< "number of crystals read:"<<ii<<endl;
00741
00742 }
00743
00744
00745
00746 for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00747 for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00748
00749 EcalMGPAGainRatio gr;
00750 gr.setGain12Over6( 2. );
00751 gr.setGain6Over1( 6. );
00752
00753
00754 if (EEDetId::validDetId(iX,iY,1))
00755 {
00756 EEDetId eedetidpos(iX,iY,1);
00757 gratio->setValue( eedetidpos.rawId(), gr );
00758 }
00759 if (EEDetId::validDetId(iX,iY,-1))
00760 {
00761 EEDetId eedetidneg(iX,iY,-1);
00762 gratio->setValue( eedetidneg.rawId(), gr );
00763 }
00764 }
00765 }
00766
00767
00768 std::cout <<" gratio pointer="<<gratio<<endl;
00769
00770
00771
00772 std::cout<< "now leaving"<<endl;
00773
00774
00775
00776 return gratio;
00777
00778 }
00779
00780 EcalChannelStatus*
00781 StoreEcalCondition::readEcalChannelStatusFromFile(const char* inputFile)
00782 {
00783 EcalChannelStatus* status = new EcalChannelStatus();
00784
00785 for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta)
00786 {
00787 if(ieta==0) continue;
00788 for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00789 if (EBDetId::validDetId(ieta,iphi)) {
00790 EBDetId ebid(ieta,iphi);
00791 status->setValue( ebid, 0 );
00792 }
00793 }
00794 }
00795
00796 for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX)
00797 {
00798 for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY)
00799 {
00800
00801 if (EEDetId::validDetId(iX,iY,1))
00802 {
00803 EEDetId eedetidpos(iX,iY,1);
00804 status->setValue( eedetidpos, 0 );
00805 }
00806 if (EEDetId::validDetId(iX,iY,-1))
00807 {
00808 EEDetId eedetidneg(iX,iY,-1);
00809 status->setValue( eedetidneg, 0 );
00810 }
00811 }
00812 }
00813
00814
00815
00816 std::cout << "Reading channel status from file " << inputFile << std::endl;
00817 FILE *ifile = fopen( inputFile ,"r" );
00818 if ( !ifile )
00819 throw cms::Exception ("Cannot open ECAL channel status file") ;
00820
00821 char line[256];
00822
00823 fgets(line,255,ifile);
00824 std::string gen_tag= line;
00825 std::cout << "Gen tag " << gen_tag << std::endl ;
00826
00827 fgets(line,255,ifile);
00828 std::string comment = line ;
00829 std::cout << "Gen comment " << comment << std::endl ;
00830
00831 int iovRunStart(0);
00832 fgets(line,255,ifile);
00833 sscanf (line, "%d", &iovRunStart);
00834 std::cout << "IOV START " << iovRunStart << std::endl;
00835
00836
00837 int iovRunEnd(0);
00838 fgets(line,255,ifile);
00839 sscanf (line, "%d", &iovRunEnd);
00840 std::cout << "IOV END " << iovRunEnd << std::endl;
00841
00842
00843 int ii = 0;
00844 while(fgets(line,255,ifile))
00845 {
00846 std::string EBorEE;
00847 int hashedIndex(0);
00848 int chStatus(0);
00849 std::stringstream aStrStream;
00850 aStrStream << line;
00851 aStrStream >> EBorEE >> hashedIndex >> chStatus;
00852
00853 std::cout << EBorEE << " hashedIndex " << hashedIndex << " status " << chStatus << std::endl;
00854
00855 if (EBorEE == "EB")
00856 {
00857 EBDetId aEBDetId=EBDetId::unhashIndex(hashedIndex);
00858 status->setValue( aEBDetId, chStatus );
00859 }
00860 else if (EBorEE == "EE")
00861 {
00862 EEDetId aEEDetId=EEDetId::unhashIndex(hashedIndex);
00863 status->setValue( aEEDetId, chStatus );
00864 }
00865
00866 ii++ ;
00867
00868 }
00869
00870 fclose(ifile);
00871 return status;
00872 }