28 typedef std::vector< edm::ParameterSet >
Parameters;
30 for(Parameters::iterator itToPut = toPut.begin(); itToPut != toPut.end(); ++itToPut)
32 inpFileName_.push_back(itToPut->getUntrackedParameter<std::string>(
"inputFile"));
33 inpFileNameEE_.push_back(itToPut->getUntrackedParameter<std::string>(
"inputFileEE"));
34 objectName_.push_back(itToPut->getUntrackedParameter<std::string>(
"conditionType"));
35 since_.push_back(itToPut->getUntrackedParameter<
unsigned int>(
"since"));
45 edm::LogError(
"StoreEcalCondition")<<
"PoolDBOutputService is unavailable"<<std::endl;
51 std::string
message =
"finished OK\n";
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;
341 int nSamples = -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++) {
364 for(
int j = 0;
j < nSamples; ++
j) {
365 double ww = 0.0; WeightsFileTB >> ww;
372 for(
int j = 0;
j < nSamples; ++
j) {
373 double ww = 0.0; WeightsFileTB >> ww;
380 for(
int j = 0;
j < nSamples; ++
j) {
381 double ww = 0.0; WeightsFileTB >> ww;
387 for(
int j = 0;
j < nSamples; ++
j) {
390 for(
int k = 0;
k < nSamples; ++
k) {
391 double ww = 0.0; WeightsFileTB >> ww;
399 for(
int j = 0;
j < nSamples; ++
j) {
400 double ww = 0.0; WeightsFileTB >> ww;
407 for(
int j = 0;
j < nSamples; ++
j) {
408 double ww = 0.0; WeightsFileTB >> ww;
415 for(
int j = 0;
j < nSamples; ++
j) {
416 double ww = 0.0; WeightsFileTB >> ww;
422 for(
int j = 0;
j < nSamples; ++
j) {
425 for(
int k = 0;
k < nSamples; ++
k) {
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);
886 sm_number=atoi(line);
887 str <<
"sm= " << sm_number << endl ;
894 fgets(line,255,inpFile);
897 fgets(line,255,inpFile);
899 str <<
"gen tag " << gen_tag << endl ;
901 fgets(line,255,inpFile);
903 str <<
"cali method " << cali_method << endl ;
905 fgets(line,255,inpFile);
907 str <<
"cali version " << cali_version << endl ;
910 fgets(line,255,inpFile);
913 str <<
"cali type " << cali_type << endl ;
915 edm::LogInfo(
"StoreEcalCondition") <<
"GainRatio file " << str.str() ;
919 int cry_num[61200]={0};
920 float g1_g12[61200]={0};
921 float g6_g12[61200]={0};
922 int calib_status[61200]={0};
930 while(fgets(line,255,inpFile)) {
931 sscanf(line,
"%d %d %d %f %f %d", &dummy1, &dummy2, &cry_num[ii], &g1_g12[ii], &g6_g12[ii], &calib_status[ii] );
940 edm::LogInfo(
"StoreEcalCondition") <<
"Read gainRatios for " << ii <<
" xtals " ;
941 if(ii!=1700)
edm::LogWarning(
"StoreEcalCondition") <<
" Missing crystals:: missing channels will be set to 0" << endl;
946 for(
int i=0;
i<1700;
i++){
964 cout<<
"mode ALL BARREL" <<endl;
965 while(fgets(line,255,inpFile)) {
968 sscanf(line,
"%d %d %d %f %f",&hash1, &eta, &phi, &g1_g12[ii], &g6_g12[ii]);
969 if(ii<20)
cout<<
"crystal eta/phi="<<eta<<
"/"<<phi<<
" g1_12/g6_12= "<< g1_g12[ii]<<
"/"<<g6_g12[ii]<<endl;
971 if(g1_g12[ii]<9 || g1_g12[ii]>15 ) g1_g12[ii]=12.0;
972 if(g6_g12[ii]<1 || g6_g12[ii]>3 ) g6_g12[ii]=2.0;
974 if(eta<-85|| eta>85 || eta==0)
std::cout<<
"error!!!"<<endl;
975 if(phi<1 || phi>360)
std::cout<<
"error!!!"<<endl;
987 if(ii!=61200)
edm::LogWarning(
"StoreEcalCondition") <<
" Missing crystals !!!!!!!" << endl;
989 std::cout<<
"number of crystals read:"<<ii<<endl;
1017 std::cout <<
" gratio pointer="<<gratio<<endl;
1036 if(ieta==0)
continue;
1065 std::cout <<
"Reading channel status from file " << inputFile << std::endl;
1066 FILE *
ifile = fopen( inputFile ,
"r" );
1072 fgets(line,255,ifile);
1073 std::string gen_tag=
line;
1074 std::cout <<
"Gen tag " << gen_tag << std::endl ;
1076 fgets(line,255,ifile);
1078 std::cout <<
"Gen comment " << comment << std::endl ;
1081 fgets(line,255,ifile);
1082 sscanf (line,
"%d", &iovRunStart);
1083 std::cout <<
"IOV START " << iovRunStart << std::endl;
1087 fgets(line,255,ifile);
1088 sscanf (line,
"%d", &iovRunEnd);
1089 std::cout <<
"IOV END " << iovRunEnd << std::endl;
1093 while(fgets(line,255,ifile))
1098 std::stringstream aStrStream;
1100 aStrStream >> EBorEE >> hashedIndex >> chStatus;
1102 std::cout << EBorEE <<
" hashedIndex " << hashedIndex <<
" status " << chStatus << std::endl;
1107 status->
setValue( aEBDetId, chStatus );
1109 else if (EBorEE ==
"EE")
1113 status->
setValue( aEEDetId, chStatus );
1115 else if (EBorEE ==
"EBTT")
1124 int ixmax=(ixtt+1)*5-1;
1125 int iymax=(iytt+1)*5-1;
1126 for(
int ieta=iymin; ieta<=iymax; ieta++) {
1127 for(
int iphi=ixmin; iphi<=ixmax; iphi++) {
1128 int ixt=ieta*20+iphi+1;
1129 std::cout<<
"killing crystal "<< ism <<
"/" << ixt << endl;
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
static bool validDetId(int i, int j)
check if a valid index combination
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)
EcalCondObjectContainer< EcalXtalGroupId > EcalWeightXtalGroups
virtual void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup)
void setValue(const EcalXtalGroupId &groupId, const EcalTDCId &tdcId, const EcalWeightSet &weight)
static EEDetId unhashIndex(int hi)
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
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)
MVATrainerComputer * calib
unsigned long long Time_t
EcalChannelStatusMap EcalChannelStatus
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()
std::vector< std::string > inpFileName_
EcalADCToGeVConstant * readEcalADCToGeVConstantFromFile(const char *)
vector< ParameterSet > Parameters
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 EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
static const int MAX_IETA
cond::Time_t endOfTime() const
EcalIntercalibConstantMap EcalIntercalibConstants
math::Matrix< 3, 10 >::type EcalWeightMatrix
static const int SMCRYSTALMODE
int ism(int ieta, int iphi)
void setGain6Over1(const float &g)