Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:06

0001 //
0002 // F.Ratnikov (UMd), Oct 28, 2005
0003 //
0004 #include <vector>
0005 #include <string>
0006 #include <cstdio>
0007 #include <sstream>
0008 #include <memory>
0009 #include <iostream>
0010 
0011 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
0012 #include "DataFormats/HcalDetId/interface/HcalElectronicsId.h"
0013 #include "DataFormats/HcalDetId/interface/HcalDcsDetId.h"
0014 #include "CalibFormats/HcalObjects/interface/HcalText2DetIdConverter.h"
0015 
0016 #include "CondFormats/HcalObjects/interface/AllObjects.h"
0017 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 
0020 namespace {
0021   class DetIdLess {
0022   public:
0023     bool operator()(DetId fFirst, DetId fSecond) const {
0024       HcalGenericDetId first(fFirst);
0025       HcalGenericDetId second(fSecond);
0026       if (first.genericSubdet() != second.genericSubdet())
0027         return first.genericSubdet() < second.genericSubdet();
0028       if (first.isHcalDetId()) {
0029         HcalDetId f1(first);
0030         HcalDetId s1(second);
0031         return f1.zside() != s1.zside()       ? f1.zside() < s1.zside()
0032                : f1.iphi() != s1.iphi()       ? f1.iphi() < s1.iphi()
0033                : f1.ietaAbs() != s1.ietaAbs() ? f1.ietaAbs() < s1.ietaAbs()
0034                                               : f1.depth() < s1.depth();
0035       } else {
0036         return first.rawId() < second.rawId();
0037       }
0038     }
0039   };
0040   class HcalElectronicsIdLess {
0041   public:
0042     bool operator()(HcalElectronicsId first, HcalElectronicsId second) const {
0043       return first.readoutVMECrateId() != second.readoutVMECrateId()
0044                  ? first.readoutVMECrateId() < second.readoutVMECrateId()
0045              : first.htrSlot() != second.htrSlot()           ? first.htrSlot() < second.htrSlot()
0046              : first.htrTopBottom() != second.htrTopBottom() ? first.htrTopBottom() < second.htrTopBottom()
0047              : first.fiberIndex() != second.fiberIndex()     ? first.fiberIndex() < second.fiberIndex()
0048                                                              : first.fiberChanId() < second.fiberChanId();
0049     }
0050   };
0051 }  // namespace
0052 
0053 // ------------------------------ some little helpers ------------------------------
0054 
0055 std::vector<std::string> splitString(const std::string& fLine) {
0056   std::vector<std::string> result;
0057   int start = 0;
0058   bool empty = true;
0059   for (unsigned i = 0; i <= fLine.size(); i++) {
0060     if (fLine[i] == ' ' || i == fLine.size()) {
0061       if (!empty) {
0062         std::string item(fLine, start, i - start);
0063         result.push_back(item);
0064         empty = true;
0065       }
0066       start = i + 1;
0067     } else {
0068       if (empty)
0069         empty = false;
0070     }
0071   }
0072   return result;
0073 }
0074 
0075 std::vector<unsigned int> splitStringToIntByComma(const std::string& fLine) {
0076   std::vector<unsigned int> result;
0077   int start = 0;
0078   bool empty = true;
0079   for (unsigned i = 0; i <= fLine.size(); i++) {
0080     if (fLine[i] == ',' || i == fLine.size()) {
0081       if (!empty) {
0082         std::string itemString(fLine, start, i - start);
0083         result.push_back(atoi(itemString.c_str()));
0084         empty = true;
0085       }
0086       start = i + 1;
0087     } else {
0088       if (empty)
0089         empty = false;
0090     }
0091   }
0092   return result;
0093 }
0094 
0095 std::vector<float> splitStringToFloatByComma(const std::string& fLine) {
0096   std::vector<float> result;
0097   int start = 0;
0098   bool empty = true;
0099   for (unsigned i = 0; i <= fLine.size(); i++) {
0100     if (fLine[i] == ',' || i == fLine.size()) {
0101       if (!empty) {
0102         std::string itemString(fLine, start, i - start);
0103         result.push_back(atof(itemString.c_str()));
0104         empty = true;
0105       }
0106       start = i + 1;
0107     } else {
0108       if (empty)
0109         empty = false;
0110     }
0111   }
0112   return result;
0113 }
0114 
0115 std::vector<double> splitStringToDoubleByComma(const std::string& fLine) {
0116   std::vector<double> result;
0117   int start = 0;
0118   bool empty = true;
0119   for (unsigned i = 0; i <= fLine.size(); i++) {
0120     if (fLine[i] == ',' || i == fLine.size()) {
0121       if (!empty) {
0122         std::string itemString(fLine, start, i - start);
0123         result.push_back(atof(itemString.c_str()));
0124         empty = true;
0125       }
0126       start = i + 1;
0127     } else {
0128       if (empty)
0129         empty = false;
0130     }
0131   }
0132   return result;
0133 }
0134 
0135 DetId HcalDbASCIIIO::getId(const std::vector<std::string>& items) {
0136   HcalText2DetIdConverter converter(items[3], items[0], items[1], items[2]);
0137   return converter.getId();
0138 }
0139 
0140 void HcalDbASCIIIO::dumpId(std::ostream& fOutput, DetId id) {
0141   HcalText2DetIdConverter converter(id);
0142   char buffer[1024];
0143   sprintf(buffer,
0144           "  %15s %15s %15s %15s",
0145           converter.getField1().c_str(),
0146           converter.getField2().c_str(),
0147           converter.getField3().c_str(),
0148           converter.getFlavor().c_str());
0149   fOutput << buffer;
0150 }
0151 
0152 void HcalDbASCIIIO::dumpIdShort(std::ostream& fOutput, DetId id) {
0153   HcalText2DetIdConverter converter(id);
0154   char buffer[1024];
0155   sprintf(buffer,
0156           "  %5s %4s %4s %10s",
0157           converter.getField1().c_str(),
0158           converter.getField2().c_str(),
0159           converter.getField3().c_str(),
0160           converter.getFlavor().c_str());
0161   fOutput << buffer;
0162 }
0163 
0164 // ------------------------------ start templates ------------------------------
0165 
0166 template <class T>
0167 bool from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {
0168   std::istringstream iss(s);
0169   return !(iss >> f >> t).fail();
0170 }
0171 
0172 template <class S, class T>
0173 bool getHcalObject(std::istream& fInput, T* fObject) {
0174   if (!fObject)
0175     return false;  //fObject = new T;
0176   char buffer[1024];
0177   while (fInput.getline(buffer, 1024)) {
0178     if (buffer[0] == '#')
0179       continue;  //ignore comment
0180     std::vector<std::string> items = splitString(std::string(buffer));
0181     if (items.empty())
0182       continue;  // blank line
0183     if (items.size() < 8) {
0184       edm::LogWarning("Format Error") << "Bad line: " << buffer
0185                                       << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
0186                                       << std::endl;
0187       continue;
0188     }
0189     DetId id = HcalDbASCIIIO::getId(items);
0190 
0191     //    if (fObject->exists(id) )
0192     //      edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
0193     //    else
0194     //      {
0195     S fCondObject(id, atof(items[4].c_str()), atof(items[5].c_str()), atof(items[6].c_str()), atof(items[7].c_str()));
0196     fObject->addValues(fCondObject);
0197     //      }
0198   }
0199 
0200   return true;
0201 }
0202 
0203 template <class T>
0204 bool dumpHcalObject(std::ostream& fOutput, const T& fObject) {
0205   char buffer[1024];
0206   sprintf(buffer,
0207           "# %15s %15s %15s %15s %8s %8s %8s %8s %10s\n",
0208           "eta",
0209           "phi",
0210           "dep",
0211           "det",
0212           "cap0",
0213           "cap1",
0214           "cap2",
0215           "cap3",
0216           "DetId");
0217   fOutput << buffer;
0218   std::vector<DetId> channels = fObject.getAllChannels();
0219   std::sort(channels.begin(), channels.end(), DetIdLess());
0220   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
0221     const float* values = fObject.getValues(*channel)->getValues();
0222     if (values) {
0223       HcalDbASCIIIO::dumpId(fOutput, *channel);
0224       sprintf(
0225           buffer, " %10.7f %10.7f %10.7f %10.7f %10X\n", values[0], values[1], values[2], values[3], channel->rawId());
0226       fOutput << buffer;
0227     }
0228   }
0229   return true;
0230 }
0231 
0232 template <class ObjectPrimitiveType, class S, class T>
0233 bool getHcalSingleObject(std::istream& fInput, T* fObject) {
0234   if (!fObject)
0235     return false;  //fObject = new T;
0236   char buffer[1024];
0237   while (fInput.getline(buffer, 1024)) {
0238     if (buffer[0] == '#')
0239       continue;  //ignore comment
0240     std::vector<std::string> items = splitString(std::string(buffer));
0241     if (items.empty())
0242       continue;  // blank line
0243     if (items.size() < 5) {
0244       edm::LogWarning("Format Error") << "Bad line: " << buffer
0245                                       << "\n line must contain 5 items: eta, phi, depth, subdet, value" << std::endl;
0246       continue;
0247     }
0248     DetId id = HcalDbASCIIIO::getId(items);
0249 
0250     //    if (fObject->exists(id) )
0251     //      edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
0252     //    else
0253     //      {
0254     std::stringstream ss(items[4]);
0255     ObjectPrimitiveType x = 0;  // usually int or float
0256     ss >> x;
0257     S fCondObject(id, x);
0258     fObject->addValues(fCondObject);
0259     //      }
0260   }
0261   return true;
0262 }
0263 
0264 template <class T>
0265 bool dumpHcalDoubleFloatObject(std::ostream& fOutput, const T& fObject) {
0266   char buffer[1024];
0267   sprintf(buffer, "# %15s %15s %15s %15s %10s %10s %10s\n", "eta", "phi", "dep", "det", "value0", "value1", "DetId");
0268   fOutput << buffer;
0269   std::vector<DetId> channels = fObject.getAllChannels();
0270   std::sort(channels.begin(), channels.end(), DetIdLess());
0271   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
0272     const float value0 = fObject.getValues(*channel)->getValue0();
0273     const float value1 = fObject.getValues(*channel)->getValue1();
0274     HcalDbASCIIIO::dumpId(fOutput, *channel);
0275     sprintf(buffer, " %10.7f %10.7f %10X\n", value0, value1, channel->rawId());
0276     fOutput << buffer;
0277   }
0278   return true;
0279 }
0280 
0281 template <class S, class T>
0282 bool getHcalDoubleFloatObject(std::istream& fInput, T* fObject) {
0283   if (!fObject)
0284     return false;  //fObject = new T;
0285   char buffer[1024];
0286   while (fInput.getline(buffer, 1024)) {
0287     if (buffer[0] == '#')
0288       continue;  //ignore comment
0289     std::vector<std::string> items = splitString(std::string(buffer));
0290     if (items.empty())
0291       continue;  // blank line
0292     if (items.size() < 6) {
0293       edm::LogWarning("Format Error") << "Bad line: " << buffer
0294                                       << "\n line must contain 6 items: eta, phi, depth, subdet, value0, value1"
0295                                       << std::endl;
0296       continue;
0297     }
0298     DetId id = HcalDbASCIIIO::getId(items);
0299     S fCondObject(id, atof(items[4].c_str()), atof(items[5].c_str()));
0300     fObject->addValues(fCondObject);
0301   }
0302 
0303   return true;
0304 }
0305 
0306 template <class T>
0307 bool dumpHcalSingleFloatObject(std::ostream& fOutput, const T& fObject) {
0308   char buffer[1024];
0309   sprintf(buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
0310   fOutput << buffer;
0311   std::vector<DetId> channels = fObject.getAllChannels();
0312   std::sort(channels.begin(), channels.end(), DetIdLess());
0313   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
0314     const float value = fObject.getValues(*channel)->getValue();
0315     HcalDbASCIIIO::dumpId(fOutput, *channel);
0316     sprintf(buffer, " %8.5f %10X\n", value, channel->rawId());
0317     fOutput << buffer;
0318   }
0319   return true;
0320 }
0321 
0322 template <class T>
0323 bool dumpHcalSingleIntObject(std::ostream& fOutput, const T& fObject) {
0324   char buffer[1024];
0325   sprintf(buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
0326   fOutput << buffer;
0327   std::vector<DetId> channels = fObject.getAllChannels();
0328   std::sort(channels.begin(), channels.end(), DetIdLess());
0329   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
0330     const int value = fObject.getValues(*channel)->getValue();
0331     HcalDbASCIIIO::dumpId(fOutput, *channel);
0332     sprintf(buffer, " %15d %10X\n", value, channel->rawId());
0333     fOutput << buffer;
0334   }
0335   return true;
0336 }
0337 
0338 template <class S, class T>
0339 bool getHcalMatrixObject(std::istream& fInput, T* fObject, S* fCondObject) {
0340   if (!fObject)
0341     return false;  //fObject = new T;
0342   char buffer[1024];
0343   while (fInput.getline(buffer, 1024)) {
0344     if (buffer[0] == '#')
0345       continue;  //ignore comment
0346     std::vector<std::string> items = splitString(std::string(buffer));
0347     if (items.empty())
0348       continue;  // blank line
0349     DetId firstid = HcalDbASCIIIO::getId(items);
0350     fCondObject = new S(firstid.rawId());
0351     for (int j = 0; j != 10; j++)
0352       fCondObject->setValue(atoi(items[4].c_str()), 0, j, atof(items[j + 5].c_str()));
0353     for (int i = 1; i != 40; i++) {
0354       fInput.getline(buffer, 1024);
0355       items = splitString(std::string(buffer));
0356       DetId id = HcalDbASCIIIO::getId(items);
0357       if (id.rawId() != firstid.rawId())
0358         break;  //throw cms::Exception("Wrong number of elements");
0359       for (int j = 0; j != 10; j++)
0360         fCondObject->setValue(atoi(items[4].c_str()), i % 10, j, atof(items[j + 5].c_str()));
0361     }
0362     fObject->addValues(*fCondObject);
0363     delete fCondObject;
0364   }
0365   return true;
0366 }
0367 
0368 template <class T>
0369 bool dumpHcalMatrixObject(std::ostream& fOutput, const T& fObject) {
0370   char buffer[1024];
0371   sprintf(buffer,
0372           "# %5s %5s %5s %5s %5s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
0373           "eta",
0374           "phi",
0375           "dep",
0376           "det",
0377           "capid",
0378           "c0",
0379           "c1",
0380           "c2",
0381           "c3",
0382           "c4",
0383           "c5",
0384           "c6",
0385           "c7",
0386           "c8",
0387           "c9",
0388           "DetId");
0389   fOutput << buffer;
0390   std::vector<DetId> channels = fObject.getAllChannels();
0391   std::sort(channels.begin(), channels.end(), DetIdLess());
0392   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
0393     float thisline[10];
0394     for (int m = 0; m != 4; m++) {
0395       for (int i = 0; i != 10; i++) {
0396         for (int j = 0; j != 10; j++) {
0397           //          std::cout <<"test "<<(fObject.getValues(*channel))->getValue(0,0,0);
0398           thisline[j] = fObject.getValues(*channel)->getValue(m, i, j);
0399           //          thisline[j] = fObject.getValues(*channel)->getValue(1,1,1);
0400         }
0401         HcalDbASCIIIO::dumpId(fOutput, *channel);
0402         sprintf(buffer,
0403                 " %5i %8.5f %8.5f %8.5f %8.5f  %8.5f %8.5f %8.5f %8.5f  %8.5f %8.5f %10X\n",
0404                 m,
0405                 thisline[0],
0406                 thisline[1],
0407                 thisline[2],
0408                 thisline[3],
0409                 thisline[4],
0410                 thisline[5],
0411                 thisline[6],
0412                 thisline[7],
0413                 thisline[8],
0414                 thisline[9],
0415                 channel->rawId());
0416         fOutput << buffer;
0417       }
0418     }
0419   }
0420 
0421   return true;
0422 }
0423 
0424 // ------------------------------ end templates ------------------------------
0425 
0426 namespace HcalDbASCIIIO {
0427   bool getObject(std::istream& fInput, HcalGains* fObject) { return getHcalObject<HcalGain>(fInput, fObject); }
0428   bool dumpObject(std::ostream& fOutput, const HcalGains& fObject) { return dumpHcalObject(fOutput, fObject); }
0429   bool getObject(std::istream& fInput, HcalGainWidths* fObject) {
0430     return getHcalObject<HcalGainWidth>(fInput, fObject);
0431   }
0432   bool dumpObject(std::ostream& fOutput, const HcalGainWidths& fObject) { return dumpHcalObject(fOutput, fObject); }
0433 
0434   bool getObject(std::istream& fInput, HcalPFCuts* fObject) {
0435     return getHcalDoubleFloatObject<HcalPFCut>(fInput, fObject);
0436   }
0437   bool dumpObject(std::ostream& fOutput, const HcalPFCuts& fObject) {
0438     return dumpHcalDoubleFloatObject(fOutput, fObject);
0439   }
0440 
0441   bool getObject(std::istream& fInput, HcalRespCorrs* fObject) {
0442     return getHcalSingleObject<float, HcalRespCorr>(fInput, fObject);
0443   }
0444   bool dumpObject(std::ostream& fOutput, const HcalRespCorrs& fObject) {
0445     return dumpHcalSingleFloatObject(fOutput, fObject);
0446   }
0447 
0448   bool getObject(std::istream& fInput, HcalLUTCorrs* fObject) {
0449     return getHcalSingleObject<float, HcalLUTCorr>(fInput, fObject);
0450   }
0451   bool dumpObject(std::ostream& fOutput, const HcalLUTCorrs& fObject) {
0452     return dumpHcalSingleFloatObject(fOutput, fObject);
0453   }
0454 
0455   bool getObject(std::istream& fInput, HcalPFCorrs* fObject) {
0456     return getHcalSingleObject<float, HcalPFCorr>(fInput, fObject);
0457   }
0458   bool dumpObject(std::ostream& fOutput, const HcalPFCorrs& fObject) {
0459     return dumpHcalSingleFloatObject(fOutput, fObject);
0460   }
0461 
0462   bool getObject(std::istream& fInput, HcalTimeCorrs* fObject) {
0463     return getHcalSingleObject<float, HcalTimeCorr>(fInput, fObject);
0464   }
0465   bool dumpObject(std::ostream& fOutput, const HcalTimeCorrs& fObject) {
0466     return dumpHcalSingleFloatObject(fOutput, fObject);
0467   }
0468 
0469   bool getObject(std::istream& fInput, HcalZSThresholds* fObject) {
0470     return getHcalSingleObject<int, HcalZSThreshold>(fInput, fObject);
0471   }
0472   bool dumpObject(std::ostream& fOutput, const HcalZSThresholds& fObject) {
0473     return dumpHcalSingleIntObject(fOutput, fObject);
0474   }
0475 
0476   bool getObject(std::istream& fInput, HcalZDCLowGainFractions* fObject) {
0477     return getHcalSingleObject<float, HcalZDCLowGainFraction>(fInput, fObject);
0478   }
0479   bool dumpObject(std::ostream& fOutput, const HcalZDCLowGainFractions& fObject) {
0480     return dumpHcalSingleFloatObject(fOutput, fObject);
0481   }
0482 
0483   bool getObject(std::istream& fInput, HcalValidationCorrs* fObject) {
0484     return getHcalSingleObject<float, HcalValidationCorr>(fInput, fObject);
0485   }
0486   bool dumpObject(std::ostream& fOutput, const HcalValidationCorrs& fObject) {
0487     return dumpHcalSingleFloatObject(fOutput, fObject);
0488   }
0489 
0490   bool getObject(std::istream& fInput, HcalQIETypes* fObject) {
0491     return getHcalSingleObject<int, HcalQIEType>(fInput, fObject);
0492   }
0493   bool dumpObject(std::ostream& fOutput, const HcalQIETypes& fObject) {
0494     return dumpHcalSingleIntObject(fOutput, fObject);
0495   }
0496 }  // namespace HcalDbASCIIIO
0497 
0498 // ------------------------------ start specific implementations ------------------------------
0499 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalRecoParams* fObject) {
0500   if (!fObject)
0501     return false;  // fObject = new HcalRecoParams();  This was always useless...
0502   char buffer[1024];
0503   while (fInput.getline(buffer, 1024)) {
0504     if (buffer[0] == '#')
0505       continue;  //ignore comment
0506     std::vector<std::string> items = splitString(std::string(buffer));
0507     if (items.empty())
0508       continue;  // blank line
0509     if (items.size() < 6) {
0510       edm::LogWarning("Format Error") << "Bad line: " << buffer
0511                                       << "\n line must contain 6 items: eta, phi, depth, subdet, param1, param2"
0512                                       << std::endl;
0513       continue;
0514     }
0515     DetId id = HcalDbASCIIIO::getId(items);
0516 
0517     int packingScheme = 0;
0518     if (items.size() > 22) {
0519       packingScheme = atoi(items[22].c_str());
0520     }
0521 
0522     int param1 = 0;
0523     int param2 = 0;
0524     if (packingScheme == 0) {
0525       param1 = atoi(items[4].c_str());
0526       param2 = atoi(items[5].c_str());
0527     }  // packing scheme 0  (old format).
0528 
0529     if (packingScheme == 1) {
0530       //             0 1 2 3 4 5 6 7 8 9
0531       int aabits[6] = {1, 1, 8, 4, 4, 9};
0532       int aamax[6] = {1, 1, 255, 15, 15, 511};
0533 
0534       int bbbits[10] = {1, 4, 1, 4, 1, 4, 4, 4, 4, 4};
0535       int bbmax[10] = {1, 15, 1, 15, 1, 15, 15, 15, 15, 15};
0536 
0537       // param 1
0538       int j = 0;
0539       int aa;
0540       int aashift = 0;
0541       for (int i = 0; i < 6; i++) {
0542         j = i + 7;
0543         if (i == 2) {
0544           float phase = atof(items[j].c_str());
0545           float xphase = (phase + 32.0) * 4.0;  // range of phase [-30.0,30.0]
0546           aa = xphase;
0547         } else {
0548           aa = atoi(items[j].c_str());
0549         }
0550         if (aa > aamax[i] || aa < 0) {
0551           edm::LogWarning("Format Error")
0552               << "Bad line: " << buffer << "\n value for a" << i << " should be less than" << aamax[i] << std::endl;
0553         }
0554         param1 = param1 | aa << aashift;
0555         aashift = aashift + aabits[i];
0556       }
0557 
0558       // param 2
0559       int bb;
0560       int bbshift = 0;
0561       for (int i = 0; i < 10; i++) {
0562         j = i + 13;
0563         bb = atoi(items[j].c_str());
0564         if (bb > bbmax[i]) {
0565           edm::LogWarning("Format Error")
0566               << "Bad line: " << buffer << "\n value for b" << i << " should be less than" << bbmax[i] << std::endl;
0567         }
0568         param2 = param2 | bb << bbshift;
0569         bbshift = bbshift + bbbits[i];
0570       }
0571     }  // packing sheme 1.
0572 
0573     // HcalRecoParam* fCondObject = new HcalRecoParam(id, atoi (items [4].c_str()), atoi (items [5].c_str()) );
0574 
0575     // std::cout<<"  buffer "<<buffer<<std::endl;
0576     // std::cout<<"  param1, param2 "<<param1<<"  "<<param2<<std::endl;
0577 
0578     HcalRecoParam* fCondObject = new HcalRecoParam(id, param1, param2);
0579     fObject->addValues(*fCondObject);
0580     delete fCondObject;
0581   }
0582   return true;
0583 }
0584 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalRecoParams& fObject) {
0585   char buffer[1024];
0586   //  sprintf (buffer, "# %15s %15s %15s %15s %18s %15s %10s\n", "eta", "phi", "dep", "det", "firstSample", "samplesToAdd", "DetId");
0587   // fOutput << buffer;
0588   std::vector<DetId> channels = fObject.getAllChannels();
0589   std::sort(channels.begin(), channels.end(), DetIdLess());
0590   int myCounter = 0;
0591   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
0592     myCounter++;
0593     int param1 = fObject.getValues(*channel)->param1();
0594     int param2 = fObject.getValues(*channel)->param2();
0595     int packingScheme = fObject.getValues(*channel)->packingScheme();
0596 
0597     // std::cout<<"  Param1 "<<Param1<<"  Param2 "<<Param2<<"  packing "<<packingScheme<<std::endl;
0598 
0599     if (packingScheme == 0) {
0600       // old format
0601       if (myCounter == 1) {
0602         sprintf(buffer,
0603                 "# %15s %15s %15s %15s %18s %15s %10s\n",
0604                 "eta",
0605                 "phi",
0606                 "dep",
0607                 "det",
0608                 "firstSample",
0609                 "samplesToAdd",
0610                 "DetId");
0611       }
0612       HcalDbASCIIIO::dumpId(fOutput, *channel);
0613       sprintf(buffer,
0614               " %15d %15d %16X\n",
0615               fObject.getValues(*channel)->firstSample(),
0616               fObject.getValues(*channel)->samplesToAdd(),
0617               channel->rawId());
0618       fOutput << buffer;
0619     }
0620 
0621     if (packingScheme == 1) {
0622       if (myCounter == 1) {
0623         char lineT[100], lineA[200], lineB[200];
0624         //
0625         sprintf(lineT, "#%50s", "  ");
0626         fOutput << lineT;
0627         sprintf(lineA, " %31s", "a0: correctForPhaseContainment");
0628         fOutput << lineA;
0629         sprintf(lineB, " %36s", "b0: useLeakCorrection\n");
0630         fOutput << lineB;
0631         //
0632         sprintf(lineT, "#%50s", "  ");
0633         fOutput << lineT;
0634         sprintf(lineA, " %31s", "a1: correctForLeadingEdge");
0635         fOutput << lineA;
0636         sprintf(lineB, " %36s", "b1: leakCorrectionID\n");
0637         fOutput << lineB;
0638         //
0639         sprintf(lineT, "#%50s", "  ");
0640         fOutput << lineT;
0641         sprintf(lineA, " %31s", "a2: correctionPhaseNS");
0642         fOutput << lineA;
0643         sprintf(lineB, " %36s", "b2:  correctForTimeslew\n");
0644         fOutput << lineB;
0645         //
0646         sprintf(lineT, "#%50s", "  ");
0647         fOutput << lineT;
0648         sprintf(lineA, " %31s", "a3: firstSample");
0649         fOutput << lineA;
0650         sprintf(lineB, " %36s", "b3: timeslewCorrectionID\n");
0651         fOutput << lineB;
0652         //
0653         sprintf(lineT, "#%50s", "  ");
0654         fOutput << lineT;
0655         sprintf(lineA, " %31s", "a4: samplesToAdd");
0656         fOutput << lineA;
0657         sprintf(lineB, " %36s", "b4: correctTiming\n");
0658         fOutput << lineB;
0659         //
0660         sprintf(lineT, "#%50s", "  ");
0661         fOutput << lineT;
0662         sprintf(lineA, " %31s", "a5: pulseShapeID");
0663         fOutput << lineA;
0664         sprintf(lineB, " %36s", "b5: firstAuxTS\n");
0665         fOutput << lineB;
0666         //
0667         sprintf(lineT, "#%50s", "  ");
0668         fOutput << lineT;
0669         sprintf(lineA, " %31s", "  ");
0670         fOutput << lineA;
0671         sprintf(lineB, " %36s", "b6: specialCaseID\n");
0672         fOutput << lineB;
0673         //
0674         sprintf(lineT, "#%50s", "  ");
0675         fOutput << lineT;
0676         sprintf(lineA, " %31s", "  ");
0677         fOutput << lineA;
0678         sprintf(lineB, " %36s", "b7: noiseFlaggingID\n");
0679         fOutput << lineB;
0680         //
0681         sprintf(lineT, "#%50s", "  ");
0682         fOutput << lineT;
0683         sprintf(lineA, " %31s", "  ");
0684         fOutput << lineA;
0685         sprintf(lineB, " %36s", "b8: pileupCleaningID\n");
0686         fOutput << lineB;
0687 
0688         sprintf(lineT, "#%50s", "  ");
0689         fOutput << lineT;
0690         sprintf(lineA, " %31s", "  ");
0691         fOutput << lineA;
0692         sprintf(lineB, " %36s", "b9: packingScheme\n");
0693         fOutput << lineB;
0694 
0695         //
0696         sprintf(lineT, "# %5s %4s %4s %10s %11s %10s %10s", "eta", "phi", "dep", "det", "param1", "param2", "DetId");
0697         fOutput << lineT;
0698 
0699         sprintf(lineA, " %6s %4s %6s %4s %4s %4s", "a0", "a1", "a2", "a3", "a4", "a5");
0700         fOutput << lineA;
0701 
0702         sprintf(lineB, " %6s %3s %3s %3s %3s %3s %3s %3s %3s\n", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8");
0703         fOutput << lineB;
0704       }
0705 
0706       HcalDbASCIIIO::dumpIdShort(fOutput, *channel);
0707       sprintf(buffer, " %11d %10d %10X", param1, param2, channel->rawId());
0708       fOutput << buffer;
0709 
0710       bool aa0 = fObject.getValues(*channel)->correctForPhaseContainment();
0711       bool aa1 = fObject.getValues(*channel)->correctForLeadingEdge();
0712       float aa2 = fObject.getValues(*channel)->correctionPhaseNS();
0713       int aa3 = fObject.getValues(*channel)->firstSample();
0714       int aa4 = fObject.getValues(*channel)->samplesToAdd();
0715       int aa5 = fObject.getValues(*channel)->pulseShapeID();
0716       sprintf(buffer, " %6d %4d %6.1f %4d %4d %4d", aa0, aa1, aa2, aa3, aa4, aa5);
0717       fOutput << buffer;
0718 
0719       bool bb0 = fObject.getValues(*channel)->useLeakCorrection();
0720       int bb1 = fObject.getValues(*channel)->leakCorrectionID();
0721       bool bb2 = fObject.getValues(*channel)->correctForTimeslew();
0722       int bb3 = fObject.getValues(*channel)->timeslewCorrectionID();
0723       bool bb4 = fObject.getValues(*channel)->correctTiming();
0724       int bb5 = fObject.getValues(*channel)->firstAuxTS();
0725       int bb6 = fObject.getValues(*channel)->specialCaseID();
0726       int bb7 = fObject.getValues(*channel)->noiseFlaggingID();
0727       int bb8 = fObject.getValues(*channel)->pileupCleaningID();
0728       int bb9 = fObject.getValues(*channel)->packingScheme();
0729       sprintf(buffer, " %6d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n", bb0, bb1, bb2, bb3, bb4, bb5, bb6, bb7, bb8, bb9);
0730       fOutput << buffer;
0731     }  // packingScheme 1.
0732 
0733   }  // loop ever channels
0734   return true;
0735 }
0736 
0737 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalLongRecoParams* fObject) {
0738   if (!fObject)
0739     return false;  // fObject = new HcalLongRecoParams();
0740   char buffer[1024];
0741   while (fInput.getline(buffer, 1024)) {
0742     if (buffer[0] == '#')
0743       continue;  //ignore comment
0744     std::vector<std::string> items = splitString(std::string(buffer));
0745     if (items.empty())
0746       continue;  // blank line
0747     if (items.size() < 5) {
0748       edm::LogWarning("Format Error") << "Bad line: " << buffer
0749                                       << "\n line must contain 6 items: eta, phi, depth, subdet, signalTSs, noiseTSs"
0750                                       << std::endl;
0751       continue;
0752     }
0753     if (items.size() > 7) {
0754       edm::LogWarning("Format Error")
0755           << "Check line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, signalTSs, noiseTSs. "
0756           << "\n ! signalTS and noiseTS must be of format <ts1,ts2,ts3,...> withOUT spaces. Ignoring line for safety"
0757           << std::endl;
0758       continue;
0759     }
0760     DetId id = HcalDbASCIIIO::getId(items);
0761 
0762     std::vector<unsigned int> mySignalTS = splitStringToIntByComma(items[4]);
0763     std::vector<unsigned int> myNoiseTS = splitStringToIntByComma(items[5]);
0764 
0765     HcalLongRecoParam* fCondObject = new HcalLongRecoParam(id, mySignalTS, myNoiseTS);
0766     fObject->addValues(*fCondObject);
0767     delete fCondObject;
0768   }
0769   return true;
0770 }
0771 
0772 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalTimingParams* fObject) {
0773   if (!fObject)
0774     return false;  // fObject = new HcalTimingParams();
0775   char buffer[1024];
0776   while (fInput.getline(buffer, 1024)) {
0777     if (buffer[0] == '#')
0778       continue;  //ignore comment
0779     std::vector<std::string> items = splitString(std::string(buffer));
0780     if (items.empty())
0781       continue;  // blank line
0782     if (items.size() < 7) {
0783       edm::LogWarning("Format Error") << "Bad line: " << buffer
0784                                       << "\n line must contain 7 items: eta, phi, depth, subdet, nhit, phase, rms,detid"
0785                                       << std::endl;
0786       continue;
0787     }
0788     //std::cout<<"items[3] "<<items [3]<<std::endl;
0789     //std::cout<<"items[0] "<<items [0]<<std::endl;
0790     //std::cout<<"items[1] "<<items [1]<<std::endl;
0791     //std::cout<<"items[2] "<<items [2]<<std::endl;
0792 
0793     //std::cout<<"items[4] "<<items [4]<<std::endl;
0794     //std::cout<<"items[5] "<<items [5]<<std::endl;
0795     //std::cout<<"items[6] "<<items [6]<<std::endl;
0796     DetId id = HcalDbASCIIIO::getId(items);
0797     //std::cout<<"calculated id "<<id.rawId()<<std::endl;
0798     HcalTimingParam* fCondObject =
0799         new HcalTimingParam(id, atoi(items[4].c_str()), atof(items[5].c_str()), atof(items[6].c_str()));
0800     fObject->addValues(*fCondObject);
0801     delete fCondObject;
0802   }
0803   return true;
0804 }
0805 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalTimingParams& fObject) {
0806   char buffer[1024];
0807   sprintf(
0808       buffer, "# %15s %15s %15s %15s %15s %15s %15s %15s\n", "eta", "phi", "dep", "det", "nhit", "mean", "rms", "DetId");
0809   fOutput << buffer;
0810   std::vector<DetId> channels = fObject.getAllChannels();
0811   std::sort(channels.begin(), channels.end(), DetIdLess());
0812   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
0813     HcalDbASCIIIO::dumpId(fOutput, *channel);
0814     sprintf(buffer,
0815             " %15d %8.5f %8.5f %16X\n",
0816             fObject.getValues(*channel)->nhits(),
0817             fObject.getValues(*channel)->phase(),
0818             fObject.getValues(*channel)->rms(),
0819             channel->rawId());
0820     fOutput << buffer;
0821   }
0822   return true;
0823 }
0824 
0825 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalLongRecoParams& fObject) {
0826   char buffer[1024];
0827   sprintf(
0828       buffer, "# %15s %15s %15s %15s %10s %10s %10s\n", "eta", "phi", "dep", "det", "signalTSs", "noiseTSs", "DetId");
0829   fOutput << buffer;
0830   std::vector<DetId> channels = fObject.getAllChannels();
0831   std::sort(channels.begin(), channels.end(), DetIdLess());
0832   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
0833     HcalGenericDetId fId(*channel);
0834     if (fId.isHcalZDCDetId()) {
0835       std::vector<unsigned int> vSignalTS = fObject.getValues(*channel)->signalTS();
0836       std::vector<unsigned int> vNoiseTS = fObject.getValues(*channel)->noiseTS();
0837       HcalDbASCIIIO::dumpId(fOutput, *channel);
0838       sprintf(buffer, "    ");
0839       fOutput << buffer;
0840       for (unsigned int i = 0; i < vSignalTS.size(); i++) {
0841         if (i > 0) {
0842           sprintf(buffer, ",");
0843           fOutput << buffer;
0844         }
0845         sprintf(buffer, "%u", vSignalTS.at(i));
0846         fOutput << buffer;
0847       }
0848       sprintf(buffer, "       ");
0849       fOutput << buffer;
0850       for (unsigned int i = 0; i < vNoiseTS.size(); i++) {
0851         if (i > 0) {
0852           sprintf(buffer, ",");
0853           fOutput << buffer;
0854         }
0855         sprintf(buffer, "%u", vNoiseTS.at(i));
0856         fOutput << buffer;
0857       }
0858       sprintf(buffer, "     %10X\n", channel->rawId());
0859       fOutput << buffer;
0860     }
0861   }
0862   return true;
0863 }
0864 
0865 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalMCParams* fObject) {
0866   if (!fObject)
0867     return false;  // fObject = new HcalMCParams();
0868   char buffer[1024];
0869   while (fInput.getline(buffer, 1024)) {
0870     if (buffer[0] == '#')
0871       continue;  //ignore comment
0872     std::vector<std::string> items = splitString(std::string(buffer));
0873     if (items.empty())
0874       continue;  // blank line
0875     if (items.size() < 5) {
0876       edm::LogWarning("Format Error") << "Bad line: " << buffer
0877                                       << "\n line must contain 5 items: eta, phi, depth, subdet, signalShape"
0878                                       << std::endl;
0879       continue;
0880     }
0881     DetId id = HcalDbASCIIIO::getId(items);
0882 
0883     int packingScheme = 0;
0884     if (items.size() > 11) {
0885       packingScheme = atoi(items[11].c_str());
0886     }
0887 
0888     int param1 = 0;
0889     if (packingScheme == 0) {
0890       param1 = atoi(items[4].c_str());
0891     }
0892 
0893     if (packingScheme == 1) {
0894       int aabits[6] = {9, 1, 4, 8, 5, 4};  // 4 spear bits added to aabits[5]
0895       int aamax[6] = {511, 1, 15, 255, 1, 16};
0896       int j = 0;
0897       int aa;
0898       int aashift = 0;
0899       for (int i = 0; i < 6; i++) {
0900         j = i + 6;
0901         if (i == 3) {
0902           float phase = atof(items[j].c_str());
0903           float xphase = (phase + 32.0) * 4.0;  // range of phase [-30.0,30.0]
0904           aa = xphase;
0905         } else {
0906           aa = atoi(items[j].c_str());
0907         }
0908         if (aa > aamax[i] || aa < 0) {
0909           edm::LogWarning("Format Error")
0910               << "Bad line: " << buffer << "\n value for a" << i << " should be less than" << aamax[i] << std::endl;
0911         }
0912 
0913         param1 = param1 | aa << aashift;
0914         aashift = aashift + aabits[i];
0915       }
0916     }
0917 
0918     HcalMCParam* fCondObject = new HcalMCParam(id, param1);
0919     fObject->addValues(*fCondObject);
0920     delete fCondObject;
0921   }
0922   return true;
0923 }
0924 
0925 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalMCParams& fObject) {
0926   char buffer[1024];
0927   // sprintf (buffer, "# %15s %15s %15s %15s %14s %10s\n", "eta", "phi", "dep", "det", "signalShape", "DetId");
0928   // fOutput << buffer;
0929   std::vector<DetId> channels = fObject.getAllChannels();
0930   std::sort(channels.begin(), channels.end(), DetIdLess());
0931   int myCounter = 0;
0932   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
0933     myCounter++;
0934     ;
0935     int packingScheme = fObject.getValues(*channel)->packingScheme();
0936     if (packingScheme == 0) {
0937       if (myCounter == 1) {
0938         sprintf(buffer, "# %15s %15s %15s %15s %14s %10s\n", "eta", "phi", "dep", "det", "signalShape", "DetId");
0939         fOutput << buffer;
0940       }
0941       const int value = fObject.getValues(*channel)->signalShape();
0942       HcalDbASCIIIO::dumpId(fOutput, *channel);
0943       sprintf(buffer, " %10d %17X\n", value, channel->rawId());
0944       fOutput << buffer;
0945     }  // packingScheme 0
0946     if (packingScheme == 1) {
0947       if (myCounter == 1) {
0948         char lineT[100], lineA[200];
0949         //
0950         sprintf(lineT, "#%40s", "  ");
0951         fOutput << lineT;
0952         sprintf(lineA, " %31s", "a0: signalShape\n");
0953         fOutput << lineA;
0954         sprintf(lineT, "#%40s", "  ");
0955         fOutput << lineT;
0956         sprintf(lineA, " %31s", "a1: syncPhase\n");
0957         fOutput << lineA;
0958         sprintf(lineT, "#%40s", "  ");
0959         fOutput << lineT;
0960         sprintf(lineA, " %31s", "a2: binOfMaximum\n");
0961         fOutput << lineA;
0962         sprintf(lineT, "#%40s", "  ");
0963         fOutput << lineT;
0964         sprintf(lineA, " %31s", "a3: timePhase\n");
0965         fOutput << lineA;
0966         sprintf(lineT, "#%40s", "  ");
0967         fOutput << lineT;
0968         sprintf(lineA, " %31s", "a4: timeSmearing\n");
0969         fOutput << lineA;
0970         sprintf(lineT, "#%40s", "  ");
0971         fOutput << lineT;
0972         sprintf(lineA, " %31s", "a5: packingScheme\n");
0973         fOutput << lineA;
0974         sprintf(lineT, "# %5s %4s %4s %10s %11s %10s", "eta", "phi", "dep", "det", "param1", "DetId");
0975         fOutput << lineT;
0976         sprintf(lineA, " %6s %4s %4s %6s %4s %4s\n", "a0", "a1", "a2", "a3", "a4", "a5");
0977         fOutput << lineA;
0978       }
0979       int param1 = fObject.getValues(*channel)->param1();
0980       HcalDbASCIIIO::dumpIdShort(fOutput, *channel);
0981       sprintf(buffer, " %11d  %10X", param1, channel->rawId());
0982       fOutput << buffer;
0983       int aa0 = fObject.getValues(*channel)->signalShape();
0984       bool aa1 = fObject.getValues(*channel)->syncPhase();
0985       int aa2 = fObject.getValues(*channel)->binOfMaximum();
0986       float aa3 = fObject.getValues(*channel)->timePhase();
0987       bool aa4 = fObject.getValues(*channel)->timeSmearing();
0988       int aa5 = fObject.getValues(*channel)->packingScheme();
0989       sprintf(buffer, "%6d %4d %4d %6.1f %4d %4d\n", aa0, aa1, aa2, aa3, aa4, aa5);
0990       fOutput << buffer;
0991     }
0992   }
0993   return true;
0994 }
0995 
0996 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalPedestals* fObject) {
0997   char buffer[1024];
0998 
0999   while (fInput.getline(buffer, 1024)) {
1000     std::vector<std::string> items = splitString(std::string(buffer));
1001     if (items.empty())
1002       continue;  // blank line
1003     else {
1004       if (items[0] == "#U") {
1005         if (items[1] == (std::string) "ADC")
1006           fObject->setUnitADC(true);
1007         else if (items[1] == (std::string) "fC")
1008           fObject->setUnitADC(false);
1009         else {
1010           edm::LogWarning("Pedestal Unit Error") << "Unrecognized unit for pedestals. Assuming fC." << std::endl;
1011           fObject->setUnitADC(false);
1012         }
1013         break;
1014       } else {
1015         edm::LogWarning("Pedestal Unit Missing")
1016             << "The unit for the pedestals is missing in the txt file." << std::endl;
1017         return false;
1018       }
1019     }
1020   }
1021   while (fInput.getline(buffer, 1024)) {
1022     if (buffer[0] == '#')
1023       continue;
1024     std::vector<std::string> items = splitString(std::string(buffer));
1025     if (items.empty())
1026       continue;  // blank line
1027     if (items.size() < 8) {
1028       edm::LogWarning("Format Error")
1029           << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
1030           << " or 12 items: eta, phi, depth, subdet, 4x values for mean, 4x values for width" << std::endl;
1031       continue;
1032     }
1033     DetId id = getId(items);
1034 
1035     //    if (fObject->exists(id) )
1036     //      edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1037     //    else
1038     //      {
1039 
1040     if (items.size() < 12)  // old format without widths
1041     {
1042       HcalPedestal* fCondObject = new HcalPedestal(id,
1043                                                    atof(items[4].c_str()),
1044                                                    atof(items[5].c_str()),
1045                                                    atof(items[6].c_str()),
1046                                                    atof(items[7].c_str()),
1047                                                    0.,
1048                                                    0.,
1049                                                    0.,
1050                                                    0.);
1051       fObject->addValues(*fCondObject);
1052       delete fCondObject;
1053     } else  // new format with widths
1054     {
1055       HcalPedestal* fCondObject = new HcalPedestal(id,
1056                                                    atof(items[4].c_str()),
1057                                                    atof(items[5].c_str()),
1058                                                    atof(items[6].c_str()),
1059                                                    atof(items[7].c_str()),
1060                                                    atof(items[8].c_str()),
1061                                                    atof(items[9].c_str()),
1062                                                    atof(items[10].c_str()),
1063                                                    atof(items[11].c_str()));
1064       fObject->addValues(*fCondObject);
1065       delete fCondObject;
1066     }
1067 
1068     //      }
1069   }
1070   return true;
1071 }
1072 
1073 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalPedestals& fObject) {
1074   char buffer[1024];
1075   if (fObject.isADC())
1076     sprintf(buffer, "#U ADC  << this is the unit \n");
1077   else
1078     sprintf(buffer, "#U fC  << this is the unit \n");
1079   fOutput << buffer;
1080 
1081   sprintf(buffer,
1082           "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
1083           "eta",
1084           "phi",
1085           "dep",
1086           "det",
1087           "cap0",
1088           "cap1",
1089           "cap2",
1090           "cap3",
1091           "widthcap0",
1092           "widthcap1",
1093           "widthcap2",
1094           "widthcap3",
1095           "DetId");
1096   fOutput << buffer;
1097 
1098   std::vector<DetId> channels = fObject.getAllChannels();
1099   std::sort(channels.begin(), channels.end(), DetIdLess());
1100   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
1101     const float* values = fObject.getValues(*channel)->getValues();
1102     if (values) {
1103       dumpId(fOutput, *channel);
1104       sprintf(buffer,
1105               " %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
1106               values[0],
1107               values[1],
1108               values[2],
1109               values[3],
1110               values[4],
1111               values[5],
1112               values[6],
1113               values[7],
1114               channel->rawId());
1115       fOutput << buffer;
1116     }
1117   }
1118   return true;
1119 }
1120 
1121 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1122 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalChannelQuality* fObject) {
1123   if (!fObject)
1124     return false;  //fObject = new HcalChannelQuality;
1125   char buffer[1024];
1126   while (fInput.getline(buffer, 1024)) {
1127     if (buffer[0] == '#')
1128       continue;  //ignore comment
1129     std::vector<std::string> items = splitString(std::string(buffer));
1130     if (items.empty())
1131       continue;  // blank line
1132     if (items.size() < 6) {
1133       edm::LogWarning("Format Error")
1134           << "Bad line: " << buffer
1135           << "\n line must contain 6 items: eta, phi, depth, subdet, base - either (hex) or (dec), value" << std::endl;
1136       continue;
1137     }
1138     DetId id = getId(items);
1139 
1140     //    if (fObject->exists(id) )
1141     //      edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1142     //    else
1143     //      {
1144     uint32_t mystatus;
1145     if (items[4] == "(hex)")
1146       sscanf(items[5].c_str(), "%X", &mystatus);
1147     else if (items[4] == "(dec)")
1148       sscanf(items[5].c_str(), "%u", &mystatus);
1149     else {
1150       edm::LogWarning("Format Error") << "Bad line: " << buffer
1151                                       << "\n value field must contain the base: one of (hex), (dec)" << std::endl;
1152       continue;
1153     }
1154 
1155     HcalChannelStatus* fCondObject = new HcalChannelStatus(id, mystatus);  //atoi (items [4].c_str()) );
1156     fObject->addValues(*fCondObject);
1157     delete fCondObject;
1158     //      }
1159   }
1160   return true;
1161 }
1162 
1163 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalChannelQuality& fObject) {
1164   char buffer[1024];
1165   sprintf(buffer, "# %15s %15s %15s %15s %15s %10s\n", "eta", "phi", "dep", "det", "(base) value", "DetId");
1166   fOutput << buffer;
1167   std::vector<DetId> channels = fObject.getAllChannels();
1168   std::sort(channels.begin(), channels.end(), DetIdLess());
1169   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
1170     const int value = fObject.getValues(*channel)->getValue();
1171     dumpId(fOutput, *channel);
1172     sprintf(buffer, "%6s %15X %10X\n", "(hex)", value, channel->rawId());
1173     fOutput << buffer;
1174   }
1175   return true;
1176 }
1177 
1178 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1179 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalL1TriggerObjects* fObject) {
1180   char buffer[1024];
1181 
1182   while (fInput.getline(buffer, 1024)) {
1183     if (buffer[0] == '#') {
1184       if (buffer[1] == 'T')  // contains tag name
1185       {
1186         std::vector<std::string> items = splitString(std::string(buffer));
1187         fObject->setTagString(items[1]);
1188         continue;
1189       }
1190       if (buffer[1] == 'A')  // contains algo name
1191       {
1192         std::vector<std::string> items = splitString(std::string(buffer));
1193         fObject->setAlgoString(items[1]);
1194         continue;
1195       } else
1196         continue;  //ignore comment
1197     }
1198     std::vector<std::string> items = splitString(std::string(buffer));
1199     if (items.empty())
1200       continue;  // blank line
1201     if (items.size() < 7) {
1202       edm::LogWarning("Format Error")
1203           << "Bad line: " << buffer
1204           << "\n line must contain 7 items: eta, phi, depth, subdet, pedestal, resp.corr.gain, flag" << std::endl;
1205       continue;
1206     }
1207     DetId id = getId(items);
1208 
1209     HcalL1TriggerObject* fCondObject =
1210         new HcalL1TriggerObject(id, atof(items[4].c_str()), atof(items[5].c_str()), atoi(items[6].c_str()));
1211 
1212     fObject->addValues(*fCondObject);
1213     delete fCondObject;
1214   }
1215   return true;
1216 }
1217 
1218 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalL1TriggerObjects& fObject) {
1219   char buffer[1024];
1220   //first print tag and algo
1221   sprintf(buffer, "#T %s  << this is the tag name \n", fObject.getTagString().c_str());
1222   fOutput << buffer;
1223   sprintf(buffer, "#A %s  << this is the algorithm name \n", fObject.getAlgoString().c_str());
1224   fOutput << buffer;
1225 
1226   //then the values
1227   sprintf(buffer,
1228           "# %15s %15s %15s %15s %8s %13s %8s %10s\n",
1229           "eta",
1230           "phi",
1231           "dep",
1232           "det",
1233           "ped",
1234           "respcorrgain",
1235           "flag",
1236           "DetId");
1237   fOutput << buffer;
1238   std::vector<DetId> channels = fObject.getAllChannels();
1239   //  std::sort (channels.begin(), channels.end(), DetIdLess ());
1240   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
1241     const HcalL1TriggerObject* item = fObject.getValues(*channel);
1242     if (item) {
1243       dumpId(fOutput, *channel);
1244       sprintf(buffer,
1245               " %12.7f %13.10f %12d %10X\n",
1246               item->getPedestal(),
1247               item->getRespGain(),
1248               item->getFlag(),
1249               channel->rawId());
1250       fOutput << buffer;
1251     }
1252   }
1253   return true;
1254 }
1255 
1256 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1257 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalPedestalWidths* fObject) {
1258   char buffer[1024];
1259   int linecounter = 0;
1260 
1261   while (fInput.getline(buffer, 1024)) {
1262     linecounter++;
1263     std::vector<std::string> items = splitString(std::string(buffer));
1264     if (items.empty())
1265       continue;  // blank line
1266     else {
1267       if (items[0] == (std::string) "#U") {
1268         if (items[1] == (std::string) "ADC")
1269           fObject->setUnitADC(true);
1270         else if (items[1] == (std::string) "fC")
1271           fObject->setUnitADC(false);
1272         else {
1273           edm::LogWarning("Pedestal Width Unit Error")
1274               << "Unrecognized unit for pedestal widths. Assuming fC." << std::endl;
1275           fObject->setUnitADC(false);
1276         }
1277         break;
1278       } else {
1279         edm::LogWarning("Pedestal Width Unit Missing")
1280             << "The unit for the pedestal widths is missing in the txt file." << std::endl;
1281         return false;
1282       }
1283     }
1284   }
1285 
1286   while (fInput.getline(buffer, 1024)) {
1287     linecounter++;
1288     if (buffer[0] == '#')
1289       continue;  //ignore comment
1290     std::vector<std::string> items = splitString(std::string(buffer));
1291     if (items.empty())
1292       continue;  // blank line
1293     if (items.size() < 14) {
1294       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line number: " << linecounter
1295                                       << "\n line must contain 14 items: eta, phi, depth, subdet, 10x correlations"
1296                                       << " or 20 items: eta, phi, depth, subdet, 16x correlations" << std::endl;
1297       continue;
1298     }
1299     DetId id = getId(items);
1300 
1301     //    if (fObject->exists(id) )
1302     //      edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1303     //    else
1304     //      {
1305 
1306     if (items.size() < 20)  //old format
1307     {
1308       HcalPedestalWidth values(id);
1309       values.setSigma(0, 0, atof(items[4].c_str()));
1310       values.setSigma(1, 0, atof(items[5].c_str()));
1311       values.setSigma(1, 1, atof(items[6].c_str()));
1312       values.setSigma(2, 0, atof(items[7].c_str()));
1313       values.setSigma(2, 1, atof(items[8].c_str()));
1314       values.setSigma(2, 2, atof(items[9].c_str()));
1315       values.setSigma(3, 0, atof(items[10].c_str()));
1316       values.setSigma(3, 1, atof(items[11].c_str()));
1317       values.setSigma(3, 2, atof(items[12].c_str()));
1318       values.setSigma(3, 3, atof(items[13].c_str()));
1319       values.setSigma(0, 1, 0.);
1320       values.setSigma(0, 2, 0.);
1321       values.setSigma(0, 3, 0.);
1322       values.setSigma(1, 2, 0.);
1323       values.setSigma(1, 3, 0.);
1324       values.setSigma(2, 3, 0.);
1325       fObject->addValues(values);
1326     } else  // new format
1327     {
1328       HcalPedestalWidth values(id);
1329       values.setSigma(0, 0, atof(items[4].c_str()));
1330       values.setSigma(0, 1, atof(items[5].c_str()));
1331       values.setSigma(0, 2, atof(items[6].c_str()));
1332       values.setSigma(0, 3, atof(items[7].c_str()));
1333       values.setSigma(1, 0, atof(items[8].c_str()));
1334       values.setSigma(1, 1, atof(items[9].c_str()));
1335       values.setSigma(1, 2, atof(items[10].c_str()));
1336       values.setSigma(1, 3, atof(items[11].c_str()));
1337       values.setSigma(2, 0, atof(items[12].c_str()));
1338       values.setSigma(2, 1, atof(items[13].c_str()));
1339       values.setSigma(2, 2, atof(items[14].c_str()));
1340       values.setSigma(2, 3, atof(items[15].c_str()));
1341       values.setSigma(3, 0, atof(items[16].c_str()));
1342       values.setSigma(3, 1, atof(items[17].c_str()));
1343       values.setSigma(3, 2, atof(items[18].c_str()));
1344       values.setSigma(3, 3, atof(items[19].c_str()));
1345       fObject->addValues(values);
1346     }
1347 
1348     //      }
1349   }
1350   return true;
1351 }
1352 
1353 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalPedestalWidths& fObject) {
1354   char buffer[1024];
1355   if (fObject.isADC())
1356     sprintf(buffer, "#U ADC  << this is the unit \n");
1357   else
1358     sprintf(buffer, "#U fC  << this is the unit \n");
1359   fOutput << buffer;
1360 
1361   sprintf(buffer,
1362           "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
1363           "eta",
1364           "phi",
1365           "dep",
1366           "det",
1367           "cov_0_0",
1368           "cov_0_1",
1369           "cov_0_2",
1370           "cov_0_3",
1371           "cov_1_0",
1372           "cov_1_1",
1373           "cov_1_2",
1374           "cov_1_3",
1375           "cov_2_0",
1376           "cov_2_1",
1377           "cov_2_2",
1378           "cov_2_3",
1379           "cov_3_0",
1380           "cov_3_1",
1381           "cov_3_2",
1382           "cov_3_3",
1383           "DetId");
1384   fOutput << buffer;
1385   std::vector<DetId> channels = fObject.getAllChannels();
1386   std::sort(channels.begin(), channels.end(), DetIdLess());
1387   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
1388     const HcalPedestalWidth* item = fObject.getValues(*channel);
1389     if (item) {
1390       dumpId(fOutput, *channel);
1391       sprintf(buffer,
1392               " %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
1393               item->getSigma(0, 0),
1394               item->getSigma(0, 1),
1395               item->getSigma(0, 2),
1396               item->getSigma(0, 3),
1397               item->getSigma(1, 0),
1398               item->getSigma(1, 1),
1399               item->getSigma(1, 2),
1400               item->getSigma(1, 3),
1401               item->getSigma(2, 0),
1402               item->getSigma(2, 1),
1403               item->getSigma(2, 2),
1404               item->getSigma(2, 3),
1405               item->getSigma(3, 0),
1406               item->getSigma(3, 1),
1407               item->getSigma(3, 2),
1408               item->getSigma(3, 3),
1409               channel->rawId());
1410       fOutput << buffer;
1411     }
1412   }
1413   return true;
1414 }
1415 
1416 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1417 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalQIEData* fObject) {
1418   char buffer[1024];
1419   while (fInput.getline(buffer, 1024)) {
1420     if (buffer[0] == '#')
1421       continue;  //ignore comment
1422     std::vector<std::string> items = splitString(std::string(buffer));
1423     if (items.empty())
1424       continue;
1425     if (items[0] == "SHAPE") {  // basic shape
1426       //this shape keyword is obsolete
1427     } else {  // QIE parameters
1428       if (items.size() < 36) {
1429         edm::LogWarning("Format Error") << "Bad line: " << buffer
1430                                         << "\n line must contain 36 items: eta, phi, depth, subdet, 4 capId x 4 Ranges "
1431                                            "x offsets, 4 capId x 4 Ranges x slopes"
1432                                         << std::endl;
1433         continue;
1434       }
1435       DetId id = getId(items);
1436       fObject->sort();
1437       //      try {
1438       //      fObject->getCoder (id);
1439       //      edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1440       //      }
1441       //      catch (cms::Exception& e) {
1442       HcalQIECoder coder(id.rawId());
1443       int index = 4;
1444       for (unsigned capid = 0; capid < 4; capid++) {
1445         for (unsigned range = 0; range < 4; range++) {
1446           coder.setOffset(capid, range, atof(items[index++].c_str()));
1447         }
1448       }
1449       for (unsigned capid = 0; capid < 4; capid++) {
1450         for (unsigned range = 0; range < 4; range++) {
1451           coder.setSlope(capid, range, atof(items[index++].c_str()));
1452         }
1453       }
1454 
1455       fObject->addCoder(coder);
1456       //      }
1457     }
1458   }
1459   fObject->sort();
1460   return true;
1461 }
1462 
1463 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalQIEData& fObject) {
1464   char buffer[1024];
1465 
1466   fOutput << "# QIE data" << std::endl;
1467   sprintf(buffer,
1468           "# %15s %15s %15s %15s %36s %36s %36s %36s %36s %36s %36s %36s\n",
1469           "eta",
1470           "phi",
1471           "dep",
1472           "det",
1473           "4 x offsets cap0",
1474           "4 x offsets cap1",
1475           "4 x offsets cap2",
1476           "4 x offsets cap3",
1477           "4 x slopes cap0",
1478           "4 x slopes cap1",
1479           "4 x slopes cap2",
1480           "4 x slopes cap3");
1481   fOutput << buffer;
1482   std::vector<DetId> channels = fObject.getAllChannels();
1483   std::sort(channels.begin(), channels.end(), DetIdLess());
1484   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
1485     const HcalQIECoder* coder = fObject.getCoder(*channel);
1486     dumpId(fOutput, *channel);
1487     for (unsigned capid = 0; capid < 4; capid++) {
1488       for (unsigned range = 0; range < 4; range++) {
1489         sprintf(buffer, " %8.5f", coder->offset(capid, range));
1490         fOutput << buffer;
1491       }
1492     }
1493     for (unsigned capid = 0; capid < 4; capid++) {
1494       for (unsigned range = 0; range < 4; range++) {
1495         sprintf(buffer, " %8.5f", coder->slope(capid, range));
1496         fOutput << buffer;
1497       }
1498     }
1499     fOutput << std::endl;
1500   }
1501   return true;
1502 }
1503 
1504 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1505 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalCalibrationQIEData* fObject) {
1506   char buffer[1024];
1507   while (fInput.getline(buffer, 1024)) {
1508     if (buffer[0] == '#')
1509       continue;  //ignore comment
1510     std::vector<std::string> items = splitString(std::string(buffer));
1511     if (items.size() < 36) {
1512       edm::LogWarning("Format Error") << "Bad line: " << buffer
1513                                       << "\n line must contain 36 items: eta, phi, depth, subdet, 32 bin values"
1514                                       << std::endl;
1515       continue;
1516     }
1517     DetId id = getId(items);
1518     fObject->sort();
1519     //    try {
1520     //    fObject->getCoder (id);
1521     //    edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1522     //    }
1523     //    catch (cms::Exception& e) {
1524     HcalCalibrationQIECoder coder(id.rawId());
1525     int index = 4;
1526     float values[32];
1527     for (unsigned bin = 0; bin < 32; bin++) {
1528       values[bin] = atof(items[index++].c_str());
1529     }
1530     coder.setMinCharges(values);
1531     fObject->addCoder(coder);
1532     //    }
1533   }
1534   fObject->sort();
1535   return true;
1536 }
1537 
1538 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalCalibrationQIEData& fObject) {
1539   char buffer[1024];
1540   fOutput << "# QIE data in calibration mode" << std::endl;
1541   sprintf(buffer, "# %15s %15s %15s %15s %288s\n", "eta", "phi", "dep", "det", "32 x charges");
1542   fOutput << buffer;
1543   std::vector<DetId> channels = fObject.getAllChannels();
1544   std::sort(channels.begin(), channels.end(), DetIdLess());
1545   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
1546     const HcalCalibrationQIECoder* coder = fObject.getCoder(*channel);
1547     if (coder) {
1548       dumpId(fOutput, *channel);
1549       const float* lowEdge = coder->minCharges();
1550       for (unsigned bin = 0; bin < 32; bin++) {
1551         sprintf(buffer, " %8.5f", lowEdge[bin]);
1552         fOutput << buffer;
1553       }
1554       fOutput << std::endl;
1555     }
1556   }
1557   return true;
1558 }
1559 
1560 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1561 namespace HcalDbASCIIIO {
1562   template <>
1563   std::unique_ptr<HcalElectronicsMap> createObject<HcalElectronicsMap>(std::istream& fInput) {
1564     HcalElectronicsMapAddons::Helper fObjectHelper;
1565     char buffer[1024];
1566     while (fInput.getline(buffer, 1024)) {
1567       if (buffer[0] == '#')
1568         continue;  //ignore comment
1569       std::vector<std::string> items = splitString(std::string(buffer));
1570       if (items.size() < 12) {
1571         if (items.empty())
1572           continue;  // no warning here
1573         if (items.size() < 9) {
1574           edm::LogError("MapFormat") << "HcalElectronicsMap-> line too short: " << buffer;
1575           continue;
1576         }
1577         if (items[8] == "NA" || items[8] == "NT") {
1578           while (items.size() < 12)
1579             items.push_back("");  // don't worry here
1580         } else if (items[8] == "HT") {
1581           if (items.size() == 11)
1582             items.push_back("");
1583           else {
1584             edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer
1585                                        << "\n HT line must contain at least 11 items: i  cr sl tb dcc spigot fiber "
1586                                           "fiberchan subdet=HT ieta iphi";
1587             continue;
1588           }
1589         } else {
1590           edm::LogError("MapFormat")
1591               << "HcalElectronicsMap-> Bad line: " << buffer
1592               << "\n line must contain 12 items: i  cr sl tb dcc spigot fiber fiberchan subdet ieta iphi depth";
1593           continue;
1594         }
1595       }
1596       int crate = atoi(items[1].c_str());
1597       int slot = atoi(items[2].c_str());
1598       int top = 1;
1599       if (items[3] == "b")
1600         top = 0;
1601       int dcc = atoi(items[4].c_str());
1602       int spigot = atoi(items[5].c_str());
1603       HcalElectronicsId elId;
1604       if (items[3][0] == 'u') {  // uTCA!
1605         int fiber = atoi(items[6].c_str());
1606         int fiberCh = atoi(items[7].c_str());
1607         bool isTrig = (items[8] == "HT" || items[8] == "NT");
1608         elId = HcalElectronicsId(crate, slot, fiber, fiberCh, isTrig);
1609       } else if (items[8] == "HT" || items[8] == "NT") {
1610         int slb = atoi(items[6].c_str());
1611         int slbCh = atoi(items[7].c_str());
1612         elId = HcalElectronicsId(slbCh, slb, spigot, dcc, crate, slot, top);
1613       } else {
1614         int fiber = atoi(items[6].c_str());
1615         int fiberCh = atoi(items[7].c_str());
1616 
1617         elId = HcalElectronicsId(fiberCh, fiber, spigot, dcc);
1618         elId.setHTR(crate, slot, top);
1619       }
1620 
1621       // first, handle undefined cases
1622       if (items[8] == "NA") {  // undefined channel
1623         fObjectHelper.mapEId2chId(elId, DetId(HcalDetId::Undefined));
1624       } else if (items[8] == "NT") {  // undefined trigger channel
1625         fObjectHelper.mapEId2tId(elId, DetId(HcalTrigTowerDetId::Undefined));
1626       } else {
1627         HcalText2DetIdConverter converter(items[8], items[9], items[10], items[11]);
1628         if (converter.isHcalDetId() or converter.isHcalCalibDetId() or converter.isHcalZDCDetId()) {
1629           fObjectHelper.mapEId2chId(elId, converter.getId());
1630         } else if (converter.isHcalTrigTowerDetId()) {
1631           fObjectHelper.mapEId2tId(elId, converter.getId());
1632         } else {
1633           edm::LogWarning("Format Error") << "HcalElectronicsMap-> Unknown subdetector: " << items[8] << '/' << items[9]
1634                                           << '/' << items[10] << '/' << items[11] << std::endl;
1635         }
1636       }
1637     }
1638     auto fObject = std::make_unique<HcalElectronicsMap>(fObjectHelper);
1639     return fObject;
1640   }
1641 }  // namespace HcalDbASCIIIO
1642 
1643 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalElectronicsMap& fObject) {
1644   std::vector<HcalElectronicsId> eids = fObject.allElectronicsId();
1645   char buf[1024];
1646   // changes by Jared, 6.03.09/(included 25.03.09)
1647   //  sprintf (buf, "#%10s %6s %6s %6s %6s %6s %6s %6s %15s %15s %15s %15s",
1648   sprintf(buf,
1649           "# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
1650           "i",
1651           "cr",
1652           "sl",
1653           "tb",
1654           "dcc",
1655           "spigot",
1656           "fiber/slb",
1657           "fibcha/slbcha",
1658           "subdet",
1659           "ieta",
1660           "iphi",
1661           "depth");
1662   fOutput << buf << std::endl;
1663 
1664   for (unsigned i = 0; i < eids.size(); i++) {
1665     HcalElectronicsId eid = eids[i];
1666     if (eid.isTriggerChainId()) {
1667       DetId trigger = fObject.lookupTrigger(eid);
1668       if (trigger.rawId()) {
1669         HcalText2DetIdConverter converter(trigger);
1670         if (eid.isVMEid()) {
1671           // changes by Jared, 6.03.09/(included 25.03.09)
1672           //    sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
1673           sprintf(
1674               buf,
1675               " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
1676               //         i,
1677               converter.getId().rawId(),
1678               // changes by Jared, 6.03.09/(included 25.03.09)
1679               //         eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
1680               eid.readoutVMECrateId(),
1681               eid.htrSlot(),
1682               eid.htrTopBottom() > 0 ? 't' : 'b',
1683               eid.dccid(),
1684               eid.spigot(),
1685               eid.slbSiteNumber(),
1686               eid.slbChannelIndex(),
1687               converter.getFlavor().c_str(),
1688               converter.getField1().c_str(),
1689               converter.getField2().c_str(),
1690               converter.getField3().c_str());
1691           fOutput << buf << std::endl;
1692         } else if (eid.isUTCAid()) {
1693           sprintf(buf,
1694                   " %7X %3d %3d   u %4d %7d %10d %14d %7s %5s %5s %6s",
1695                   converter.getId().rawId(),
1696                   //                    eid.crateId(), eid.slot(), 0, eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
1697                   eid.crateId(),
1698                   eid.slot(),
1699                   0,
1700                   0,
1701                   eid.fiberIndex(),
1702                   eid.fiberChanId(),
1703                   converter.getFlavor().c_str(),
1704                   converter.getField1().c_str(),
1705                   converter.getField2().c_str(),
1706                   converter.getField3().c_str());
1707           fOutput << buf << std::endl;
1708         } else {
1709           sprintf(buf, "NOT SUPPORTED!");
1710           fOutput << buf << std::endl;
1711         }
1712       }
1713     } else {
1714       DetId channel = fObject.lookup(eid);
1715       if (channel.rawId()) {
1716         HcalText2DetIdConverter converter(channel);
1717         if (eid.isVMEid()) {
1718           // changes by Jared, 6.03.09/(included 25.03.09)
1719           //    sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
1720           sprintf(buf,
1721                   " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
1722                   //         i,
1723                   converter.getId().rawId(),
1724                   eid.readoutVMECrateId(),
1725                   eid.htrSlot(),
1726                   eid.htrTopBottom() > 0 ? 't' : 'b',
1727                   eid.dccid(),
1728                   eid.spigot(),
1729                   eid.fiberIndex(),
1730                   eid.fiberChanId(),
1731                   converter.getFlavor().c_str(),
1732                   converter.getField1().c_str(),
1733                   converter.getField2().c_str(),
1734                   converter.getField3().c_str());
1735         } else {
1736           sprintf(buf,
1737                   " %7X %3d %3d   u %4d %7d %10d %14d %7s %5s %5s %6s",
1738                   //         i,
1739                   converter.getId().rawId(),
1740                   //           eid.crateId(), eid.slot(), 0, eid.slot(), eid.fiberIndex(), eid.fiberChanId(),
1741                   eid.crateId(),
1742                   eid.slot(),
1743                   0,
1744                   0,
1745                   eid.fiberIndex(),
1746                   eid.fiberChanId(),
1747                   converter.getFlavor().c_str(),
1748                   converter.getField1().c_str(),
1749                   converter.getField2().c_str(),
1750                   converter.getField3().c_str());
1751         }
1752         fOutput << buf << std::endl;
1753       }
1754     }
1755   }
1756   return true;
1757 }
1758 
1759 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalLutMetadata* fObject) {
1760   if (!fObject)
1761     return false;  //fObject = new HcalLutMetadata;
1762   char buffer[1024];
1763   while (fInput.getline(buffer, 1024)) {
1764     if (buffer[0] == '#')
1765       continue;  //ignore comment
1766     std::vector<std::string> items = splitString(std::string(buffer));
1767     if (items.empty())
1768       continue;  // blank line
1769     // now get non-channel data
1770     if (items.size() > 1 && items[0].find("RctLsb") != std::string::npos) {
1771       fObject->setRctLsb(atof(items[1].c_str()));
1772       continue;
1773     }
1774     if (items.size() > 1 && items[0].find("Gain") != std::string::npos) {
1775       fObject->setNominalGain(atof(items[1].c_str()));
1776       continue;
1777     }
1778     // now proceeed to per-channel data
1779     if (items.size() < 7) {
1780       edm::LogWarning("Format Error")
1781           << "Bad line: " << buffer
1782           << "\n line must contain 7 items: eta, phi, depth, subdet, Rcalib, LutGranularity, OutputLutThreshold"
1783           << std::endl;
1784       continue;
1785     }
1786     DetId id = getId(items);
1787 
1788     HcalLutMetadatum* fCondObject =
1789         new HcalLutMetadatum(id, atof(items[4].c_str()), atoi(items[5].c_str()), atoi(items[6].c_str()));
1790     fObject->addValues(*fCondObject);
1791     delete fCondObject;
1792   }
1793   return true;
1794 }
1795 
1796 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalLutMetadata& fObject) {
1797   char buffer[1024];
1798   const float _rctLsb = fObject.getRctLsb();
1799   const float _gain = fObject.getNominalGain();
1800   sprintf(buffer, "# %20s\n", "Non-channel data");
1801   fOutput << buffer;
1802   sprintf(buffer, "%8s %8.5f\n", "RctLsb", _rctLsb);
1803   fOutput << buffer;
1804   sprintf(buffer, "%8s %8.5f\n", "Gain", _gain);
1805   fOutput << buffer;
1806   sprintf(buffer,
1807           "# %15s %15s %15s %15s %8s %15s %19s %10s\n",
1808           "eta",
1809           "phi",
1810           "dep",
1811           "det",
1812           "Rcalib",
1813           "LutGranularity",
1814           "OutputLutThreshold",
1815           "DetId");
1816   fOutput << buffer;
1817   std::vector<DetId> channels = fObject.getAllChannels();
1818   std::sort(channels.begin(), channels.end(), DetIdLess());
1819   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
1820     const float _rCalib = fObject.getValues(*channel)->getRCalib();
1821     const uint8_t _lutGranularity = fObject.getValues(*channel)->getLutGranularity();
1822     const uint8_t _outputLutThreshold = fObject.getValues(*channel)->getOutputLutThreshold();
1823     dumpId(fOutput, *channel);
1824     sprintf(buffer, " %8.5f %15d %19d %10X\n", _rCalib, _lutGranularity, _outputLutThreshold, channel->rawId());
1825     fOutput << buffer;
1826   }
1827   return true;
1828 }
1829 
1830 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1831 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalDcsValues* fObject) {
1832   if (!fObject)
1833     return false;  //fObject = new HcalDcsValues;
1834   std::string buffer;
1835   while (getline(fInput, buffer)) {
1836     if (buffer.at(0) == '#')
1837       continue;  //ignore comment
1838     std::vector<std::string> items = splitString(buffer);
1839     if (items.empty())
1840       continue;  // blank line
1841 
1842     if (items.size() < 9) {
1843       edm::LogWarning("Format Error") << "Bad line: " << buffer
1844                                       << "\n line must contain 9 items: subDet, side_ring, slice, type, subChannel, "
1845                                          "LS, Value, UpperLimit, LowerLimit"
1846                                       << std::endl;
1847       continue;
1848     }
1849 
1850     HcalOtherSubdetector subd;
1851     int sidering;
1852     unsigned int slice, subchan;
1853     switch (items[0].at(1)) {
1854       case 'B':
1855         subd = HcalDcsBarrel;
1856         break;
1857       case 'E':
1858         subd = HcalDcsEndcap;
1859         break;
1860       case 'F':
1861         subd = HcalDcsForward;
1862         break;
1863       case 'O':
1864         subd = HcalDcsOuter;
1865         break;
1866       default:
1867         continue;
1868     }
1869     //from_string<int>(subd, items[0], std::dec);
1870     from_string<int>(sidering, items[1], std::dec);
1871     from_string<unsigned int>(slice, items[2], std::dec);
1872     //from_string<int>(ty, items[3], std::dec);
1873     from_string<unsigned int>(subchan, items[4], std::dec);
1874 
1875     HcalDcsDetId newId(subd, sidering, slice, HcalDcsDetId::DcsTypeFromString(items[3]), subchan);
1876 
1877     int LS;
1878     float val, upper, lower;
1879     from_string<int>(LS, items[5], std::dec);
1880     from_string<float>(val, items[6], std::dec);
1881     from_string<float>(upper, items[7], std::dec);
1882     from_string<float>(lower, items[8], std::dec);
1883 
1884     HcalDcsValue newVal(newId.rawId(), LS, val, upper, lower);
1885     //     std::cout << buffer << '\n';
1886     //     std::cout << subd << ' ' << sidering << ' ' << slice << ' '
1887     //        << ty << ' ' << subchan << ' ' << LS << ' '
1888     //        << val << ' ' << upper << ' ' << lower << '\n';
1889     //     std::cout << newId ;
1890     if (!(fObject->addValue(newVal))) {
1891       edm::LogWarning("Data Error") << "Data from line " << buffer << "\nwas not added to the HcalDcsValues object."
1892                                     << std::endl;
1893     }
1894     //     std::cout << std::endl;
1895   }
1896   fObject->sortAll();
1897   return true;
1898 }
1899 
1900 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, HcalDcsValues const& fObject) {
1901   fOutput << "# subDet side_ring slice type subChan LS Value UpperLimit LowerLimit DcsId\n";
1902   for (int subd = HcalDcsValues::HcalHB; subd <= HcalDcsValues::HcalHF; ++subd) {
1903     //     std::cout << "subd: " << subd << '\n';
1904     HcalDcsValues::DcsSet const& vals = fObject.getAllSubdetValues(HcalDcsValues::DcsSubDet(subd));
1905     for (HcalDcsValues::DcsSet::const_iterator val = vals.begin(); val != vals.end(); ++val) {
1906       HcalDcsDetId valId(val->DcsId());
1907 
1908       switch (valId.subdet()) {
1909         case HcalDcsBarrel:
1910           fOutput << "HB ";
1911           break;
1912         case HcalDcsEndcap:
1913           fOutput << "HE ";
1914           break;
1915         case HcalDcsOuter:
1916           fOutput << "HO ";
1917           break;
1918         case HcalDcsForward:
1919           fOutput << "HF ";
1920           break;
1921         default:
1922           fOutput << valId.subdet() << ' ';
1923       }
1924 
1925       if (valId.subdet() == HcalDcsOuter)
1926         fOutput << valId.ring() << ' ';
1927       else
1928         fOutput << valId.zside() << ' ';
1929 
1930       fOutput << valId.slice() << ' ' << valId.typeString(valId.type()) << ' ' << valId.subchannel() << ' ';
1931       fOutput << val->LS() << ' ' << val->getValue() << ' ' << val->getUpperLimit() << ' ' << val->getLowerLimit()
1932               << ' ';
1933       fOutput << std::hex << val->DcsId() << std::dec << '\n';
1934 
1935       //       std::cout << valId << ' '
1936       //        << valId.subdet() << ' '
1937       //        << val->LS() << ' ' << val->getValue() << ' '
1938       //        << val->getUpperLimit() << ' ' << val->getLowerLimit()
1939       //        << std::endl;
1940     }
1941   }
1942 
1943   return true;
1944 }
1945 
1946 // Format of the ASCII file:
1947 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
1948 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1949 namespace HcalDbASCIIIO {
1950   template <>
1951   std::unique_ptr<HcalDcsMap> createObject<HcalDcsMap>(std::istream& fInput) {
1952     char buffer[1024];
1953     HcalDcsMapAddons::Helper fObjectHelper;
1954     while (fInput.getline(buffer, 1024)) {
1955       if (buffer[0] == '#')
1956         continue;  //ignore comment
1957       std::vector<std::string> items = splitString(std::string(buffer));
1958       if (items.size() < 8) {
1959         if (items.empty())
1960           continue;  // no warning here
1961         else {
1962           edm::LogError("MapFormat")
1963               << "HcalDcsMap-> Bad line: " << buffer
1964               << "\n line must contain 8 items: line side_ring slice subchannel subdet ieta iphi depth";
1965           continue;
1966         }
1967       }
1968       int ring = atoi(items[1].c_str());
1969       unsigned int slice = atoi(items[2].c_str());
1970       unsigned int subchannel = atoi(items[3].c_str());
1971       HcalDcsDetId::DcsType type = HcalDcsDetId::DCSUNKNOWN;
1972       HcalOtherSubdetector subdet = HcalOtherEmpty;
1973       if (items[4].find("CALIB") != std::string::npos) {
1974         subdet = HcalCalibration;
1975       } else if (items[4].find("HB") != std::string::npos) {
1976         subdet = HcalDcsBarrel;
1977       } else if (items[4].find("HE") != std::string::npos) {
1978         subdet = HcalDcsEndcap;
1979       } else if (items[4].find("HO") != std::string::npos) {
1980         subdet = HcalDcsOuter;
1981       } else if (items[4].find("HF") != std::string::npos) {
1982         subdet = HcalDcsForward;
1983       } else {
1984         edm::LogError("MapFormat") << "HcalDcsMap-> Unknown subdetector, line is not accepted: " << items[5];
1985         continue;
1986       }
1987       HcalDcsDetId dcsId(subdet, ring, slice, type, subchannel);
1988       HcalText2DetIdConverter converter(items[4], items[5], items[6], items[7]);
1989       HcalDetId id(0);
1990       if (converter.isHcalDetId()) {
1991         id = converter.getId();
1992       } else {
1993         edm::LogWarning("Invalid HCAL channel") << "HcalDcsMap-> invalid channel: " << items[4] << '/' << items[5]
1994                                                 << '/' << items[6] << '/' << items[7] << std::endl;
1995         continue;
1996       }
1997       fObjectHelper.mapGeomId2DcsId(id, dcsId);
1998     }
1999     auto fObject = std::make_unique<HcalDcsMap>(fObjectHelper);
2000     return fObject;
2001   }
2002 }  // namespace HcalDbASCIIIO
2003 
2004 // Format of the ASCII file:
2005 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
2006 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2007 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalDcsMap& fObject) {
2008   char buf[1024];
2009   sprintf(buf,
2010           "# %7s %10s %6s %8s %7s %5s %5s %6s",
2011           "i",
2012           "side_ring",
2013           "slice",
2014           "subchan",
2015           "subdet",
2016           "ieta",
2017           "iphi",
2018           "depth");
2019   fOutput << buf << std::endl;
2020   HcalDcsMap::const_iterator _line;
2021   unsigned int line_counter = 0;
2022   for (_line = fObject.beginById(); _line != fObject.endById(); ++_line) {
2023     HcalDcsDetId dcsId = _line.getHcalDcsDetId();
2024     //std::string _dcs_type = "DCSUNKNOWN";
2025     HcalText2DetIdConverter _converter(_line.getHcalDetId());
2026     sprintf(buf,
2027             " %8X %10d %6d %8d %7s %5s %5s %6s",
2028             line_counter,
2029             dcsId.ring(),  // contains zside() already
2030             dcsId.slice(),
2031             dcsId.subchannel(),
2032             _converter.getFlavor().c_str(),
2033             _converter.getField1().c_str(),
2034             _converter.getField2().c_str(),
2035             _converter.getField3().c_str());
2036     fOutput << buf << std::endl;
2037     ++line_counter;
2038   }
2039   return true;
2040 }
2041 
2042 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalFlagHFDigiTimeParams* fObject) {
2043   if (!fObject)
2044     return false;  //fObject = new HcalFlagHFDigiTimeParams();
2045   char buffer[1024];
2046   while (fInput.getline(buffer, 1024)) {
2047     if (buffer[0] == '#')
2048       continue;  //ignore comment
2049     std::vector<std::string> items = splitString(std::string(buffer));
2050     if (items.empty())
2051       continue;  // blank line
2052     if (items.size() != 9) {
2053       edm::LogWarning("Format Error")
2054           << "Bad line: " << buffer
2055           << "\n line must contain at 9 least items: eta, phi, depth, subdet, firstSample, samplesToAdd, ExpectedPeak, "
2056              "MinEnergy, and a set of comma-separated coefficients"
2057           << std::endl;
2058       continue;
2059     }
2060     // expects (ieta, iphi, depth, subdet) as first four arguments
2061     DetId id = HcalDbASCIIIO::getId(items);
2062     std::vector<double> coef = splitStringToDoubleByComma(items[8]);
2063 
2064     HcalFlagHFDigiTimeParam* fCondObject = new HcalFlagHFDigiTimeParam(id,
2065                                                                        atoi(items[4].c_str()),  //firstSample
2066                                                                        atoi(items[5].c_str()),  //samplesToAdd
2067                                                                        atoi(items[6].c_str()),  //expectedPeak
2068                                                                        atof(items[7].c_str()),  // minEThreshold
2069                                                                        coef                     // coefficients
2070     );
2071     fObject->addValues(*fCondObject);
2072     delete fCondObject;
2073   }
2074   return true;
2075 }  // getObject (HcalFlagHFDigiTime)
2076 
2077 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalFlagHFDigiTimeParams& fObject) {
2078   char buffer[1024];
2079   sprintf(buffer,
2080           "# %15s %15s %15s %15s  %15s %15s %15s %15s %30s\n",
2081           "eta",
2082           "phi",
2083           "dep",
2084           "det",
2085           "FirstSample",
2086           "SamplesToAdd",
2087           "ExpectedPeak",
2088           "MinEnergy",
2089           "Coefficients");
2090   fOutput << buffer;
2091   std::vector<DetId> channels = fObject.getAllChannels();
2092   std::sort(channels.begin(), channels.end(), DetIdLess());
2093   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
2094     // Dump out channel (ieta,iphi,depth,subdet) info
2095     HcalDbASCIIIO::dumpId(fOutput, *channel);
2096     // Dump out values for channel
2097     sprintf(buffer,
2098             " %15u %15u %15u %15f",
2099             fObject.getValues(*channel)->HFdigiflagFirstSample(),
2100             fObject.getValues(*channel)->HFdigiflagSamplesToAdd(),
2101             fObject.getValues(*channel)->HFdigiflagExpectedPeak(),
2102             fObject.getValues(*channel)->HFdigiflagMinEThreshold());
2103 
2104     fOutput << buffer;             // dump flag reco values to buffer
2105     fOutput << "               ";  // simple spacer
2106 
2107     std::vector<double> coef = fObject.getValues(*channel)->HFdigiflagCoefficients();
2108     for (std::vector<double>::size_type x = 0; x < coef.size(); ++x) {
2109       // dump comma-separated list of coefficients
2110       fOutput << coef[x];
2111       if (x < coef.size() - 1)  // add commas where necessary
2112         fOutput << ",";
2113     }
2114     sprintf(buffer, "\n");
2115     fOutput << buffer;
2116   }
2117   return true;
2118 }
2119 
2120 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2121 namespace HcalDbASCIIIO {
2122   template <>
2123   std::unique_ptr<HcalFrontEndMap> createObject<HcalFrontEndMap>(std::istream& fInput) {
2124     char buffer[1024];
2125     HcalFrontEndMapAddons::Helper fObjectHelper;
2126     unsigned int all(0), good(0);
2127     while (fInput.getline(buffer, 1024)) {
2128       ++all;
2129       if (buffer[0] == '#')
2130         continue;  //ignore comment
2131       std::vector<std::string> items = splitString(std::string(buffer));
2132       if (items.size() != 6) {
2133         edm::LogError("Format Error") << "HcalFrontEndMap-> line ignored: " << buffer;
2134         continue;
2135       }
2136       ++good;
2137       DetId id = HcalDbASCIIIO::getId(items);
2138       int rm = atoi(items[5].c_str());
2139       fObjectHelper.loadObject(id, rm, items[4]);
2140     }
2141     edm::LogInfo("MapFormat") << "HcalFrontEndMap:: processed " << good << " records in " << all << " record"
2142                               << std::endl;
2143     auto fObject = std::make_unique<HcalFrontEndMap>(fObjectHelper);
2144     return fObject;
2145   }
2146 }  // namespace HcalDbASCIIIO
2147 
2148 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalFrontEndMap& fObject) {
2149   char buffer[1024];
2150   sprintf(buffer, "# %15s %15s %15s %15s %8s %8s\n", "eta", "phi", "dep", "det", "rbx", "rm");
2151   fOutput << buffer;
2152 
2153   std::vector<DetId> channels = fObject.allDetIds();
2154   std::sort(channels.begin(), channels.end(), DetIdLess());
2155   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
2156     const std::string rbx = fObject.lookupRBX(*channel);
2157     const int rm = fObject.lookupRM(*channel);
2158     dumpId(fOutput, *channel);
2159     sprintf(buffer, " %8s %8d \n", rbx.c_str(), rm);
2160     fOutput << buffer;
2161   }
2162   return true;
2163 }
2164 
2165 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2166 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalSiPMParameters* fObject) {
2167   if (!fObject)
2168     return false;
2169   char buffer[1024];
2170   while (fInput.getline(buffer, 1024)) {
2171     if (buffer[0] == '#')
2172       continue;  //ignore comment
2173     std::vector<std::string> items = splitString(std::string(buffer));
2174     if (items.empty())
2175       continue;  // blank line
2176     if (items.size() < 9) {
2177       edm::LogWarning("Format Error") << "Bad line: " << buffer
2178                                       << "\n line must contain 9 items: eta, phi, depth, subdet, 5x values"
2179                                       << std::endl;
2180       continue;
2181     }
2182     DetId id = HcalDbASCIIIO::getId(items);
2183 
2184     HcalSiPMParameter* obj = new HcalSiPMParameter(id,
2185                                                    atoi(items[4].c_str()),
2186                                                    atof(items[5].c_str()),
2187                                                    atof(items[6].c_str()),
2188                                                    atoi(items[7].c_str()),
2189                                                    atof(items[8].c_str()));
2190     fObject->addValues(*obj);
2191     delete obj;
2192   }
2193   return true;
2194 }
2195 
2196 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalSiPMParameters& fObject) {
2197   char buffer[1024];
2198   sprintf(buffer,
2199           "# %15s %15s %15s %15s %8s %15s %15s %8s %15s\n",
2200           "eta",
2201           "phi",
2202           "dep",
2203           "det",
2204           "type",
2205           "fcByPE",
2206           "darkCurrent",
2207           "auxi1",
2208           "auxi2");
2209   fOutput << buffer;
2210   std::vector<DetId> channels = fObject.getAllChannels();
2211   std::sort(channels.begin(), channels.end(), DetIdLess());
2212   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
2213     const int type = fObject.getValues(*channel)->getType();
2214     const float fcByPE = fObject.getValues(*channel)->getFCByPE();
2215     const float darkC = fObject.getValues(*channel)->getDarkCurrent();
2216     const int auxi1 = fObject.getValues(*channel)->getauxi1();
2217     const float auxi2 = fObject.getValues(*channel)->getauxi2();
2218     HcalDbASCIIIO::dumpId(fOutput, *channel);
2219     sprintf(buffer, " %8d %15.6f %15.6f %8d %15.6f\n", type, fcByPE, darkC, auxi1, auxi2);
2220     fOutput << buffer;
2221   }
2222   return true;
2223 }
2224 
2225 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2226 namespace HcalDbASCIIIO {
2227   template <>
2228   std::unique_ptr<HcalSiPMCharacteristics> createObject<HcalSiPMCharacteristics>(std::istream& fInput) {
2229     char buffer[1024];
2230     HcalSiPMCharacteristicsAddons::Helper fObjectHelper;
2231     unsigned int all(0), good(0);
2232     while (fInput.getline(buffer, 1024)) {
2233       ++all;
2234       if (buffer[0] == '#')
2235         continue;  //ignore comment
2236       std::vector<std::string> items = splitString(std::string(buffer));
2237       if (items.size() != 8) {
2238         edm::LogError("MapFormat") << "HcalSiPMCharacteristics-> line ignored: " << buffer;
2239         continue;
2240       }
2241       ++good;
2242       //    std::cout << "HcalSiPMCharacteristics-> processing line: " << buffer << std::endl;
2243       int type = atoi(items[0].c_str());
2244       int pixels = atoi(items[1].c_str());
2245       float parL0 = atof(items[2].c_str());
2246       float parL1 = atof(items[3].c_str());
2247       float parL2 = atof(items[4].c_str());
2248       float cTalk = atof(items[5].c_str());
2249       int auxi1 = atoi(items[6].c_str());
2250       float auxi2 = atof(items[7].c_str());
2251       fObjectHelper.loadObject(type, pixels, parL0, parL1, parL2, cTalk, auxi1, auxi2);
2252     }
2253     edm::LogInfo("MapFormat") << "HcalSiPMCharacteristics:: processed " << good << " records in " << all << " record"
2254                               << std::endl;
2255     auto fObject = std::make_unique<HcalSiPMCharacteristics>(fObjectHelper);
2256     return fObject;
2257   }
2258 }  // namespace HcalDbASCIIIO
2259 
2260 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalSiPMCharacteristics& fObject) {
2261   char buffer[1024];
2262   sprintf(buffer,
2263           "# %8s %8s %15s %15s %15s %15s %8s %15s\n",
2264           "type",
2265           "pixels",
2266           "parLin1",
2267           "parLin2",
2268           "parLin3",
2269           "crossTalk",
2270           "auxi1",
2271           "auxi2");
2272   fOutput << buffer;
2273 
2274   unsigned int size = fObject.getTypes();
2275   for (unsigned int k = 0; k < size; ++k) {
2276     const int type = fObject.getType(k);
2277     const int pixels = fObject.getPixels(type);
2278     const std::vector<float> pars = fObject.getNonLinearities(type);
2279     const float cTalk = fObject.getCrossTalk(type);
2280     const int auxi1 = fObject.getAuxi1(type);
2281     const float auxi2 = fObject.getAuxi2(type);
2282     const float par0 = (!pars.empty()) ? pars[0] : 0;
2283     const float par1 = (pars.size() > 1) ? pars[1] : 0;
2284     const float par2 = (pars.size() > 2) ? pars[2] : 0;
2285     sprintf(
2286         buffer, " %8d %8d %15.6e %15.6e %15.6e %15.6f %8d %15.6f\n", type, pixels, par0, par1, par2, cTalk, auxi1, auxi2);
2287     fOutput << buffer;
2288   }
2289   return true;
2290 }
2291 
2292 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2293 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalTPChannelParameters* fObject) {
2294   if (!fObject)
2295     return false;
2296   char buffer[1024];
2297   while (fInput.getline(buffer, 1024)) {
2298     if (buffer[0] == '#')
2299       continue;  //ignore comment
2300     std::vector<std::string> items = splitString(std::string(buffer));
2301     if (items.empty())
2302       continue;  // blank line
2303     if (items.size() < 8) {
2304       edm::LogWarning("Format Error") << "Bad line: " << buffer
2305                                       << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
2306                                       << std::endl;
2307       continue;
2308     }
2309     DetId id = HcalDbASCIIIO::getId(items);
2310 
2311     HcalTPChannelParameter* obj = new HcalTPChannelParameter(
2312         id.rawId(), atoi(items[4].c_str()), atoi(items[5].c_str()), atoi(items[6].c_str()), atoi(items[7].c_str()));
2313     fObject->addValues(*obj);
2314     delete obj;
2315   }
2316   return true;
2317 }
2318 
2319 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalTPChannelParameters& fObject) {
2320   char buffer[1024];
2321   sprintf(buffer,
2322           "# %15s %15s %15s %15s %15s %15s %15s %15s\n",
2323           "eta",
2324           "phi",
2325           "dep",
2326           "det",
2327           "Mask",
2328           "FGBitInfo",
2329           "auxi1",
2330           "auxi2");
2331   fOutput << buffer;
2332   std::vector<DetId> channels = fObject.getAllChannels();
2333   std::sort(channels.begin(), channels.end(), DetIdLess());
2334   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
2335     const uint32_t mask = fObject.getValues(*channel)->getMask();
2336     const uint32_t fgBitInfo = fObject.getValues(*channel)->getFGBitInfo();
2337     const int auxi1 = fObject.getValues(*channel)->getauxi1();
2338     const int auxi2 = fObject.getValues(*channel)->getauxi2();
2339     HcalDbASCIIIO::dumpId(fOutput, *channel);
2340     sprintf(buffer, " %15d %15d %15d %15d \n", mask, fgBitInfo, auxi1, auxi2);
2341     fOutput << buffer;
2342   }
2343   return true;
2344 }
2345 
2346 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2347 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalTPParameters* fObject) {
2348   char buffer[1024];
2349   unsigned int all(0), good(0);
2350   while (fInput.getline(buffer, 1024)) {
2351     ++all;
2352     if (buffer[0] == '#')
2353       continue;  //ignore comment
2354     std::vector<std::string> items = splitString(std::string(buffer));
2355     if (items.size() != 6) {
2356       edm::LogError("Format Error") << "HcalTPParameters-> line ignored: " << buffer;
2357       continue;
2358     }
2359     ++good;
2360     //    std::cout << "HcalTPParameters-> processing line: " << buffer << std::endl;
2361     int version = atoi(items[0].c_str());
2362     int adcCut = atoi(items[1].c_str());
2363     uint64_t tdcMask = strtoull(items[2].c_str(), nullptr, 16);
2364     uint32_t tbits = atoi(items[3].c_str());
2365     int auxi1 = atoi(items[4].c_str());
2366     int auxi2 = atoi(items[5].c_str());
2367     fObject->loadObject(version, adcCut, tdcMask, tbits, auxi1, auxi2);
2368     break;
2369   }
2370   edm::LogInfo("MapFormat") << "HcalTPParameters:: processed " << good << " records in " << all << " record"
2371                             << std::endl;
2372   return true;
2373 }
2374 
2375 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalTPParameters& fObject) {
2376   char buffer[1024];
2377   sprintf(
2378       buffer, "# %15s %15s %16s %15s %15s %15s\n", "FGAlgo_HBHE", "ADCThrHF", "TDCMaskHF", "STBitsHF", "auxi1", "auxi2");
2379   fOutput << buffer;
2380 
2381   const int version = fObject.getFGVersionHBHE();
2382   const int adcCut = fObject.getADCThresholdHF();
2383   const uint64_t tdcMask = fObject.getTDCMaskHF();
2384   const uint32_t tbits = fObject.getHFTriggerInfo();
2385   const int auxi1 = fObject.getAuxi1();
2386   const int auxi2 = fObject.getAuxi2();
2387 
2388   sprintf(buffer, " %15d %15d  %16jx %15x %15d %15d\n", version, adcCut, tdcMask, tbits, auxi1, auxi2);
2389   fOutput << buffer;
2390 
2391   return true;
2392 }
2393 
2394 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2395 
2396 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalCalibrationsSet& fObject) {
2397   char buffer[1024];
2398   sprintf(buffer,
2399           "# %15s %15s %15s %15s %8s %8s %8s %8s %11s %11s %11s %11s %9s %9s %9s %9s %10s\n",
2400           "eta",
2401           "phi",
2402           "dep",
2403           "det",
2404           "pedcap0",
2405           "pedcap1",
2406           "pedcap2",
2407           "pedcap3",
2408           "effpedcap0",
2409           "effpedcap1",
2410           "effpedcap2",
2411           "effpedcap3",
2412           "gaincap0",
2413           "gaincap1",
2414           "gaincap2",
2415           "gaincap3",
2416           "DetId");
2417   fOutput << buffer;
2418 
2419   std::vector<DetId> channels = fObject.getAllChannels();
2420   std::sort(channels.begin(), channels.end(), DetIdLess());
2421   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
2422     dumpId(fOutput, *channel);
2423     const HcalCalibrations& values = fObject.getCalibrations(*channel);
2424     sprintf(buffer,
2425             " %8.5f %8.5f %8.5f %8.5f %11.5f %11.5f %11.5f %11.5f %9.5f %9.5f %9.5f %9.5f %10X\n",
2426             values.pedestal(0),
2427             values.pedestal(1),
2428             values.pedestal(2),
2429             values.pedestal(3),
2430             values.effpedestal(0),
2431             values.effpedestal(1),
2432             values.effpedestal(2),
2433             values.effpedestal(3),
2434             values.respcorrgain(0),
2435             values.respcorrgain(1),
2436             values.respcorrgain(2),
2437             values.respcorrgain(3),
2438             channel->rawId());
2439     fOutput << buffer;
2440   }
2441   return true;
2442 }
2443 
2444 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalCalibrationWidthsSet& fObject) {
2445   char buffer[1024];
2446   sprintf(buffer,
2447           "# %15s %15s %15s %15s %9s %9s %9s %9s %12s %12s %12s %12s %10s %10s %10s %10s %10s\n",
2448           "eta",
2449           "phi",
2450           "dep",
2451           "det",
2452           "pedwcap0",
2453           "pedwcap1",
2454           "pedwcap2",
2455           "pedwcap3",
2456           "effpedwcap0",
2457           "effpedwcap1",
2458           "effpedwcap2",
2459           "effpedwcap3",
2460           "gainwcap0",
2461           "gainwcap1",
2462           "gainwcap2",
2463           "gainwcap3",
2464           "DetId");
2465   fOutput << buffer;
2466 
2467   std::vector<DetId> channels = fObject.getAllChannels();
2468   std::sort(channels.begin(), channels.end(), DetIdLess());
2469   for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
2470     dumpId(fOutput, *channel);
2471     const HcalCalibrationWidths& values = fObject.getCalibrationWidths(*channel);
2472     sprintf(buffer,
2473             " %9.5f %9.5f %9.5f %9.5f %12.5f %12.5f %12.5f %12.5f %10.5f %10.5f %10.5f %10.5f %10X\n",
2474             values.pedestal(0),
2475             values.pedestal(1),
2476             values.pedestal(2),
2477             values.pedestal(3),
2478             values.effpedestal(0),
2479             values.effpedestal(1),
2480             values.effpedestal(2),
2481             values.effpedestal(3),
2482             values.gain(0),
2483             values.gain(1),
2484             values.gain(2),
2485             values.gain(3),
2486             channel->rawId());
2487     fOutput << buffer;
2488   }
2489   return true;
2490 }