24 typedef std::vector<edm::ParameterSet>
Parameters;
26 for (Parameters::iterator itToPut = toPut.begin(); itToPut != toPut.end(); ++itToPut) {
30 since_.push_back(itToPut->getUntrackedParameter<
unsigned int>(
"since"));
39 edm::LogError(
"StoreEcalCondition") <<
"PoolDBOutputService is unavailable";
43 bool toAppend =
false;
46 size_t messageSize = message.size() + 1;
47 char* messChar =
new char[messageSize];
48 strncpy(messChar, message.c_str(), messageSize);
89 }
else if (
objectName_[
i] ==
"EcalIntercalibConstants") {
103 }
else if (
objectName_[
i] ==
"EcalIntercalibConstantsMC") {
132 edm::LogInfo(
"StoreEcalCondition") <<
"Finished endJob";
150 outFile = fopen(
logfile_.c_str(),
"a");
159 sprintf(appendMode,
"append");
161 sprintf(appendMode,
"create");
164 "%s %s condition from file %s written into DB for SM %d (mapped to SM %d) in %s mode (since run %u)\n",
171 (
unsigned int)since);
180 outFile = fopen(
logfile_.c_str(),
"a");
187 fprintf(outFile,
"%s %s\n", header, arg);
198 timeinfo = localtime(&rawtime);
200 sprintf(user,
"%s", getlogin());
201 sprintf(header,
"%s %s:", asctime(timeinfo), user);
241 auto xtalGroups = std::make_shared<EcalWeightXtalGroups>();
242 std::ifstream groupid_in(inputFile);
244 if (!groupid_in.is_open()) {
249 int smnumber = -99999;
251 std::ostringstream
str;
252 groupid_in >> smnumber;
253 if (smnumber == -99999) {
254 edm::LogError(
"StoreEcalCondition") <<
"ERROR: SM number not found in file";
257 str <<
"sm= " << smnumber <<
"\n";
262 for (
int i = 0;
i <= 5;
i++) {
263 groupid_in.getline(temp, 255);
268 groupid_in.getline(temp, 255);
271 edm::LogInfo(
"StoreEcalCondition") <<
"GROUPID file " << str.str();
274 int xtal, ietaf, iphif, groupID;
275 while (groupid_in.good()) {
276 groupid_in >> xtal >> ietaf >> iphif >> groupID;
277 if (groupid_in.eof()) {
281 LogDebug(
"StoreEcalCondition") <<
"XTAL=" << xtal <<
" ETA=" << ietaf <<
" PHI=" << iphif <<
" GROUP=" << groupID;
291 edm::LogError(
"StoreEcalCondition") <<
"ERROR: GROUPID file did not contain data for 1700 crystals";
295 edm::LogInfo(
"StoreEcalCondition") <<
"Groups for " << xtals <<
" xtals written into DB";
307 auto tbwgt = std::make_shared<EcalTBWeights>();
309 std::ifstream WeightsFileTB(inputFile);
310 if (!WeightsFileTB.is_open()) {
315 int smnumber = -99999;
317 std::ostringstream
str;
318 WeightsFileTB >> smnumber;
319 if (smnumber == -99999)
322 str <<
"sm= " << smnumber <<
"\n";
326 for (
int i = 0;
i <= 5;
i++) {
327 WeightsFileTB.getline(temp, 255);
331 edm::LogInfo(
"StoreEcalCondition") <<
"Weights file " << str.str();
334 while (WeightsFileTB.good()) {
335 int igroup_ID = -99999;
337 int nTdcBins = -99999;
339 WeightsFileTB >> igroup_ID >> nSamples >> nTdcBins;
340 if (igroup_ID == -99999 || nSamples == -99999 || nTdcBins == -99999)
343 std::ostringstream
str;
344 str <<
"Igroup=" << igroup_ID <<
" Nsamples=" << nSamples <<
" NTdcBins=" << nTdcBins <<
"\n";
346 for (
int iTdcBin = 0; iTdcBin < nTdcBins; iTdcBin++) {
435 LogDebug(
"StoreEcalCondition") << str.str();
438 tbwgt->setValue(std::make_pair(igroup_ID, iTdcBin + 1), wgt);
445 edm::LogInfo(
"StoreEcalCondition") <<
"Weights for " << ngroups <<
" groups written into DB";
454 inpFile = fopen(inputFile,
"r");
462 std::ostringstream
str;
464 fgets(line, 255, inpFile);
465 int sm_number = atoi(line);
466 str <<
"sm= " << sm_number <<
"\n";
468 fgets(line, 255, inpFile);
471 fgets(line, 255, inpFile);
473 str <<
"gen tag " << gen_tag <<
"\n";
475 fgets(line, 255, inpFile);
477 str <<
"cali method " << cali_method <<
"\n";
479 fgets(line, 255, inpFile);
481 str <<
"cali version " << cali_version <<
"\n";
483 fgets(line, 255, inpFile);
485 str <<
"cali type " << cali_type <<
"\n";
487 edm::LogInfo(
"StoreEcalCondition") <<
"ADCToGeV file " << str.str();
489 fgets(line, 255, inpFile);
490 float adc_to_gev = 0;
491 sscanf(line,
"%f", &adc_to_gev);
492 LogDebug(
"StoreEcalCondition") <<
" calib=" << adc_to_gev;
493 fgets(line, 255, inpFile);
494 float adc_to_gev_ee = 0;
495 sscanf(line,
"%f", &adc_to_gev_ee);
496 LogDebug(
"StoreEcalCondition") <<
" calib=" << adc_to_gev_ee;
503 auto agc = std::make_shared<EcalADCToGeVConstant>(adc_to_gev, adc_to_gev_ee);
504 edm::LogInfo(
"StoreEcalCondition") <<
"ADCtoGeV scale written into the DB";
510 const char*
inputFile,
const char* inputFileEE) {
513 auto ical = std::make_shared<EcalPFRecHitThresholds>();
516 inpFile = fopen(inputFile,
"r");
533 while (fgets(line, 255, inpFile)) {
534 sscanf(line,
"%d %d %f ", &ieta, &iphi, &thresh);
536 edm::LogVerbatim(
"StoreEcalCondition") <<
"crystal " << ieta <<
"/" << iphi <<
" Thresh= " << thresh <<
"\n";
548 edm::LogInfo(
"StoreEcalCondition") <<
"Read PF RecHits for " << ii <<
" xtals ";
551 inpFileEE = fopen(inputFileEE,
"r");
553 edm::LogError(
"StoreEcalCondition") <<
"*** Can not open file: " << inputFileEE;
557 while (fgets(line, 255, inpFileEE)) {
558 sscanf(line,
"%d %d %d %f ", &ix, &iy, &iz, &thresh);
561 <<
"crystal " << ix <<
"/" << iy <<
"/" << iz <<
" Thresh= " << thresh <<
"\n";
572 edm::LogInfo(
"StoreEcalCondition") <<
"loop on EE channels done - number of crystals =" <<
ii;
579 const char*
inputFile,
const char* inputFileEE) {
582 auto ical = std::make_shared<EcalIntercalibConstants>();
585 inpFile = fopen(inputFile,
"r");
593 std::ostringstream
str;
595 fgets(line, 255, inpFile);
599 sm_number = atoi(line);
600 str <<
"sm= " << sm_number <<
"\n";
601 if (sm_number != -1) {
607 fgets(line, 255, inpFile);
610 fgets(line, 255, inpFile);
612 str <<
"gen tag " << gen_tag <<
"\n";
614 fgets(line, 255, inpFile);
616 str <<
"cali method " << cali_method <<
"\n";
618 fgets(line, 255, inpFile);
620 str <<
"cali version " << cali_version <<
"\n";
622 fgets(line, 255, inpFile);
624 str <<
"cali type " << cali_type <<
"\n";
626 edm::LogInfo(
"StoreEcalCondition") <<
"Intercalibration file " << str.str();
628 int sm_num[61200] = {0};
629 int cry_num[61200] = {0};
630 float calib[61200] = {0};
631 float calib_rms[61200] = {0};
632 int calib_nevents[61200] = {0};
633 int calib_status[61200] = {0};
636 if (sm_number != -1) {
637 while (fgets(line, 255, inpFile)) {
638 sscanf(line,
"%d %f %f %d %d", &cry_num[ii], &calib[ii], &calib_rms[ii], &calib_nevents[ii], &calib_status[ii]);
642 sm_num[
ii] = sm_number;
647 edm::LogInfo(
"StoreEcalCondition") <<
"mode ALL BARREL";
648 while (fgets(line, 255, inpFile)) {
649 sscanf(line,
"%d %d %f %f %d", &sm_num[ii], &cry_num[ii], &calib[ii], &calib_rms[ii], &calib_status[ii]);
652 <<
"crystal " << cry_num[
ii] <<
" of sm " << sm_num[
ii] <<
" cali= " << calib[
ii] <<
"\n";
660 edm::LogInfo(
"StoreEcalCondition") <<
"Read intercalibrations for " << ii <<
" xtals ";
663 edm::LogWarning(
"StoreEcalCondition") <<
"Some crystals missing. Missing channels will be set to 0";
670 for (
int i = 0;
i < nchan;
i++) {
677 ical->setValue(ebid.
rawId(), calib[
i]);
680 edm::LogVerbatim(
"StoreEcalCondition") <<
"crystal " << cry_num[
i] <<
" of sm " << sm_num[
i] <<
" in slot "
681 << slot_num <<
" calib= " << calib[
i] <<
"\n";
685 edm::LogInfo(
"StoreEcalCondition") <<
"loop on channels done";
688 inpFileEE = fopen(inputFileEE,
"r");
699 ical->setValue(eedetidpos, 1.0);
702 EEDetId eedetidneg(iX, iY, -1);
703 ical->setValue(eedetidneg, 1.0);
709 edm::LogInfo(
"StoreEcalCondition") <<
"... now reading EE file ...";
712 while (fgets(line, 255, inpFileEE)) {
715 sscanf(line,
"%d %d %d %f", &iz, &ix, &iy, &calibee);
718 <<
"crystal " << iz <<
"/" << ix <<
"/" << iy <<
" cali=" << calibee <<
"\n";
722 ical->setValue(eedetid, calibee);
731 edm::LogInfo(
"StoreEcalCondition") <<
"loop on EE channels done";
738 const char*
inputFile,
const char* inputFileEE) {
741 auto ical = std::make_shared<EcalIntercalibConstantsMC>();
744 inpFile = fopen(inputFile,
"r");
752 std::ostringstream
str;
754 fgets(line, 255, inpFile);
758 sm_number = atoi(line);
759 str <<
"sm= " << sm_number <<
"\n";
760 if (sm_number != -1) {
766 fgets(line, 255, inpFile);
769 fgets(line, 255, inpFile);
771 str <<
"gen tag " << gen_tag <<
"\n";
773 fgets(line, 255, inpFile);
775 str <<
"cali method " << cali_method <<
"\n";
777 fgets(line, 255, inpFile);
779 str <<
"cali version " << cali_version <<
"\n";
781 fgets(line, 255, inpFile);
783 str <<
"cali type " << cali_type <<
"\n";
785 edm::LogInfo(
"StoreEcalCondition") <<
"Intercalibration file " << str.str();
787 int sm_num[61200] = {0};
788 int cry_num[61200] = {0};
789 float calib[61200] = {0};
790 float calib_rms[61200] = {0};
791 int calib_nevents[61200] = {0};
792 int calib_status[61200] = {0};
795 if (sm_number != -1) {
796 while (fgets(line, 255, inpFile)) {
797 sscanf(line,
"%d %f %f %d %d", &cry_num[ii], &calib[ii], &calib_rms[ii], &calib_nevents[ii], &calib_status[ii]);
801 sm_num[
ii] = sm_number;
806 edm::LogInfo(
"StoreEcalCondition") <<
"mode ALL BARREL";
807 while (fgets(line, 255, inpFile)) {
808 sscanf(line,
"%d %d %f %f %d", &sm_num[ii], &cry_num[ii], &calib[ii], &calib_rms[ii], &calib_status[ii]);
811 <<
"crystal " << cry_num[
ii] <<
" of sm " << sm_num[
ii] <<
" cali= " << calib[
ii] <<
"\n";
819 edm::LogInfo(
"StoreEcalCondition") <<
"Read intercalibrations for " << ii <<
" xtals ";
822 edm::LogWarning(
"StoreEcalCondition") <<
"Some crystals missing. Missing channels will be set to 0";
829 for (
int i = 0;
i < nchan;
i++) {
836 ical->setValue(ebid.
rawId(), calib[
i]);
839 edm::LogVerbatim(
"StoreEcalCondition") <<
"crystal " << cry_num[
i] <<
" of sm " << sm_num[
i] <<
" in slot "
840 << slot_num <<
" calib= " << calib[
i] <<
"\n";
844 edm::LogInfo(
"StoreEcalCondition") <<
"loop on channels done";
847 inpFileEE = fopen(inputFileEE,
"r");
858 ical->setValue(eedetidpos, 1.0);
861 EEDetId eedetidneg(iX, iY, -1);
862 ical->setValue(eedetidneg, 1.0);
868 edm::LogInfo(
"StoreEcalCondition") <<
"... now reading EE file ...";
871 while (fgets(line, 255, inpFileEE)) {
874 sscanf(line,
"%d %d %d %f", &iz, &ix, &iy, &calibee);
877 <<
"crystal " << iz <<
"/" << ix <<
"/" << iy <<
" cali=" << calibee <<
"\n";
881 ical->setValue(eedetid, calibee);
890 edm::LogInfo(
"StoreEcalCondition") <<
"loop on EE channels done";
901 int slot_to_constr[37] = {-1, 12, 17, 10, 1, 8, 4, 27, 20, 23, 25, 6, 34, 35, 15, 18, 30, 21, 9,
902 24, 22, 13, 31, 26, 16, 2, 11, 5, 0, 29, 28, 14, 33, 32, 3, 7, 19};
903 int constr_to_slot[36] = {28, 4, 25, 34, 6, 27, 11, 35, 5, 18, 3, 26, 1, 21, 31, 14, 24, 2,
904 15, 36, 8, 17, 20, 9, 19, 10, 23, 7, 30, 29, 16, 22, 33, 32, 12, 13};
907 if (sm_constr != -1) {
908 result = constr_to_slot[sm_constr];
909 }
else if (sm_slot != -1) {
910 result = slot_to_constr[sm_slot];
920 auto gratio = std::make_shared<EcalGainRatios>();
923 inpFile = fopen(inputFile,
"r");
930 std::ostringstream
str;
932 fgets(line, 255, inpFile);
935 sm_number = atoi(line);
936 str <<
"sm= " << sm_number <<
"\n";
938 fgets(line, 255, inpFile);
941 fgets(line, 255, inpFile);
943 str <<
"gen tag " << gen_tag <<
"\n";
945 fgets(line, 255, inpFile);
947 str <<
"cali method " << cali_method <<
"\n";
949 fgets(line, 255, inpFile);
951 str <<
"cali version " << cali_version <<
"\n";
953 fgets(line, 255, inpFile);
956 str <<
"cali type " << cali_type <<
"\n";
958 edm::LogInfo(
"StoreEcalCondition") <<
"GainRatio file " << str.str();
960 int cry_num[61200] = {0};
961 float g1_g12[61200] = {0};
962 float g6_g12[61200] = {0};
963 int calib_status[61200] = {0};
970 if (sm_number != -1) {
971 while (fgets(line, 255, inpFile)) {
972 sscanf(line,
"%d %d %d %f %f %d", &dummy1, &dummy2, &cry_num[ii], &g1_g12[ii], &g6_g12[ii], &calib_status[ii]);
978 edm::LogInfo(
"StoreEcalCondition") <<
"Read gainRatios for " << ii <<
" xtals ";
980 edm::LogWarning(
"StoreEcalCondition") <<
" Missing crystals:: missing channels will be set to 0";
985 for (
int i = 0;
i < 1700;
i++) {
992 gratio->setValue(ebid.
rawId(), gr);
997 edm::LogInfo(
"StoreEcalCondition") <<
"mode ALL BARREL";
998 while (fgets(line, 255, inpFile)) {
1001 sscanf(line,
"%d %d %d %f %f", &hash1, &eta, &phi, &g1_g12[ii], &g6_g12[ii]);
1004 <<
"crystal eta/phi=" << eta <<
"/" << phi <<
" g1_12/g6_12= " << g1_g12[
ii] <<
"/" << g6_g12[
ii] <<
"\n";
1006 if (g1_g12[ii] < 9 || g1_g12[ii] > 15)
1008 if (g6_g12[ii] < 1 || g6_g12[ii] > 3)
1011 if (eta < -85 || eta > 85 || eta == 0)
1013 if (phi < 1 || phi > 360)
1020 gratio->setValue(ebid.
rawId(), gr);
1029 edm::LogInfo(
"StoreEcalCondition") <<
"number of crystals read:" <<
ii;
1040 EEDetId eedetidpos(iX, iY, 1);
1041 gratio->setValue(eedetidpos.
rawId(), gr);
1044 EEDetId eedetidneg(iX, iY, -1);
1045 gratio->setValue(eedetidneg.
rawId(), gr);
1050 edm::LogInfo(
"StoreEcalCondition") <<
" gratio pointer=" << gratio;
1058 auto status = std::make_shared<EcalChannelStatus>();
1066 status->setValue(ebid, 0);
1075 EEDetId eedetidpos(iX, iY, 1);
1076 status->setValue(eedetidpos, 0);
1079 EEDetId eedetidneg(iX, iY, -1);
1080 status->setValue(eedetidneg, 0);
1086 FILE*
ifile = fopen(inputFile,
"r");
1092 fgets(line, 255, ifile);
1096 fgets(line, 255, ifile);
1098 edm::LogVerbatim(
"StoreEcalCondition") <<
"Gen comment " << comment <<
"\n";
1101 fgets(line, 255, ifile);
1102 sscanf(line,
"%d", &iovRunStart);
1103 edm::LogVerbatim(
"StoreEcalCondition") <<
"IOV START " << iovRunStart <<
"\n";
1107 fgets(line, 255, ifile);
1108 sscanf(line,
"%d", &iovRunEnd);
1113 while (fgets(line, 255, ifile)) {
1117 std::stringstream aStrStream;
1119 aStrStream >> EBorEE >> hashedIndex >> chStatus;
1122 << EBorEE <<
" hashedIndex " << hashedIndex <<
" status " << chStatus <<
"\n";
1124 if (EBorEE ==
"EB") {
1126 status->setValue(aEBDetId, chStatus);
1127 }
else if (EBorEE ==
"EE") {
1130 status->setValue(aEEDetId, chStatus);
1131 }
else if (EBorEE ==
"EBTT") {
1135 int ixtt = (itt - 1) % 4;
1136 int iytt = (itt - 1) / 4;
1137 int ixmin = ixtt * 5;
1138 int iymin = iytt * 5;
1139 int ixmax = (ixtt + 1) * 5 - 1;
1140 int iymax = (iytt + 1) * 5 - 1;
1141 for (
int ieta = iymin; ieta <= iymax; ieta++) {
1142 for (
int iphi = ixmin; iphi <= ixmax; iphi++) {
1143 int ixt = ieta * 20 + iphi + 1;
1144 edm::LogVerbatim(
"StoreEcalCondition") <<
"killing crystal " << ism <<
"/" << ixt <<
"\n";
1146 status->setValue(ebid, 1);
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
Log< level::Info, true > LogVerbatim
T getUntrackedParameter(std::string const &, T const &) const
static const int MIN_IPHI
void writeToLogFileResults(char *)
std::vector< std::string > inpFileName_
StoreEcalCondition(const edm::ParameterSet &iConfig)
~StoreEcalCondition() override
std::vector< std::string > inpFileNameEE_
constexpr uint32_t rawId() const
get the raw id
std::shared_ptr< EcalChannelStatus > readEcalChannelStatusFromFile(const char *)
std::shared_ptr< EcalIntercalibConstants > readEcalIntercalibConstantsFromFile(const char *, const char *)
math::Matrix< 10, 10 >::type EcalChi2WeightMatrix
math::Matrix< 3, 10 >::type EcalWeightMatrix
Log< level::Error, false > LogError
static EEDetId unhashIndex(int hi)
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
static bool validDetId(int i, int j)
check if a valid index combination
void setGain12Over6(const float &g)
std::shared_ptr< EcalADCToGeVConstant > readEcalADCToGeVConstantFromFile(const char *)
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
int hashedIndex(int ieta, int iphi)
unsigned long long Time_t
vector< ParameterSet > Parameters
bool isNewTagRequest(const std::string &recordName)
cond::Time_t beginOfTime() const
std::vector< unsigned long long > since_
EcalChi2WeightMatrix & getChi2WeightsAfterGainSwitch()
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
constexpr size_t nSamples
EcalWeightMatrix & getWeightsAfterGainSwitch()
static const int ETAPHIMODE
std::shared_ptr< EcalTBWeights > readEcalTBWeightsFromFile(const char *)
std::shared_ptr< EcalIntercalibConstantsMC > readEcalIntercalibConstantsMCFromFile(const char *, const char *)
void writeToLogFile(std::string, std::string, unsigned long long)
Log< level::Info, false > LogInfo
std::shared_ptr< EcalWeightXtalGroups > readEcalWeightXtalGroupsFromFile(const char *)
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)
T getParameter(std::string const &) const
static const int MAX_IETA
std::shared_ptr< EcalGainRatios > readEcalGainRatiosFromFile(const char *)
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
std::shared_ptr< EcalPFRecHitThresholds > readEcalPFRecHitThresholdsFromFile(const char *, const char *)
std::vector< std::string > objectName_
Log< level::Warning, false > LogWarning
static const int SMCRYSTALMODE
int ism(int ieta, int iphi)
void setGain6Over1(const float &g)