28 typedef std::vector< edm::ParameterSet >
Parameters;
30 for(Parameters::iterator itToPut = toPut.begin(); itToPut != toPut.end(); ++itToPut)
35 since_.push_back(itToPut->getUntrackedParameter<
unsigned int>(
"since"));
45 edm::LogError(
"StoreEcalCondition")<<
"PoolDBOutputService is unavailable"<<std::endl;
52 size_t messageSize = message.size() + 1;
53 char * messChar =
new char [messageSize];
54 strncpy(messChar, message.c_str(), messageSize);
72 <<
" from file and writing to DB with newTime " << newTime << endl;
74 <<
" from file and writing to DB with newTime " << newTime << endl;
97 }
else if (
objectName_[
i] ==
"EcalIntercalibConstants") {
104 }
else if (
objectName_[
i] ==
"EcalIntercalibConstantsMC") {
135 edm::LogInfo(
"StoreEcalCondition") <<
"Finished endJob" << endl;
158 outFile = fopen(
logfile_.c_str(),
"a");
167 sprintf(appendMode,
"append");
169 sprintf(appendMode,
"create");
171 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",
182 outFile = fopen(
logfile_.c_str(),
"a");
189 fprintf(outFile,
"%s %s\n", header,arg);
198 struct tm * timeinfo;
200 timeinfo = localtime ( &rawtime );
202 sprintf(user,
"%s",getlogin());
203 sprintf(header,
"%s %s:",asctime(timeinfo),user);
245 std::ifstream groupid_in(inputFile);
247 if(!groupid_in.is_open()) {
254 std::ostringstream
str;
255 groupid_in >> smnumber;
256 if (smnumber == -99999) {
257 edm::LogError(
"StoreEcalCondition") <<
"ERROR: SM number not found in file" << endl;
260 str <<
"sm= " << smnumber << endl;
265 for (
int i=0;
i<=5;
i++) {
266 groupid_in.getline(temp,255);
271 groupid_in.getline(temp, 255);
274 edm::LogInfo(
"StoreEcalCondition") <<
"GROUPID file " << str.str() ;
277 int xtal, ietaf, iphif, groupID;
278 while (groupid_in.good()) {
279 groupid_in >> xtal >> ietaf >> iphif >> groupID;
280 if (groupid_in.eof()) {
break; }
282 LogDebug(
"StoreEcalCondition") <<
"XTAL=" << xtal <<
" ETA=" << ietaf <<
" PHI=" << iphif
283 <<
" GROUP=" << groupID ;
293 edm::LogError(
"StoreEcalCondition") <<
"ERROR: GROUPID file did not contain data for 1700 crystals" << endl;
297 edm::LogInfo(
"StoreEcalCondition") <<
"Groups for " << xtals <<
" xtals written into DB" ;
312 std::ifstream WeightsFileTB(inputFile);
313 if(!WeightsFileTB.is_open()) {
320 std::ostringstream
str;
321 WeightsFileTB >> smnumber;
322 if (smnumber == -99999)
325 str <<
"sm= " << smnumber << endl;
329 for (
int i=0;
i<=5;
i++)
331 WeightsFileTB.getline(temp,255);
335 edm::LogInfo(
"StoreEcalCondition") <<
"Weights file " << str.str() ;
338 while (WeightsFileTB.good())
340 int igroup_ID = -99999;
342 int nTdcBins = -99999;
344 WeightsFileTB >> igroup_ID >> nSamples >> nTdcBins;
345 if (igroup_ID == -99999 || nSamples == -99999 || nTdcBins == -99999)
348 std::ostringstream
str;
349 str <<
"Igroup=" << igroup_ID <<
" Nsamples=" << nSamples <<
" NTdcBins=" << nTdcBins <<
"\n" ;
351 for (
int iTdcBin = 0; iTdcBin < nTdcBins; iTdcBin++) {
365 double ww = 0.0; WeightsFileTB >> ww;
373 double ww = 0.0; WeightsFileTB >> ww;
381 double ww = 0.0; WeightsFileTB >> ww;
391 double ww = 0.0; WeightsFileTB >> ww;
400 double ww = 0.0; WeightsFileTB >> ww;
408 double ww = 0.0; WeightsFileTB >> ww;
416 double ww = 0.0; WeightsFileTB >> ww;
426 double ww = 0.0; WeightsFileTB >> ww;
433 LogDebug(
"StoreEcalCondition") << str.str();
436 tbwgt->
setValue(std::make_pair( igroup_ID , iTdcBin+1 ), wgt);
444 edm::LogInfo(
"StoreEcalCondition") <<
"Weights for " << ngroups <<
" groups written into DB" ;
456 inpFile = fopen(inputFile,
"r");
464 std::ostringstream
str;
466 fgets(line,255,inpFile);
467 int sm_number=atoi(line);
468 str <<
"sm= " << sm_number << endl ;
470 fgets(line,255,inpFile);
473 fgets(line,255,inpFile);
475 str <<
"gen tag " << gen_tag << endl ;
477 fgets(line,255,inpFile);
479 str <<
"cali method " << cali_method << endl ;
481 fgets(line,255,inpFile);
483 str <<
"cali version " << cali_version << endl ;
485 fgets(line,255,inpFile);
487 str <<
"cali type " << cali_type << endl ;
489 edm::LogInfo(
"StoreEcalCondition") <<
"ADCToGeV file " << str.str() ;
491 fgets(line,255,inpFile);
493 sscanf(line,
"%f", &adc_to_gev );
494 LogDebug(
"StoreEcalCondition") <<
" calib="<< adc_to_gev ;
495 fgets(line,255,inpFile);
496 float adc_to_gev_ee=0;
497 sscanf(line,
"%f", &adc_to_gev_ee );
498 LogDebug(
"StoreEcalCondition") <<
" calib="<< adc_to_gev_ee ;
506 edm::LogInfo(
"StoreEcalCondition") <<
"ADCtoGeV scale written into the DB";
520 inpFile = fopen(inputFile,
"r");
528 std::ostringstream
str;
530 fgets(line,255,inpFile);
534 sm_number=atoi(line);
535 str <<
"sm= " << sm_number << endl ;
543 fgets(line,255,inpFile);
546 fgets(line,255,inpFile);
548 str <<
"gen tag " << gen_tag << endl ;
550 fgets(line,255,inpFile);
552 str <<
"cali method " << cali_method << endl ;
554 fgets(line,255,inpFile);
556 str <<
"cali version " << cali_version << endl ;
558 fgets(line,255,inpFile);
560 str <<
"cali type " << cali_type << endl ;
562 edm::LogInfo(
"StoreEcalCondition") <<
"Intercalibration file " << str.str() ;
564 int sm_num[61200]={0};
565 int cry_num[61200]={0};
566 float calib[61200]={0};
567 float calib_rms[61200]={0};
568 int calib_nevents[61200]={0};
569 int calib_status[61200]={0};
573 while(fgets(line,255,inpFile)) {
574 sscanf(line,
"%d %f %f %d %d", &cry_num[ii], &calib[ii], &calib_rms[ii], &calib_nevents[ii], &calib_status[ii] );
578 sm_num[
ii]=sm_number;
583 cout<<
"mode ALL BARREL" <<endl;
584 while(fgets(line,255,inpFile)) {
585 sscanf(line,
"%d %d %f %f %d", &sm_num[ii], &cry_num[ii], &calib[ii], &calib_rms[ii], &calib_status[ii] );
586 if(ii==0)
cout<<
"crystal "<<cry_num[
ii]<<
" of sm "<<sm_num[
ii]<<
" cali= "<< calib[
ii]<<endl;
594 edm::LogInfo(
"StoreEcalCondition") <<
"Read intercalibrations for " << ii <<
" xtals " ;
596 cout <<
" I read the calibrations for "<< ii<<
" crystals " << endl;
597 if(ii!=nchan)
edm::LogWarning(
"StoreEcalCondition") <<
"Some crystals missing. Missing channels will be set to 0" << endl;
615 if(i==0)
cout<<
"crystal "<<cry_num[
i]<<
" of sm "<<sm_num[
i]<<
" in slot " <<slot_num<<
" calib= "<< calib[
i]<<endl;
619 cout<<
"loop on channels done" << endl;
622 inpFileEE = fopen(inputFileEE,
"r");
647 cout<<
"... now reading EE file ..." <<endl;
650 while(fgets(line,255,inpFileEE)) {
653 sscanf(line,
"%d %d %d %f", &iz, &ix, &iy, &calibee );
654 if(ii<=0)
cout<<
"crystal "<<iz<<
"/"<<ix<<
"/"<<iy<<
" cali="<< calibee<<endl;
670 cout<<
"loop on EE channels done" << endl;
686 inpFile = fopen(inputFile,
"r");
694 std::ostringstream
str;
696 fgets(line,255,inpFile);
700 sm_number=atoi(line);
701 str <<
"sm= " << sm_number << endl ;
709 fgets(line,255,inpFile);
712 fgets(line,255,inpFile);
714 str <<
"gen tag " << gen_tag << endl ;
716 fgets(line,255,inpFile);
718 str <<
"cali method " << cali_method << endl ;
720 fgets(line,255,inpFile);
722 str <<
"cali version " << cali_version << endl ;
724 fgets(line,255,inpFile);
726 str <<
"cali type " << cali_type << endl ;
728 edm::LogInfo(
"StoreEcalCondition") <<
"Intercalibration file " << str.str() ;
730 int sm_num[61200]={0};
731 int cry_num[61200]={0};
732 float calib[61200]={0};
733 float calib_rms[61200]={0};
734 int calib_nevents[61200]={0};
735 int calib_status[61200]={0};
739 while(fgets(line,255,inpFile)) {
740 sscanf(line,
"%d %f %f %d %d", &cry_num[ii], &calib[ii], &calib_rms[ii], &calib_nevents[ii], &calib_status[ii] );
744 sm_num[
ii]=sm_number;
749 cout<<
"mode ALL BARREL" <<endl;
750 while(fgets(line,255,inpFile)) {
751 sscanf(line,
"%d %d %f %f %d", &sm_num[ii], &cry_num[ii], &calib[ii], &calib_rms[ii], &calib_status[ii] );
752 if(ii==0)
cout<<
"crystal "<<cry_num[
ii]<<
" of sm "<<sm_num[
ii]<<
" cali= "<< calib[
ii]<<endl;
760 edm::LogInfo(
"StoreEcalCondition") <<
"Read intercalibrations for " << ii <<
" xtals " ;
762 cout <<
" I read the calibrations for "<< ii<<
" crystals " << endl;
763 if(ii!=nchan)
edm::LogWarning(
"StoreEcalCondition") <<
"Some crystals missing. Missing channels will be set to 0" << endl;
781 if(i==0)
cout<<
"crystal "<<cry_num[
i]<<
" of sm "<<sm_num[
i]<<
" in slot " <<slot_num<<
" calib= "<< calib[
i]<<endl;
785 cout<<
"loop on channels done" << endl;
788 inpFileEE = fopen(inputFileEE,
"r");
813 cout<<
"... now reading EE file ..." <<endl;
816 while(fgets(line,255,inpFileEE)) {
819 sscanf(line,
"%d %d %d %f", &iz, &ix, &iy, &calibee );
820 if(ii<=0)
cout<<
"crystal "<<iz<<
"/"<<ix<<
"/"<<iy<<
" cali="<< calibee<<endl;
836 cout<<
"loop on EE channels done" << endl;
849 int slot_to_constr[37]={-1,12,17,10,1,8,4,27,20,23,25,6,34,35,15,18,30,21,9
850 ,24,22,13,31,26,16,2,11,5,0,29,28,14,33,32,3,7,19};
851 int constr_to_slot[36]={28,4,25,34,6,27,11,35,5,18,3,26,1,21,31,14,24,2,15,
852 36,8,17,20,9,19,10,23,7,30,29,16,22,33,32,12,13 };
856 result=constr_to_slot[sm_constr];
857 }
else if(sm_slot!=-1) {
858 result=slot_to_constr[sm_slot];
873 inpFile = fopen(inputFile,
"r");
880 std::ostringstream
str;
882 fgets(line,255,inpFile);
885 sm_number=atoi(line);
886 str <<
"sm= " << sm_number << endl ;
888 fgets(line,255,inpFile);
891 fgets(line,255,inpFile);
893 str <<
"gen tag " << gen_tag << endl ;
895 fgets(line,255,inpFile);
897 str <<
"cali method " << cali_method << endl ;
899 fgets(line,255,inpFile);
901 str <<
"cali version " << cali_version << endl ;
904 fgets(line,255,inpFile);
907 str <<
"cali type " << cali_type << endl ;
909 edm::LogInfo(
"StoreEcalCondition") <<
"GainRatio file " << str.str() ;
913 int cry_num[61200]={0};
914 float g1_g12[61200]={0};
915 float g6_g12[61200]={0};
916 int calib_status[61200]={0};
924 while(fgets(line,255,inpFile)) {
925 sscanf(line,
"%d %d %d %f %f %d", &dummy1, &dummy2, &cry_num[ii], &g1_g12[ii], &g6_g12[ii], &calib_status[ii] );
934 edm::LogInfo(
"StoreEcalCondition") <<
"Read gainRatios for " << ii <<
" xtals " ;
935 if(ii!=1700)
edm::LogWarning(
"StoreEcalCondition") <<
" Missing crystals:: missing channels will be set to 0" << endl;
940 for(
int i=0;
i<1700;
i++){
958 cout<<
"mode ALL BARREL" <<endl;
959 while(fgets(line,255,inpFile)) {
962 sscanf(line,
"%d %d %d %f %f",&hash1, &eta, &phi, &g1_g12[ii], &g6_g12[ii]);
963 if(ii<20)
cout<<
"crystal eta/phi="<<eta<<
"/"<<phi<<
" g1_12/g6_12= "<< g1_g12[
ii]<<
"/"<<g6_g12[
ii]<<endl;
965 if(g1_g12[ii]<9 || g1_g12[ii]>15 ) g1_g12[
ii]=12.0;
966 if(g6_g12[ii]<1 || g6_g12[ii]>3 ) g6_g12[
ii]=2.0;
968 if(eta<-85|| eta>85 || eta==0)
std::cout<<
"error!!!"<<endl;
969 if(phi<1 || phi>360)
std::cout<<
"error!!!"<<endl;
981 if(ii!=61200)
edm::LogWarning(
"StoreEcalCondition") <<
" Missing crystals !!!!!!!" << endl;
983 std::cout<<
"number of crystals read:"<<ii<<endl;
1011 std::cout <<
" gratio pointer="<<gratio<<endl;
1030 if(ieta==0)
continue;
1059 std::cout <<
"Reading channel status from file " << inputFile << std::endl;
1060 FILE *
ifile = fopen( inputFile ,
"r" );
1066 fgets(line,255,ifile);
1068 std::cout <<
"Gen tag " << gen_tag << std::endl ;
1070 fgets(line,255,ifile);
1072 std::cout <<
"Gen comment " << comment << std::endl ;
1075 fgets(line,255,ifile);
1076 sscanf (line,
"%d", &iovRunStart);
1077 std::cout <<
"IOV START " << iovRunStart << std::endl;
1081 fgets(line,255,ifile);
1082 sscanf (line,
"%d", &iovRunEnd);
1083 std::cout <<
"IOV END " << iovRunEnd << std::endl;
1087 while(fgets(line,255,ifile))
1092 std::stringstream aStrStream;
1094 aStrStream >> EBorEE >> hashedIndex >> chStatus;
1096 std::cout << EBorEE <<
" hashedIndex " << hashedIndex <<
" status " << chStatus << std::endl;
1101 status->
setValue( aEBDetId, chStatus );
1103 else if (EBorEE ==
"EE")
1107 status->
setValue( aEEDetId, chStatus );
1109 else if (EBorEE ==
"EBTT")
1118 int ixmax=(ixtt+1)*5-1;
1119 int iymax=(iytt+1)*5-1;
1120 for(
int ieta=iymin; ieta<=iymax; ieta++) {
1121 for(
int iphi=ixmin; iphi<=ixmax; iphi++) {
1122 int ixt=ieta*20+iphi+1;
1123 std::cout<<
"killing crystal "<< ism <<
"/" << ixt << endl;
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
T getParameter(std::string const &) const
EcalIntercalibConstantMCMap EcalIntercalibConstantsMC
EcalIntercalibConstantsMC * readEcalIntercalibConstantsMCFromFile(const char *, const char *)
T getUntrackedParameter(std::string const &, T const &) const
std::vector< std::string > inpFileNameEE_
static const int MIN_IPHI
std::vector< unsigned long long > since_
EcalChannelStatus * readEcalChannelStatusFromFile(const char *)
void writeToLogFileResults(char *)
EcalIntercalibConstants * readEcalIntercalibConstantsFromFile(const char *, const char *)
StoreEcalCondition(const edm::ParameterSet &iConfig)
~StoreEcalCondition() override
EcalCondObjectContainer< EcalXtalGroupId > EcalWeightXtalGroups
void setValue(const EcalXtalGroupId &groupId, const EcalTDCId &tdcId, const EcalWeightSet &weight)
static EEDetId unhashIndex(int hi)
static bool validDetId(int i, int j)
check if a valid index combination
void setGain12Over6(const float &g)
uint32_t rawId() const
get the raw id
void setValue(const uint32_t id, const Item &item)
int hashedIndex(int ieta, int iphi)
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
unsigned long long Time_t
EcalChannelStatusMap EcalChannelStatus
vector< ParameterSet > Parameters
EcalGainRatioMap EcalGainRatios
bool isNewTagRequest(const std::string &recordName)
std::vector< std::string > objectName_
EcalWeightXtalGroups * readEcalWeightXtalGroupsFromFile(const char *)
cond::Time_t beginOfTime() const
EcalGainRatios * readEcalGainRatiosFromFile(const char *)
EcalChi2WeightMatrix & getChi2WeightsAfterGainSwitch()
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
std::vector< std::string > inpFileName_
EcalADCToGeVConstant * readEcalADCToGeVConstantFromFile(const char *)
constexpr size_t nSamples
EcalWeightMatrix & getWeightsAfterGainSwitch()
static const int ETAPHIMODE
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
EcalTBWeights * readEcalTBWeightsFromFile(const char *)
void writeToLogFile(std::string, std::string, unsigned long long)
math::Matrix< 10, 10 >::type EcalChi2WeightMatrix
std::string to_string(char value[])
int convertFromConstructionSMToSlot(int, int)
static const int MAX_IPHI
EcalWeightMatrix & getWeightsBeforeGainSwitch()
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
static const int MAX_IETA
cond::Time_t endOfTime() const
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
EcalIntercalibConstantMap EcalIntercalibConstants
math::Matrix< 3, 10 >::type EcalWeightMatrix
static const int SMCRYSTALMODE
int ism(int ieta, int iphi)
void setGain6Over1(const float &g)