27 typedef std::vector<edm::ParameterSet>
Parameters;
29 for (Parameters::iterator itToPut =
toPut.begin(); itToPut !=
toPut.end(); ++itToPut) {
33 since_.push_back(itToPut->getUntrackedParameter<
unsigned int>(
"since"));
42 edm::LogError(
"StoreEcalCondition") <<
"PoolDBOutputService is unavailable" << std::endl;
46 bool toAppend =
false;
49 size_t messageSize = message.size() + 1;
50 char* messChar =
new char[messageSize];
51 strncpy(messChar, message.c_str(), messageSize);
70 std::cout <<
"Reading " <<
objectName_[
i] <<
" from file and writing to DB with newTime " << newTime << endl;
76 mycali, newTime, mydbservice->
endOfTime(),
"EcalWeightXtalGroupsRcd");
91 mycali, newTime, mydbservice->
endOfTime(),
"EcalADCToGeVConstantRcd");
95 }
else if (
objectName_[
i] ==
"EcalIntercalibConstants") {
100 mycali, newTime, mydbservice->
endOfTime(),
"EcalIntercalibConstantsRcd");
104 }
else if (
objectName_[
i] ==
"EcalPFRecHitThresholds") {
109 mycali, newTime, mydbservice->
endOfTime(),
"EcalPFRecHitThresholdsRcd");
113 }
else if (
objectName_[
i] ==
"EcalIntercalibConstantsMC") {
118 mycali, newTime, mydbservice->
endOfTime(),
"EcalIntercalibConstantsMCRcd");
138 <<
"Object " <<
objectName_[
i] <<
" is not supported by this program." << endl;
145 edm::LogInfo(
"StoreEcalCondition") <<
"Finished endJob" << endl;
172 sprintf(appendMode,
"append");
174 sprintf(appendMode,
"create");
177 "%s %s condition from file %s written into DB for SM %d (mapped to SM %d) in %s mode (since run %u)\n",
211 timeinfo = localtime(&rawtime);
213 sprintf(
user,
"%s", getlogin());
214 sprintf(
header,
"%s %s:", asctime(timeinfo),
user);
257 if (!groupid_in.is_open()) {
262 int smnumber = -99999;
264 std::ostringstream
str;
265 groupid_in >> smnumber;
266 if (smnumber == -99999) {
267 edm::LogError(
"StoreEcalCondition") <<
"ERROR: SM number not found in file" << endl;
270 str <<
"sm= " << smnumber << endl;
275 for (
int i = 0;
i <= 5;
i++) {
276 groupid_in.getline(
temp, 255);
281 groupid_in.getline(
temp, 255);
287 int xtal, ietaf, iphif, groupID;
288 while (groupid_in.good()) {
289 groupid_in >> xtal >> ietaf >> iphif >> groupID;
290 if (groupid_in.eof()) {
294 LogDebug(
"StoreEcalCondition") <<
"XTAL=" << xtal <<
" ETA=" << ietaf <<
" PHI=" << iphif <<
" GROUP=" << groupID;
304 edm::LogError(
"StoreEcalCondition") <<
"ERROR: GROUPID file did not contain data for 1700 crystals" << endl;
308 edm::LogInfo(
"StoreEcalCondition") <<
"Groups for " << xtals <<
" xtals written into DB";
323 if (!WeightsFileTB.is_open()) {
328 int smnumber = -99999;
330 std::ostringstream
str;
331 WeightsFileTB >> smnumber;
332 if (smnumber == -99999)
335 str <<
"sm= " << smnumber << endl;
339 for (
int i = 0;
i <= 5;
i++) {
340 WeightsFileTB.getline(
temp, 255);
347 while (WeightsFileTB.good()) {
348 int igroup_ID = -99999;
350 int nTdcBins = -99999;
352 WeightsFileTB >> igroup_ID >>
nSamples >> nTdcBins;
353 if (igroup_ID == -99999 ||
nSamples == -99999 || nTdcBins == -99999)
356 std::ostringstream
str;
357 str <<
"Igroup=" << igroup_ID <<
" Nsamples=" <<
nSamples <<
" NTdcBins=" << nTdcBins <<
"\n";
359 for (
int iTdcBin = 0; iTdcBin < nTdcBins; iTdcBin++) {
451 tbwgt->
setValue(std::make_pair(igroup_ID, iTdcBin + 1), wgt);
458 edm::LogInfo(
"StoreEcalCondition") <<
"Weights for " << ngroups <<
" groups written into DB";
475 std::ostringstream
str;
477 fgets(
line, 255, inpFile);
478 int sm_number = atoi(
line);
479 str <<
"sm= " << sm_number << endl;
481 fgets(
line, 255, inpFile);
484 fgets(
line, 255, inpFile);
486 str <<
"gen tag " << gen_tag << endl;
488 fgets(
line, 255, inpFile);
490 str <<
"cali method " << cali_method << endl;
492 fgets(
line, 255, inpFile);
494 str <<
"cali version " << cali_version << endl;
496 fgets(
line, 255, inpFile);
498 str <<
"cali type " << cali_type << endl;
502 fgets(
line, 255, inpFile);
503 float adc_to_gev = 0;
504 sscanf(
line,
"%f", &adc_to_gev);
505 LogDebug(
"StoreEcalCondition") <<
" calib=" << adc_to_gev;
506 fgets(
line, 255, inpFile);
507 float adc_to_gev_ee = 0;
508 sscanf(
line,
"%f", &adc_to_gev_ee);
509 LogDebug(
"StoreEcalCondition") <<
" calib=" << adc_to_gev_ee;
517 edm::LogInfo(
"StoreEcalCondition") <<
"ADCtoGeV scale written into the DB";
523 const char* inputFileEE) {
546 while (fgets(
line, 255, inpFile)) {
561 edm::LogInfo(
"StoreEcalCondition") <<
"Read PF RecHits for " <<
ii <<
" xtals ";
563 cout <<
" I read the thresholds for " <<
ii <<
" crystals " << endl;
566 inpFileEE = fopen(inputFileEE,
"r");
568 edm::LogError(
"StoreEcalCondition") <<
"*** Can not open file: " << inputFileEE;
572 while (fgets(
line, 255, inpFileEE)) {
573 sscanf(
line,
"%d %d %d %f ", &ix, &iy, &iz, &
thresh);
575 cout <<
"crystal " << ix <<
"/" << iy <<
"/" << iz <<
" Thresh= " <<
thresh << endl;
586 cout <<
"loop on EE channels done - number of crystals =" <<
ii << std::endl;
592 const char* inputFileEE) {
606 std::ostringstream
str;
608 fgets(
line, 255, inpFile);
612 sm_number = atoi(
line);
613 str <<
"sm= " << sm_number << endl;
614 if (sm_number != -1) {
620 fgets(
line, 255, inpFile);
623 fgets(
line, 255, inpFile);
625 str <<
"gen tag " << gen_tag << endl;
627 fgets(
line, 255, inpFile);
629 str <<
"cali method " << cali_method << endl;
631 fgets(
line, 255, inpFile);
633 str <<
"cali version " << cali_version << endl;
635 fgets(
line, 255, inpFile);
637 str <<
"cali type " << cali_type << endl;
639 edm::LogInfo(
"StoreEcalCondition") <<
"Intercalibration file " <<
str.str();
641 int sm_num[61200] = {0};
642 int cry_num[61200] = {0};
643 float calib[61200] = {0};
644 float calib_rms[61200] = {0};
645 int calib_nevents[61200] = {0};
646 int calib_status[61200] = {0};
649 if (sm_number != -1) {
650 while (fgets(
line, 255, inpFile)) {
651 sscanf(
line,
"%d %f %f %d %d", &cry_num[
ii], &
calib[
ii], &calib_rms[
ii], &calib_nevents[
ii], &calib_status[
ii]);
655 sm_num[
ii] = sm_number;
660 cout <<
"mode ALL BARREL" << endl;
661 while (fgets(
line, 255, inpFile)) {
662 sscanf(
line,
"%d %d %f %f %d", &sm_num[
ii], &cry_num[
ii], &
calib[
ii], &calib_rms[
ii], &calib_status[
ii]);
664 cout <<
"crystal " << cry_num[
ii] <<
" of sm " << sm_num[
ii] <<
" cali= " <<
calib[
ii] << endl;
672 edm::LogInfo(
"StoreEcalCondition") <<
"Read intercalibrations for " <<
ii <<
" xtals ";
674 cout <<
" I read the calibrations for " <<
ii <<
" crystals " << endl;
676 edm::LogWarning(
"StoreEcalCondition") <<
"Some crystals missing. Missing channels will be set to 0" << endl;
693 cout <<
"crystal " << cry_num[
i] <<
" of sm " << sm_num[
i] <<
" in slot " << slot_num <<
" calib= " <<
calib[
i]
698 cout <<
"loop on channels done" << endl;
701 inpFileEE = fopen(inputFileEE,
"r");
715 EEDetId eedetidneg(iX, iY, -1);
722 cout <<
"... now reading EE file ..." << endl;
725 while (fgets(
line, 255, inpFileEE)) {
728 sscanf(
line,
"%d %d %d %f", &iz, &ix, &iy, &calibee);
730 cout <<
"crystal " << iz <<
"/" << ix <<
"/" << iy <<
" cali=" << calibee << endl;
743 cout <<
"loop on EE channels done" << endl;
750 const char* inputFileEE) {
764 std::ostringstream
str;
766 fgets(
line, 255, inpFile);
770 sm_number = atoi(
line);
771 str <<
"sm= " << sm_number << endl;
772 if (sm_number != -1) {
778 fgets(
line, 255, inpFile);
781 fgets(
line, 255, inpFile);
783 str <<
"gen tag " << gen_tag << endl;
785 fgets(
line, 255, inpFile);
787 str <<
"cali method " << cali_method << endl;
789 fgets(
line, 255, inpFile);
791 str <<
"cali version " << cali_version << endl;
793 fgets(
line, 255, inpFile);
795 str <<
"cali type " << cali_type << endl;
797 edm::LogInfo(
"StoreEcalCondition") <<
"Intercalibration file " <<
str.str();
799 int sm_num[61200] = {0};
800 int cry_num[61200] = {0};
801 float calib[61200] = {0};
802 float calib_rms[61200] = {0};
803 int calib_nevents[61200] = {0};
804 int calib_status[61200] = {0};
807 if (sm_number != -1) {
808 while (fgets(
line, 255, inpFile)) {
809 sscanf(
line,
"%d %f %f %d %d", &cry_num[
ii], &
calib[
ii], &calib_rms[
ii], &calib_nevents[
ii], &calib_status[
ii]);
813 sm_num[
ii] = sm_number;
818 cout <<
"mode ALL BARREL" << endl;
819 while (fgets(
line, 255, inpFile)) {
820 sscanf(
line,
"%d %d %f %f %d", &sm_num[
ii], &cry_num[
ii], &
calib[
ii], &calib_rms[
ii], &calib_status[
ii]);
822 cout <<
"crystal " << cry_num[
ii] <<
" of sm " << sm_num[
ii] <<
" cali= " <<
calib[
ii] << endl;
830 edm::LogInfo(
"StoreEcalCondition") <<
"Read intercalibrations for " <<
ii <<
" xtals ";
832 cout <<
" I read the calibrations for " <<
ii <<
" crystals " << endl;
834 edm::LogWarning(
"StoreEcalCondition") <<
"Some crystals missing. Missing channels will be set to 0" << endl;
851 cout <<
"crystal " << cry_num[
i] <<
" of sm " << sm_num[
i] <<
" in slot " << slot_num <<
" calib= " <<
calib[
i]
856 cout <<
"loop on channels done" << endl;
859 inpFileEE = fopen(inputFileEE,
"r");
873 EEDetId eedetidneg(iX, iY, -1);
880 cout <<
"... now reading EE file ..." << endl;
883 while (fgets(
line, 255, inpFileEE)) {
886 sscanf(
line,
"%d %d %d %f", &iz, &ix, &iy, &calibee);
888 cout <<
"crystal " << iz <<
"/" << ix <<
"/" << iy <<
" cali=" << calibee << endl;
901 cout <<
"loop on EE channels done" << endl;
912 int slot_to_constr[37] = {-1, 12, 17, 10, 1, 8, 4, 27, 20, 23, 25, 6, 34, 35, 15, 18, 30, 21, 9,
913 24, 22, 13, 31, 26, 16, 2, 11, 5, 0, 29, 28, 14, 33, 32, 3, 7, 19};
914 int constr_to_slot[36] = {28, 4, 25, 34, 6, 27, 11, 35, 5, 18, 3, 26, 1, 21, 31, 14, 24, 2,
915 15, 36, 8, 17, 20, 9, 19, 10, 23, 7, 30, 29, 16, 22, 33, 32, 12, 13};
918 if (sm_constr != -1) {
919 result = constr_to_slot[sm_constr];
920 }
else if (sm_slot != -1) {
921 result = slot_to_constr[sm_slot];
941 std::ostringstream
str;
943 fgets(
line, 255, inpFile);
946 sm_number = atoi(
line);
947 str <<
"sm= " << sm_number << endl;
949 fgets(
line, 255, inpFile);
952 fgets(
line, 255, inpFile);
954 str <<
"gen tag " << gen_tag << endl;
956 fgets(
line, 255, inpFile);
958 str <<
"cali method " << cali_method << endl;
960 fgets(
line, 255, inpFile);
962 str <<
"cali version " << cali_version << endl;
964 fgets(
line, 255, inpFile);
967 str <<
"cali type " << cali_type << endl;
971 int cry_num[61200] = {0};
972 float g1_g12[61200] = {0};
973 float g6_g12[61200] = {0};
974 int calib_status[61200] = {0};
981 if (sm_number != -1) {
982 while (fgets(
line, 255, inpFile)) {
983 sscanf(
line,
"%d %d %d %f %f %d", &dummy1, &dummy2, &cry_num[
ii], &g1_g12[
ii], &g6_g12[
ii], &calib_status[
ii]);
989 edm::LogInfo(
"StoreEcalCondition") <<
"Read gainRatios for " <<
ii <<
" xtals ";
991 edm::LogWarning(
"StoreEcalCondition") <<
" Missing crystals:: missing channels will be set to 0" << endl;
996 for (
int i = 0;
i < 1700;
i++) {
1009 cout <<
"mode ALL BARREL" << endl;
1010 while (fgets(
line, 255, inpFile)) {
1013 sscanf(
line,
"%d %d %d %f %f", &hash1, &
eta, &
phi, &g1_g12[
ii], &g6_g12[
ii]);
1015 cout <<
"crystal eta/phi=" <<
eta <<
"/" <<
phi <<
" g1_12/g6_12= " << g1_g12[
ii] <<
"/" << g6_g12[
ii] << endl;
1017 if (g1_g12[
ii] < 9 || g1_g12[
ii] > 15)
1019 if (g6_g12[
ii] < 1 || g6_g12[
ii] > 3)
1022 if (eta < -85 || eta > 85 ||
eta == 0)
1024 if (phi < 1 || phi > 360)
1038 edm::LogWarning(
"StoreEcalCondition") <<
" Missing crystals !!!!!!!" << endl;
1040 std::cout <<
"number of crystals read:" <<
ii << endl;
1051 EEDetId eedetidpos(iX, iY, 1);
1055 EEDetId eedetidneg(iX, iY, -1);
1061 std::cout <<
" gratio pointer=" << gratio << endl;
1077 status->setValue(ebid, 0);
1086 EEDetId eedetidpos(iX, iY, 1);
1087 status->setValue(eedetidpos, 0);
1090 EEDetId eedetidneg(iX, iY, -1);
1091 status->setValue(eedetidneg, 0);
1106 std::cout <<
"Gen tag " << gen_tag << std::endl;
1110 std::cout <<
"Gen comment " << comment << std::endl;
1114 sscanf(
line,
"%d", &iovRunStart);
1115 std::cout <<
"IOV START " << iovRunStart << std::endl;
1120 sscanf(
line,
"%d", &iovRunEnd);
1121 std::cout <<
"IOV END " << iovRunEnd << std::endl;
1129 std::stringstream aStrStream;
1135 if (EBorEE ==
"EB") {
1137 status->setValue(aEBDetId, chStatus);
1138 }
else if (EBorEE ==
"EE") {
1141 status->setValue(aEEDetId, chStatus);
1142 }
else if (EBorEE ==
"EBTT") {
1146 int ixtt = (itt - 1) % 4;
1147 int iytt = (itt - 1) / 4;
1148 int ixmin = ixtt * 5;
1149 int iymin = iytt * 5;
1150 int ixmax = (ixtt + 1) * 5 - 1;
1151 int iymax = (iytt + 1) * 5 - 1;
1155 std::cout <<
"killing crystal " <<
ism <<
"/" << ixt << endl;
1157 status->setValue(ebid, 1);