CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/CalibCalorimetry/HcalAlgos/src/HcalDbASCIIIO.cc

Go to the documentation of this file.
00001 //
00002 // F.Ratnikov (UMd), Oct 28, 2005
00003 // $Id: HcalDbASCIIIO.cc,v 1.66 2011/11/23 13:48:27 abdullin Exp $
00004 //
00005 #include <vector>
00006 #include <string>
00007 #include <cstdio>
00008 #include <sstream>
00009 
00010 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00011 #include "DataFormats/HcalDetId/interface/HcalElectronicsId.h"
00012 #include "DataFormats/HcalDetId/interface/HcalDcsDetId.h"
00013 #include "CalibFormats/HcalObjects/interface/HcalText2DetIdConverter.h"
00014 
00015 #include "CondFormats/HcalObjects/interface/AllObjects.h"
00016 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
00017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00018 
00019 namespace {
00020   class DetIdLess {
00021   public:
00022     bool operator () (DetId fFirst, DetId fSecond) const {
00023       HcalGenericDetId first (fFirst);
00024       HcalGenericDetId second (fSecond);
00025       if (first.genericSubdet () != second.genericSubdet ()) return first.genericSubdet () < second.genericSubdet ();
00026       if (first.isHcalDetId ()) {
00027         HcalDetId f1 (first);
00028         HcalDetId s1 (second);
00029         return  f1.zside () != s1.zside () ? f1.zside () < s1.zside () :
00030           f1.iphi () != s1.iphi () ? f1.iphi () < s1.iphi () :
00031           f1.ietaAbs () != s1.ietaAbs () ? f1.ietaAbs () < s1.ietaAbs () :
00032           f1.depth () < s1.depth ();
00033       }
00034       else {
00035         return first.rawId() < second.rawId();
00036       }
00037     }
00038   };
00039   class HcalElectronicsIdLess {
00040   public:
00041     bool operator () (HcalElectronicsId first, HcalElectronicsId second) const {
00042       return
00043         first.readoutVMECrateId () != second.readoutVMECrateId () ? first.readoutVMECrateId () < second.readoutVMECrateId () :
00044         first.htrSlot () != second.htrSlot () ? first.htrSlot () < second.htrSlot () :
00045         first.htrTopBottom () != second.htrTopBottom () ? first.htrTopBottom () < second.htrTopBottom () :
00046         first.fiberIndex () != second.fiberIndex () ? first.fiberIndex () < second.fiberIndex () :
00047         first.fiberChanId () < second.fiberChanId ();
00048     }
00049   };
00050 }
00051 
00052 // ------------------------------ some little helpers ------------------------------
00053 
00054 std::vector <std::string> splitString (const std::string& fLine) {
00055   std::vector <std::string> result;
00056   int start = 0;
00057   bool empty = true;
00058   for (unsigned i = 0; i <= fLine.size (); i++) {
00059     if (fLine [i] == ' ' || i == fLine.size ()) {
00060       if (!empty) {
00061         std::string item (fLine, start, i-start);
00062         result.push_back (item);
00063         empty = true;
00064       }
00065       start = i+1;
00066     }
00067     else {
00068       if (empty) empty = false;
00069     }
00070   }
00071   return result;
00072 }
00073 
00074 std::vector <unsigned int> splitStringToIntByComma (const std::string& fLine) {
00075   std::vector <unsigned int> result;
00076   int start = 0;
00077   bool empty = true;
00078   for (unsigned i = 0; i <= fLine.size (); i++) {
00079     if (fLine [i] == ',' || i == fLine.size ()) {
00080       if (!empty) {
00081         std::string itemString (fLine, start, i-start);
00082         result.push_back (atoi (itemString.c_str()) );
00083         empty = true;
00084       }
00085       start = i+1;
00086     }
00087     else {
00088       if (empty) empty = false;
00089     }
00090   }
00091   return result;
00092 }
00093 
00094 std::vector <float> splitStringToFloatByComma (const std::string& fLine) {
00095   std::vector <float> result;
00096   int start = 0;
00097   bool empty = true;
00098   for (unsigned i = 0; i <= fLine.size (); i++) {
00099     if (fLine [i] == ',' || i == fLine.size ()) {
00100       if (!empty) {
00101         std::string itemString (fLine, start, i-start);
00102         result.push_back (atof (itemString.c_str()) );
00103         empty = true;
00104       }
00105       start = i+1;
00106     }
00107     else {
00108       if (empty) empty = false;
00109     }
00110   }
00111   return result;
00112 }
00113 
00114 std::vector <double> splitStringToDoubleByComma (const std::string& fLine) {
00115   std::vector <double> result;
00116   int start = 0;
00117   bool empty = true;
00118   for (unsigned i = 0; i <= fLine.size (); i++) {
00119     if (fLine [i] == ',' || i == fLine.size ()) {
00120       if (!empty) {
00121         std::string itemString (fLine, start, i-start);
00122         result.push_back (atof (itemString.c_str()) );
00123         empty = true;
00124       }
00125       start = i+1;
00126     }
00127     else {
00128       if (empty) empty = false;
00129     }
00130   }
00131   return result;
00132 }
00133 
00134 DetId HcalDbASCIIIO::getId (const std::vector <std::string> & items) {
00135   HcalText2DetIdConverter converter (items [3], items [0], items [1], items [2]);
00136   return converter.getId ();
00137 }
00138 
00139 void HcalDbASCIIIO::dumpId (std::ostream& fOutput, DetId id) {
00140   HcalText2DetIdConverter converter (id);
00141   char buffer [1024];
00142   sprintf (buffer, "  %15s %15s %15s %15s",
00143            converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str (),converter.getFlavor ().c_str ());  
00144   fOutput << buffer;
00145 }
00146 
00147 void HcalDbASCIIIO::dumpIdShort (std::ostream& fOutput, DetId id) {
00148   HcalText2DetIdConverter converter (id);
00149   char buffer [1024];
00150   sprintf (buffer, "  %5s %4s %4s %10s",
00151            converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str (),converter.getFlavor ().c_str ());
00152   fOutput << buffer;
00153 }
00154 
00155 
00156 // ------------------------------ start templates ------------------------------
00157 
00158 template<class T>
00159 bool from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {
00160   std::istringstream iss(s);
00161   return !(iss >> f >> t).fail();
00162 }
00163 
00164 template <class T,class S> 
00165 bool getHcalObject (std::istream& fInput, T* fObject, S* fCondObject) {
00166   if (!fObject) fObject = new T;
00167   char buffer [1024];
00168   while (fInput.getline(buffer, 1024)) {
00169     if (buffer [0] == '#') continue; //ignore comment
00170     std::vector <std::string> items = splitString (std::string (buffer));
00171     if (items.size()==0) continue; // blank line
00172     if (items.size () < 8) {
00173       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values" << std::endl;
00174       continue;
00175     }
00176     DetId id = HcalDbASCIIIO::getId (items);
00177     
00178 //    if (fObject->exists(id) )
00179 //      edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
00180 //    else
00181 //      {
00182         fCondObject = new S(id, atof (items [4].c_str()), atof (items [5].c_str()), 
00183                            atof (items [6].c_str()), atof (items [7].c_str()));
00184         fObject->addValues(*fCondObject);
00185         delete fCondObject;
00186         //      }
00187   }
00188 
00189   return true;
00190 }
00191 
00192 template <class T>
00193 bool dumpHcalObject (std::ostream& fOutput, const T& fObject) {
00194   char buffer [1024];
00195   sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %10s\n", "eta", "phi", "dep", "det", "cap0", "cap1", "cap2", "cap3", "DetId");
00196   fOutput << buffer;
00197   std::vector<DetId> channels = fObject.getAllChannels ();
00198   std::sort (channels.begin(), channels.end(), DetIdLess ());
00199   for (std::vector<DetId>::iterator channel = channels.begin ();
00200        channel !=  channels.end ();
00201        channel++) {
00202     const float* values = fObject.getValues (*channel)->getValues ();
00203     if (values) {
00204       HcalDbASCIIIO::dumpId (fOutput, *channel);
00205       sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %10X\n",
00206                values[0], values[1], values[2], values[3], channel->rawId ());
00207       fOutput << buffer;
00208     }
00209   }
00210   return true;
00211 }
00212 
00213 template <class T,class S> 
00214 bool getHcalSingleFloatObject (std::istream& fInput, T* fObject, S* fCondObject) {
00215   if (!fObject) fObject = new T;
00216   char buffer [1024];
00217   while (fInput.getline(buffer, 1024)) {
00218     if (buffer [0] == '#') continue; //ignore comment
00219     std::vector <std::string> items = splitString (std::string (buffer));
00220     if (items.size()==0) continue; // blank line
00221     if (items.size () < 5) {
00222       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 5 items: eta, phi, depth, subdet, value" << std::endl;
00223       continue;
00224     }
00225     DetId id = HcalDbASCIIIO::getId (items);
00226     
00227 //    if (fObject->exists(id) )
00228 //      edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
00229 //    else
00230 //      {
00231         fCondObject = new S(id, atof (items [4].c_str()) );
00232         fObject->addValues(*fCondObject);
00233         delete fCondObject;
00234         //      }
00235   }
00236   return true;
00237 }
00238 
00239 template <class T>
00240 bool dumpHcalSingleFloatObject (std::ostream& fOutput, const T& fObject) {
00241   char buffer [1024];
00242   sprintf (buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
00243   fOutput << buffer;
00244   std::vector<DetId> channels = fObject.getAllChannels ();
00245   std::sort (channels.begin(), channels.end(), DetIdLess ());
00246   for (std::vector<DetId>::iterator channel = channels.begin ();
00247        channel !=  channels.end ();
00248        channel++) {
00249     const float value = fObject.getValues (*channel)->getValue ();
00250     HcalDbASCIIIO::dumpId (fOutput, *channel);
00251     sprintf (buffer, " %8.5f %10X\n",
00252              value, channel->rawId ());
00253     fOutput << buffer;
00254   }
00255   return true;
00256 }
00257 
00258 template <class T,class S> 
00259 bool getHcalSingleIntObject (std::istream& fInput, T* fObject, S* fCondObject) {
00260   if (!fObject) fObject = new T;
00261   char buffer [1024];
00262   while (fInput.getline(buffer, 1024)) {
00263     if (buffer [0] == '#') continue; //ignore comment
00264     std::vector <std::string> items = splitString (std::string (buffer));
00265     if (items.size()==0) continue; // blank line
00266     if (items.size () < 5) {
00267       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 5 items: eta, phi, depth, subdet, value" << std::endl;
00268       continue;
00269     }
00270     DetId id = HcalDbASCIIIO::getId (items);
00271     
00272 //    if (fObject->exists(id) )
00273 //      edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
00274 //    else
00275 //      {
00276         fCondObject = new S(id, atoi (items [4].c_str()) );
00277         fObject->addValues(*fCondObject);
00278         delete fCondObject;
00279         //      }
00280   }
00281   return true;
00282 }
00283 
00284 template <class T>
00285 bool dumpHcalSingleIntObject (std::ostream& fOutput, const T& fObject) {
00286   char buffer [1024];
00287   sprintf (buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
00288   fOutput << buffer;
00289   std::vector<DetId> channels = fObject.getAllChannels ();
00290   std::sort (channels.begin(), channels.end(), DetIdLess ());
00291   for (std::vector<DetId>::iterator channel = channels.begin ();
00292        channel !=  channels.end ();
00293        channel++) {
00294     const int value = fObject.getValues (*channel)->getValue ();
00295     HcalDbASCIIIO::dumpId (fOutput, *channel);
00296     sprintf (buffer, " %15d %10X\n",
00297              value, channel->rawId ());
00298     fOutput << buffer;
00299   }
00300   return true;
00301 }
00302 
00303 template <class T,class S>
00304 bool getHcalMatrixObject (std::istream& fInput, T* fObject, S* fCondObject) {
00305   if (!fObject) fObject = new T;
00306   char buffer [1024];
00307   while (fInput.getline(buffer, 1024)) {
00308     if (buffer [0] == '#') continue; //ignore comment
00309     std::vector <std::string> items = splitString (std::string (buffer));
00310     if (items.size()==0) continue; // blank line
00311     DetId firstid = HcalDbASCIIIO::getId (items);
00312     fCondObject = new S(firstid.rawId());
00313     for(int j = 0; j != 10; j++) fCondObject->setValue(atoi(items[4].c_str()), 0, j, atof(items[j+5].c_str()));
00314     for(int i = 1; i != 40; i++){
00315        fInput.getline(buffer, 1024);
00316        items = splitString (std::string (buffer));
00317        DetId id = HcalDbASCIIIO::getId (items);
00318        if(id.rawId() != firstid.rawId()) break;//throw cms::Exception("Wrong number of elements");
00319        for(int j = 0; j != 10; j++) fCondObject->setValue(atoi(items[4].c_str()), i%10, j, atof(items[j+5].c_str()));
00320      }
00321      fObject->addValues(*fCondObject);
00322      delete fCondObject;
00323   }
00324   return true;
00325 }
00326 
00327 template <class T>
00328 bool dumpHcalMatrixObject (std::ostream& fOutput, const T& fObject) {
00329   char buffer [1024];
00330   sprintf (buffer, "# %5s %5s %5s %5s %5s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
00331         "eta", "phi", "dep", "det", "capid","c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "DetId");
00332   fOutput << buffer;
00333   std::vector<DetId> channels = fObject.getAllChannels ();
00334   std::sort (channels.begin(), channels.end(), DetIdLess ());
00335   for (std::vector<DetId>::iterator channel = channels.begin ();
00336        channel !=  channels.end ();
00337        channel++) {
00338     float thisline[10];
00339     for(int m = 0; m != 4; m++){
00340        for(int i = 0; i != 10; i++){
00341           for(int j = 0; j != 10; j++){
00342 //          std::cout <<"test "<<(fObject.getValues(*channel))->getValue(0,0,0);
00343             thisline[j] = fObject.getValues(*channel)->getValue(m,i,j);
00344 //          thisline[j] = fObject.getValues(*channel)->getValue(1,1,1);
00345           }
00346           HcalDbASCIIIO::dumpId (fOutput, *channel);
00347           sprintf(buffer, " %5i %8.5f %8.5f %8.5f %8.5f  %8.5f %8.5f %8.5f %8.5f  %8.5f %8.5f %10X\n",
00348            m, thisline[0], thisline[1], thisline[2], thisline[3], thisline[4], thisline[5], thisline[6], thisline[7],
00349             thisline[8], thisline[9], channel->rawId());
00350           fOutput << buffer;
00351        }
00352     }
00353   }
00354 
00355   return true;
00356 }
00357 
00358 // ------------------------------ end templates ------------------------------
00359 
00360 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalGains* fObject) {return getHcalObject (fInput, fObject, new HcalGain);}
00361 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalGains& fObject) {return dumpHcalObject (fOutput, fObject);}
00362 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalGainWidths* fObject) {return getHcalObject (fInput, fObject, new HcalGainWidth);}
00363 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalGainWidths& fObject) {return dumpHcalObject (fOutput, fObject);}
00364 
00365 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalRespCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalRespCorr); }
00366 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalRespCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
00367 
00368 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLUTCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalLUTCorr); }
00369 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalLUTCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
00370 
00371 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPFCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalPFCorr); }
00372 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPFCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
00373 
00374 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalTimeCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalTimeCorr); }
00375 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalTimeCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
00376 
00377 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalZSThresholds* fObject) {return getHcalSingleIntObject (fInput, fObject, new HcalZSThreshold); }
00378 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalZSThresholds& fObject) {return dumpHcalSingleIntObject (fOutput, fObject); }
00379 
00380 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalValidationCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalValidationCorr); }
00381 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalValidationCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
00382 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCholeskyMatrices* fObject) {return getHcalMatrixObject (fInput, fObject, new HcalCholeskyMatrix); }
00383 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCholeskyMatrices& fObject) {return dumpHcalMatrixObject (fOutput, fObject); }
00384 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCovarianceMatrices* fObject) {return getHcalMatrixObject (fInput, fObject, new HcalCovarianceMatrix); }
00385 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCovarianceMatrices& fObject) {return dumpHcalMatrixObject (fOutput, fObject); }
00386 
00387 
00388 // ------------------------------ start specific implementations ------------------------------
00389 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalRecoParams* fObject)
00390 {
00391   if (!fObject) fObject = new HcalRecoParams();
00392   char buffer [1024];
00393   while (fInput.getline(buffer, 1024)) {
00394     if (buffer [0] == '#') continue; //ignore comment
00395     std::vector <std::string> items = splitString (std::string (buffer));
00396     if (items.size()==0) continue; // blank line
00397     if (items.size () < 6) {
00398       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, param1, param2" << std::endl;
00399       continue;
00400     }
00401     DetId id = HcalDbASCIIIO::getId (items);
00402 
00403     int packingScheme =0;
00404     if(items.size ()>22) {
00405        packingScheme = atoi (items [22].c_str());
00406     }
00407 
00408     int param1=0;
00409     int param2=0;
00410     if(packingScheme==0) {
00411        param1=atoi (items [4].c_str());
00412        param2=atoi (items [5].c_str());
00413     }   // packing scheme 0  (old format).
00414 
00415     if(packingScheme==1) {
00416        //             0 1 2 3 4 5 6 7 8 9
00417        int aabits[6]= {1,1,  8, 4, 4,  9};
00418        int aamax[ 6]= {1,1,255,15,15,511};
00419 
00420        int bbbits[10]={1, 4,1, 4,1, 4, 4, 4, 4, 4};
00421        int bbmax [10]={1,15,1,15,1,15,15,15,15,15};
00422 
00423         // param 1
00424        int j=0;
00425        int aa;
00426        int aashift=0;
00427        for(int i=0; i<6; i++) {
00428           j=i+7;
00429           if(i==2) {
00430             float phase=atof (items [j].c_str());
00431             float xphase=(phase+32.0)*4.0;   // range of phase [-30.0,30.0] 
00432             aa=xphase;
00433           } else {
00434             aa=atoi (items [j].c_str());
00435           } 
00436           if(aa>aamax[i] || aa<0) {
00437               edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value for a"<<i<<" should be less than"<<aamax[i]<< std::endl;
00438           }
00439           param1=param1|aa<<aashift;
00440           aashift=aashift+aabits[i];
00441        }
00442 
00443        // param 2
00444        int bb;
00445        int bbshift=0;
00446        for(int i=0; i<10; i++) {
00447           j=i+13;
00448           bb=atoi (items [j].c_str()); 
00449           if(bb>bbmax[i]) {
00450               edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value for b"<<i<<" should be less than"<<bbmax[i]<< std::endl;
00451           }
00452           param2=param2|bb<<bbshift;
00453           bbshift=bbshift+bbbits[i];
00454        }
00455     } // packing sheme 1.    
00456    
00457     // HcalRecoParam* fCondObject = new HcalRecoParam(id, atoi (items [4].c_str()), atoi (items [5].c_str()) );
00458 
00459     // std::cout<<"  buffer "<<buffer<<std::endl;
00460     // std::cout<<"  param1, param2 "<<param1<<"  "<<param2<<std::endl;
00461 
00462     HcalRecoParam* fCondObject = new HcalRecoParam(id, param1, param2 );
00463     fObject->addValues(*fCondObject);
00464     delete fCondObject;
00465   }
00466   return true;
00467 }
00468 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalRecoParams& fObject)
00469 {
00470   char buffer [1024];
00471   //  sprintf (buffer, "# %15s %15s %15s %15s %18s %15s %10s\n", "eta", "phi", "dep", "det", "firstSample", "samplesToAdd", "DetId");
00472   // fOutput << buffer;
00473   std::vector<DetId> channels = fObject.getAllChannels ();
00474   std::sort (channels.begin(), channels.end(), DetIdLess ());
00475   int  myCounter=0;
00476   for (std::vector<DetId>::iterator channel = channels.begin ();
00477        channel !=  channels.end ();
00478        channel++) {
00479     myCounter++;
00480     int param1=fObject.getValues (*channel)->param1();
00481     int param2=fObject.getValues (*channel)->param2();
00482     int packingScheme=fObject.getValues (*channel)->packingScheme();
00483 
00484     // std::cout<<"  Param1 "<<Param1<<"  Param2 "<<Param2<<"  packing "<<packingScheme<<std::endl;
00485 
00486     if(packingScheme==0) {
00487       // old format
00488       if(myCounter==1) {
00489            sprintf (buffer, "# %15s %15s %15s %15s %18s %15s %10s\n", "eta", "phi", "dep", "det", "firstSample", "samplesToAdd", "DetId");
00490       }
00491       HcalDbASCIIIO::dumpId(fOutput, *channel);
00492       sprintf (buffer, " %15d %15d %16X\n",
00493              fObject.getValues (*channel)->firstSample(), fObject.getValues (*channel)->samplesToAdd(), channel->rawId ());
00494       fOutput << buffer;
00495     }
00496    
00497     if(packingScheme==1) {
00498 
00499        if(myCounter==1) {
00500           char lineT[100],lineA[200],lineB[200];
00501           //
00502           sprintf (lineT, "#%50s","  ");   fOutput << lineT;
00503           sprintf (lineA, " %31s","a0: correctForPhaseContainment"); fOutput << lineA;
00504           sprintf (lineB, " %36s","b0: useLeakCorrection\n"); fOutput << lineB;
00505           //
00506           sprintf (lineT, "#%50s","  ");   fOutput << lineT;
00507           sprintf (lineA, " %31s","a1: correctForLeadingEdge"); fOutput << lineA;
00508           sprintf (lineB, " %36s","b1: leakCorrectionID\n"); fOutput << lineB;
00509           //
00510           sprintf (lineT, "#%50s","  ");   fOutput << lineT;
00511           sprintf (lineA, " %31s","a2: correctionPhaseNS"); fOutput << lineA;
00512           sprintf (lineB, " %36s","b2:  correctForTimeslew\n"); fOutput << lineB;
00513           //
00514           sprintf (lineT, "#%50s","  ");   fOutput << lineT;
00515           sprintf (lineA, " %31s","a3: firstSample"); fOutput << lineA;
00516           sprintf (lineB, " %36s","b3: timeslewCorrectionID\n"); fOutput << lineB;
00517           //
00518           sprintf (lineT, "#%50s","  ");   fOutput << lineT;
00519           sprintf (lineA, " %31s","a4: samplesToAdd"); fOutput << lineA;
00520           sprintf (lineB, " %36s","b4: correctTiming\n"); fOutput << lineB;
00521           //
00522           sprintf (lineT, "#%50s","  ");   fOutput << lineT;
00523           sprintf (lineA, " %31s","a5: pulseShapeID"); fOutput << lineA;
00524           sprintf (lineB, " %36s","b5: firstAuxTS\n"); fOutput << lineB;
00525           //
00526           sprintf (lineT, "#%50s","  ");   fOutput << lineT;
00527           sprintf (lineA, " %31s","  "); fOutput << lineA;
00528           sprintf (lineB, " %36s","b6: specialCaseID\n"); fOutput << lineB;
00529           //
00530           sprintf (lineT, "#%50s","  ");   fOutput << lineT;
00531           sprintf (lineA, " %31s","  "); fOutput << lineA;
00532           sprintf (lineB, " %36s","b7: noiseFlaggingID\n"); fOutput << lineB;
00533           //
00534          sprintf (lineT, "#%50s","  ");   fOutput << lineT;
00535          sprintf (lineA, " %31s","  "); fOutput << lineA;
00536          sprintf (lineB, " %36s","b8: pileupCleaningID\n"); fOutput << lineB;
00537 
00538          sprintf (lineT, "#%50s","  ");   fOutput << lineT;
00539          sprintf (lineA, " %31s","  "); fOutput << lineA;
00540          sprintf (lineB, " %36s","b9: packingScheme\n"); fOutput << lineB;
00541 
00542          //  
00543          sprintf (lineT, "# %5s %4s %4s %10s %11s %10s %10s", "eta", "phi", "dep", "det", "param1", "param2", "DetId");
00544          fOutput << lineT;
00545 
00546          sprintf (lineA, " %6s %4s %6s %4s %4s %4s", "a0", "a1", "a2", "a3", "a4", "a5");
00547          fOutput << lineA;
00548 
00549          sprintf (lineB, " %6s %3s %3s %3s %3s %3s %3s %3s %3s\n", "b0", "b1", "b2", "b3", "b4", "b5", "b6",  "b7", "b8");
00550          fOutput << lineB;
00551        }
00552 
00553        HcalDbASCIIIO::dumpIdShort(fOutput, *channel);
00554        sprintf (buffer, " %11d %10d %10X", param1, param2, channel->rawId ());
00555        fOutput << buffer;
00556 
00557        bool  aa0=fObject.getValues (*channel)->correctForPhaseContainment();
00558        bool  aa1=fObject.getValues (*channel)->correctForLeadingEdge();
00559        float aa2=fObject.getValues (*channel)->correctionPhaseNS();
00560        int   aa3=fObject.getValues (*channel)->firstSample();
00561        int   aa4=fObject.getValues (*channel)->samplesToAdd();
00562        int   aa5=fObject.getValues (*channel)->pulseShapeID();
00563        sprintf (buffer, " %6d %4d %6.1f %4d %4d %4d",aa0,aa1,aa2,aa3,aa4,aa5);
00564        fOutput << buffer;
00565 
00566        bool bb0=fObject.getValues (*channel)->useLeakCorrection();
00567        int  bb1=fObject.getValues (*channel)->leakCorrectionID();
00568        bool bb2=fObject.getValues (*channel)->correctForTimeslew();
00569        int  bb3=fObject.getValues (*channel)->timeslewCorrectionID();
00570        bool bb4=fObject.getValues (*channel)->correctTiming();
00571        int  bb5=fObject.getValues (*channel)->firstAuxTS();
00572        int  bb6=fObject.getValues (*channel)->specialCaseID();
00573        int  bb7=fObject.getValues (*channel)->noiseFlaggingID();
00574        int  bb8=fObject.getValues (*channel)->pileupCleaningID();
00575        int  bb9=fObject.getValues (*channel)->packingScheme();
00576        sprintf(buffer," %6d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",bb0,bb1,bb2,bb3,bb4,bb5,bb6,bb7,bb8,bb9);
00577        fOutput << buffer;
00578      }   // packingScheme 1.
00579 
00580   }  // loop ever channels
00581   return true;
00582 }
00583 
00584 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLongRecoParams* fObject)
00585 {
00586   if (!fObject) fObject = new HcalLongRecoParams();
00587   char buffer [1024];
00588   while (fInput.getline(buffer, 1024)) {
00589     if (buffer [0] == '#') continue; //ignore comment
00590     std::vector <std::string> items = splitString (std::string (buffer));
00591     if (items.size()==0) continue; // blank line
00592     if (items.size() < 5) {
00593       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, signalTSs, noiseTSs" << std::endl;
00594       continue;
00595     }
00596     if (items.size() > 7) {
00597       edm::LogWarning("Format Problem ?") << "Check line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, signalTSs, noiseTSs. "
00598                                           << "\n ! signalTS and noiseTS must be of format <ts1,ts2,ts3,...> withOUT spaces. Ignoring line for safety" << std::endl;
00599       continue;
00600     }
00601     DetId id = HcalDbASCIIIO::getId (items);
00602     
00603     std::vector<unsigned int> mySignalTS = splitStringToIntByComma(items[4]);
00604     std::vector<unsigned int> myNoiseTS = splitStringToIntByComma(items[5]);
00605 
00606     HcalLongRecoParam* fCondObject = new HcalLongRecoParam(id, mySignalTS, myNoiseTS );
00607     fObject->addValues(*fCondObject);
00608     delete fCondObject;
00609   }
00610   return true;
00611 }
00612 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalTimingParams* fObject)
00613 {
00614   if (!fObject) fObject = new HcalTimingParams();
00615   char buffer [1024];
00616   while (fInput.getline(buffer, 1024)) {
00617     if (buffer [0] == '#') continue; //ignore comment
00618     std::vector <std::string> items = splitString (std::string (buffer));
00619     if (items.size()==0) continue; // blank line
00620     if (items.size () < 7) {
00621       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, nhit, phase, rms,detid" << std::endl;
00622       continue;
00623     }
00624     //std::cout<<"items[3] "<<items [3]<<std::endl;
00625     //std::cout<<"items[0] "<<items [0]<<std::endl;
00626     //std::cout<<"items[1] "<<items [1]<<std::endl;
00627     //std::cout<<"items[2] "<<items [2]<<std::endl;
00628 
00629     //std::cout<<"items[4] "<<items [4]<<std::endl;
00630     //std::cout<<"items[5] "<<items [5]<<std::endl;
00631     //std::cout<<"items[6] "<<items [6]<<std::endl;
00632     DetId id = HcalDbASCIIIO::getId (items);
00633     //std::cout<<"calculated id "<<id.rawId()<<std::endl;
00634     HcalTimingParam* fCondObject = new HcalTimingParam(id, atoi (items [4].c_str()), atof (items [5].c_str()), atof (items [6].c_str()));
00635     fObject->addValues(*fCondObject);
00636     delete fCondObject;
00637   }
00638   return true;
00639 }
00640 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalTimingParams& fObject)
00641 {
00642   char buffer [1024];
00643   sprintf (buffer, "# %15s %15s %15s %15s %15s %15s %15s %15s\n", "eta", "phi", "dep", "det", "nhit", "mean","rms" ,"DetId");
00644   fOutput << buffer;
00645   std::vector<DetId> channels = fObject.getAllChannels ();
00646   std::sort (channels.begin(), channels.end(), DetIdLess ());
00647   for (std::vector<DetId>::iterator channel = channels.begin ();
00648        channel !=  channels.end ();
00649        channel++) {
00650     HcalDbASCIIIO::dumpId (fOutput, *channel);
00651     sprintf (buffer, " %15d %8.5f %8.5f %16X\n",
00652              fObject.getValues (*channel)->nhits(), fObject.getValues (*channel)->phase(),fObject.getValues(*channel)->rms(),channel->rawId ());
00653     fOutput << buffer;
00654   }
00655   return true;
00656 }
00657 
00658 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalLongRecoParams& fObject)
00659 {
00660   char buffer [1024];
00661   sprintf (buffer, "# %15s %15s %15s %15s %10s %10s %10s\n", "eta", "phi", "dep", "det", "signalTSs", "noiseTSs", "DetId");
00662   fOutput << buffer;
00663   std::vector<DetId> channels = fObject.getAllChannels ();
00664   std::sort (channels.begin(), channels.end(), DetIdLess ());
00665   for (std::vector<DetId>::iterator channel = channels.begin ();
00666        channel !=  channels.end ();
00667        channel++) {
00668     HcalGenericDetId fId(*channel);
00669     if (fId.isHcalZDCDetId())
00670       {
00671         std::vector<unsigned int> vSignalTS = fObject.getValues (*channel)->signalTS();
00672         std::vector<unsigned int> vNoiseTS = fObject.getValues (*channel)->noiseTS();
00673         HcalDbASCIIIO::dumpId (fOutput, *channel);
00674         sprintf (buffer, "    ");
00675         fOutput << buffer;
00676         for (unsigned int i=0; i<vSignalTS.size(); i++)
00677           {
00678             if (i>0) {sprintf (buffer, ",");   fOutput << buffer;}
00679             sprintf (buffer, "%u", vSignalTS.at(i));
00680             fOutput << buffer;
00681           }
00682         sprintf (buffer, "       ");
00683         fOutput << buffer;
00684         for (unsigned int i=0; i<vNoiseTS.size(); i++)
00685           {
00686             if (i>0) { sprintf (buffer, ",");   fOutput << buffer;}
00687             sprintf (buffer, "%u", vNoiseTS.at(i));
00688             fOutput << buffer;
00689           }
00690         sprintf (buffer, "     %10X\n", channel->rawId ());
00691         fOutput << buffer;
00692       }
00693   }
00694   return true;
00695 }
00696 
00697 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalMCParams* fObject)
00698 {
00699   if (!fObject) fObject = new HcalMCParams();
00700   char buffer [1024];
00701   while (fInput.getline(buffer, 1024)) {
00702     if (buffer [0] == '#') continue; //ignore comment
00703     std::vector <std::string> items = splitString (std::string (buffer));
00704     if (items.size()==0) continue; // blank line
00705     if (items.size () < 5) {
00706       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 5 items: eta, phi, depth, subdet, signalShape" << std::endl;
00707       continue;
00708     }
00709     DetId id = HcalDbASCIIIO::getId (items);
00710 
00711     int packingScheme=0;
00712     if(items.size ()>11) {
00713        packingScheme = atoi (items [11].c_str());
00714     }
00715 
00716     int param1=0;
00717     if(packingScheme==0) {
00718         param1=atoi (items [4].c_str());
00719     }
00720 
00721     if(packingScheme==1) {
00722        int aabits[6]={  9,1, 4,  8,5, 4};   // 4 spear bits added to aabits[5]
00723        int aamax [6]={511,1,15,255,1,16};
00724        int j=0;
00725        int aa;
00726        int aashift=0;
00727        for(int i=0; i<6; i++) {
00728           j=i+6;
00729           if(i==3) {
00730             float phase=atof (items [j].c_str());
00731             float xphase=(phase+32.0)*4.0;   // range of phase [-30.0,30.0] 
00732             aa=xphase;
00733           } else {
00734             aa=atoi (items [j].c_str());
00735           }
00736           if(aa>aamax[i] || aa<0) {
00737               edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value for a"<<i<<" should be less than"<<aamax[i]<< std::endl;
00738           }
00739 
00740           param1=param1|aa<<aashift;
00741           aashift=aashift+aabits[i];
00742        }
00743     }
00744 
00745     HcalMCParam* fCondObject = new HcalMCParam(id, param1 );
00746     fObject->addValues(*fCondObject);
00747     delete fCondObject;
00748   }
00749   return true;
00750 }
00751 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalMCParams& fObject)
00752 {
00753   char buffer [1024];
00754   // sprintf (buffer, "# %15s %15s %15s %15s %14s %10s\n", "eta", "phi", "dep", "det", "signalShape", "DetId");
00755   // fOutput << buffer;
00756   std::vector<DetId> channels = fObject.getAllChannels ();
00757   std::sort (channels.begin(), channels.end(), DetIdLess ());
00758   int  myCounter=0;
00759   for (std::vector<DetId>::iterator channel = channels.begin ();
00760        channel !=  channels.end ();
00761        channel++) {
00762     myCounter++;;  
00763     int packingScheme=fObject.getValues (*channel)->packingScheme();
00764     if(packingScheme==0) {
00765        if(myCounter==1) {
00766           sprintf (buffer, "# %15s %15s %15s %15s %14s %10s\n", "eta", "phi", "dep", "det", "signalShape", "DetId");
00767           fOutput << buffer;
00768        }
00769            const int value = fObject.getValues (*channel)->signalShape();
00770        HcalDbASCIIIO::dumpId (fOutput, *channel);
00771        sprintf (buffer, " %10d %17X\n", value, channel->rawId ());
00772        fOutput << buffer;
00773     }  // packingScheme 0
00774     if(packingScheme==1) {
00775       if(myCounter==1) {
00776         char lineT[100],lineA[200];
00777         //
00778         sprintf (lineT, "#%40s","  ");   fOutput << lineT;
00779         sprintf (lineA, " %31s","a0: signalShape\n"); fOutput << lineA;
00780         sprintf (lineT, "#%40s","  ");   fOutput << lineT;
00781         sprintf (lineA, " %31s","a1: syncPhase\n"); fOutput << lineA;
00782         sprintf (lineT, "#%40s","  ");   fOutput << lineT;
00783         sprintf (lineA, " %31s","a2: binOfMaximum\n"); fOutput << lineA;
00784         sprintf (lineT, "#%40s","  ");   fOutput << lineT;
00785         sprintf (lineA, " %31s","a3: timePhase\n"); fOutput << lineA;
00786         sprintf (lineT, "#%40s","  ");   fOutput << lineT;
00787         sprintf (lineA, " %31s","a4: timeSmearing\n"); fOutput << lineA;
00788         sprintf (lineT, "#%40s","  ");   fOutput << lineT;
00789         sprintf (lineA, " %31s","a5: packingScheme\n"); fOutput << lineA;
00790         sprintf (lineT, "# %5s %4s %4s %10s %11s %10s", "eta", "phi", "dep", "det", "param1", "DetId");
00791         fOutput << lineT;
00792         sprintf (lineA, " %6s %4s %4s %6s %4s %4s\n", "a0", "a1", "a2", "a3", "a4", "a5");
00793         fOutput << lineA;
00794       }
00795       int   param1 = fObject.getValues (*channel)->param1();
00796       HcalDbASCIIIO::dumpIdShort (fOutput, *channel);
00797       sprintf (buffer, " %11d  %10X", param1, channel->rawId ());
00798       fOutput << buffer;
00799      int   aa0 = fObject.getValues (*channel)->signalShape(); 
00800      bool  aa1 = fObject.getValues (*channel)->syncPhase(); 
00801      int   aa2 = fObject.getValues (*channel)->binOfMaximum();
00802      float aa3 = fObject.getValues (*channel)->timePhase();
00803      bool  aa4 = fObject.getValues (*channel)->timeSmearing() ;
00804      int   aa5 = fObject.getValues (*channel)->packingScheme();
00805      sprintf (buffer, "%6d %4d %4d %6.1f %4d %4d\n",aa0,aa1,aa2,aa3,aa4,aa5);
00806      fOutput << buffer;
00807     }
00808   }
00809   return true;
00810 }
00811 
00812 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPedestals* fObject) {
00813   if (!fObject) fObject = new HcalPedestals(false);
00814   char buffer [1024];
00815 
00816   while (fInput.getline(buffer, 1024)) {
00817     std::vector <std::string> items = splitString (std::string (buffer));
00818     if (items.size()==0) continue; // blank line
00819     else {
00820       if (items[0] == "#U")
00821         {
00822           if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
00823             else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
00824           else 
00825             {
00826               edm::LogWarning("Pedestal Unit Error") << "Unrecognized unit for pedestals. Assuming fC." << std::endl;
00827               fObject->setUnitADC(false);
00828             }
00829           break;
00830         }
00831       else
00832         {
00833           edm::LogWarning("Pedestal Unit Missing") << "The unit for the pedestals is missing in the txt file." << std::endl;
00834           return false;
00835         }
00836     }
00837   }
00838   while (fInput.getline(buffer, 1024)) {
00839     if (buffer [0] == '#') continue;
00840     std::vector <std::string> items = splitString (std::string (buffer));
00841     if (items.size()==0) continue; // blank line
00842     if (items.size () < 8) {
00843       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values" 
00844                                       << " or 12 items: eta, phi, depth, subdet, 4x values for mean, 4x values for width"
00845                                       << std::endl;
00846       continue;
00847     }
00848     DetId id = getId (items);
00849     
00850 //    if (fObject->exists(id) )
00851 //      edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
00852 //    else
00853 //      {
00854 
00855     if (items.size() < 12) // old format without widths
00856       {
00857         HcalPedestal* fCondObject = new HcalPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()), 
00858                                                      atof (items [6].c_str()), atof (items [7].c_str()), 
00859                                                      0., 0., 0., 0. );
00860         fObject->addValues(*fCondObject);
00861         delete fCondObject;
00862       }
00863     else // new format with widths
00864       {
00865         HcalPedestal* fCondObject = new HcalPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()), 
00866                                                      atof (items [6].c_str()), atof (items [7].c_str()), 
00867                                                      atof (items [8].c_str()), atof (items [9].c_str()),
00868                                                      atof (items [10].c_str()), atof (items [11].c_str()) );
00869         fObject->addValues(*fCondObject);
00870         delete fCondObject;
00871       }
00872 
00873         //      }
00874   }
00875   return true;
00876 }
00877 
00878 
00879 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPedestals& fObject) {
00880   char buffer [1024];
00881   if (fObject.isADC() ) sprintf (buffer, "#U ADC  << this is the unit \n");
00882   else  sprintf (buffer, "#U fC  << this is the unit \n");
00883   fOutput << buffer;
00884 
00885   sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n", "eta", "phi", "dep", "det", "cap0", "cap1", "cap2", "cap3", "widthcap0", "widthcap1", "widthcap2", "widthcap3", "DetId");
00886   fOutput << buffer;
00887 
00888   std::vector<DetId> channels = fObject.getAllChannels ();
00889   std::sort (channels.begin(), channels.end(), DetIdLess ());
00890   for (std::vector<DetId>::iterator channel = channels.begin ();
00891        channel !=  channels.end ();
00892        channel++) {
00893     const float* values = fObject.getValues (*channel)->getValues ();
00894     if (values) {
00895       dumpId (fOutput, *channel);
00896       sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
00897                values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], channel->rawId ());
00898       fOutput << buffer;
00899     }
00900   }
00901   return true;
00902 }
00903 
00904 
00905 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
00906 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalChannelQuality* fObject) 
00907 {
00908   if (!fObject) fObject = new HcalChannelQuality;
00909   char buffer [1024];
00910   while (fInput.getline(buffer, 1024)) {
00911     if (buffer [0] == '#') continue; //ignore comment
00912     std::vector <std::string> items = splitString (std::string (buffer));
00913     if (items.size()==0) continue; // blank line
00914     if (items.size () < 6) {
00915       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, base - either (hex) or (dec), value" << std::endl;
00916       continue;
00917     }
00918     DetId id = getId (items);
00919     
00920 //    if (fObject->exists(id) )
00921 //      edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
00922 //    else
00923 //      {
00924     uint32_t mystatus;
00925     if (items[4] == "(hex)")
00926       sscanf(items[5].c_str(),"%X", &mystatus);
00927     else if (items[4] == "(dec)")
00928       sscanf(items[5].c_str(),"%u", &mystatus);
00929     else
00930       {
00931         edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value field must contain the base: one of (hex), (dec)" << std::endl;
00932         continue;
00933       }
00934 
00935     HcalChannelStatus* fCondObject = new HcalChannelStatus(id, mystatus); //atoi (items [4].c_str()) );
00936     fObject->addValues(*fCondObject);
00937     delete fCondObject;
00938         //      }
00939   }
00940   return true;
00941 }
00942 
00943 
00944 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalChannelQuality& fObject) {
00945   char buffer [1024];
00946   sprintf (buffer, "# %15s %15s %15s %15s %15s %10s\n", "eta", "phi", "dep", "det", "(base) value", "DetId");
00947   fOutput << buffer;
00948   std::vector<DetId> channels = fObject.getAllChannels ();
00949   std::sort (channels.begin(), channels.end(), DetIdLess ());
00950   for (std::vector<DetId>::iterator channel = channels.begin ();
00951        channel !=  channels.end ();
00952        channel++) {
00953     const int value = fObject.getValues (*channel)->getValue ();
00954     dumpId (fOutput, *channel);
00955     sprintf (buffer, "%6s %15X %10X\n", "(hex)",
00956              value, channel->rawId ());
00957     fOutput << buffer;
00958   }
00959   return true;
00960 }
00961 
00962 
00963 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
00964 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalL1TriggerObjects* fObject)
00965 {
00966   if (!fObject) fObject = new HcalL1TriggerObjects;
00967   char buffer [1024];
00968 
00969   while (fInput.getline(buffer, 1024)) {
00970     if (buffer [0] == '#') 
00971       {
00972         if (buffer [1] == 'T') // contains tag name
00973           {
00974             std::vector <std::string> items = splitString (std::string (buffer) );
00975             fObject->setTagString(items[1]);
00976             continue;
00977           }
00978         if (buffer [1] == 'A') // contains algo name
00979           {
00980             std::vector <std::string> items = splitString (std::string (buffer) );
00981             fObject->setAlgoString(items[1]);
00982             continue;
00983           }
00984         else continue; //ignore comment
00985       }
00986     std::vector <std::string> items = splitString (std::string (buffer));
00987     if (items.size()==0) continue; // blank line
00988     if (items.size () < 7) { 
00989       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, pedestal, resp.corr.gain, flag" << std::endl;
00990       continue;
00991     }
00992     DetId id = getId (items);
00993     
00994     HcalL1TriggerObject* fCondObject = new HcalL1TriggerObject(id, atof(items[4].c_str()), atof(items[5].c_str()), atoi(items[6].c_str()) );
00995     
00996     fObject->addValues(*fCondObject);
00997     delete fCondObject;
00998   }
00999   return true;
01000 }
01001 
01002 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalL1TriggerObjects& fObject)
01003 {
01004   char buffer [1024];
01005   //first print tag and algo
01006   sprintf (buffer, "#T %s  << this is the tag name \n", fObject.getTagString().c_str() );
01007   fOutput << buffer;
01008   sprintf (buffer, "#A %s  << this is the algorithm name \n", fObject.getAlgoString().c_str() );
01009   fOutput << buffer;
01010 
01011   //then the values
01012   sprintf (buffer, "# %15s %15s %15s %15s %8s %13s %8s %10s\n", 
01013            "eta", "phi", "dep", "det", "ped", "respcorrgain", "flag",
01014            "DetId");
01015   fOutput << buffer;
01016   std::vector<DetId> channels = fObject.getAllChannels ();
01017   //  std::sort (channels.begin(), channels.end(), DetIdLess ());
01018   for (std::vector<DetId>::iterator channel = channels.begin ();
01019        channel !=  channels.end ();
01020        channel++) {
01021     const HcalL1TriggerObject* item = fObject.getValues (*channel);
01022     if (item) {
01023       dumpId (fOutput, *channel);
01024       sprintf (buffer, " %10.7f %10.7f %12d %10X\n",
01025                item->getPedestal(), item->getRespGain(), item->getFlag(), channel->rawId ());
01026       fOutput << buffer;
01027     }
01028   }
01029   return true;
01030 
01031 }
01032 
01033 
01034 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
01035 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPedestalWidths* fObject) {
01036   if (!fObject) fObject = new HcalPedestalWidths(false);
01037   char buffer [1024];
01038   int linecounter = 0;
01039 
01040   while (fInput.getline(buffer, 1024)) {
01041     linecounter++;
01042     std::vector <std::string> items = splitString (std::string (buffer));
01043     if (items.size()==0) continue; // blank line
01044     else {
01045       if (items[0] == (std::string)"#U")
01046         {
01047           if (items[1] == (std::string)"ADC") fObject->setUnitADC(true); 
01048           else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
01049           else 
01050             {
01051               edm::LogWarning("Pedestal Width Unit Error") << "Unrecognized unit for pedestal widths. Assuming fC." << std::endl;
01052               fObject->setUnitADC(false);
01053             }
01054           break;
01055         }
01056       else
01057         {
01058           edm::LogWarning("Pedestal Width Unit Missing") << "The unit for the pedestal widths is missing in the txt file." << std::endl;
01059           return false;
01060         }
01061     }
01062   }
01063 
01064   while (fInput.getline(buffer, 1024)) {
01065     linecounter++;
01066     if (buffer [0] == '#') continue; //ignore comment
01067     std::vector <std::string> items = splitString (std::string (buffer));
01068     if (items.size()==0) continue; // blank line
01069     if (items.size () < 14) {
01070       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line number: " << linecounter << "\n line must contain 14 items: eta, phi, depth, subdet, 10x correlations" 
01071                                       << " or 20 items: eta, phi, depth, subdet, 16x correlations" 
01072                                       << std::endl;
01073       continue;
01074     }
01075     DetId id = getId (items);
01076 
01077 //    if (fObject->exists(id) )
01078 //      edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
01079 //    else
01080 //      {
01081 
01082     if (items.size() < 20) //old format
01083       {
01084         HcalPedestalWidth values(id);
01085         values.setSigma (0, 0, atof (items [4].c_str()));
01086         values.setSigma (1, 0, atof (items [5].c_str()));
01087         values.setSigma (1, 1, atof (items [6].c_str()));
01088         values.setSigma (2, 0, atof (items [7].c_str()));
01089         values.setSigma (2, 1, atof (items [8].c_str()));
01090         values.setSigma (2, 2, atof (items [9].c_str()));
01091         values.setSigma (3, 0, atof (items [10].c_str()));
01092         values.setSigma (3, 1, atof (items [11].c_str()));
01093         values.setSigma (3, 2, atof (items [12].c_str()));
01094         values.setSigma (3, 3, atof (items [13].c_str()));
01095         values.setSigma (0, 1, 0.);
01096         values.setSigma (0, 2, 0.);
01097         values.setSigma (0, 3, 0.);
01098         values.setSigma (1, 2, 0.);
01099         values.setSigma (1, 3, 0.);
01100         values.setSigma (2, 3, 0.);
01101         fObject->addValues(values);     
01102       }
01103     else // new format
01104       {
01105         HcalPedestalWidth values(id);
01106         values.setSigma (0, 0, atof (items [4].c_str()) );
01107         values.setSigma (0, 1, atof (items [5].c_str()) );
01108         values.setSigma (0, 2, atof (items [6].c_str()) );
01109         values.setSigma (0, 3, atof (items [7].c_str()) );
01110         values.setSigma (1, 0, atof (items [8].c_str()) );
01111         values.setSigma (1, 1, atof (items [9].c_str()) );
01112         values.setSigma (1, 2, atof (items [10].c_str()) );
01113         values.setSigma (1, 3, atof (items [11].c_str()) );
01114         values.setSigma (2, 0, atof (items [12].c_str()) );
01115         values.setSigma (2, 1, atof (items [13].c_str()) );
01116         values.setSigma (2, 2, atof (items [14].c_str()) );
01117         values.setSigma (2, 3, atof (items [15].c_str()) );
01118         values.setSigma (3, 0, atof (items [16].c_str()) );
01119         values.setSigma (3, 1, atof (items [17].c_str()) );
01120         values.setSigma (3, 2, atof (items [18].c_str()) );
01121         values.setSigma (3, 3, atof (items [19].c_str()) );
01122         fObject->addValues(values);     
01123       }
01124 
01125         //      }
01126   }
01127   return true;
01128 }
01129 
01130 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPedestalWidths& fObject) {
01131   char buffer [1024];
01132   if (fObject.isADC() ) sprintf (buffer, "#U ADC  << this is the unit \n");
01133   else  sprintf (buffer, "#U fC  << this is the unit \n");
01134   fOutput << buffer;
01135 
01136   sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n", 
01137            "eta", "phi", "dep", "det", 
01138            "cov_0_0", "cov_0_1", "cov_0_2", "cov_0_3", "cov_1_0", "cov_1_1", "cov_1_2", "cov_1_3", "cov_2_0", "cov_2_1", "cov_2_2", "cov_2_3", "cov_3_0", "cov_3_1", "cov_3_2", "cov_3_3", 
01139            "DetId");
01140   fOutput << buffer;
01141   std::vector<DetId> channels = fObject.getAllChannels ();
01142   std::sort (channels.begin(), channels.end(), DetIdLess ());
01143   for (std::vector<DetId>::iterator channel = channels.begin ();
01144        channel !=  channels.end ();
01145        channel++) {
01146     const HcalPedestalWidth* item = fObject.getValues (*channel);
01147     if (item) {
01148       dumpId (fOutput, *channel);
01149       sprintf (buffer, " %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",
01150                item->getSigma (0,0), item->getSigma (0,1), item->getSigma (0,2), item->getSigma (0,3), 
01151                item->getSigma (1,0), item->getSigma (1,1), item->getSigma (1,2), item->getSigma (1,3),
01152                item->getSigma (2,0), item->getSigma (2,1), item->getSigma (2,2), item->getSigma (2,3),
01153                item->getSigma (3,0), item->getSigma (3,1), item->getSigma (3,2), item->getSigma (3,3), channel->rawId ());
01154       fOutput << buffer;
01155     }
01156   }
01157   return true;
01158 }
01159 
01160 
01161 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
01162 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalQIEData* fObject) {
01163   char buffer [1024];
01164   while (fInput.getline(buffer, 1024)) {
01165     if (buffer [0] == '#') continue; //ignore comment
01166     std::vector <std::string> items = splitString (std::string (buffer));
01167     if (items.size()<1) continue;
01168     if (items [0] == "SHAPE") { // basic shape
01169       if (items.size () < 33) {
01170         edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 33 items: SHAPE  32 x low QIE edges for first 32 bins" << std::endl;
01171         continue;
01172       }
01173       // comment, as normally not used ----------------------- 
01174       /* 
01175       float lowEdges [32];
01176       int i = 32;
01177       while (--i >= 0) lowEdges [i] = atof (items [i+1].c_str ());
01178       */
01179       //      fObject->setShape (lowEdges);
01180     }
01181     else { // QIE parameters
01182       if (items.size () < 36) {
01183         edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 36 items: eta, phi, depth, subdet, 4 capId x 4 Ranges x offsets, 4 capId x 4 Ranges x slopes" << std::endl;
01184         continue;
01185       }
01186       DetId id = getId (items);
01187       fObject->sort ();
01188       //      try {
01189       //      fObject->getCoder (id);
01190       //      edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
01191         //      }
01192 //      catch (cms::Exception& e) {
01193         HcalQIECoder coder (id.rawId ());
01194         int index = 4;
01195         for (unsigned capid = 0; capid < 4; capid++) {
01196           for (unsigned range = 0; range < 4; range++) {
01197             coder.setOffset (capid, range, atof (items [index++].c_str ()));
01198           }
01199         }
01200         for (unsigned capid = 0; capid < 4; capid++) {
01201           for (unsigned range = 0; range < 4; range++) {
01202             coder.setSlope (capid, range, atof (items [index++].c_str ()));
01203           }
01204         }
01205         fObject->addCoder (coder);
01206 //      }
01207     }
01208   }
01209   fObject->sort ();
01210   return true;
01211 }
01212 
01213 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalQIEData& fObject) {
01214   char buffer [1024];
01215   fOutput << "# QIE basic shape: SHAPE 32 x low edge values for first 32 channels" << std::endl;
01216   sprintf (buffer, "SHAPE ");
01217   fOutput << buffer;
01218   for (unsigned bin = 0; bin < 32; bin++) {
01219     sprintf (buffer, " %8.5f", fObject.getShape ().lowEdge (bin));
01220     fOutput << buffer;
01221   }
01222   fOutput << std::endl;
01223 
01224   fOutput << "# QIE data" << std::endl;
01225   sprintf (buffer, "# %15s %15s %15s %15s %36s %36s %36s %36s %36s %36s %36s %36s\n", 
01226            "eta", "phi", "dep", "det", 
01227            "4 x offsets cap0", "4 x offsets cap1", "4 x offsets cap2", "4 x offsets cap3",
01228            "4 x slopes cap0", "4 x slopes cap1", "4 x slopes cap2", "4 x slopes cap3");
01229   fOutput << buffer;
01230   std::vector<DetId> channels = fObject.getAllChannels ();
01231   std::sort (channels.begin(), channels.end(), DetIdLess ());
01232   for (std::vector<DetId>::iterator channel = channels.begin ();
01233        channel !=  channels.end ();
01234        channel++) {
01235     const HcalQIECoder* coder = fObject.getCoder (*channel);
01236     dumpId (fOutput, *channel);
01237     for (unsigned capid = 0; capid < 4; capid++) {
01238       for (unsigned range = 0; range < 4; range++) {
01239         sprintf (buffer, " %8.5f", coder->offset (capid, range));
01240         fOutput << buffer;
01241       }
01242     }
01243     for (unsigned capid = 0; capid < 4; capid++) {
01244       for (unsigned range = 0; range < 4; range++) {
01245         sprintf (buffer, " %8.5f", coder->slope (capid, range));
01246         fOutput << buffer;
01247       }
01248     }
01249     fOutput << std::endl;
01250   }
01251   return true;
01252 }
01253 
01254 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
01255 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCalibrationQIEData* fObject) {
01256   char buffer [1024];
01257   while (fInput.getline(buffer, 1024)) {
01258     if (buffer [0] == '#') continue; //ignore comment
01259     std::vector <std::string> items = splitString (std::string (buffer));
01260     if (items.size () < 36) {
01261       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 36 items: eta, phi, depth, subdet, 32 bin values" << std::endl;
01262       continue;
01263     }
01264     DetId id = getId (items);
01265     fObject->sort ();
01266     //    try {
01267     //    fObject->getCoder (id);
01268     //    edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
01269       //    }
01270 //    catch (cms::Exception& e) {
01271       HcalCalibrationQIECoder coder (id.rawId ());
01272       int index = 4;
01273       float values [32];
01274       for (unsigned bin = 0; bin < 32; bin++) {
01275         values[bin] = atof (items [index++].c_str ());
01276       }
01277       coder.setMinCharges (values);
01278       fObject->addCoder (coder);
01279 //    }
01280   }
01281   fObject->sort ();
01282   return true;
01283 }
01284 
01285 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCalibrationQIEData& fObject) {
01286   char buffer [1024];
01287   fOutput << "# QIE data in calibration mode" << std::endl;
01288   sprintf (buffer, "# %15s %15s %15s %15s %288s\n", 
01289            "eta", "phi", "dep", "det", "32 x charges");
01290   fOutput << buffer;
01291   std::vector<DetId> channels = fObject.getAllChannels ();
01292   std::sort (channels.begin(), channels.end(), DetIdLess ());
01293   for (std::vector<DetId>::iterator channel = channels.begin ();
01294        channel !=  channels.end ();
01295        channel++) {
01296     const HcalCalibrationQIECoder* coder = fObject.getCoder (*channel);
01297     if (coder) {
01298       dumpId (fOutput, *channel);
01299       const float* lowEdge = coder->minCharges ();
01300       for (unsigned bin = 0; bin < 32; bin++) {
01301         sprintf (buffer, " %8.5f", lowEdge [bin]);
01302         fOutput << buffer;
01303       }
01304       fOutput << std::endl;
01305     }
01306   }
01307   return true;
01308 }
01309 
01310 
01311 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
01312 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalElectronicsMap* fObject) {
01313   char buffer [1024];
01314   while (fInput.getline(buffer, 1024)) {
01315     if (buffer [0] == '#') continue; //ignore comment
01316     std::vector <std::string> items = splitString (std::string (buffer));
01317     if (items.size () < 12) {
01318       if (items.size()==0) continue; // no warning here
01319       if (items.size()<9) {
01320         edm::LogError("MapFormat") << "HcalElectronicsMap-> line too short: " << buffer;
01321         continue;
01322       }
01323       if (items[8]=="NA" || items[8]=="NT") {
01324         while (items.size()<12) items.push_back(""); // don't worry here
01325       } else if (items[8]=="HT") {
01326         if (items.size()==11) items.push_back("");
01327         else {
01328           edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer 
01329                                      << "\n HT line must contain at least 11 items: i  cr sl tb dcc spigot fiber fiberchan subdet=HT ieta iphi";
01330           continue;
01331         }
01332       } else {
01333         edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer 
01334                                    << "\n line must contain 12 items: i  cr sl tb dcc spigot fiber fiberchan subdet ieta iphi depth";
01335         continue;
01336       }
01337     }
01338     //    std::cout << "HcalElectronicsMap-> processing line: " << buffer << std::endl;
01339     int crate = atoi (items [1].c_str());
01340     int slot = atoi (items [2].c_str());
01341     int top = 1;
01342     if (items [3] == "b") top = 0;
01343     int dcc = atoi (items [4].c_str());
01344     int spigot = atoi (items [5].c_str());
01345     HcalElectronicsId elId;
01346     if (items[8] == "HT" || items[8] == "NT") {
01347       int slb = atoi (items [6].c_str());
01348       int slbCh = atoi (items [7].c_str());
01349       elId=HcalElectronicsId(slbCh, slb, spigot, dcc,crate,slot,top);
01350     } else {
01351       int fiber = atoi (items [6].c_str());
01352       int fiberCh = atoi (items [7].c_str());
01353 
01354       elId=HcalElectronicsId(fiberCh, fiber, spigot, dcc);
01355       elId.setHTR (crate, slot, top);
01356     }
01357 
01358     // first, handle undefined cases
01359     if (items [8] == "NA") { // undefined channel
01360       fObject->mapEId2chId (elId, DetId (HcalDetId::Undefined));
01361     } else if (items [8] == "NT") { // undefined trigger channel
01362       fObject->mapEId2tId (elId, DetId (HcalTrigTowerDetId::Undefined));
01363     } else {
01364       HcalText2DetIdConverter converter (items [8], items [9], items [10], items [11]);
01365       if (converter.isHcalDetId ()) { 
01366         fObject->mapEId2chId (elId, converter.getId ());
01367       }
01368       else if (converter.isHcalTrigTowerDetId ()) {
01369         fObject->mapEId2tId (elId, converter.getId ());
01370       }
01371       else if (converter.isHcalCalibDetId ()) {
01372         fObject->mapEId2chId (elId, converter.getId ());
01373       }
01374       else if (converter.isHcalZDCDetId ()) {
01375         fObject->mapEId2chId (elId, converter.getId ());
01376       }
01377       else {
01378         edm::LogWarning("Format Error") << "HcalElectronicsMap-> Unknown subdetector: " 
01379                   << items [8] << '/' << items [9] << '/' << items [10] << '/' << items [11] << std::endl; 
01380       }
01381     }
01382   }
01383   fObject->sort ();
01384   return true;
01385 }
01386 
01387 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalElectronicsMap& fObject) {
01388   std::vector<HcalElectronicsId> eids = fObject.allElectronicsId ();
01389   char buf [1024];
01390   // changes by Jared, 6.03.09/(included 25.03.09)
01391   //  sprintf (buf, "#%10s %6s %6s %6s %6s %6s %6s %6s %15s %15s %15s %15s",
01392   sprintf (buf, "# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
01393            "i", "cr", "sl", "tb", "dcc", "spigot", "fiber/slb", "fibcha/slbcha", "subdet", "ieta", "iphi", "depth");
01394   fOutput << buf << std::endl;
01395 
01396   for (unsigned i = 0; i < eids.size (); i++) {
01397     HcalElectronicsId eid = eids[i];
01398     if (eid.isTriggerChainId()) {
01399       DetId trigger = fObject.lookupTrigger (eid);
01400       if (trigger.rawId ()) {
01401         HcalText2DetIdConverter converter (trigger);
01402         // changes by Jared, 6.03.09/(included 25.03.09)
01403         //      sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
01404         sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
01405                  //              i,
01406                  converter.getId().rawId(),
01407                  // changes by Jared, 6.03.09/(included 25.03.09)
01408                  //              eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
01409                  eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.slbSiteNumber(), eid.slbChannelIndex(),
01410                  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
01411                  );
01412         fOutput << buf << std::endl;
01413       }
01414     } else {
01415       DetId channel = fObject.lookup (eid);
01416       if (channel.rawId()) {
01417         HcalText2DetIdConverter converter (channel);
01418         // changes by Jared, 6.03.09/(included 25.03.09)
01419         //      sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
01420         sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
01421                  //              i,
01422                  converter.getId().rawId(),
01423                  eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
01424                  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
01425                );
01426         fOutput << buf << std::endl;
01427       }
01428     }
01429   }
01430   return true;
01431 }
01432 
01433 
01434 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLutMetadata* fObject){
01435   if (!fObject) fObject = new HcalLutMetadata;
01436   char buffer [1024];
01437   while (fInput.getline(buffer, 1024)) {
01438     if (buffer [0] == '#') continue; //ignore comment
01439     std::vector <std::string> items = splitString (std::string (buffer));
01440     if (items.size()==0) continue; // blank line
01441     // now get non-channel data
01442     if (items.size() > 1 && 
01443         items[0].find("RctLsb")!=std::string::npos){
01444       fObject->setRctLsb( atof( items[1].c_str() ) );
01445       continue;
01446     }
01447     if (items.size() > 1 && 
01448         items[0].find("Gain")!=std::string::npos){
01449       fObject->setNominalGain( atof( items[1].c_str() ) );
01450       continue;
01451     }
01452     // now proceeed to per-channel data
01453     if (items.size () < 7) {
01454       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, Rcalib, LutGranularity, OutputLutThreshold" << std::endl;
01455       continue;
01456     }
01457     DetId id = getId (items);
01458     
01459     HcalLutMetadatum * fCondObject = new HcalLutMetadatum(id,
01460                                                           atof (items [4].c_str()),
01461                                                           atoi (items [5].c_str()),
01462                                                           atoi (items [6].c_str()));
01463     fObject->addValues(*fCondObject);
01464     delete fCondObject;
01465   }
01466   return true;
01467 }
01468 
01469 
01470 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalLutMetadata& fObject){
01471   char buffer [1024];
01472   const float _rctLsb = fObject.getRctLsb();
01473   const float _gain   = fObject.getNominalGain();
01474   sprintf (buffer, "# %20s\n", "Non-channel data");
01475   fOutput << buffer;
01476   sprintf (buffer, "%8s %8.5f\n", "RctLsb", _rctLsb);
01477   fOutput << buffer;
01478   sprintf (buffer, "%8s %8.5f\n", "Gain", _gain);
01479   fOutput << buffer;
01480   sprintf (buffer, "# %15s %15s %15s %15s %8s %15s %19s %10s\n", "eta", "phi", "dep", "det", "Rcalib", "LutGranularity", "OutputLutThreshold", "DetId");
01481   fOutput << buffer;
01482   std::vector<DetId> channels = fObject.getAllChannels ();
01483   std::sort (channels.begin(), channels.end(), DetIdLess ());
01484   for (std::vector<DetId>::iterator channel = channels.begin ();
01485        channel !=  channels.end ();
01486        channel++) {
01487     const float   _rCalib             = fObject.getValues (*channel)->getRCalib();
01488     const uint8_t _lutGranularity     = fObject.getValues (*channel)->getLutGranularity();
01489     const uint8_t _outputLutThreshold = fObject.getValues (*channel)->getOutputLutThreshold();
01490     dumpId (fOutput, *channel);
01491     sprintf (buffer, " %8.5f %15d %19d %10X\n",
01492              _rCalib,
01493              _lutGranularity,
01494              _outputLutThreshold,
01495              channel->rawId ());
01496     fOutput << buffer;
01497   }
01498   return true;
01499 }
01500 
01501 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
01502 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalDcsValues * fObject) {
01503   if (!fObject) fObject = new HcalDcsValues;
01504   std::string buffer;
01505   while (getline(fInput, buffer)) {
01506     if (buffer.at(0) == '#') continue; //ignore comment
01507     std::vector <std::string> items = splitString (buffer);
01508     if (items.size()==0) continue; // blank line
01509 
01510     if (items.size() < 9) {
01511       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 9 items: subDet, side_ring, slice, type, subChannel, LS, Value, UpperLimit, LowerLimit" << std::endl;
01512       continue;
01513     }
01514 
01515     HcalOtherSubdetector subd;
01516     int sidering;
01517     unsigned int slice, subchan;
01518     switch (items[0].at(1)) {
01519     case 'B':
01520       subd = HcalDcsBarrel;
01521       break;
01522     case 'E':
01523       subd = HcalDcsEndcap;
01524       break;
01525     case 'F':
01526       subd = HcalDcsForward;
01527       break;
01528     case 'O':
01529       subd = HcalDcsOuter;
01530       break;
01531     default:
01532       continue;
01533     }
01534     //from_string<int>(subd, items[0], std::dec);
01535     from_string<int>(sidering, items[1], std::dec);
01536     from_string<unsigned int>(slice, items[2], std::dec);
01537     //from_string<int>(ty, items[3], std::dec);
01538     from_string<unsigned int>(subchan, items[4], std::dec);
01539 
01540     HcalDcsDetId newId(subd, sidering, slice, 
01541                        HcalDcsDetId::DcsTypeFromString(items[3]), subchan);
01542 
01543     int LS;
01544     float val,upper,lower;
01545     from_string<int>(LS, items[5], std::dec);
01546     from_string<float>(val, items[6], std::dec);
01547     from_string<float>(upper, items[7], std::dec);
01548     from_string<float>(lower, items[8], std::dec);
01549 
01550     HcalDcsValue newVal(newId.rawId(),LS,val,upper,lower);
01551 //     std::cout << buffer << '\n';
01552 //     std::cout << subd << ' ' << sidering << ' ' << slice << ' '
01553 //            << ty << ' ' << subchan << ' ' << LS << ' '
01554 //            << val << ' ' << upper << ' ' << lower << '\n';
01555 //     std::cout << newId ;
01556     if (!(fObject->addValue(newVal))) {
01557       edm::LogWarning("Data Error") << "Data from line " << buffer 
01558                                     << "\nwas not added to the HcalDcsValues object." << std::endl;
01559     }
01560 //     std::cout << std::endl;
01561   }
01562   fObject->sortAll();
01563   return true;
01564 }
01565 
01566 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, 
01567                                HcalDcsValues const& fObject) {
01568   fOutput << "# subDet side_ring slice type subChan LS Value UpperLimit LowerLimit DcsId\n";
01569   for(int subd = HcalDcsValues::HcalHB; 
01570       subd <= HcalDcsValues::HcalHF; ++subd) {
01571 //     std::cout << "subd: " << subd << '\n';
01572     HcalDcsValues::DcsSet const & vals= 
01573       fObject.getAllSubdetValues(HcalDcsValues::DcsSubDet(subd));
01574     for (HcalDcsValues::DcsSet::const_iterator val = vals.begin(); 
01575          val != vals.end(); ++val) {
01576       HcalDcsDetId valId(val->DcsId());
01577 
01578       switch (valId.subdet()) {
01579       case HcalDcsBarrel:
01580         fOutput << "HB ";
01581         break;
01582       case HcalDcsEndcap:
01583         fOutput << "HE ";
01584         break;
01585       case HcalDcsOuter:
01586         fOutput << "HO ";
01587         break;
01588       case HcalDcsForward:
01589         fOutput << "HF ";
01590         break;
01591       default :
01592         fOutput << valId.subdet() << ' ';
01593       }
01594 
01595       if (valId.subdet() == HcalDcsOuter)
01596         fOutput << valId.ring() << ' ';
01597       else
01598         fOutput << valId.zside() << ' ';
01599 
01600       fOutput << valId.slice() << ' ' 
01601               << valId.typeString(valId.type()) << ' '
01602               << valId.subchannel() << ' ';
01603       fOutput << val->LS() << ' ' 
01604               << val->getValue() << ' '
01605               << val->getUpperLimit() << ' '
01606               << val->getLowerLimit() << ' ';
01607       fOutput << std::hex << val->DcsId() << std::dec << '\n';
01608 
01609 //       std::cout << valId << ' '
01610 //              << valId.subdet() << ' ' 
01611 //              << val->LS() << ' ' << val->getValue() << ' '
01612 //              << val->getUpperLimit() << ' ' << val->getLowerLimit()
01613 //              << std::endl;
01614     }
01615   }
01616 
01617   return true;
01618 }
01619 
01620 
01621 // Format of the ASCII file:
01622 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
01623 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
01624 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalDcsMap* fObject) {
01625   char buffer [1024];
01626   while (fInput.getline(buffer, 1024)) {
01627     if (buffer [0] == '#') continue; //ignore comment
01628     std::vector <std::string> items = splitString (std::string (buffer));
01629     if (items.size () < 8) {
01630       if (items.size()==0) continue; // no warning here
01631       else {
01632         edm::LogError("MapFormat") << "HcalDcsMap-> Bad line: " << buffer 
01633                                    << "\n line must contain 8 items: line side_ring slice subchannel subdet ieta iphi depth";
01634         continue;
01635       }
01636     }
01637     //    std::cout << "HcalDcsMap-> processing line: " << buffer << std::endl;
01638     //int ring = atoi (items [1].c_str());
01639     int ring = atoi(items[1].c_str());
01640     unsigned int slice = atoi (items [2].c_str());
01641     unsigned int subchannel = atoi (items [3].c_str());
01642     HcalDcsDetId::DcsType type = HcalDcsDetId::DCSUNKNOWN;
01643 //    if(items[4].find("HV")!=std::string::npos){
01644 //      type = HcalDcsDetId::HV;
01645 //    }
01646 //    else if (items[4].find("BV")!=std::string::npos){
01647 //      type = HcalDcsDetId::BV;
01648 //    }
01649 //    else if (items[4].find("CATH")!=std::string::npos){
01650 //      type = HcalDcsDetId::CATH;
01651 //    }
01652 //    else if (items[4].find("DYN7")!=std::string::npos){
01653 //      type = HcalDcsDetId::DYN7;
01654 //    }
01655 //    else if (items[4].find("DYN8")!=std::string::npos){
01656 //      type = HcalDcsDetId::DYN8;
01657 //    }
01658 //    else if (items[4].find("RM_TEMP")!=std::string::npos){
01659 //      type = HcalDcsDetId::RM_TEMP;
01660 //    }
01661 //    else if (items[4].find("CCM_TEMP")!=std::string::npos){
01662 //      type = HcalDcsDetId::CCM_TEMP;
01663 //    }
01664 //    else if (items[4].find("CALIB_TEMP")!=std::string::npos){
01665 //      type = HcalDcsDetId::CALIB_TEMP;
01666 //    }
01667 //    else if (items[4].find("LVTTM_TEMP")!=std::string::npos){
01668 //      type = HcalDcsDetId::LVTTM_TEMP;
01669 //    }
01670 //    else if (items[4].find("TEMP")!=std::string::npos){
01671 //      type = HcalDcsDetId::TEMP;
01672 //    }
01673 //    else if (items[4].find("QPLL_LOCK")!=std::string::npos){
01674 //      type = HcalDcsDetId::QPLL_LOCK;
01675 //    }
01676 //    else if (items[4].find("STATUS")!=std::string::npos){
01677 //      type = HcalDcsDetId::STATUS;
01678 //    }
01679 //    else if (items[4].find("DCS_MAX")!=std::string::npos){
01680 //      type = HcalDcsDetId::DCS_MAX;
01681 //    }
01682 //    else{
01683 //      edm::LogError("MapFormat") << "HcalDcsMap-> Unknown DCS Type, line is not accepted: " << items[4];
01684 //      continue;
01685 //    }
01686     HcalOtherSubdetector subdet = HcalOtherEmpty;
01687     if (items[4].find("CALIB")!=std::string::npos){
01688       subdet = HcalCalibration;
01689     }
01690     else if (items[4].find("HB")!=std::string::npos){
01691       subdet = HcalDcsBarrel;
01692     }
01693     else if (items[4].find("HE")!=std::string::npos){
01694       subdet = HcalDcsEndcap;
01695     }
01696     else if (items[4].find("HO")!=std::string::npos){
01697       subdet = HcalDcsOuter;
01698     }
01699     else if (items[4].find("HF")!=std::string::npos){
01700       subdet = HcalDcsForward;
01701     }
01702     else{
01703       edm::LogError("MapFormat") << "HcalDcsMap-> Unknown subdetector, line is not accepted: " << items[5];
01704       continue;
01705     }
01706     HcalDcsDetId dcsId(subdet, ring, slice, type, subchannel);
01707     HcalText2DetIdConverter converter (items [4], items [5], items [6], items [7]);
01708     HcalDetId id(0);
01709     if (converter.isHcalDetId()){
01710       id = converter.getId();
01711     }
01712     else{
01713       edm::LogWarning("Invalid HCAL channel") << "HcalDcsMap-> invalid channel: " 
01714                                               << items [4] << '/' 
01715                                               << items [5] << '/'
01716                                               << items [6] << '/' 
01717                                               << items [7] << std::endl; 
01718       continue;
01719     }
01720     fObject->mapGeomId2DcsId(id, dcsId);
01721   }
01722   fObject->sort ();
01723   return true;
01724 }
01725 
01726 // Format of the ASCII file:
01727 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
01728 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
01729 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalDcsMap& fObject) {
01730   char buf [1024];
01731   sprintf (buf, "# %7s %10s %6s %8s %7s %5s %5s %6s",
01732            "i", "side_ring", "slice", "subchan", "subdet", "ieta", "iphi", "depth");
01733   fOutput << buf << std::endl;
01734   HcalDcsMap::const_iterator _line;
01735   unsigned int line_counter = 0;
01736   for (_line = fObject.beginById();
01737        _line != fObject.endById();
01738        ++_line) {
01739     HcalDcsDetId dcsId = _line.getHcalDcsDetId();
01740     //std::string _dcs_type = "DCSUNKNOWN";
01741     HcalText2DetIdConverter _converter(_line.getHcalDetId());
01742     sprintf (buf, " %8X %10d %6d %8d %7s %5s %5s %6s",
01743              line_counter,
01744              dcsId.ring(), // contains zside() already
01745              dcsId.slice(),
01746              dcsId.subchannel(),
01747              _converter.getFlavor().c_str(),
01748              _converter.getField1().c_str(),
01749              _converter.getField2().c_str(),
01750              _converter.getField3().c_str()
01751              );
01752     fOutput << buf << std::endl;
01753     ++line_counter;
01754   }
01755   return true;
01756 }
01757 
01758 
01759 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalFlagHFDigiTimeParams* fObject)
01760 {
01761   
01762   if (!fObject) fObject = new HcalFlagHFDigiTimeParams();
01763   char buffer [1024];
01764   while (fInput.getline(buffer, 1024)) {
01765     if (buffer [0] == '#') continue; //ignore comment
01766     std::vector <std::string> items = splitString (std::string (buffer));
01767     if (items.size()==0) continue; // blank line
01768     if (items.size () != 9) {
01769       edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain at 9 least items: eta, phi, depth, subdet, firstSample, samplesToAdd, ExpectedPeak, MinEnergy, and a set of comma-separated coefficients" << std::endl;
01770       continue;
01771     }
01772     // expects (ieta, iphi, depth, subdet) as first four arguments
01773     DetId id = HcalDbASCIIIO::getId (items);
01774     std::vector<double> coef= splitStringToDoubleByComma(items[8].c_str());
01775 
01776     HcalFlagHFDigiTimeParam* fCondObject = new HcalFlagHFDigiTimeParam(id, 
01777                                                                        atoi (items [4].c_str()), //firstSample
01778                                                                        atoi (items [5].c_str()), //samplesToAdd
01779                                                                        atoi (items [6].c_str()), //expectedPeak
01780                                                                        atof (items [7].c_str()), // minEThreshold
01781                                                                        coef // coefficients
01782                                                                   );
01783     fObject->addValues(*fCondObject);
01784     delete fCondObject;
01785   }
01786   return true;
01787 } // getObject (HcalFlagHFDigiTime)
01788 
01789 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalFlagHFDigiTimeParams& fObject)
01790 {
01791   char buffer [1024];
01792   sprintf (buffer, "# %15s %15s %15s %15s  %15s %15s %15s %15s %30s\n", "eta", "phi", "dep", "det", "FirstSample", "SamplesToAdd", "ExpectedPeak","MinEnergy","Coefficients");
01793   fOutput << buffer;
01794   std::vector<DetId> channels = fObject.getAllChannels ();
01795   std::sort (channels.begin(), channels.end(), DetIdLess ());
01796   for (std::vector<DetId>::iterator channel = channels.begin ();
01797        channel !=  channels.end ();
01798        channel++) {
01799     // Dump out channel (ieta,iphi,depth,subdet) info
01800     HcalDbASCIIIO::dumpId (fOutput, *channel);
01801     // Dump out values for channel
01802     sprintf (buffer, " %15u %15u %15u %15f",
01803              fObject.getValues (*channel)->HFdigiflagFirstSample(), 
01804              fObject.getValues (*channel)->HFdigiflagSamplesToAdd(), 
01805              fObject.getValues (*channel)->HFdigiflagExpectedPeak(), 
01806              fObject.getValues (*channel)->HFdigiflagMinEThreshold() 
01807              );
01808 
01809     fOutput<<buffer; // dump flag reco values to buffer
01810     fOutput<<"               "; // simple spacer
01811 
01812     std::vector<double> coef=fObject.getValues(*channel)->HFdigiflagCoefficients();
01813     for (std::vector<double>::size_type x=0;x<coef.size();++x)
01814       {
01815         // dump comma-separated list of coefficients
01816         fOutput<<coef[x];
01817         if (x<coef.size()-1) // add commas where necessary
01818           fOutput<<",";
01819       }
01820     sprintf(buffer,"\n");
01821     fOutput << buffer;
01822   }
01823   return true;
01824 }
01825 
01826