00001
00002
00003
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
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
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) return false;
00167 char buffer [1024];
00168 while (fInput.getline(buffer, 1024)) {
00169 if (buffer [0] == '#') continue;
00170 std::vector <std::string> items = splitString (std::string (buffer));
00171 if (items.size()==0) continue;
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
00179
00180
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) return false;
00216 char buffer [1024];
00217 while (fInput.getline(buffer, 1024)) {
00218 if (buffer [0] == '#') continue;
00219 std::vector <std::string> items = splitString (std::string (buffer));
00220 if (items.size()==0) continue;
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
00228
00229
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) return false;
00261 char buffer [1024];
00262 while (fInput.getline(buffer, 1024)) {
00263 if (buffer [0] == '#') continue;
00264 std::vector <std::string> items = splitString (std::string (buffer));
00265 if (items.size()==0) continue;
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
00273
00274
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) return false;
00306 char buffer [1024];
00307 while (fInput.getline(buffer, 1024)) {
00308 if (buffer [0] == '#') continue;
00309 std::vector <std::string> items = splitString (std::string (buffer));
00310 if (items.size()==0) continue;
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;
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
00343 thisline[j] = fObject.getValues(*channel)->getValue(m,i,j);
00344
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
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
00389 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalRecoParams* fObject)
00390 {
00391 if (!fObject) return false;
00392 char buffer [1024];
00393 while (fInput.getline(buffer, 1024)) {
00394 if (buffer [0] == '#') continue;
00395 std::vector <std::string> items = splitString (std::string (buffer));
00396 if (items.size()==0) continue;
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 }
00414
00415 if(packingScheme==1) {
00416
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
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;
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
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 }
00456
00457
00458
00459
00460
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
00472
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
00485
00486 if(packingScheme==0) {
00487
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 }
00579
00580 }
00581 return true;
00582 }
00583
00584 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLongRecoParams* fObject)
00585 {
00586 if (!fObject) return false;
00587 char buffer [1024];
00588 while (fInput.getline(buffer, 1024)) {
00589 if (buffer [0] == '#') continue;
00590 std::vector <std::string> items = splitString (std::string (buffer));
00591 if (items.size()==0) continue;
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) return false;
00615 char buffer [1024];
00616 while (fInput.getline(buffer, 1024)) {
00617 if (buffer [0] == '#') continue;
00618 std::vector <std::string> items = splitString (std::string (buffer));
00619 if (items.size()==0) continue;
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
00625
00626
00627
00628
00629
00630
00631
00632 DetId id = HcalDbASCIIIO::getId (items);
00633
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) return false;
00700 char buffer [1024];
00701 while (fInput.getline(buffer, 1024)) {
00702 if (buffer [0] == '#') continue;
00703 std::vector <std::string> items = splitString (std::string (buffer));
00704 if (items.size()==0) continue;
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};
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;
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
00755
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 }
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 char buffer [1024];
00814
00815 while (fInput.getline(buffer, 1024)) {
00816 std::vector <std::string> items = splitString (std::string (buffer));
00817 if (items.size()==0) continue;
00818 else {
00819 if (items[0] == "#U")
00820 {
00821 if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
00822 else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
00823 else
00824 {
00825 edm::LogWarning("Pedestal Unit Error") << "Unrecognized unit for pedestals. Assuming fC." << std::endl;
00826 fObject->setUnitADC(false);
00827 }
00828 break;
00829 }
00830 else
00831 {
00832 edm::LogWarning("Pedestal Unit Missing") << "The unit for the pedestals is missing in the txt file." << std::endl;
00833 return false;
00834 }
00835 }
00836 }
00837 while (fInput.getline(buffer, 1024)) {
00838 if (buffer [0] == '#') continue;
00839 std::vector <std::string> items = splitString (std::string (buffer));
00840 if (items.size()==0) continue;
00841 if (items.size () < 8) {
00842 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
00843 << " or 12 items: eta, phi, depth, subdet, 4x values for mean, 4x values for width"
00844 << std::endl;
00845 continue;
00846 }
00847 DetId id = getId (items);
00848
00849
00850
00851
00852
00853
00854 if (items.size() < 12)
00855 {
00856 HcalPedestal* fCondObject = new HcalPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
00857 atof (items [6].c_str()), atof (items [7].c_str()),
00858 0., 0., 0., 0. );
00859 fObject->addValues(*fCondObject);
00860 delete fCondObject;
00861 }
00862 else
00863 {
00864 HcalPedestal* fCondObject = new HcalPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
00865 atof (items [6].c_str()), atof (items [7].c_str()),
00866 atof (items [8].c_str()), atof (items [9].c_str()),
00867 atof (items [10].c_str()), atof (items [11].c_str()) );
00868 fObject->addValues(*fCondObject);
00869 delete fCondObject;
00870 }
00871
00872
00873 }
00874 return true;
00875 }
00876
00877
00878 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPedestals& fObject) {
00879 char buffer [1024];
00880 if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
00881 else sprintf (buffer, "#U fC << this is the unit \n");
00882 fOutput << buffer;
00883
00884 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");
00885 fOutput << buffer;
00886
00887 std::vector<DetId> channels = fObject.getAllChannels ();
00888 std::sort (channels.begin(), channels.end(), DetIdLess ());
00889 for (std::vector<DetId>::iterator channel = channels.begin ();
00890 channel != channels.end ();
00891 channel++) {
00892 const float* values = fObject.getValues (*channel)->getValues ();
00893 if (values) {
00894 dumpId (fOutput, *channel);
00895 sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
00896 values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], channel->rawId ());
00897 fOutput << buffer;
00898 }
00899 }
00900 return true;
00901 }
00902
00903
00904
00905 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalChannelQuality* fObject)
00906 {
00907 if (!fObject) return false;
00908 char buffer [1024];
00909 while (fInput.getline(buffer, 1024)) {
00910 if (buffer [0] == '#') continue;
00911 std::vector <std::string> items = splitString (std::string (buffer));
00912 if (items.size()==0) continue;
00913 if (items.size () < 6) {
00914 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;
00915 continue;
00916 }
00917 DetId id = getId (items);
00918
00919
00920
00921
00922
00923 uint32_t mystatus;
00924 if (items[4] == "(hex)")
00925 sscanf(items[5].c_str(),"%X", &mystatus);
00926 else if (items[4] == "(dec)")
00927 sscanf(items[5].c_str(),"%u", &mystatus);
00928 else
00929 {
00930 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value field must contain the base: one of (hex), (dec)" << std::endl;
00931 continue;
00932 }
00933
00934 HcalChannelStatus* fCondObject = new HcalChannelStatus(id, mystatus);
00935 fObject->addValues(*fCondObject);
00936 delete fCondObject;
00937
00938 }
00939 return true;
00940 }
00941
00942
00943 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalChannelQuality& fObject) {
00944 char buffer [1024];
00945 sprintf (buffer, "# %15s %15s %15s %15s %15s %10s\n", "eta", "phi", "dep", "det", "(base) value", "DetId");
00946 fOutput << buffer;
00947 std::vector<DetId> channels = fObject.getAllChannels ();
00948 std::sort (channels.begin(), channels.end(), DetIdLess ());
00949 for (std::vector<DetId>::iterator channel = channels.begin ();
00950 channel != channels.end ();
00951 channel++) {
00952 const int value = fObject.getValues (*channel)->getValue ();
00953 dumpId (fOutput, *channel);
00954 sprintf (buffer, "%6s %15X %10X\n", "(hex)",
00955 value, channel->rawId ());
00956 fOutput << buffer;
00957 }
00958 return true;
00959 }
00960
00961
00962
00963 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalL1TriggerObjects* fObject)
00964 {
00965 char buffer [1024];
00966
00967 while (fInput.getline(buffer, 1024)) {
00968 if (buffer [0] == '#')
00969 {
00970 if (buffer [1] == 'T')
00971 {
00972 std::vector <std::string> items = splitString (std::string (buffer) );
00973 fObject->setTagString(items[1]);
00974 continue;
00975 }
00976 if (buffer [1] == 'A')
00977 {
00978 std::vector <std::string> items = splitString (std::string (buffer) );
00979 fObject->setAlgoString(items[1]);
00980 continue;
00981 }
00982 else continue;
00983 }
00984 std::vector <std::string> items = splitString (std::string (buffer));
00985 if (items.size()==0) continue;
00986 if (items.size () < 7) {
00987 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, pedestal, resp.corr.gain, flag" << std::endl;
00988 continue;
00989 }
00990 DetId id = getId (items);
00991
00992 HcalL1TriggerObject* fCondObject = new HcalL1TriggerObject(id, atof(items[4].c_str()), atof(items[5].c_str()), atoi(items[6].c_str()) );
00993
00994 fObject->addValues(*fCondObject);
00995 delete fCondObject;
00996 }
00997 return true;
00998 }
00999
01000 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalL1TriggerObjects& fObject)
01001 {
01002 char buffer [1024];
01003
01004 sprintf (buffer, "#T %s << this is the tag name \n", fObject.getTagString().c_str() );
01005 fOutput << buffer;
01006 sprintf (buffer, "#A %s << this is the algorithm name \n", fObject.getAlgoString().c_str() );
01007 fOutput << buffer;
01008
01009
01010 sprintf (buffer, "# %15s %15s %15s %15s %8s %13s %8s %10s\n",
01011 "eta", "phi", "dep", "det", "ped", "respcorrgain", "flag",
01012 "DetId");
01013 fOutput << buffer;
01014 std::vector<DetId> channels = fObject.getAllChannels ();
01015
01016 for (std::vector<DetId>::iterator channel = channels.begin ();
01017 channel != channels.end ();
01018 channel++) {
01019 const HcalL1TriggerObject* item = fObject.getValues (*channel);
01020 if (item) {
01021 dumpId (fOutput, *channel);
01022 sprintf (buffer, " %10.7f %10.7f %12d %10X\n",
01023 item->getPedestal(), item->getRespGain(), item->getFlag(), channel->rawId ());
01024 fOutput << buffer;
01025 }
01026 }
01027 return true;
01028
01029 }
01030
01031
01032
01033 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPedestalWidths* fObject) {
01034 char buffer [1024];
01035 int linecounter = 0;
01036
01037 while (fInput.getline(buffer, 1024)) {
01038 linecounter++;
01039 std::vector <std::string> items = splitString (std::string (buffer));
01040 if (items.size()==0) continue;
01041 else {
01042 if (items[0] == (std::string)"#U")
01043 {
01044 if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
01045 else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
01046 else
01047 {
01048 edm::LogWarning("Pedestal Width Unit Error") << "Unrecognized unit for pedestal widths. Assuming fC." << std::endl;
01049 fObject->setUnitADC(false);
01050 }
01051 break;
01052 }
01053 else
01054 {
01055 edm::LogWarning("Pedestal Width Unit Missing") << "The unit for the pedestal widths is missing in the txt file." << std::endl;
01056 return false;
01057 }
01058 }
01059 }
01060
01061 while (fInput.getline(buffer, 1024)) {
01062 linecounter++;
01063 if (buffer [0] == '#') continue;
01064 std::vector <std::string> items = splitString (std::string (buffer));
01065 if (items.size()==0) continue;
01066 if (items.size () < 14) {
01067 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line number: " << linecounter << "\n line must contain 14 items: eta, phi, depth, subdet, 10x correlations"
01068 << " or 20 items: eta, phi, depth, subdet, 16x correlations"
01069 << std::endl;
01070 continue;
01071 }
01072 DetId id = getId (items);
01073
01074
01075
01076
01077
01078
01079 if (items.size() < 20)
01080 {
01081 HcalPedestalWidth values(id);
01082 values.setSigma (0, 0, atof (items [4].c_str()));
01083 values.setSigma (1, 0, atof (items [5].c_str()));
01084 values.setSigma (1, 1, atof (items [6].c_str()));
01085 values.setSigma (2, 0, atof (items [7].c_str()));
01086 values.setSigma (2, 1, atof (items [8].c_str()));
01087 values.setSigma (2, 2, atof (items [9].c_str()));
01088 values.setSigma (3, 0, atof (items [10].c_str()));
01089 values.setSigma (3, 1, atof (items [11].c_str()));
01090 values.setSigma (3, 2, atof (items [12].c_str()));
01091 values.setSigma (3, 3, atof (items [13].c_str()));
01092 values.setSigma (0, 1, 0.);
01093 values.setSigma (0, 2, 0.);
01094 values.setSigma (0, 3, 0.);
01095 values.setSigma (1, 2, 0.);
01096 values.setSigma (1, 3, 0.);
01097 values.setSigma (2, 3, 0.);
01098 fObject->addValues(values);
01099 }
01100 else
01101 {
01102 HcalPedestalWidth values(id);
01103 values.setSigma (0, 0, atof (items [4].c_str()) );
01104 values.setSigma (0, 1, atof (items [5].c_str()) );
01105 values.setSigma (0, 2, atof (items [6].c_str()) );
01106 values.setSigma (0, 3, atof (items [7].c_str()) );
01107 values.setSigma (1, 0, atof (items [8].c_str()) );
01108 values.setSigma (1, 1, atof (items [9].c_str()) );
01109 values.setSigma (1, 2, atof (items [10].c_str()) );
01110 values.setSigma (1, 3, atof (items [11].c_str()) );
01111 values.setSigma (2, 0, atof (items [12].c_str()) );
01112 values.setSigma (2, 1, atof (items [13].c_str()) );
01113 values.setSigma (2, 2, atof (items [14].c_str()) );
01114 values.setSigma (2, 3, atof (items [15].c_str()) );
01115 values.setSigma (3, 0, atof (items [16].c_str()) );
01116 values.setSigma (3, 1, atof (items [17].c_str()) );
01117 values.setSigma (3, 2, atof (items [18].c_str()) );
01118 values.setSigma (3, 3, atof (items [19].c_str()) );
01119 fObject->addValues(values);
01120 }
01121
01122
01123 }
01124 return true;
01125 }
01126
01127 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPedestalWidths& fObject) {
01128 char buffer [1024];
01129 if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
01130 else sprintf (buffer, "#U fC << this is the unit \n");
01131 fOutput << buffer;
01132
01133 sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
01134 "eta", "phi", "dep", "det",
01135 "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",
01136 "DetId");
01137 fOutput << buffer;
01138 std::vector<DetId> channels = fObject.getAllChannels ();
01139 std::sort (channels.begin(), channels.end(), DetIdLess ());
01140 for (std::vector<DetId>::iterator channel = channels.begin ();
01141 channel != channels.end ();
01142 channel++) {
01143 const HcalPedestalWidth* item = fObject.getValues (*channel);
01144 if (item) {
01145 dumpId (fOutput, *channel);
01146 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",
01147 item->getSigma (0,0), item->getSigma (0,1), item->getSigma (0,2), item->getSigma (0,3),
01148 item->getSigma (1,0), item->getSigma (1,1), item->getSigma (1,2), item->getSigma (1,3),
01149 item->getSigma (2,0), item->getSigma (2,1), item->getSigma (2,2), item->getSigma (2,3),
01150 item->getSigma (3,0), item->getSigma (3,1), item->getSigma (3,2), item->getSigma (3,3), channel->rawId ());
01151 fOutput << buffer;
01152 }
01153 }
01154 return true;
01155 }
01156
01157
01158
01159 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalQIEData* fObject) {
01160 char buffer [1024];
01161 while (fInput.getline(buffer, 1024)) {
01162 if (buffer [0] == '#') continue;
01163 std::vector <std::string> items = splitString (std::string (buffer));
01164 if (items.size()<1) continue;
01165 if (items [0] == "SHAPE") {
01166
01167 }
01168 else {
01169 if (items.size () < 36) {
01170 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;
01171 continue;
01172 }
01173 DetId id = getId (items);
01174 fObject->sort ();
01175
01176
01177
01178
01179
01180 HcalQIECoder coder (id.rawId ());
01181 int index = 4;
01182 for (unsigned capid = 0; capid < 4; capid++) {
01183 for (unsigned range = 0; range < 4; range++) {
01184 coder.setOffset (capid, range, atof (items [index++].c_str ()));
01185 }
01186 }
01187 for (unsigned capid = 0; capid < 4; capid++) {
01188 for (unsigned range = 0; range < 4; range++) {
01189 coder.setSlope (capid, range, atof (items [index++].c_str ()));
01190 }
01191 }
01192 if (items.size()>36)
01193 coder.setQIEIndex(atoi(items[index++].c_str()));
01194
01195 fObject->addCoder (coder);
01196
01197 }
01198 }
01199 fObject->sort ();
01200 return true;
01201 }
01202
01203 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalQIEData& fObject) {
01204 std::cout <<"dumping object\n";
01205 char buffer [1024];
01206
01207 fOutput << "# QIE data" << std::endl;
01208 sprintf (buffer, "# %15s %15s %15s %15s %36s %36s %36s %36s %36s %36s %36s %36s\n",
01209 "eta", "phi", "dep", "det",
01210 "4 x offsets cap0", "4 x offsets cap1", "4 x offsets cap2", "4 x offsets cap3",
01211 "4 x slopes cap0", "4 x slopes cap1", "4 x slopes cap2", "4 x slopes cap3");
01212 fOutput << buffer;
01213 std::vector<DetId> channels = fObject.getAllChannels ();
01214 std::sort (channels.begin(), channels.end(), DetIdLess ());
01215 for (std::vector<DetId>::iterator channel = channels.begin ();
01216 channel != channels.end ();
01217 channel++) {
01218 const HcalQIECoder* coder = fObject.getCoder (*channel);
01219 dumpId (fOutput, *channel);
01220 for (unsigned capid = 0; capid < 4; capid++) {
01221 for (unsigned range = 0; range < 4; range++) {
01222 sprintf (buffer, " %8.5f", coder->offset (capid, range));
01223 fOutput << buffer;
01224 }
01225 }
01226 for (unsigned capid = 0; capid < 4; capid++) {
01227 for (unsigned range = 0; range < 4; range++) {
01228 sprintf (buffer, " %8.5f", coder->slope (capid, range));
01229 fOutput << buffer;
01230 }
01231 }
01232 sprintf (buffer, " %2d", coder->qieIndex());
01233 fOutput << buffer;
01234 fOutput << std::endl;
01235 }
01236 return true;
01237 }
01238
01239
01240 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCalibrationQIEData* fObject) {
01241 char buffer [1024];
01242 while (fInput.getline(buffer, 1024)) {
01243 if (buffer [0] == '#') continue;
01244 std::vector <std::string> items = splitString (std::string (buffer));
01245 if (items.size () < 36) {
01246 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 36 items: eta, phi, depth, subdet, 32 bin values" << std::endl;
01247 continue;
01248 }
01249 DetId id = getId (items);
01250 fObject->sort ();
01251
01252
01253
01254
01255
01256 HcalCalibrationQIECoder coder (id.rawId ());
01257 int index = 4;
01258 float values [32];
01259 for (unsigned bin = 0; bin < 32; bin++) {
01260 values[bin] = atof (items [index++].c_str ());
01261 }
01262 coder.setMinCharges (values);
01263 fObject->addCoder (coder);
01264
01265 }
01266 fObject->sort ();
01267 return true;
01268 }
01269
01270 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCalibrationQIEData& fObject) {
01271 char buffer [1024];
01272 fOutput << "# QIE data in calibration mode" << std::endl;
01273 sprintf (buffer, "# %15s %15s %15s %15s %288s\n",
01274 "eta", "phi", "dep", "det", "32 x charges");
01275 fOutput << buffer;
01276 std::vector<DetId> channels = fObject.getAllChannels ();
01277 std::sort (channels.begin(), channels.end(), DetIdLess ());
01278 for (std::vector<DetId>::iterator channel = channels.begin ();
01279 channel != channels.end ();
01280 channel++) {
01281 const HcalCalibrationQIECoder* coder = fObject.getCoder (*channel);
01282 if (coder) {
01283 dumpId (fOutput, *channel);
01284 const float* lowEdge = coder->minCharges ();
01285 for (unsigned bin = 0; bin < 32; bin++) {
01286 sprintf (buffer, " %8.5f", lowEdge [bin]);
01287 fOutput << buffer;
01288 }
01289 fOutput << std::endl;
01290 }
01291 }
01292 return true;
01293 }
01294
01295
01296
01297 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalElectronicsMap* fObject) {
01298 char buffer [1024];
01299 while (fInput.getline(buffer, 1024)) {
01300 if (buffer [0] == '#') continue;
01301 std::vector <std::string> items = splitString (std::string (buffer));
01302 if (items.size () < 12) {
01303 if (items.size()==0) continue;
01304 if (items.size()<9) {
01305 edm::LogError("MapFormat") << "HcalElectronicsMap-> line too short: " << buffer;
01306 continue;
01307 }
01308 if (items[8]=="NA" || items[8]=="NT") {
01309 while (items.size()<12) items.push_back("");
01310 } else if (items[8]=="HT") {
01311 if (items.size()==11) items.push_back("");
01312 else {
01313 edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer
01314 << "\n HT line must contain at least 11 items: i cr sl tb dcc spigot fiber fiberchan subdet=HT ieta iphi";
01315 continue;
01316 }
01317 } else {
01318 edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer
01319 << "\n line must contain 12 items: i cr sl tb dcc spigot fiber fiberchan subdet ieta iphi depth";
01320 continue;
01321 }
01322 }
01323
01324 int crate = atoi (items [1].c_str());
01325 int slot = atoi (items [2].c_str());
01326 int top = 1;
01327 if (items [3] == "b") top = 0;
01328 int dcc = atoi (items [4].c_str());
01329 int spigot = atoi (items [5].c_str());
01330 HcalElectronicsId elId;
01331 if (items[8] == "HT" || items[8] == "NT") {
01332 int slb = atoi (items [6].c_str());
01333 int slbCh = atoi (items [7].c_str());
01334 elId=HcalElectronicsId(slbCh, slb, spigot, dcc,crate,slot,top);
01335 } else {
01336 int fiber = atoi (items [6].c_str());
01337 int fiberCh = atoi (items [7].c_str());
01338
01339 elId=HcalElectronicsId(fiberCh, fiber, spigot, dcc);
01340 elId.setHTR (crate, slot, top);
01341 }
01342
01343
01344 if (items [8] == "NA") {
01345 fObject->mapEId2chId (elId, DetId (HcalDetId::Undefined));
01346 } else if (items [8] == "NT") {
01347 fObject->mapEId2tId (elId, DetId (HcalTrigTowerDetId::Undefined));
01348 } else {
01349 HcalText2DetIdConverter converter (items [8], items [9], items [10], items [11]);
01350 if (converter.isHcalDetId ()) {
01351 fObject->mapEId2chId (elId, converter.getId ());
01352 }
01353 else if (converter.isHcalTrigTowerDetId ()) {
01354 fObject->mapEId2tId (elId, converter.getId ());
01355 }
01356 else if (converter.isHcalCalibDetId ()) {
01357 fObject->mapEId2chId (elId, converter.getId ());
01358 }
01359 else if (converter.isHcalZDCDetId ()) {
01360 fObject->mapEId2chId (elId, converter.getId ());
01361 }
01362 else {
01363 edm::LogWarning("Format Error") << "HcalElectronicsMap-> Unknown subdetector: "
01364 << items [8] << '/' << items [9] << '/' << items [10] << '/' << items [11] << std::endl;
01365 }
01366 }
01367 }
01368 fObject->sort ();
01369 return true;
01370 }
01371
01372 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalElectronicsMap& fObject) {
01373 std::vector<HcalElectronicsId> eids = fObject.allElectronicsId ();
01374 char buf [1024];
01375
01376
01377 sprintf (buf, "# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
01378 "i", "cr", "sl", "tb", "dcc", "spigot", "fiber/slb", "fibcha/slbcha", "subdet", "ieta", "iphi", "depth");
01379 fOutput << buf << std::endl;
01380
01381 for (unsigned i = 0; i < eids.size (); i++) {
01382 HcalElectronicsId eid = eids[i];
01383 if (eid.isTriggerChainId()) {
01384 DetId trigger = fObject.lookupTrigger (eid);
01385 if (trigger.rawId ()) {
01386 HcalText2DetIdConverter converter (trigger);
01387
01388
01389 sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
01390
01391 converter.getId().rawId(),
01392
01393
01394 eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.slbSiteNumber(), eid.slbChannelIndex(),
01395 converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
01396 );
01397 fOutput << buf << std::endl;
01398 }
01399 } else {
01400 DetId channel = fObject.lookup (eid);
01401 if (channel.rawId()) {
01402 HcalText2DetIdConverter converter (channel);
01403
01404
01405 sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
01406
01407 converter.getId().rawId(),
01408 eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
01409 converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
01410 );
01411 fOutput << buf << std::endl;
01412 }
01413 }
01414 }
01415 return true;
01416 }
01417
01418
01419 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLutMetadata* fObject){
01420 if (!fObject) return false;
01421 char buffer [1024];
01422 while (fInput.getline(buffer, 1024)) {
01423 if (buffer [0] == '#') continue;
01424 std::vector <std::string> items = splitString (std::string (buffer));
01425 if (items.size()==0) continue;
01426
01427 if (items.size() > 1 &&
01428 items[0].find("RctLsb")!=std::string::npos){
01429 fObject->setRctLsb( atof( items[1].c_str() ) );
01430 continue;
01431 }
01432 if (items.size() > 1 &&
01433 items[0].find("Gain")!=std::string::npos){
01434 fObject->setNominalGain( atof( items[1].c_str() ) );
01435 continue;
01436 }
01437
01438 if (items.size () < 7) {
01439 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, Rcalib, LutGranularity, OutputLutThreshold" << std::endl;
01440 continue;
01441 }
01442 DetId id = getId (items);
01443
01444 HcalLutMetadatum * fCondObject = new HcalLutMetadatum(id,
01445 atof (items [4].c_str()),
01446 atoi (items [5].c_str()),
01447 atoi (items [6].c_str()));
01448 fObject->addValues(*fCondObject);
01449 delete fCondObject;
01450 }
01451 return true;
01452 }
01453
01454
01455 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalLutMetadata& fObject){
01456 char buffer [1024];
01457 const float _rctLsb = fObject.getRctLsb();
01458 const float _gain = fObject.getNominalGain();
01459 sprintf (buffer, "# %20s\n", "Non-channel data");
01460 fOutput << buffer;
01461 sprintf (buffer, "%8s %8.5f\n", "RctLsb", _rctLsb);
01462 fOutput << buffer;
01463 sprintf (buffer, "%8s %8.5f\n", "Gain", _gain);
01464 fOutput << buffer;
01465 sprintf (buffer, "# %15s %15s %15s %15s %8s %15s %19s %10s\n", "eta", "phi", "dep", "det", "Rcalib", "LutGranularity", "OutputLutThreshold", "DetId");
01466 fOutput << buffer;
01467 std::vector<DetId> channels = fObject.getAllChannels ();
01468 std::sort (channels.begin(), channels.end(), DetIdLess ());
01469 for (std::vector<DetId>::iterator channel = channels.begin ();
01470 channel != channels.end ();
01471 channel++) {
01472 const float _rCalib = fObject.getValues (*channel)->getRCalib();
01473 const uint8_t _lutGranularity = fObject.getValues (*channel)->getLutGranularity();
01474 const uint8_t _outputLutThreshold = fObject.getValues (*channel)->getOutputLutThreshold();
01475 dumpId (fOutput, *channel);
01476 sprintf (buffer, " %8.5f %15d %19d %10X\n",
01477 _rCalib,
01478 _lutGranularity,
01479 _outputLutThreshold,
01480 channel->rawId ());
01481 fOutput << buffer;
01482 }
01483 return true;
01484 }
01485
01486
01487 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalDcsValues * fObject) {
01488 if (!fObject) return false;
01489 std::string buffer;
01490 while (getline(fInput, buffer)) {
01491 if (buffer.at(0) == '#') continue;
01492 std::vector <std::string> items = splitString (buffer);
01493 if (items.size()==0) continue;
01494
01495 if (items.size() < 9) {
01496 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;
01497 continue;
01498 }
01499
01500 HcalOtherSubdetector subd;
01501 int sidering;
01502 unsigned int slice, subchan;
01503 switch (items[0].at(1)) {
01504 case 'B':
01505 subd = HcalDcsBarrel;
01506 break;
01507 case 'E':
01508 subd = HcalDcsEndcap;
01509 break;
01510 case 'F':
01511 subd = HcalDcsForward;
01512 break;
01513 case 'O':
01514 subd = HcalDcsOuter;
01515 break;
01516 default:
01517 continue;
01518 }
01519
01520 from_string<int>(sidering, items[1], std::dec);
01521 from_string<unsigned int>(slice, items[2], std::dec);
01522
01523 from_string<unsigned int>(subchan, items[4], std::dec);
01524
01525 HcalDcsDetId newId(subd, sidering, slice,
01526 HcalDcsDetId::DcsTypeFromString(items[3]), subchan);
01527
01528 int LS;
01529 float val,upper,lower;
01530 from_string<int>(LS, items[5], std::dec);
01531 from_string<float>(val, items[6], std::dec);
01532 from_string<float>(upper, items[7], std::dec);
01533 from_string<float>(lower, items[8], std::dec);
01534
01535 HcalDcsValue newVal(newId.rawId(),LS,val,upper,lower);
01536
01537
01538
01539
01540
01541 if (!(fObject->addValue(newVal))) {
01542 edm::LogWarning("Data Error") << "Data from line " << buffer
01543 << "\nwas not added to the HcalDcsValues object." << std::endl;
01544 }
01545
01546 }
01547 fObject->sortAll();
01548 return true;
01549 }
01550
01551 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput,
01552 HcalDcsValues const& fObject) {
01553 fOutput << "# subDet side_ring slice type subChan LS Value UpperLimit LowerLimit DcsId\n";
01554 for(int subd = HcalDcsValues::HcalHB;
01555 subd <= HcalDcsValues::HcalHF; ++subd) {
01556
01557 HcalDcsValues::DcsSet const & vals=
01558 fObject.getAllSubdetValues(HcalDcsValues::DcsSubDet(subd));
01559 for (HcalDcsValues::DcsSet::const_iterator val = vals.begin();
01560 val != vals.end(); ++val) {
01561 HcalDcsDetId valId(val->DcsId());
01562
01563 switch (valId.subdet()) {
01564 case HcalDcsBarrel:
01565 fOutput << "HB ";
01566 break;
01567 case HcalDcsEndcap:
01568 fOutput << "HE ";
01569 break;
01570 case HcalDcsOuter:
01571 fOutput << "HO ";
01572 break;
01573 case HcalDcsForward:
01574 fOutput << "HF ";
01575 break;
01576 default :
01577 fOutput << valId.subdet() << ' ';
01578 }
01579
01580 if (valId.subdet() == HcalDcsOuter)
01581 fOutput << valId.ring() << ' ';
01582 else
01583 fOutput << valId.zside() << ' ';
01584
01585 fOutput << valId.slice() << ' '
01586 << valId.typeString(valId.type()) << ' '
01587 << valId.subchannel() << ' ';
01588 fOutput << val->LS() << ' '
01589 << val->getValue() << ' '
01590 << val->getUpperLimit() << ' '
01591 << val->getLowerLimit() << ' ';
01592 fOutput << std::hex << val->DcsId() << std::dec << '\n';
01593
01594
01595
01596
01597
01598
01599 }
01600 }
01601
01602 return true;
01603 }
01604
01605
01606
01607
01608
01609 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalDcsMap* fObject) {
01610 char buffer [1024];
01611 while (fInput.getline(buffer, 1024)) {
01612 if (buffer [0] == '#') continue;
01613 std::vector <std::string> items = splitString (std::string (buffer));
01614 if (items.size () < 8) {
01615 if (items.size()==0) continue;
01616 else {
01617 edm::LogError("MapFormat") << "HcalDcsMap-> Bad line: " << buffer
01618 << "\n line must contain 8 items: line side_ring slice subchannel subdet ieta iphi depth";
01619 continue;
01620 }
01621 }
01622
01623
01624 int ring = atoi(items[1].c_str());
01625 unsigned int slice = atoi (items [2].c_str());
01626 unsigned int subchannel = atoi (items [3].c_str());
01627 HcalDcsDetId::DcsType type = HcalDcsDetId::DCSUNKNOWN;
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671 HcalOtherSubdetector subdet = HcalOtherEmpty;
01672 if (items[4].find("CALIB")!=std::string::npos){
01673 subdet = HcalCalibration;
01674 }
01675 else if (items[4].find("HB")!=std::string::npos){
01676 subdet = HcalDcsBarrel;
01677 }
01678 else if (items[4].find("HE")!=std::string::npos){
01679 subdet = HcalDcsEndcap;
01680 }
01681 else if (items[4].find("HO")!=std::string::npos){
01682 subdet = HcalDcsOuter;
01683 }
01684 else if (items[4].find("HF")!=std::string::npos){
01685 subdet = HcalDcsForward;
01686 }
01687 else{
01688 edm::LogError("MapFormat") << "HcalDcsMap-> Unknown subdetector, line is not accepted: " << items[5];
01689 continue;
01690 }
01691 HcalDcsDetId dcsId(subdet, ring, slice, type, subchannel);
01692 HcalText2DetIdConverter converter (items [4], items [5], items [6], items [7]);
01693 HcalDetId id(0);
01694 if (converter.isHcalDetId()){
01695 id = converter.getId();
01696 }
01697 else{
01698 edm::LogWarning("Invalid HCAL channel") << "HcalDcsMap-> invalid channel: "
01699 << items [4] << '/'
01700 << items [5] << '/'
01701 << items [6] << '/'
01702 << items [7] << std::endl;
01703 continue;
01704 }
01705 fObject->mapGeomId2DcsId(id, dcsId);
01706 }
01707 fObject->sort ();
01708 return true;
01709 }
01710
01711
01712
01713
01714 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalDcsMap& fObject) {
01715 char buf [1024];
01716 sprintf (buf, "# %7s %10s %6s %8s %7s %5s %5s %6s",
01717 "i", "side_ring", "slice", "subchan", "subdet", "ieta", "iphi", "depth");
01718 fOutput << buf << std::endl;
01719 HcalDcsMap::const_iterator _line;
01720 unsigned int line_counter = 0;
01721 for (_line = fObject.beginById();
01722 _line != fObject.endById();
01723 ++_line) {
01724 HcalDcsDetId dcsId = _line.getHcalDcsDetId();
01725
01726 HcalText2DetIdConverter _converter(_line.getHcalDetId());
01727 sprintf (buf, " %8X %10d %6d %8d %7s %5s %5s %6s",
01728 line_counter,
01729 dcsId.ring(),
01730 dcsId.slice(),
01731 dcsId.subchannel(),
01732 _converter.getFlavor().c_str(),
01733 _converter.getField1().c_str(),
01734 _converter.getField2().c_str(),
01735 _converter.getField3().c_str()
01736 );
01737 fOutput << buf << std::endl;
01738 ++line_counter;
01739 }
01740 return true;
01741 }
01742
01743
01744 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalFlagHFDigiTimeParams* fObject)
01745 {
01746
01747 if (!fObject) return false;
01748 char buffer [1024];
01749 while (fInput.getline(buffer, 1024)) {
01750 if (buffer [0] == '#') continue;
01751 std::vector <std::string> items = splitString (std::string (buffer));
01752 if (items.size()==0) continue;
01753 if (items.size () != 9) {
01754 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;
01755 continue;
01756 }
01757
01758 DetId id = HcalDbASCIIIO::getId (items);
01759 std::vector<double> coef= splitStringToDoubleByComma(items[8].c_str());
01760
01761 HcalFlagHFDigiTimeParam* fCondObject = new HcalFlagHFDigiTimeParam(id,
01762 atoi (items [4].c_str()),
01763 atoi (items [5].c_str()),
01764 atoi (items [6].c_str()),
01765 atof (items [7].c_str()),
01766 coef
01767 );
01768 fObject->addValues(*fCondObject);
01769 delete fCondObject;
01770 }
01771 return true;
01772 }
01773
01774 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalFlagHFDigiTimeParams& fObject)
01775 {
01776 char buffer [1024];
01777 sprintf (buffer, "# %15s %15s %15s %15s %15s %15s %15s %15s %30s\n", "eta", "phi", "dep", "det", "FirstSample", "SamplesToAdd", "ExpectedPeak","MinEnergy","Coefficients");
01778 fOutput << buffer;
01779 std::vector<DetId> channels = fObject.getAllChannels ();
01780 std::sort (channels.begin(), channels.end(), DetIdLess ());
01781 for (std::vector<DetId>::iterator channel = channels.begin ();
01782 channel != channels.end ();
01783 channel++) {
01784
01785 HcalDbASCIIIO::dumpId (fOutput, *channel);
01786
01787 sprintf (buffer, " %15u %15u %15u %15f",
01788 fObject.getValues (*channel)->HFdigiflagFirstSample(),
01789 fObject.getValues (*channel)->HFdigiflagSamplesToAdd(),
01790 fObject.getValues (*channel)->HFdigiflagExpectedPeak(),
01791 fObject.getValues (*channel)->HFdigiflagMinEThreshold()
01792 );
01793
01794 fOutput<<buffer;
01795 fOutput<<" ";
01796
01797 std::vector<double> coef=fObject.getValues(*channel)->HFdigiflagCoefficients();
01798 for (std::vector<double>::size_type x=0;x<coef.size();++x)
01799 {
01800
01801 fOutput<<coef[x];
01802 if (x<coef.size()-1)
01803 fOutput<<",";
01804 }
01805 sprintf(buffer,"\n");
01806 fOutput << buffer;
01807 }
01808 return true;
01809 }
01810
01811