Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-15 04:27:41

0001 // user include files
0002 #include "EcalTrigPrimESProducer.h"
0003 
0004 #include <TMath.h>
0005 #include <fstream>
0006 #include <iostream>
0007 #include <sstream>
0008 
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 //
0012 // input stream from a gz file
0013 //
0014 
0015 struct GzInputStream {
0016   gzFile gzf;
0017   char buffer[256];
0018   std::istringstream iss;
0019   bool eof;
0020   GzInputStream(const char *file) : eof(false) {
0021     gzf = gzopen(file, "rb");
0022     if (gzf == Z_NULL) {
0023       eof = true;
0024       edm::LogWarning("EcalTPG") << "Database file " << file << " not found!!!";
0025     } else
0026       readLine();
0027   }
0028   void readLine() {
0029     char *res = gzgets(gzf, buffer, 256);
0030     eof = (res == Z_NULL);
0031     if (!eof) {
0032       iss.clear();
0033       iss.str(buffer);
0034       const auto content = iss.str();
0035       std::size_t found = content.find("COMMENT");
0036       if (found != std::string::npos) {
0037         iss.str("");
0038       }
0039     }
0040   }
0041   ~GzInputStream() { gzclose(gzf); }
0042   explicit operator bool() const { return ((eof == true) ? false : !iss.fail()); }
0043 };
0044 
0045 template <typename T>
0046 GzInputStream &operator>>(GzInputStream &gis, T &var) {
0047   while ((bool)gis && !(gis.iss >> var)) {
0048     gis.readLine();
0049   }
0050   return gis;
0051 }
0052 
0053 //
0054 // constructors and destructor
0055 //
0056 
0057 EcalTrigPrimESProducer::EcalTrigPrimESProducer(const edm::ParameterSet &iConfig)
0058     : dbFilename_(iConfig.getUntrackedParameter<std::string>("DatabaseFile", "")),
0059       flagPrint_(iConfig.getParameter<bool>("WriteInFile")) {
0060   // the following line is needed to tell the framework what
0061   // data is being produced
0062   setWhatProduced(this, &EcalTrigPrimESProducer::producePedestals);
0063   setWhatProduced(this, &EcalTrigPrimESProducer::produceLinearizationConst);
0064   setWhatProduced(this, &EcalTrigPrimESProducer::produceSlidingWindow);
0065   setWhatProduced(this, &EcalTrigPrimESProducer::produceFineGrainEB);
0066   setWhatProduced(this, &EcalTrigPrimESProducer::produceFineGrainEEstrip);
0067   setWhatProduced(this, &EcalTrigPrimESProducer::produceFineGrainEEtower);
0068   setWhatProduced(this, &EcalTrigPrimESProducer::produceLUT);
0069   setWhatProduced(this, &EcalTrigPrimESProducer::produceWeight);
0070   setWhatProduced(this, &EcalTrigPrimESProducer::produceWeightGroup);
0071   setWhatProduced(this, &EcalTrigPrimESProducer::produceOddWeight);
0072   setWhatProduced(this, &EcalTrigPrimESProducer::produceOddWeightGroup);
0073   setWhatProduced(this, &EcalTrigPrimESProducer::produceTPMode);
0074   setWhatProduced(this, &EcalTrigPrimESProducer::produceLutGroup);
0075   setWhatProduced(this, &EcalTrigPrimESProducer::produceFineGrainEBGroup);
0076   setWhatProduced(this, &EcalTrigPrimESProducer::producePhysicsConst);
0077   setWhatProduced(this, &EcalTrigPrimESProducer::produceBadX);
0078   setWhatProduced(this, &EcalTrigPrimESProducer::produceBadStrip);
0079   setWhatProduced(this, &EcalTrigPrimESProducer::produceBadTT);
0080   setWhatProduced(this, &EcalTrigPrimESProducer::produceSpike);
0081   // now do what ever other initialization is needed
0082   //init TPmode
0083   tpMode_ = std::vector<uint32_t>(18, 0);
0084 }
0085 
0086 EcalTrigPrimESProducer::~EcalTrigPrimESProducer() {}
0087 
0088 //
0089 // member functions
0090 //
0091 
0092 // ------------ method called to produce the data  ------------
0093 
0094 std::unique_ptr<EcalTPGPedestals> EcalTrigPrimESProducer::producePedestals(const EcalTPGPedestalsRcd &iRecord) {
0095   auto prod = std::make_unique<EcalTPGPedestals>();
0096   parseTextFile();
0097   std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0098   for (it = mapXtal_.begin(); it != mapXtal_.end(); it++) {
0099     EcalTPGPedestal item;
0100     item.mean_x12 = (it->second)[0];
0101     item.mean_x6 = (it->second)[3];
0102     item.mean_x1 = (it->second)[6];
0103     prod->setValue(it->first, item);
0104   }
0105   return prod;
0106 }
0107 
0108 std::unique_ptr<EcalTPGLinearizationConst> EcalTrigPrimESProducer::produceLinearizationConst(
0109     const EcalTPGLinearizationConstRcd &iRecord) {
0110   auto prod = std::make_unique<EcalTPGLinearizationConst>();
0111   parseTextFile();
0112   std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0113   for (it = mapXtal_.begin(); it != mapXtal_.end(); it++) {
0114     EcalTPGLinearizationConstant item;
0115     item.mult_x12 = (it->second)[1];
0116     item.mult_x6 = (it->second)[4];
0117     item.mult_x1 = (it->second)[7];
0118     item.shift_x12 = (it->second)[2];
0119     item.shift_x6 = (it->second)[5];
0120     item.shift_x1 = (it->second)[8];
0121     prod->setValue(it->first, item);
0122   }
0123   return prod;
0124 }
0125 
0126 std::unique_ptr<EcalTPGSlidingWindow> EcalTrigPrimESProducer::produceSlidingWindow(
0127     const EcalTPGSlidingWindowRcd &iRecord) {
0128   auto prod = std::make_unique<EcalTPGSlidingWindow>();
0129   parseTextFile();
0130   for (int subdet = 0; subdet < 2; subdet++) {
0131     std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0132     for (it = mapStrip_[subdet].begin(); it != mapStrip_[subdet].end(); it++) {
0133       prod->setValue(it->first, (it->second)[0]);
0134     }
0135   }
0136   return prod;
0137 }
0138 
0139 std::unique_ptr<EcalTPGFineGrainEBIdMap> EcalTrigPrimESProducer::produceFineGrainEB(
0140     const EcalTPGFineGrainEBIdMapRcd &iRecord) {
0141   auto prod = std::make_unique<EcalTPGFineGrainEBIdMap>();
0142   parseTextFile();
0143   EcalTPGFineGrainConstEB fg;
0144   std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0145   for (it = mapFg_.begin(); it != mapFg_.end(); it++) {
0146     fg.setValues((it->second)[0], (it->second)[1], (it->second)[2], (it->second)[3], (it->second)[4]);
0147     prod->setValue(it->first, fg);
0148   }
0149   return prod;
0150 }
0151 
0152 std::unique_ptr<EcalTPGFineGrainStripEE> EcalTrigPrimESProducer::produceFineGrainEEstrip(
0153     const EcalTPGFineGrainStripEERcd &iRecord) {
0154   auto prod = std::make_unique<EcalTPGFineGrainStripEE>();
0155   parseTextFile();
0156   // EE Strips
0157   std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0158   for (it = mapStrip_[1].begin(); it != mapStrip_[1].end(); it++) {
0159     EcalTPGFineGrainStripEE::Item item;
0160     item.threshold = (it->second)[3];
0161     item.lut = (it->second)[4];
0162     prod->setValue(it->first, item);
0163   }
0164   // EB Strips
0165   for (it = mapStrip_[0].begin(); it != mapStrip_[0].end(); it++) {
0166     EcalTPGFineGrainStripEE::Item item;
0167     item.threshold = (it->second)[3];
0168     item.lut = (it->second)[4];
0169     prod->setValue(it->first, item);
0170   }
0171   return prod;
0172 }
0173 
0174 std::unique_ptr<EcalTPGFineGrainTowerEE> EcalTrigPrimESProducer::produceFineGrainEEtower(
0175     const EcalTPGFineGrainTowerEERcd &iRecord) {
0176   auto prod = std::make_unique<EcalTPGFineGrainTowerEE>();
0177   parseTextFile();
0178   std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0179   for (it = mapTower_[1].begin(); it != mapTower_[1].end(); it++) {
0180     prod->setValue(it->first, (it->second)[1]);
0181   }
0182   return prod;
0183 }
0184 
0185 std::unique_ptr<EcalTPGLutIdMap> EcalTrigPrimESProducer::produceLUT(const EcalTPGLutIdMapRcd &iRecord) {
0186   auto prod = std::make_unique<EcalTPGLutIdMap>();
0187   parseTextFile();
0188   EcalTPGLut lut;
0189   std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0190   for (it = mapLut_.begin(); it != mapLut_.end(); it++) {
0191     unsigned int lutArray[1024];
0192     for (int i = 0; i < 1024; i++)
0193       lutArray[i] = (it->second)[i];
0194     lut.setLut(lutArray);
0195     prod->setValue(it->first, lut);
0196   }
0197   return prod;
0198 }
0199 
0200 std::unique_ptr<EcalTPGWeightIdMap> EcalTrigPrimESProducer::produceWeight(const EcalTPGWeightIdMapRcd &iRecord) {
0201   auto prod = std::make_unique<EcalTPGWeightIdMap>();
0202   parseTextFile();
0203   EcalTPGWeights weights;
0204   std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0205   for (it = mapWeight_.begin(); it != mapWeight_.end(); it++) {
0206     weights.setValues((it->second)[0], (it->second)[1], (it->second)[2], (it->second)[3], (it->second)[4]);
0207     prod->setValue(it->first, weights);
0208   }
0209   return prod;
0210 }
0211 
0212 std::unique_ptr<EcalTPGWeightGroup> EcalTrigPrimESProducer::produceWeightGroup(const EcalTPGWeightGroupRcd &iRecord) {
0213   auto prod = std::make_unique<EcalTPGWeightGroup>();
0214   parseTextFile();
0215   for (int subdet = 0; subdet < 2; subdet++) {
0216     std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0217     for (it = mapStrip_[subdet].begin(); it != mapStrip_[subdet].end(); it++) {
0218       prod->setValue(it->first, (it->second)[1]);
0219     }
0220   }
0221   return prod;
0222 }
0223 
0224 std::unique_ptr<EcalTPGOddWeightIdMap> EcalTrigPrimESProducer::produceOddWeight(
0225     const EcalTPGOddWeightIdMapRcd &iRecord) {
0226   auto prod = std::make_unique<EcalTPGOddWeightIdMap>();
0227   parseTextFile();
0228   EcalTPGWeights weights;
0229   std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0230   for (it = mapWeight_odd_.begin(); it != mapWeight_odd_.end(); it++) {
0231     weights.setValues((it->second)[0], (it->second)[1], (it->second)[2], (it->second)[3], (it->second)[4]);
0232     prod->setValue(it->first, weights);
0233   }
0234   return prod;
0235 }
0236 
0237 std::unique_ptr<EcalTPGOddWeightGroup> EcalTrigPrimESProducer::produceOddWeightGroup(
0238     const EcalTPGOddWeightGroupRcd &iRecord) {
0239   auto prod = std::make_unique<EcalTPGOddWeightGroup>();
0240   parseTextFile();
0241   for (int subdet = 0; subdet < 2; subdet++) {
0242     std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0243     for (it = mapStrip_[subdet].begin(); it != mapStrip_[subdet].end(); it++) {
0244       prod->setValue(it->first, (it->second)[2]);
0245     }
0246   }
0247   return prod;
0248 }
0249 
0250 std::unique_ptr<EcalTPGTPMode> EcalTrigPrimESProducer::produceTPMode(const EcalTPGTPModeRcd &iRecord) {
0251   auto prod = std::make_unique<EcalTPGTPMode>();
0252   parseTextFile();
0253   if (tpMode_.size() < 14)
0254     edm::LogError("EcalTPG") << "Missing TPMode entries!";
0255 
0256   prod->EnableEBOddFilter = tpMode_[0];
0257   prod->EnableEEOddFilter = tpMode_[1];
0258   prod->EnableEBOddPeakFinder = tpMode_[2];
0259   prod->EnableEEOddPeakFinder = tpMode_[3];
0260   prod->DisableEBEvenPeakFinder = tpMode_[4];
0261   prod->DisableEEEvenPeakFinder = tpMode_[5];
0262   prod->FenixEBStripOutput = tpMode_[6];
0263   prod->FenixEEStripOutput = tpMode_[7];
0264   prod->FenixEBStripInfobit2 = tpMode_[8];
0265   prod->FenixEEStripInfobit2 = tpMode_[9];
0266   prod->EBFenixTcpOutput = tpMode_[10];
0267   prod->EBFenixTcpInfobit1 = tpMode_[11];
0268   prod->EEFenixTcpOutput = tpMode_[12];
0269   prod->EEFenixTcpInfobit1 = tpMode_[13];
0270   prod->FenixPar15 = tpMode_[14];
0271   prod->FenixPar16 = tpMode_[15];
0272   prod->FenixPar17 = tpMode_[16];
0273   prod->FenixPar18 = tpMode_[17];
0274   return prod;
0275 }
0276 
0277 std::unique_ptr<EcalTPGLutGroup> EcalTrigPrimESProducer::produceLutGroup(const EcalTPGLutGroupRcd &iRecord) {
0278   auto prod = std::make_unique<EcalTPGLutGroup>();
0279   parseTextFile();
0280   for (int subdet = 0; subdet < 2; subdet++) {
0281     std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0282     for (it = mapTower_[subdet].begin(); it != mapTower_[subdet].end(); it++) {
0283       prod->setValue(it->first, (it->second)[0]);
0284     }
0285   }
0286   return prod;
0287 }
0288 
0289 std::unique_ptr<EcalTPGFineGrainEBGroup> EcalTrigPrimESProducer::produceFineGrainEBGroup(
0290     const EcalTPGFineGrainEBGroupRcd &iRecord) {
0291   auto prod = std::make_unique<EcalTPGFineGrainEBGroup>();
0292   parseTextFile();
0293   std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0294   for (it = mapTower_[0].begin(); it != mapTower_[0].end(); it++) {
0295     prod->setValue(it->first, (it->second)[1]);
0296   }
0297   return prod;
0298 }
0299 
0300 std::unique_ptr<EcalTPGPhysicsConst> EcalTrigPrimESProducer::producePhysicsConst(const EcalTPGPhysicsConstRcd &iRecord) {
0301   auto prod = std::make_unique<EcalTPGPhysicsConst>();
0302   parseTextFile();
0303   std::map<uint32_t, std::vector<float>>::const_iterator it;
0304   for (it = mapPhys_.begin(); it != mapPhys_.end(); it++) {
0305     EcalTPGPhysicsConst::Item item;
0306     item.EtSat = (it->second)[0];
0307     item.ttf_threshold_Low = (it->second)[1];
0308     item.ttf_threshold_High = (it->second)[2];
0309     item.FG_lowThreshold = (it->second)[3];
0310     item.FG_highThreshold = (it->second)[4];
0311     item.FG_lowRatio = (it->second)[5];
0312     item.FG_highRatio = (it->second)[6];
0313     prod->setValue(it->first, item);
0314   }
0315   return prod;
0316 }
0317 
0318 std::unique_ptr<EcalTPGCrystalStatus> EcalTrigPrimESProducer::produceBadX(const EcalTPGCrystalStatusRcd &iRecord) {
0319   auto prod = std::make_unique<EcalTPGCrystalStatus>();
0320   parseTextFile();
0321   std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0322   for (it = mapXtal_.begin(); it != mapXtal_.end(); it++) {
0323     EcalTPGCrystalStatusCode badXValue;
0324     badXValue.setStatusCode(0);
0325     prod->setValue(it->first, badXValue);
0326   }
0327   return prod;
0328 }
0329 
0330 std::unique_ptr<EcalTPGStripStatus> EcalTrigPrimESProducer::produceBadStrip(const EcalTPGStripStatusRcd &iRecord) {
0331   auto prod = std::make_unique<EcalTPGStripStatus>();
0332   // returns an empty map
0333   return prod;
0334 }
0335 
0336 std::unique_ptr<EcalTPGTowerStatus> EcalTrigPrimESProducer::produceBadTT(const EcalTPGTowerStatusRcd &iRecord) {
0337   auto prod = std::make_unique<EcalTPGTowerStatus>();
0338   parseTextFile();
0339   std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0340   // Barrel
0341   for (it = mapTower_[0].begin(); it != mapTower_[0].end(); it++) {
0342     // set the BadTT status to 0
0343     prod->setValue(it->first, 0);
0344   }
0345   // Endcap
0346   for (it = mapTower_[1].begin(); it != mapTower_[1].end(); it++) {
0347     // set the BadTT status to 0
0348     prod->setValue(it->first, 0);
0349   }
0350 
0351   return prod;
0352 }
0353 
0354 std::unique_ptr<EcalTPGSpike> EcalTrigPrimESProducer::produceSpike(const EcalTPGSpikeRcd &iRecord) {
0355   auto prod = std::make_unique<EcalTPGSpike>();
0356   parseTextFile();
0357   // Only need to do barrel
0358   std::map<uint32_t, std::vector<uint32_t>>::const_iterator it;
0359   for (it = mapTower_[0].begin(); it != mapTower_[0].end(); ++it) {
0360     prod->setValue(it->first, (it->second)[2]);
0361   }
0362   return prod;
0363 }
0364 
0365 void EcalTrigPrimESProducer::parseTextFile() {
0366   if (!mapXtal_.empty())
0367     return;  // just parse the file once!
0368 
0369   uint32_t id;
0370   std::string dataCard;
0371   std::string line;
0372   std::ifstream infile;
0373   std::vector<unsigned int> param;
0374   std::vector<float> paramF;
0375   int NBstripparams[2] = {5, 5};
0376   unsigned int data;
0377   float dataF;
0378 
0379   std::string bufString;
0380   std::string iString;
0381   std::string fString;
0382   std::string filename = "SimCalorimetry/EcalTrigPrimProducers/data/" + dbFilename_;
0383   std::string finalFileName;
0384   size_t slash = dbFilename_.find('/');
0385   if (slash != 0) {
0386     edm::FileInPath fileInPath(filename);
0387     finalFileName = fileInPath.fullPath();
0388   } else {
0389     finalFileName = dbFilename_;
0390     edm::LogWarning("EcalTPG") << "Couldnt find database file via fileinpath, "
0391                                   "trying with pathname directly!!";
0392   }
0393 
0394   int k = 0;
0395 
0396   GzInputStream gis(finalFileName.c_str());
0397   while (gis >> dataCard) {
0398     if (dataCard == "PHYSICS_EB" || dataCard == "PHYSICS_EE") {
0399       gis >> std::dec >> id;
0400 
0401       if (flagPrint_) {
0402         edm::LogVerbatim("EcalTrigPrimESProducer") << dataCard << " " << std::dec << id;
0403       }
0404 
0405       paramF.clear();
0406 
0407       std::string st1;
0408       std::string st2;
0409 
0410       for (int i = 0; i < 7; i++) {
0411         gis >> std::dec >> dataF;
0412         paramF.push_back(dataF);
0413 
0414         // edm::LogVerbatim("EcalTrigPrimESProducer")<<", "<<std::dec<<dataF ;
0415         if (flagPrint_) {
0416           //---------------------------------
0417           if (i < 3) {
0418             std::ostringstream oss;
0419             oss << dataF;
0420             std::string result1 = oss.str();
0421 
0422             st1.append(result1);
0423             if (i != 2)
0424               st1.append(" ");
0425           }
0426 
0427           if (i > 2) {
0428             std::ostringstream oss;
0429             oss << dataF;
0430             std::string result2 = oss.str();
0431 
0432             st2.append(result2);
0433             if (i != 6)
0434               st2.append(" ");
0435           }
0436           //----------------------------------
0437         }
0438       }
0439 
0440       if (flagPrint_) {
0441         edm::LogVerbatim("EcalTrigPrimESProducer") << "" << st1;
0442         edm::LogVerbatim("EcalTrigPrimESProducer") << "" << st2;
0443         edm::LogVerbatim("EcalTrigPrimESProducer") << "";
0444       }
0445 
0446       // edm::LogVerbatim("EcalTrigPrimESProducer")<<std::endl ;
0447       mapPhys_[id] = paramF;
0448     }
0449 
0450     if (dataCard == "CRYSTAL") {
0451       gis >> std::dec >> id;
0452       // edm::LogVerbatim("EcalTrigPrimESProducer")<<dataCard<<" "<<std::dec<<id;
0453       std::string st3;
0454       std::string st4;
0455       std::string st5;
0456 
0457       if (flagPrint_) {
0458         // Print this comment only one time
0459         if (k == 0)
0460           edm::LogVerbatim("EcalTrigPrimESProducer") << "COMMENT ====== barrel crystals ====== ";
0461 
0462         if (k == 61200)
0463           edm::LogVerbatim("EcalTrigPrimESProducer") << "COMMENT ====== endcap crystals ====== ";
0464 
0465         k = k + 1;
0466 
0467         edm::LogVerbatim("EcalTrigPrimESProducer") << dataCard << " " << std::dec << id;
0468       }
0469 
0470       param.clear();
0471       for (int i = 0; i < 9; i++) {
0472         gis >> std::hex >> data;
0473         // edm::LogVerbatim("EcalTrigPrimESProducer")<<", "<<std::hex<<data ;
0474         param.push_back(data);
0475 
0476         if (flagPrint_) {
0477           if (i < 3) {
0478             std::ostringstream oss;
0479             oss << std::hex << data;
0480             std::string result1 = oss.str();
0481 
0482             st3.append("0x");
0483             st3.append(result1);
0484             if (i != 2)
0485               st3.append(" ");
0486 
0487           } else if (i > 2 && i < 6) {
0488             std::ostringstream oss;
0489             oss << std::hex << data;
0490             std::string result2 = oss.str();
0491 
0492             st4.append("0x");
0493             st4.append(result2);
0494             if (i != 5)
0495               st4.append(" ");
0496           } else if (i > 5 && i < 9) {
0497             std::ostringstream oss;
0498             oss << std::hex << data;
0499             std::string result3 = oss.str();
0500 
0501             st5.append("0x");
0502             st5.append(result3);
0503             if (i != 8)
0504               st5.append(" ");
0505           }
0506         }
0507 
0508       }  // end for
0509 
0510       if (flagPrint_) {
0511         edm::LogVerbatim("EcalTrigPrimESProducer") << " " << st3;
0512         edm::LogVerbatim("EcalTrigPrimESProducer") << " " << st4;
0513         edm::LogVerbatim("EcalTrigPrimESProducer") << " " << st5;
0514       }
0515 
0516       // edm::LogVerbatim("EcalTrigPrimESProducer")<<std::endl ;
0517       mapXtal_[id] = param;
0518     }
0519 
0520     if (dataCard == "STRIP_EB") {
0521       gis >> std::dec >> id;
0522 
0523       std::string st1;
0524 
0525       if (flagPrint_)
0526         edm::LogVerbatim("EcalTrigPrimESProducer") << dataCard << " " << std::dec << id;
0527 
0528       param.clear();
0529       for (int i = 0; i < NBstripparams[0]; i++) {
0530         gis >> std::hex >> data;
0531         // edm::LogVerbatim("EcalTrigPrimESProducer") << " data = " << data;
0532         param.push_back(data);
0533 
0534         if (flagPrint_) {
0535           if (i == 0) {
0536             edm::LogVerbatim("EcalTrigPrimESProducer") << "0x" << std::hex << data;
0537           } else if (i >= 1 && i < 3) {
0538             edm::LogVerbatim("EcalTrigPrimESProducer") << "" << std::dec << data;
0539           } else if (i > 2) {
0540             std::ostringstream oss;
0541             if (i == 3) {
0542               oss << "0x" << std::hex << data;
0543               std::string result4 = oss.str();
0544               st1.append(result4);
0545             } else if (i == 4) {
0546               std::ostringstream oss;
0547               oss << " 0x" << std::hex << data;
0548               std::string result5 = oss.str();
0549               st1.append(result5);
0550               edm::LogVerbatim("EcalTrigPrimESProducer") << "" << st1;
0551             }
0552           }
0553         }
0554       }
0555 
0556       // edm::LogVerbatim("EcalTrigPrimESProducer")<<std::endl ;
0557       mapStrip_[0][id] = param;
0558     }
0559 
0560     if (dataCard == "STRIP_EE") {
0561       gis >> std::dec >> id;
0562 
0563       std::string st6;
0564 
0565       if (flagPrint_) {
0566         edm::LogVerbatim("EcalTrigPrimESProducer") << dataCard << " " << std::dec << id;
0567       }
0568 
0569       param.clear();
0570       for (int i = 0; i < NBstripparams[1]; i++) {
0571         gis >> std::hex >> data;
0572         param.push_back(data);
0573 
0574         if (flagPrint_) {
0575           if (i == 0) {
0576             edm::LogVerbatim("EcalTrigPrimESProducer") << "0x" << std::hex << data;
0577           } else if (i >= 1 && i < 3) {
0578             edm::LogVerbatim("EcalTrigPrimESProducer") << " " << std::hex << data;
0579           } else if (i > 2) {
0580             std::ostringstream oss;
0581             if (i == 3) {
0582               oss << "0x" << std::hex << data;
0583               std::string result4 = oss.str();
0584               st6.append(result4);
0585             } else if (i == 4) {
0586               std::ostringstream oss;
0587               oss << " 0x" << std::hex << data;
0588               std::string result5 = oss.str();
0589 
0590               st6.append(result5);
0591               edm::LogVerbatim("EcalTrigPrimESProducer") << "" << st6;
0592             }
0593           }
0594         }
0595       }
0596 
0597       // edm::LogVerbatim("EcalTrigPrimESProducer")<<std::endl ;
0598       mapStrip_[1][id] = param;
0599     }
0600 
0601     if (dataCard == "TOWER_EE") {
0602       gis >> std::dec >> id;
0603 
0604       if (flagPrint_)
0605         edm::LogVerbatim("EcalTrigPrimESProducer") << dataCard << " " << std::dec << id;
0606 
0607       param.clear();
0608       for (int i = 0; i < 2; i++) {
0609         gis >> std::hex >> data;
0610         param.push_back(data);
0611 
0612         if (flagPrint_) {
0613           if (i == 1) {
0614             edm::LogVerbatim("EcalTrigPrimESProducer") << "0x" << std::dec << data;
0615           } else {
0616             edm::LogVerbatim("EcalTrigPrimESProducer") << " " << std::dec << data;
0617           }
0618         }
0619       }
0620 
0621       // edm::LogVerbatim("EcalTrigPrimESProducer")<<std::endl ;
0622       mapTower_[1][id] = param;
0623     }
0624 
0625     if (dataCard == "TOWER_EB") {
0626       gis >> std::dec >> id;
0627 
0628       if (flagPrint_)
0629         edm::LogVerbatim("EcalTrigPrimESProducer") << dataCard << " " << std::dec << id;
0630 
0631       param.clear();
0632       for (int i = 0; i < 3; i++) {
0633         gis >> std::dec >> data;
0634 
0635         if (flagPrint_) {
0636           edm::LogVerbatim("EcalTrigPrimESProducer") << " " << std::dec << data;
0637         }
0638 
0639         param.push_back(data);
0640       }
0641 
0642       // edm::LogVerbatim("EcalTrigPrimESProducer")<<std::endl ;
0643       mapTower_[0][id] = param;
0644     }
0645 
0646     if (dataCard == "WEIGHT") {
0647       gis >> std::hex >> id;
0648       if (flagPrint_) {
0649         edm::LogVerbatim("EcalTrigPrimESProducer") << dataCard << " " << std::dec << id;
0650       }
0651 
0652       param.clear();
0653 
0654       std::string st6;
0655       for (int i = 0; i < 5; i++) {
0656         gis >> std::hex >> data;
0657         param.push_back(data);
0658 
0659         if (flagPrint_) {
0660           std::ostringstream oss;
0661           oss << std::hex << data;
0662           std::string result4 = oss.str();
0663 
0664           st6.append("0x");
0665           st6.append(result4);
0666           st6.append(" ");
0667         }
0668       }
0669 
0670       if (flagPrint_) {
0671         edm::LogVerbatim("EcalTrigPrimESProducer") << st6;
0672       }
0673 
0674       // edm::LogVerbatim("EcalTrigPrimESProducer")<<std::endl ;
0675       mapWeight_[id] = param;
0676     }
0677 
0678     if (dataCard == "WEIGHT_ODD") {
0679       gis >> std::hex >> id;
0680       if (flagPrint_) {
0681         edm::LogVerbatim("EcalTrigPrimESProducer") << dataCard << " " << std::dec << id;
0682       }
0683 
0684       param.clear();
0685 
0686       std::string st6;
0687       for (int i = 0; i < 5; i++) {
0688         gis >> std::hex >> data;
0689         param.push_back(data);
0690 
0691         if (flagPrint_) {
0692           std::ostringstream oss;
0693           oss << std::hex << data;
0694           std::string result4 = oss.str();
0695 
0696           st6.append("0x");
0697           st6.append(result4);
0698           st6.append(" ");
0699         }
0700       }
0701 
0702       if (flagPrint_) {
0703         edm::LogVerbatim("EcalTrigPrimESProducer") << st6;
0704       }
0705 
0706       // edm::LogVerbatim("EcalTrigPrimESProducer")<<std::endl ;
0707       mapWeight_odd_[id] = param;
0708     }
0709 
0710     if (dataCard == "FG") {
0711       gis >> std::hex >> id;
0712       if (flagPrint_)
0713         edm::LogVerbatim("EcalTrigPrimESProducer") << dataCard << " " << std::dec << id;
0714 
0715       param.clear();
0716       std::string st7;
0717       for (int i = 0; i < 5; i++) {
0718         gis >> std::hex >> data;
0719         param.push_back(data);
0720 
0721         if (flagPrint_) {
0722           std::ostringstream oss;
0723           oss << std::hex << data;
0724 
0725           std::string result5 = oss.str();
0726 
0727           st7.append("0x");
0728           st7.append(result5);
0729           if (i != 4)
0730             st7.append(" ");
0731         }
0732       }
0733 
0734       if (flagPrint_) {
0735         edm::LogVerbatim("EcalTrigPrimESProducer") << st7;
0736       }
0737 
0738       mapFg_[id] = param;
0739     }
0740 
0741     if (dataCard == "LUT") {
0742       gis >> std::hex >> id;
0743 
0744       if (flagPrint_)
0745         edm::LogVerbatim("EcalTrigPrimESProducer") << dataCard << " " << std::dec << id;
0746 
0747       param.clear();
0748       for (int i = 0; i < 1024; i++) {
0749         gis >> std::hex >> data;
0750         param.push_back(data);
0751 
0752         if (flagPrint_) {
0753           edm::LogVerbatim("EcalTrigPrimESProducer") << "0x" << std::hex << data;
0754         }
0755       }
0756 
0757       mapLut_[id] = param;
0758     }
0759 
0760     if (dataCard == "TP_MODE") {
0761       param.clear();
0762 
0763       std::string st8;
0764       for (int i = 0; i < 18; i++) {
0765         gis >> std::dec >> data;
0766         param.push_back(data);
0767 
0768         if (flagPrint_) {
0769           std::ostringstream oss;
0770           oss << std::dec << data;
0771           std::string result6 = oss.str();
0772 
0773           st8.append(result6);
0774           st8.append(" ");
0775         }
0776       }
0777 
0778       if (flagPrint_) {
0779         edm::LogVerbatim("EcalTrigPrimESProducer") << dataCard << " " << st8;
0780       }
0781 
0782       // edm::LogVerbatim("EcalTrigPrimESProducer")<<std::endl ;
0783       tpMode_ = param;
0784     }
0785   }
0786 }
0787 
0788 std::vector<int> EcalTrigPrimESProducer::getRange(
0789     int subdet, int tccNb, int towerNbInTcc, int stripNbInTower, int xtalNbInStrip) {
0790   std::vector<int> range;
0791   if (subdet == 0) {
0792     // Barrel
0793     range.push_back(37);  // stccNbMin
0794     range.push_back(73);  // tccNbMax
0795     range.push_back(1);   // towerNbMin
0796     range.push_back(69);  // towerNbMax
0797     range.push_back(1);   // stripNbMin
0798     range.push_back(6);   // stripNbMax
0799     range.push_back(1);   // xtalNbMin
0800     range.push_back(6);   // xtalNbMax
0801   } else {
0802     // Endcap eta >0
0803     if (subdet > 0) {
0804       range.push_back(73);   // tccNbMin
0805       range.push_back(109);  // tccNbMax
0806     } else {                 // endcap eta <0
0807       range.push_back(1);    // tccNbMin
0808       range.push_back(37);   // tccNbMax
0809     }
0810     range.push_back(1);   // towerNbMin
0811     range.push_back(29);  // towerNbMax
0812     range.push_back(1);   // stripNbMin
0813     range.push_back(6);   // stripNbMax
0814     range.push_back(1);   // xtalNbMin
0815     range.push_back(6);   // xtalNbMax
0816   }
0817 
0818   if (tccNb > 0) {
0819     range[0] = tccNb;
0820     range[1] = tccNb + 1;
0821   }
0822   if (towerNbInTcc > 0) {
0823     range[2] = towerNbInTcc;
0824     range[3] = towerNbInTcc + 1;
0825   }
0826   if (stripNbInTower > 0) {
0827     range[4] = stripNbInTower;
0828     range[5] = stripNbInTower + 1;
0829   }
0830   if (xtalNbInStrip > 0) {
0831     range[6] = xtalNbInStrip;
0832     range[7] = xtalNbInStrip + 1;
0833   }
0834 
0835   return range;
0836 }
0837 
0838 // bool EcalTrigPrimESProducer::getNextString(gzFile &gzf){
0839 //   size_t blank;
0840 //   if (bufpos_==0) {
0841 //     gzgets(gzf,buf_,80);
0842 //     if (gzeof(gzf)) return true;
0843 //     bufString_=std::string(buf_);
0844 //   }
0845 //   int  pos=0;
0846 //   pos =bufpos_;
0847 //   // look for next non-blank
0848 //   while (pos<bufString_.size()) {
0849 //     if (!bufString_.compare(pos,1," ")) pos++;
0850 //     else break;
0851 //   }
0852 //   blank=bufString_.find(" ",pos);
0853 //   size_t end = blank;
0854 //   if (blank==std::string::npos) end=bufString_.size();
0855 //   sub_=bufString_.substr(pos,end-pos);
0856 //   bufpos_= blank;
0857 //   if (blank==std::string::npos) bufpos_=0;
0858 //   return false;
0859 // }
0860 //
0861 // int EcalTrigPrimESProducer::converthex() {
0862 //   // converts hex dec string sub to hexa
0863 //   //FIXME:: find something better (istrstream?)!!!!
0864 //
0865 //   std::string chars("0123456789abcdef");
0866 //   int hex=0;
0867 //   for (size_t i=2;i<sub_.length();++i) {
0868 //     size_t f=chars.find(sub_[i]);
0869 //     if (f==std::string::npos) break;  //FIXME: length is 4 for 0x3!!
0870 //     hex=hex*16+chars.find(sub_[i]);
0871 //   }
0872 //   return hex;
0873 // }