Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-11 04:36:46

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