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] ==
"EcalPFRecHitThresholds") {
111 }
else if (
objectName_[
i] ==
"EcalIntercalibConstantsMC") {
142 edm::LogInfo(
"StoreEcalCondition") <<
"Finished endJob" << endl;
165 outFile = fopen(
logfile_.c_str(),
"a");
174 sprintf(appendMode,
"append");
176 sprintf(appendMode,
"create");
178 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",
189 outFile = fopen(
logfile_.c_str(),
"a");
196 fprintf(outFile,
"%s %s\n", header,arg);
205 struct tm * timeinfo;
207 timeinfo = localtime ( &rawtime );
209 sprintf(user,
"%s",getlogin());
210 sprintf(header,
"%s %s:",asctime(timeinfo),user);
252 std::ifstream groupid_in(inputFile);
254 if(!groupid_in.is_open()) {
261 std::ostringstream
str;
262 groupid_in >> smnumber;
263 if (smnumber == -99999) {
264 edm::LogError(
"StoreEcalCondition") <<
"ERROR: SM number not found in file" << endl;
267 str <<
"sm= " << smnumber << endl;
272 for (
int i=0;
i<=5;
i++) {
273 groupid_in.getline(temp,255);
278 groupid_in.getline(temp, 255);
281 edm::LogInfo(
"StoreEcalCondition") <<
"GROUPID file " << str.str() ;
284 int xtal, ietaf, iphif, groupID;
285 while (groupid_in.good()) {
286 groupid_in >> xtal >> ietaf >> iphif >> groupID;
287 if (groupid_in.eof()) {
break; }
289 LogDebug(
"StoreEcalCondition") <<
"XTAL=" << xtal <<
" ETA=" << ietaf <<
" PHI=" << iphif
290 <<
" GROUP=" << groupID ;
300 edm::LogError(
"StoreEcalCondition") <<
"ERROR: GROUPID file did not contain data for 1700 crystals" << endl;
304 edm::LogInfo(
"StoreEcalCondition") <<
"Groups for " << xtals <<
" xtals written into DB" ;
319 std::ifstream WeightsFileTB(inputFile);
320 if(!WeightsFileTB.is_open()) {
327 std::ostringstream
str;
328 WeightsFileTB >> smnumber;
329 if (smnumber == -99999)
332 str <<
"sm= " << smnumber << endl;
336 for (
int i=0;
i<=5;
i++)
338 WeightsFileTB.getline(temp,255);
342 edm::LogInfo(
"StoreEcalCondition") <<
"Weights file " << str.str() ;
345 while (WeightsFileTB.good())
347 int igroup_ID = -99999;
349 int nTdcBins = -99999;
351 WeightsFileTB >> igroup_ID >> nSamples >> nTdcBins;
352 if (igroup_ID == -99999 || nSamples == -99999 || nTdcBins == -99999)
355 std::ostringstream
str;
356 str <<
"Igroup=" << igroup_ID <<
" Nsamples=" << nSamples <<
" NTdcBins=" << nTdcBins <<
"\n" ;
358 for (
int iTdcBin = 0; iTdcBin < nTdcBins; iTdcBin++) {
372 double ww = 0.0; WeightsFileTB >> ww;
380 double ww = 0.0; WeightsFileTB >> ww;
388 double ww = 0.0; WeightsFileTB >> ww;
398 double ww = 0.0; WeightsFileTB >> ww;
407 double ww = 0.0; WeightsFileTB >> ww;
415 double ww = 0.0; WeightsFileTB >> ww;
423 double ww = 0.0; WeightsFileTB >> ww;
433 double ww = 0.0; WeightsFileTB >> ww;
440 LogDebug(
"StoreEcalCondition") << str.str();
443 tbwgt->
setValue(std::make_pair( igroup_ID , iTdcBin+1 ), wgt);
451 edm::LogInfo(
"StoreEcalCondition") <<
"Weights for " << ngroups <<
" groups written into DB" ;
463 inpFile = fopen(inputFile,
"r");
471 std::ostringstream
str;
473 fgets(line,255,inpFile);
474 int sm_number=atoi(line);
475 str <<
"sm= " << sm_number << endl ;
477 fgets(line,255,inpFile);
480 fgets(line,255,inpFile);
482 str <<
"gen tag " << gen_tag << endl ;
484 fgets(line,255,inpFile);
486 str <<
"cali method " << cali_method << endl ;
488 fgets(line,255,inpFile);
490 str <<
"cali version " << cali_version << endl ;
492 fgets(line,255,inpFile);
494 str <<
"cali type " << cali_type << endl ;
496 edm::LogInfo(
"StoreEcalCondition") <<
"ADCToGeV file " << str.str() ;
498 fgets(line,255,inpFile);
500 sscanf(line,
"%f", &adc_to_gev );
501 LogDebug(
"StoreEcalCondition") <<
" calib="<< adc_to_gev ;
502 fgets(line,255,inpFile);
503 float adc_to_gev_ee=0;
504 sscanf(line,
"%f", &adc_to_gev_ee );
505 LogDebug(
"StoreEcalCondition") <<
" calib="<< adc_to_gev_ee ;
513 edm::LogInfo(
"StoreEcalCondition") <<
"ADCtoGeV scale written into the DB";
527 inpFile = fopen(inputFile,
"r");
546 while(fgets(line,255,inpFile)) {
547 sscanf(line,
"%d %d %f ", &ieta, &iphi, &thresh);
548 if(ii==0)
cout<<
"crystal "<<ieta<<
"/"<<iphi<<
" Thresh= "<< thresh<<endl;
561 edm::LogInfo(
"StoreEcalCondition") <<
"Read PF RecHits for " << ii <<
" xtals " ;
563 cout <<
" I read the thresholds for "<< ii<<
" crystals " << endl;
568 inpFileEE = fopen(inputFileEE,
"r");
570 edm::LogError(
"StoreEcalCondition")<<
"*** Can not open file: "<<inputFileEE;
574 while(fgets(line,255,inpFileEE)) {
575 sscanf(line,
"%d %d %d %f ", &ix,&iy,&iz, &thresh);
576 if(ii==0)
cout<<
"crystal "<<ix<<
"/"<<iy<<
"/"<<iz<<
" Thresh= "<< thresh<<endl;
589 cout<<
"loop on EE channels done - number of crystals =" <<ii<< std::endl;
605 inpFile = fopen(inputFile,
"r");
613 std::ostringstream
str;
615 fgets(line,255,inpFile);
619 sm_number=atoi(line);
620 str <<
"sm= " << sm_number << endl ;
628 fgets(line,255,inpFile);
631 fgets(line,255,inpFile);
633 str <<
"gen tag " << gen_tag << endl ;
635 fgets(line,255,inpFile);
637 str <<
"cali method " << cali_method << endl ;
639 fgets(line,255,inpFile);
641 str <<
"cali version " << cali_version << endl ;
643 fgets(line,255,inpFile);
645 str <<
"cali type " << cali_type << endl ;
647 edm::LogInfo(
"StoreEcalCondition") <<
"Intercalibration file " << str.str() ;
649 int sm_num[61200]={0};
650 int cry_num[61200]={0};
651 float calib[61200]={0};
652 float calib_rms[61200]={0};
653 int calib_nevents[61200]={0};
654 int calib_status[61200]={0};
658 while(fgets(line,255,inpFile)) {
659 sscanf(line,
"%d %f %f %d %d", &cry_num[ii], &calib[ii], &calib_rms[ii], &calib_nevents[ii], &calib_status[ii] );
663 sm_num[
ii]=sm_number;
668 cout<<
"mode ALL BARREL" <<endl;
669 while(fgets(line,255,inpFile)) {
670 sscanf(line,
"%d %d %f %f %d", &sm_num[ii], &cry_num[ii], &calib[ii], &calib_rms[ii], &calib_status[ii] );
671 if(ii==0)
cout<<
"crystal "<<cry_num[
ii]<<
" of sm "<<sm_num[
ii]<<
" cali= "<< calib[
ii]<<endl;
679 edm::LogInfo(
"StoreEcalCondition") <<
"Read intercalibrations for " << ii <<
" xtals " ;
681 cout <<
" I read the calibrations for "<< ii<<
" crystals " << endl;
682 if(ii!=nchan)
edm::LogWarning(
"StoreEcalCondition") <<
"Some crystals missing. Missing channels will be set to 0" << endl;
700 if(i==0)
cout<<
"crystal "<<cry_num[
i]<<
" of sm "<<sm_num[
i]<<
" in slot " <<slot_num<<
" calib= "<< calib[
i]<<endl;
704 cout<<
"loop on channels done" << endl;
707 inpFileEE = fopen(inputFileEE,
"r");
732 cout<<
"... now reading EE file ..." <<endl;
735 while(fgets(line,255,inpFileEE)) {
738 sscanf(line,
"%d %d %d %f", &iz, &ix, &iy, &calibee );
739 if(ii<=0)
cout<<
"crystal "<<iz<<
"/"<<ix<<
"/"<<iy<<
" cali="<< calibee<<endl;
755 cout<<
"loop on EE channels done" << endl;
771 inpFile = fopen(inputFile,
"r");
779 std::ostringstream
str;
781 fgets(line,255,inpFile);
785 sm_number=atoi(line);
786 str <<
"sm= " << sm_number << endl ;
794 fgets(line,255,inpFile);
797 fgets(line,255,inpFile);
799 str <<
"gen tag " << gen_tag << endl ;
801 fgets(line,255,inpFile);
803 str <<
"cali method " << cali_method << endl ;
805 fgets(line,255,inpFile);
807 str <<
"cali version " << cali_version << endl ;
809 fgets(line,255,inpFile);
811 str <<
"cali type " << cali_type << endl ;
813 edm::LogInfo(
"StoreEcalCondition") <<
"Intercalibration file " << str.str() ;
815 int sm_num[61200]={0};
816 int cry_num[61200]={0};
817 float calib[61200]={0};
818 float calib_rms[61200]={0};
819 int calib_nevents[61200]={0};
820 int calib_status[61200]={0};
824 while(fgets(line,255,inpFile)) {
825 sscanf(line,
"%d %f %f %d %d", &cry_num[ii], &calib[ii], &calib_rms[ii], &calib_nevents[ii], &calib_status[ii] );
829 sm_num[
ii]=sm_number;
834 cout<<
"mode ALL BARREL" <<endl;
835 while(fgets(line,255,inpFile)) {
836 sscanf(line,
"%d %d %f %f %d", &sm_num[ii], &cry_num[ii], &calib[ii], &calib_rms[ii], &calib_status[ii] );
837 if(ii==0)
cout<<
"crystal "<<cry_num[
ii]<<
" of sm "<<sm_num[
ii]<<
" cali= "<< calib[
ii]<<endl;
845 edm::LogInfo(
"StoreEcalCondition") <<
"Read intercalibrations for " << ii <<
" xtals " ;
847 cout <<
" I read the calibrations for "<< ii<<
" crystals " << endl;
848 if(ii!=nchan)
edm::LogWarning(
"StoreEcalCondition") <<
"Some crystals missing. Missing channels will be set to 0" << endl;
866 if(i==0)
cout<<
"crystal "<<cry_num[
i]<<
" of sm "<<sm_num[
i]<<
" in slot " <<slot_num<<
" calib= "<< calib[
i]<<endl;
870 cout<<
"loop on channels done" << endl;
873 inpFileEE = fopen(inputFileEE,
"r");
898 cout<<
"... now reading EE file ..." <<endl;
901 while(fgets(line,255,inpFileEE)) {
904 sscanf(line,
"%d %d %d %f", &iz, &ix, &iy, &calibee );
905 if(ii<=0)
cout<<
"crystal "<<iz<<
"/"<<ix<<
"/"<<iy<<
" cali="<< calibee<<endl;
921 cout<<
"loop on EE channels done" << endl;
934 int slot_to_constr[37]={-1,12,17,10,1,8,4,27,20,23,25,6,34,35,15,18,30,21,9
935 ,24,22,13,31,26,16,2,11,5,0,29,28,14,33,32,3,7,19};
936 int constr_to_slot[36]={28,4,25,34,6,27,11,35,5,18,3,26,1,21,31,14,24,2,15,
937 36,8,17,20,9,19,10,23,7,30,29,16,22,33,32,12,13 };
941 result=constr_to_slot[sm_constr];
942 }
else if(sm_slot!=-1) {
943 result=slot_to_constr[sm_slot];
958 inpFile = fopen(inputFile,
"r");
965 std::ostringstream
str;
967 fgets(line,255,inpFile);
970 sm_number=atoi(line);
971 str <<
"sm= " << sm_number << endl ;
973 fgets(line,255,inpFile);
976 fgets(line,255,inpFile);
978 str <<
"gen tag " << gen_tag << endl ;
980 fgets(line,255,inpFile);
982 str <<
"cali method " << cali_method << endl ;
984 fgets(line,255,inpFile);
986 str <<
"cali version " << cali_version << endl ;
989 fgets(line,255,inpFile);
992 str <<
"cali type " << cali_type << endl ;
994 edm::LogInfo(
"StoreEcalCondition") <<
"GainRatio file " << str.str() ;
998 int cry_num[61200]={0};
999 float g1_g12[61200]={0};
1000 float g6_g12[61200]={0};
1001 int calib_status[61200]={0};
1009 while(fgets(line,255,inpFile)) {
1010 sscanf(line,
"%d %d %d %f %f %d", &dummy1, &dummy2, &cry_num[ii], &g1_g12[ii], &g6_g12[ii], &calib_status[ii] );
1019 edm::LogInfo(
"StoreEcalCondition") <<
"Read gainRatios for " << ii <<
" xtals " ;
1020 if(ii!=1700)
edm::LogWarning(
"StoreEcalCondition") <<
" Missing crystals:: missing channels will be set to 0" << endl;
1025 for(
int i=0;
i<1700;
i++){
1043 cout<<
"mode ALL BARREL" <<endl;
1044 while(fgets(line,255,inpFile)) {
1047 sscanf(line,
"%d %d %d %f %f",&hash1, &eta, &phi, &g1_g12[ii], &g6_g12[ii]);
1048 if(ii<20)
cout<<
"crystal eta/phi="<<eta<<
"/"<<phi<<
" g1_12/g6_12= "<< g1_g12[
ii]<<
"/"<<g6_g12[
ii]<<endl;
1050 if(g1_g12[ii]<9 || g1_g12[ii]>15 ) g1_g12[
ii]=12.0;
1051 if(g6_g12[ii]<1 || g6_g12[ii]>3 ) g6_g12[
ii]=2.0;
1053 if(eta<-85|| eta>85 || eta==0)
std::cout<<
"error!!!"<<endl;
1054 if(phi<1 || phi>360)
std::cout<<
"error!!!"<<endl;
1066 if(ii!=61200)
edm::LogWarning(
"StoreEcalCondition") <<
" Missing crystals !!!!!!!" << endl;
1068 std::cout<<
"number of crystals read:"<<ii<<endl;
1096 std::cout <<
" gratio pointer="<<gratio<<endl;
1115 if(ieta==0)
continue;
1144 std::cout <<
"Reading channel status from file " << inputFile << std::endl;
1145 FILE *
ifile = fopen( inputFile ,
"r" );
1151 fgets(line,255,ifile);
1153 std::cout <<
"Gen tag " << gen_tag << std::endl ;
1155 fgets(line,255,ifile);
1157 std::cout <<
"Gen comment " << comment << std::endl ;
1160 fgets(line,255,ifile);
1161 sscanf (line,
"%d", &iovRunStart);
1162 std::cout <<
"IOV START " << iovRunStart << std::endl;
1166 fgets(line,255,ifile);
1167 sscanf (line,
"%d", &iovRunEnd);
1168 std::cout <<
"IOV END " << iovRunEnd << std::endl;
1172 while(fgets(line,255,ifile))
1177 std::stringstream aStrStream;
1179 aStrStream >> EBorEE >> hashedIndex >> chStatus;
1181 std::cout << EBorEE <<
" hashedIndex " << hashedIndex <<
" status " << chStatus << std::endl;
1186 status->
setValue( aEBDetId, chStatus );
1188 else if (EBorEE ==
"EE")
1192 status->
setValue( aEEDetId, chStatus );
1194 else if (EBorEE ==
"EBTT")
1203 int ixmax=(ixtt+1)*5-1;
1204 int iymax=(iytt+1)*5-1;
1205 for(
int ieta=iymin; ieta<=iymax; ieta++) {
1206 for(
int iphi=ixmin; iphi<=ixmax; iphi++) {
1207 int ixt=ieta*20+iphi+1;
1208 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
EcalPFRecHitThresholdsMap EcalPFRecHitThresholds
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
constexpr uint32_t rawId() const
get the raw id
EcalCondObjectContainer< EcalXtalGroupId > EcalWeightXtalGroups
void setValue(const EcalXtalGroupId &groupId, const EcalTDCId &tdcId, const EcalWeightSet &weight)
static EEDetId unhashIndex(int hi)
EcalPFRecHitThresholds * readEcalPFRecHitThresholdsFromFile(const char *, const char *)
static bool validDetId(int i, int j)
check if a valid index combination
void setGain12Over6(const float &g)
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)