00001
00002
00003
00004
00005
00006 #include <vector>
00007 #include <string>
00008 #include <cstdio>
00009 #include <sstream>
00010
00011 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00012 #include "DataFormats/HcalDetId/interface/HcalElectronicsId.h"
00013 #include "DataFormats/HcalDetId/interface/HcalDcsDetId.h"
00014 #include "CalibFormats/HcalObjects/interface/HcalText2DetIdConverter.h"
00015
00016 #include "CondFormats/HcalObjects/interface/AllObjects.h"
00017 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019
00020 namespace {
00021 class DetIdLess {
00022 public:
00023 bool operator () (DetId fFirst, DetId fSecond) const {
00024 HcalGenericDetId first (fFirst);
00025 HcalGenericDetId second (fSecond);
00026 if (first.genericSubdet () != second.genericSubdet ()) return first.genericSubdet () < second.genericSubdet ();
00027 if (first.isHcalDetId ()) {
00028 HcalDetId f1 (first);
00029 HcalDetId s1 (second);
00030 return f1.zside () != s1.zside () ? f1.zside () < s1.zside () :
00031 f1.iphi () != s1.iphi () ? f1.iphi () < s1.iphi () :
00032 f1.ietaAbs () != s1.ietaAbs () ? f1.ietaAbs () < s1.ietaAbs () :
00033 f1.depth () < s1.depth ();
00034 }
00035 else {
00036 return first.rawId() < second.rawId();
00037 }
00038 }
00039 };
00040 class HcalElectronicsIdLess {
00041 public:
00042 bool operator () (HcalElectronicsId first, HcalElectronicsId second) const {
00043 return
00044 first.readoutVMECrateId () != second.readoutVMECrateId () ? first.readoutVMECrateId () < second.readoutVMECrateId () :
00045 first.htrSlot () != second.htrSlot () ? first.htrSlot () < second.htrSlot () :
00046 first.htrTopBottom () != second.htrTopBottom () ? first.htrTopBottom () < second.htrTopBottom () :
00047 first.fiberIndex () != second.fiberIndex () ? first.fiberIndex () < second.fiberIndex () :
00048 first.fiberChanId () < second.fiberChanId ();
00049 }
00050 };
00051 }
00052
00053 std::vector <std::string> splitString (const std::string& fLine) {
00054 std::vector <std::string> result;
00055 int start = 0;
00056 bool empty = true;
00057 for (unsigned i = 0; i <= fLine.size (); i++) {
00058 if (fLine [i] == ' ' || i == fLine.size ()) {
00059 if (!empty) {
00060 std::string item (fLine, start, i-start);
00061 result.push_back (item);
00062 empty = true;
00063 }
00064 start = i+1;
00065 }
00066 else {
00067 if (empty) empty = false;
00068 }
00069 }
00070 return result;
00071 }
00072
00073 DetId HcalDbASCIIIO::getId (const std::vector <std::string> & items) {
00074 HcalText2DetIdConverter converter (items [3], items [0], items [1], items [2]);
00075 return converter.getId ();
00076 }
00077
00078 void HcalDbASCIIIO::dumpId (std::ostream& fOutput, DetId id) {
00079 HcalText2DetIdConverter converter (id);
00080 char buffer [1024];
00081 sprintf (buffer, " %15s %15s %15s %15s",
00082 converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str (),converter.getFlavor ().c_str ());
00083 fOutput << buffer;
00084 }
00085
00086 template<class T>
00087 bool from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {
00088 std::istringstream iss(s);
00089 return !(iss >> f >> t).fail();
00090 }
00091
00092 template <class T,class S>
00093 bool getHcalObject (std::istream& fInput, T* fObject, S* fCondObject) {
00094 if (!fObject) fObject = new T;
00095 char buffer [1024];
00096 while (fInput.getline(buffer, 1024)) {
00097 if (buffer [0] == '#') continue;
00098 std::vector <std::string> items = splitString (std::string (buffer));
00099 if (items.size()==0) continue;
00100 if (items.size () < 8) {
00101 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values" << std::endl;
00102 continue;
00103 }
00104 DetId id = HcalDbASCIIIO::getId (items);
00105
00106
00107
00108
00109
00110 fCondObject = new S(id, atof (items [4].c_str()), atof (items [5].c_str()),
00111 atof (items [6].c_str()), atof (items [7].c_str()));
00112 fObject->addValues(*fCondObject);
00113 delete fCondObject;
00114
00115 }
00116
00117 return true;
00118 }
00119
00120 template <class T>
00121 bool dumpHcalObject (std::ostream& fOutput, const T& fObject) {
00122 char buffer [1024];
00123 sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %10s\n", "eta", "phi", "dep", "det", "cap0", "cap1", "cap2", "cap3", "DetId");
00124 fOutput << buffer;
00125 std::vector<DetId> channels = fObject.getAllChannels ();
00126 std::sort (channels.begin(), channels.end(), DetIdLess ());
00127 for (std::vector<DetId>::iterator channel = channels.begin ();
00128 channel != channels.end ();
00129 channel++) {
00130 const float* values = fObject.getValues (*channel)->getValues ();
00131 if (values) {
00132 HcalDbASCIIIO::dumpId (fOutput, *channel);
00133 sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %10X\n",
00134 values[0], values[1], values[2], values[3], channel->rawId ());
00135 fOutput << buffer;
00136 }
00137 }
00138 return true;
00139 }
00140
00141 template <class T,class S>
00142 bool getHcalSingleFloatObject (std::istream& fInput, T* fObject, S* fCondObject) {
00143 if (!fObject) fObject = new T;
00144 char buffer [1024];
00145 while (fInput.getline(buffer, 1024)) {
00146 if (buffer [0] == '#') continue;
00147 std::vector <std::string> items = splitString (std::string (buffer));
00148 if (items.size()==0) continue;
00149 if (items.size () < 5) {
00150 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, value" << std::endl;
00151 continue;
00152 }
00153 DetId id = HcalDbASCIIIO::getId (items);
00154
00155
00156
00157
00158
00159 fCondObject = new S(id, atof (items [4].c_str()) );
00160 fObject->addValues(*fCondObject);
00161 delete fCondObject;
00162
00163 }
00164 return true;
00165 }
00166
00167 template <class T>
00168 bool dumpHcalSingleFloatObject (std::ostream& fOutput, const T& fObject) {
00169 char buffer [1024];
00170 sprintf (buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
00171 fOutput << buffer;
00172 std::vector<DetId> channels = fObject.getAllChannels ();
00173 std::sort (channels.begin(), channels.end(), DetIdLess ());
00174 for (std::vector<DetId>::iterator channel = channels.begin ();
00175 channel != channels.end ();
00176 channel++) {
00177 const float value = fObject.getValues (*channel)->getValue ();
00178 HcalDbASCIIIO::dumpId (fOutput, *channel);
00179 sprintf (buffer, " %8.5f %10X\n",
00180 value, channel->rawId ());
00181 fOutput << buffer;
00182 }
00183 return true;
00184 }
00185
00186 template <class T,class S>
00187 bool getHcalSingleIntObject (std::istream& fInput, T* fObject, S* fCondObject) {
00188 if (!fObject) fObject = new T;
00189 char buffer [1024];
00190 while (fInput.getline(buffer, 1024)) {
00191 if (buffer [0] == '#') continue;
00192 std::vector <std::string> items = splitString (std::string (buffer));
00193 if (items.size()==0) continue;
00194 if (items.size () < 5) {
00195 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, value" << std::endl;
00196 continue;
00197 }
00198 DetId id = HcalDbASCIIIO::getId (items);
00199
00200
00201
00202
00203
00204 fCondObject = new S(id, atoi (items [4].c_str()) );
00205 fObject->addValues(*fCondObject);
00206 delete fCondObject;
00207
00208 }
00209 return true;
00210 }
00211
00212 template <class T>
00213 bool dumpHcalSingleIntObject (std::ostream& fOutput, const T& fObject) {
00214 char buffer [1024];
00215 sprintf (buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
00216 fOutput << buffer;
00217 std::vector<DetId> channels = fObject.getAllChannels ();
00218 std::sort (channels.begin(), channels.end(), DetIdLess ());
00219 for (std::vector<DetId>::iterator channel = channels.begin ();
00220 channel != channels.end ();
00221 channel++) {
00222 const int value = fObject.getValues (*channel)->getValue ();
00223 HcalDbASCIIIO::dumpId (fOutput, *channel);
00224 sprintf (buffer, " %15d %10X\n",
00225 value, channel->rawId ());
00226 fOutput << buffer;
00227 }
00228 return true;
00229 }
00230
00231 template <class T,class S>
00232 bool getHcalMatrixObject (std::istream& fInput, T* fObject, S* fCondObject) {
00233 if (!fObject) fObject = new T;
00234 char buffer [1024];
00235 while (fInput.getline(buffer, 1024)) {
00236 if (buffer [0] == '#') continue;
00237 std::vector <std::string> items = splitString (std::string (buffer));
00238 if (items.size()==0) continue;
00239 DetId firstid = HcalDbASCIIIO::getId (items);
00240 fCondObject = new S(firstid.rawId());
00241 for(int j = 0; j != 10; j++) fCondObject->setValue(atoi(items[4].c_str()), 0, j, atof(items[j+5].c_str()));
00242 for(int i = 1; i != 40; i++){
00243 fInput.getline(buffer, 1024);
00244 items = splitString (std::string (buffer));
00245 DetId id = HcalDbASCIIIO::getId (items);
00246 if(id.rawId() != firstid.rawId()) break;
00247 for(int j = 0; j != 10; j++) fCondObject->setValue(atoi(items[4].c_str()), i%10, j, atof(items[j+5].c_str()));
00248 }
00249 fObject->addValues(*fCondObject);
00250 delete fCondObject;
00251 }
00252 return true;
00253 }
00254
00255 template <class T>
00256 bool dumpHcalMatrixObject (std::ostream& fOutput, const T& fObject) {
00257 char buffer [1024];
00258 sprintf (buffer, "# %5s %5s %5s %5s %5s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
00259 "eta", "phi", "dep", "det", "capid","c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "DetId");
00260 fOutput << buffer;
00261 std::vector<DetId> channels = fObject.getAllChannels ();
00262 std::sort (channels.begin(), channels.end(), DetIdLess ());
00263 for (std::vector<DetId>::iterator channel = channels.begin ();
00264 channel != channels.end ();
00265 channel++) {
00266 float thisline[10];
00267 for(int m = 0; m != 4; m++){
00268 for(int i = 0; i != 10; i++){
00269 for(int j = 0; j != 10; j++){
00270
00271 thisline[j] = fObject.getValues(*channel)->getValue(m,i,j);
00272
00273 }
00274 HcalDbASCIIIO::dumpId (fOutput, *channel);
00275 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",
00276 m, thisline[0], thisline[1], thisline[2], thisline[3], thisline[4], thisline[5], thisline[6], thisline[7],
00277 thisline[8], thisline[9], channel->rawId());
00278 fOutput << buffer;
00279 }
00280 }
00281 }
00282
00283 return true;
00284 }
00285
00286 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalGains* fObject) {return getHcalObject (fInput, fObject, new HcalGain);}
00287 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalGains& fObject) {return dumpHcalObject (fOutput, fObject);}
00288 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalGainWidths* fObject) {return getHcalObject (fInput, fObject, new HcalGainWidth);}
00289 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalGainWidths& fObject) {return dumpHcalObject (fOutput, fObject);}
00290
00291 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalRespCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalRespCorr); }
00292 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalRespCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
00293
00294 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLUTCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalLUTCorr); }
00295 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalLUTCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
00296
00297 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPFCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalPFCorr); }
00298 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPFCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
00299
00300 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalTimeCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalTimeCorr); }
00301 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalTimeCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
00302
00303 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalZSThresholds* fObject) {return getHcalSingleIntObject (fInput, fObject, new HcalZSThreshold); }
00304 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalZSThresholds& fObject) {return dumpHcalSingleIntObject (fOutput, fObject); }
00305
00306 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalValidationCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalValidationCorr); }
00307 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalValidationCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
00308 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCholeskyMatrices* fObject) {return getHcalMatrixObject (fInput, fObject, new HcalCholeskyMatrix); }
00309 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCholeskyMatrices& fObject) {return dumpHcalMatrixObject (fOutput, fObject); }
00310 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCovarianceMatrices* fObject) {return getHcalMatrixObject (fInput, fObject, new HcalCovarianceMatrix); }
00311 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCovarianceMatrices& fObject) {return dumpHcalMatrixObject (fOutput, fObject); }
00312
00313
00314
00315
00316
00317 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPedestals* fObject) {
00318 if (!fObject) fObject = new HcalPedestals(false);
00319 char buffer [1024];
00320
00321 while (fInput.getline(buffer, 1024)) {
00322 std::vector <std::string> items = splitString (std::string (buffer));
00323 if (items.size()==0) continue;
00324 else {
00325 if (items[0] == "#U")
00326 {
00327 if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
00328 else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
00329 else
00330 {
00331 edm::LogWarning("Pedestal Unit Error") << "Unrecognized unit for pedestals. Assuming fC." << std::endl;
00332 fObject->setUnitADC(false);
00333 }
00334 break;
00335 }
00336 else
00337 {
00338 edm::LogWarning("Pedestal Unit Missing") << "The unit for the pedestals is missing in the txt file." << std::endl;
00339 return false;
00340 }
00341 }
00342 }
00343 while (fInput.getline(buffer, 1024)) {
00344 if (buffer [0] == '#') continue;
00345 std::vector <std::string> items = splitString (std::string (buffer));
00346 if (items.size()==0) continue;
00347 if (items.size () < 8) {
00348 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
00349 << " or 12 items: eta, phi, depth, subdet, 4x values for mean, 4x values for width"
00350 << std::endl;
00351 continue;
00352 }
00353 DetId id = getId (items);
00354
00355
00356
00357
00358
00359
00360 if (items.size() < 12)
00361 {
00362 HcalPedestal* fCondObject = new HcalPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
00363 atof (items [6].c_str()), atof (items [7].c_str()),
00364 0., 0., 0., 0. );
00365 fObject->addValues(*fCondObject);
00366 delete fCondObject;
00367 }
00368 else
00369 {
00370 HcalPedestal* fCondObject = new HcalPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
00371 atof (items [6].c_str()), atof (items [7].c_str()),
00372 atof (items [8].c_str()), atof (items [9].c_str()),
00373 atof (items [10].c_str()), atof (items [11].c_str()) );
00374 fObject->addValues(*fCondObject);
00375 delete fCondObject;
00376 }
00377
00378
00379 }
00380 return true;
00381 }
00382
00383
00384 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPedestals& fObject) {
00385 char buffer [1024];
00386 if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
00387 else sprintf (buffer, "#U fC << this is the unit \n");
00388 fOutput << buffer;
00389
00390 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");
00391 fOutput << buffer;
00392
00393 std::vector<DetId> channels = fObject.getAllChannels ();
00394 std::sort (channels.begin(), channels.end(), DetIdLess ());
00395 for (std::vector<DetId>::iterator channel = channels.begin ();
00396 channel != channels.end ();
00397 channel++) {
00398 const float* values = fObject.getValues (*channel)->getValues ();
00399 if (values) {
00400 dumpId (fOutput, *channel);
00401 sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
00402 values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], channel->rawId ());
00403 fOutput << buffer;
00404 }
00405 }
00406 return true;
00407 }
00408
00409
00410
00411 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalChannelQuality* fObject)
00412 {
00413 if (!fObject) fObject = new HcalChannelQuality;
00414 char buffer [1024];
00415 while (fInput.getline(buffer, 1024)) {
00416 if (buffer [0] == '#') continue;
00417 std::vector <std::string> items = splitString (std::string (buffer));
00418 if (items.size()==0) continue;
00419 if (items.size () < 6) {
00420 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;
00421 continue;
00422 }
00423 DetId id = getId (items);
00424
00425
00426
00427
00428
00429 uint32_t mystatus;
00430 if (items[4] == "(hex)")
00431 sscanf(items[5].c_str(),"%X", &mystatus);
00432 else if (items[4] == "(dec)")
00433 sscanf(items[5].c_str(),"%u", &mystatus);
00434 else
00435 {
00436 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value field must contain the base: one of (hex), (dec)" << std::endl;
00437 continue;
00438 }
00439
00440 HcalChannelStatus* fCondObject = new HcalChannelStatus(id, mystatus);
00441 fObject->addValues(*fCondObject);
00442 delete fCondObject;
00443
00444 }
00445 return true;
00446 }
00447
00448
00449 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalChannelQuality& fObject) {
00450 char buffer [1024];
00451 sprintf (buffer, "# %15s %15s %15s %15s %15s %10s\n", "eta", "phi", "dep", "det", "(base) value", "DetId");
00452 fOutput << buffer;
00453 std::vector<DetId> channels = fObject.getAllChannels ();
00454 std::sort (channels.begin(), channels.end(), DetIdLess ());
00455 for (std::vector<DetId>::iterator channel = channels.begin ();
00456 channel != channels.end ();
00457 channel++) {
00458 const int value = fObject.getValues (*channel)->getValue ();
00459 dumpId (fOutput, *channel);
00460 sprintf (buffer, "%6s %15X %10X\n", "(hex)",
00461 value, channel->rawId ());
00462 fOutput << buffer;
00463 }
00464 return true;
00465 }
00466
00467
00468
00469 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalL1TriggerObjects* fObject)
00470 {
00471 if (!fObject) fObject = new HcalL1TriggerObjects;
00472 char buffer [1024];
00473
00474 while (fInput.getline(buffer, 1024)) {
00475 if (buffer [0] == '#')
00476 {
00477 if (buffer [1] == 'T')
00478 {
00479 std::vector <std::string> items = splitString (std::string (buffer) );
00480 fObject->setTagString(items[1]);
00481 continue;
00482 }
00483 if (buffer [1] == 'A')
00484 {
00485 std::vector <std::string> items = splitString (std::string (buffer) );
00486 fObject->setAlgoString(items[1]);
00487 continue;
00488 }
00489 else continue;
00490 }
00491 std::vector <std::string> items = splitString (std::string (buffer));
00492 if (items.size()==0) continue;
00493 if (items.size () < 7) {
00494 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, pedestal, resp.corr.gain, flag" << std::endl;
00495 continue;
00496 }
00497 DetId id = getId (items);
00498
00499 HcalL1TriggerObject* fCondObject = new HcalL1TriggerObject(id, atof(items[4].c_str()), atof(items[5].c_str()), atoi(items[6].c_str()) );
00500
00501 fObject->addValues(*fCondObject);
00502 delete fCondObject;
00503 }
00504 return true;
00505 }
00506
00507 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalL1TriggerObjects& fObject)
00508 {
00509 char buffer [1024];
00510
00511 sprintf (buffer, "#T %s << this is the tag name \n", fObject.getTagString().c_str() );
00512 fOutput << buffer;
00513 sprintf (buffer, "#A %s << this is the algorithm name \n", fObject.getAlgoString().c_str() );
00514 fOutput << buffer;
00515
00516
00517 sprintf (buffer, "# %15s %15s %15s %15s %8s %13s %8s %10s\n",
00518 "eta", "phi", "dep", "det", "ped", "respcorrgain", "flag",
00519 "DetId");
00520 fOutput << buffer;
00521 std::vector<DetId> channels = fObject.getAllChannels ();
00522
00523 for (std::vector<DetId>::iterator channel = channels.begin ();
00524 channel != channels.end ();
00525 channel++) {
00526 const HcalL1TriggerObject* item = fObject.getValues (*channel);
00527 if (item) {
00528 dumpId (fOutput, *channel);
00529 sprintf (buffer, " %10.7f %10.7f %12d %10X\n",
00530 item->getPedestal(), item->getRespGain(), item->getFlag(), channel->rawId ());
00531 fOutput << buffer;
00532 }
00533 }
00534 return true;
00535
00536 }
00537
00538
00539
00540 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPedestalWidths* fObject) {
00541 if (!fObject) fObject = new HcalPedestalWidths(false);
00542 char buffer [1024];
00543 int linecounter = 0;
00544
00545 while (fInput.getline(buffer, 1024)) {
00546 linecounter++;
00547 std::vector <std::string> items = splitString (std::string (buffer));
00548 if (items.size()==0) continue;
00549 else {
00550 if (items[0] == (std::string)"#U")
00551 {
00552 if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
00553 else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
00554 else
00555 {
00556 edm::LogWarning("Pedestal Width Unit Error") << "Unrecognized unit for pedestal widths. Assuming fC." << std::endl;
00557 fObject->setUnitADC(false);
00558 }
00559 break;
00560 }
00561 else
00562 {
00563 edm::LogWarning("Pedestal Width Unit Missing") << "The unit for the pedestal widths is missing in the txt file." << std::endl;
00564 return false;
00565 }
00566 }
00567 }
00568
00569 while (fInput.getline(buffer, 1024)) {
00570 linecounter++;
00571 if (buffer [0] == '#') continue;
00572 std::vector <std::string> items = splitString (std::string (buffer));
00573 if (items.size()==0) continue;
00574 if (items.size () < 14) {
00575 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line number: " << linecounter << "\n line must contain 14 items: eta, phi, depth, subdet, 10x correlations"
00576 << " or 20 items: eta, phi, depth, subdet, 16x correlations"
00577 << std::endl;
00578 continue;
00579 }
00580 DetId id = getId (items);
00581
00582
00583
00584
00585
00586
00587 if (items.size() < 20)
00588 {
00589 HcalPedestalWidth values(id);
00590 values.setSigma (0, 0, atof (items [4].c_str()));
00591 values.setSigma (1, 0, atof (items [5].c_str()));
00592 values.setSigma (1, 1, atof (items [6].c_str()));
00593 values.setSigma (2, 0, atof (items [7].c_str()));
00594 values.setSigma (2, 1, atof (items [8].c_str()));
00595 values.setSigma (2, 2, atof (items [9].c_str()));
00596 values.setSigma (3, 0, atof (items [10].c_str()));
00597 values.setSigma (3, 1, atof (items [11].c_str()));
00598 values.setSigma (3, 2, atof (items [12].c_str()));
00599 values.setSigma (3, 3, atof (items [13].c_str()));
00600 values.setSigma (0, 1, 0.);
00601 values.setSigma (0, 2, 0.);
00602 values.setSigma (0, 3, 0.);
00603 values.setSigma (1, 2, 0.);
00604 values.setSigma (1, 3, 0.);
00605 values.setSigma (2, 3, 0.);
00606 fObject->addValues(values);
00607 }
00608 else
00609 {
00610 HcalPedestalWidth values(id);
00611 values.setSigma (0, 0, atof (items [4].c_str()) );
00612 values.setSigma (0, 1, atof (items [5].c_str()) );
00613 values.setSigma (0, 2, atof (items [6].c_str()) );
00614 values.setSigma (0, 3, atof (items [7].c_str()) );
00615 values.setSigma (1, 0, atof (items [8].c_str()) );
00616 values.setSigma (1, 1, atof (items [9].c_str()) );
00617 values.setSigma (1, 2, atof (items [10].c_str()) );
00618 values.setSigma (1, 3, atof (items [11].c_str()) );
00619 values.setSigma (2, 0, atof (items [12].c_str()) );
00620 values.setSigma (2, 1, atof (items [13].c_str()) );
00621 values.setSigma (2, 2, atof (items [14].c_str()) );
00622 values.setSigma (2, 3, atof (items [15].c_str()) );
00623 values.setSigma (3, 0, atof (items [16].c_str()) );
00624 values.setSigma (3, 1, atof (items [17].c_str()) );
00625 values.setSigma (3, 2, atof (items [18].c_str()) );
00626 values.setSigma (3, 3, atof (items [19].c_str()) );
00627 fObject->addValues(values);
00628 }
00629
00630
00631 }
00632 return true;
00633 }
00634
00635 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPedestalWidths& fObject) {
00636 char buffer [1024];
00637 if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
00638 else sprintf (buffer, "#U fC << this is the unit \n");
00639 fOutput << buffer;
00640
00641 sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
00642 "eta", "phi", "dep", "det",
00643 "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",
00644 "DetId");
00645 fOutput << buffer;
00646 std::vector<DetId> channels = fObject.getAllChannels ();
00647 std::sort (channels.begin(), channels.end(), DetIdLess ());
00648 for (std::vector<DetId>::iterator channel = channels.begin ();
00649 channel != channels.end ();
00650 channel++) {
00651 const HcalPedestalWidth* item = fObject.getValues (*channel);
00652 if (item) {
00653 dumpId (fOutput, *channel);
00654 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",
00655 item->getSigma (0,0), item->getSigma (0,1), item->getSigma (0,2), item->getSigma (0,3),
00656 item->getSigma (1,0), item->getSigma (1,1), item->getSigma (1,2), item->getSigma (1,3),
00657 item->getSigma (2,0), item->getSigma (2,1), item->getSigma (2,2), item->getSigma (2,3),
00658 item->getSigma (3,0), item->getSigma (3,1), item->getSigma (3,2), item->getSigma (3,3), channel->rawId ());
00659 fOutput << buffer;
00660 }
00661 }
00662 return true;
00663 }
00664
00665
00666
00667 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalQIEData* fObject) {
00668 char buffer [1024];
00669 while (fInput.getline(buffer, 1024)) {
00670 if (buffer [0] == '#') continue;
00671 std::vector <std::string> items = splitString (std::string (buffer));
00672 if (items.size()<1) continue;
00673 if (items [0] == "SHAPE") {
00674 if (items.size () < 33) {
00675 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;
00676 continue;
00677 }
00678 float lowEdges [32];
00679 int i = 32;
00680 while (--i >= 0) lowEdges [i] = atof (items [i+1].c_str ());
00681
00682 }
00683 else {
00684 if (items.size () < 36) {
00685 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;
00686 continue;
00687 }
00688 DetId id = getId (items);
00689 fObject->sort ();
00690
00691
00692
00693
00694
00695 HcalQIECoder coder (id.rawId ());
00696 int index = 4;
00697 for (unsigned capid = 0; capid < 4; capid++) {
00698 for (unsigned range = 0; range < 4; range++) {
00699 coder.setOffset (capid, range, atof (items [index++].c_str ()));
00700 }
00701 }
00702 for (unsigned capid = 0; capid < 4; capid++) {
00703 for (unsigned range = 0; range < 4; range++) {
00704 coder.setSlope (capid, range, atof (items [index++].c_str ()));
00705 }
00706 }
00707 fObject->addCoder (coder);
00708
00709 }
00710 }
00711 fObject->sort ();
00712 return true;
00713 }
00714
00715 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalQIEData& fObject) {
00716 char buffer [1024];
00717 fOutput << "# QIE basic shape: SHAPE 32 x low edge values for first 32 channels" << std::endl;
00718 sprintf (buffer, "SHAPE ");
00719 fOutput << buffer;
00720 for (unsigned bin = 0; bin < 32; bin++) {
00721 sprintf (buffer, " %8.5f", fObject.getShape ().lowEdge (bin));
00722 fOutput << buffer;
00723 }
00724 fOutput << std::endl;
00725
00726 fOutput << "# QIE data" << std::endl;
00727 sprintf (buffer, "# %15s %15s %15s %15s %36s %36s %36s %36s %36s %36s %36s %36s\n",
00728 "eta", "phi", "dep", "det",
00729 "4 x offsets cap0", "4 x offsets cap1", "4 x offsets cap2", "4 x offsets cap3",
00730 "4 x slopes cap0", "4 x slopes cap1", "4 x slopes cap2", "4 x slopes cap3");
00731 fOutput << buffer;
00732 std::vector<DetId> channels = fObject.getAllChannels ();
00733 std::sort (channels.begin(), channels.end(), DetIdLess ());
00734 for (std::vector<DetId>::iterator channel = channels.begin ();
00735 channel != channels.end ();
00736 channel++) {
00737 const HcalQIECoder* coder = fObject.getCoder (*channel);
00738 dumpId (fOutput, *channel);
00739 for (unsigned capid = 0; capid < 4; capid++) {
00740 for (unsigned range = 0; range < 4; range++) {
00741 sprintf (buffer, " %8.5f", coder->offset (capid, range));
00742 fOutput << buffer;
00743 }
00744 }
00745 for (unsigned capid = 0; capid < 4; capid++) {
00746 for (unsigned range = 0; range < 4; range++) {
00747 sprintf (buffer, " %8.5f", coder->slope (capid, range));
00748 fOutput << buffer;
00749 }
00750 }
00751 fOutput << std::endl;
00752 }
00753 return true;
00754 }
00755
00756
00757 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCalibrationQIEData* fObject) {
00758 char buffer [1024];
00759 while (fInput.getline(buffer, 1024)) {
00760 if (buffer [0] == '#') continue;
00761 std::vector <std::string> items = splitString (std::string (buffer));
00762 if (items.size () < 36) {
00763 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 36 items: eta, phi, depth, subdet, 32 bin values" << std::endl;
00764 continue;
00765 }
00766 DetId id = getId (items);
00767 fObject->sort ();
00768
00769
00770
00771
00772
00773 HcalCalibrationQIECoder coder (id.rawId ());
00774 int index = 4;
00775 float values [32];
00776 for (unsigned bin = 0; bin < 32; bin++) {
00777 values[bin] = atof (items [index++].c_str ());
00778 }
00779 coder.setMinCharges (values);
00780 fObject->addCoder (coder);
00781
00782 }
00783 fObject->sort ();
00784 return true;
00785 }
00786
00787 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCalibrationQIEData& fObject) {
00788 char buffer [1024];
00789 fOutput << "# QIE data in calibration mode" << std::endl;
00790 sprintf (buffer, "# %15s %15s %15s %15s %288s\n",
00791 "eta", "phi", "dep", "det", "32 x charges");
00792 fOutput << buffer;
00793 std::vector<DetId> channels = fObject.getAllChannels ();
00794 std::sort (channels.begin(), channels.end(), DetIdLess ());
00795 for (std::vector<DetId>::iterator channel = channels.begin ();
00796 channel != channels.end ();
00797 channel++) {
00798 const HcalCalibrationQIECoder* coder = fObject.getCoder (*channel);
00799 if (coder) {
00800 dumpId (fOutput, *channel);
00801 const float* lowEdge = coder->minCharges ();
00802 for (unsigned bin = 0; bin < 32; bin++) {
00803 sprintf (buffer, " %8.5f", lowEdge [bin]);
00804 fOutput << buffer;
00805 }
00806 fOutput << std::endl;
00807 }
00808 }
00809 return true;
00810 }
00811
00812
00813
00814 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalElectronicsMap* fObject) {
00815 char buffer [1024];
00816 while (fInput.getline(buffer, 1024)) {
00817 if (buffer [0] == '#') continue;
00818 std::vector <std::string> items = splitString (std::string (buffer));
00819 if (items.size () < 12) {
00820 if (items.size()==0) continue;
00821 if (items.size()<9) {
00822 edm::LogError("MapFormat") << "HcalElectronicsMap-> line too short: " << buffer;
00823 continue;
00824 }
00825 if (items[8]=="NA" || items[8]=="NT") {
00826 while (items.size()<12) items.push_back("");
00827 } else if (items[8]=="HT") {
00828 if (items.size()==11) items.push_back("");
00829 else {
00830 edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer
00831 << "\n HT line must contain at least 11 items: i cr sl tb dcc spigot fiber fiberchan subdet=HT ieta iphi";
00832 continue;
00833 }
00834 } else {
00835 edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer
00836 << "\n line must contain 12 items: i cr sl tb dcc spigot fiber fiberchan subdet ieta iphi depth";
00837 continue;
00838 }
00839 }
00840
00841 int crate = atoi (items [1].c_str());
00842 int slot = atoi (items [2].c_str());
00843 int top = 1;
00844 if (items [3] == "b") top = 0;
00845 int dcc = atoi (items [4].c_str());
00846 int spigot = atoi (items [5].c_str());
00847 HcalElectronicsId elId;
00848 if (items[8] == "HT" || items[8] == "NT") {
00849 int slb = atoi (items [6].c_str());
00850 int slbCh = atoi (items [7].c_str());
00851 elId=HcalElectronicsId(slbCh, slb, spigot, dcc,crate,slot,top);
00852 } else {
00853 int fiber = atoi (items [6].c_str());
00854 int fiberCh = atoi (items [7].c_str());
00855
00856 elId=HcalElectronicsId(fiberCh, fiber, spigot, dcc);
00857 elId.setHTR (crate, slot, top);
00858 }
00859
00860
00861 if (items [8] == "NA") {
00862 fObject->mapEId2chId (elId, DetId (HcalDetId::Undefined));
00863 } else if (items [8] == "NT") {
00864 fObject->mapEId2tId (elId, DetId (HcalTrigTowerDetId::Undefined));
00865 } else {
00866 HcalText2DetIdConverter converter (items [8], items [9], items [10], items [11]);
00867 if (converter.isHcalDetId ()) {
00868 fObject->mapEId2chId (elId, converter.getId ());
00869 }
00870 else if (converter.isHcalTrigTowerDetId ()) {
00871 fObject->mapEId2tId (elId, converter.getId ());
00872 }
00873 else if (converter.isHcalCalibDetId ()) {
00874 fObject->mapEId2chId (elId, converter.getId ());
00875 }
00876 else if (converter.isHcalZDCDetId ()) {
00877 fObject->mapEId2chId (elId, converter.getId ());
00878 }
00879 else {
00880 edm::LogWarning("Format Error") << "HcalElectronicsMap-> Unknown subdetector: "
00881 << items [8] << '/' << items [9] << '/' << items [10] << '/' << items [11] << std::endl;
00882 }
00883 }
00884 }
00885 fObject->sort ();
00886 return true;
00887 }
00888
00889 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalElectronicsMap& fObject) {
00890 std::vector<HcalElectronicsId> eids = fObject.allElectronicsId ();
00891 char buf [1024];
00892
00893
00894 sprintf (buf, "# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
00895 "i", "cr", "sl", "tb", "dcc", "spigot", "fiber/slb", "fibcha/slbcha", "subdet", "ieta", "iphi", "depth");
00896 fOutput << buf << std::endl;
00897
00898 for (unsigned i = 0; i < eids.size (); i++) {
00899 HcalElectronicsId eid = eids[i];
00900 if (eid.isTriggerChainId()) {
00901 DetId trigger = fObject.lookupTrigger (eid);
00902 if (trigger.rawId ()) {
00903 HcalText2DetIdConverter converter (trigger);
00904
00905
00906 sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
00907
00908 converter.getId().rawId(),
00909
00910
00911 eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.slbSiteNumber(), eid.slbChannelIndex(),
00912 converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
00913 );
00914 fOutput << buf << std::endl;
00915 }
00916 } else {
00917 DetId channel = fObject.lookup (eid);
00918 if (channel.rawId()) {
00919 HcalText2DetIdConverter converter (channel);
00920
00921
00922 sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
00923
00924 converter.getId().rawId(),
00925 eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
00926 converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
00927 );
00928 fOutput << buf << std::endl;
00929 }
00930 }
00931 }
00932 return true;
00933 }
00934
00935
00936 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLutMetadata* fObject){
00937 if (!fObject) fObject = new HcalLutMetadata;
00938 char buffer [1024];
00939 while (fInput.getline(buffer, 1024)) {
00940 if (buffer [0] == '#') continue;
00941 std::vector <std::string> items = splitString (std::string (buffer));
00942 if (items.size()==0) continue;
00943
00944 if (items.size() > 1 &&
00945 items[0].find("RctLsb")!=std::string::npos){
00946 fObject->setRctLsb( atof( items[1].c_str() ) );
00947 continue;
00948 }
00949 if (items.size() > 1 &&
00950 items[0].find("Gain")!=std::string::npos){
00951 fObject->setNominalGain( atof( items[1].c_str() ) );
00952 continue;
00953 }
00954
00955 if (items.size () < 7) {
00956 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, Rcalib, LutGranularity, OutputLutThreshold" << std::endl;
00957 continue;
00958 }
00959 DetId id = getId (items);
00960
00961 HcalLutMetadatum * fCondObject = new HcalLutMetadatum(id,
00962 atof (items [4].c_str()),
00963 atoi (items [5].c_str()),
00964 atoi (items [6].c_str()));
00965 fObject->addValues(*fCondObject);
00966 delete fCondObject;
00967 }
00968 return true;
00969 }
00970
00971
00972 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalLutMetadata& fObject){
00973 char buffer [1024];
00974 const float _rctLsb = fObject.getRctLsb();
00975 const float _gain = fObject.getNominalGain();
00976 sprintf (buffer, "# %20s\n", "Non-channel data");
00977 fOutput << buffer;
00978 sprintf (buffer, "%8s %8.5f\n", "RctLsb", _rctLsb);
00979 fOutput << buffer;
00980 sprintf (buffer, "%8s %8.5f\n", "Gain", _gain);
00981 fOutput << buffer;
00982 sprintf (buffer, "# %15s %15s %15s %15s %8s %15s %19s %10s\n", "eta", "phi", "dep", "det", "Rcalib", "LutGranularity", "OutputLutThreshold", "DetId");
00983 fOutput << buffer;
00984 std::vector<DetId> channels = fObject.getAllChannels ();
00985 std::sort (channels.begin(), channels.end(), DetIdLess ());
00986 for (std::vector<DetId>::iterator channel = channels.begin ();
00987 channel != channels.end ();
00988 channel++) {
00989 const float _rCalib = fObject.getValues (*channel)->getRCalib();
00990 const uint8_t _lutGranularity = fObject.getValues (*channel)->getLutGranularity();
00991 const uint8_t _outputLutThreshold = fObject.getValues (*channel)->getOutputLutThreshold();
00992 dumpId (fOutput, *channel);
00993 sprintf (buffer, " %8.5f %15d %19d %10X\n",
00994 _rCalib,
00995 _lutGranularity,
00996 _outputLutThreshold,
00997 channel->rawId ());
00998 fOutput << buffer;
00999 }
01000 return true;
01001 }
01002
01003
01004 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalDcsValues * fObject) {
01005 if (!fObject) fObject = new HcalDcsValues;
01006 std::string buffer;
01007 while (getline(fInput, buffer)) {
01008 if (buffer.at(0) == '#') continue;
01009 std::vector <std::string> items = splitString (buffer);
01010 if (items.size()==0) continue;
01011
01012 if (items.size() < 9) {
01013 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;
01014 continue;
01015 }
01016
01017 HcalOtherSubdetector subd;
01018 int sidering;
01019 unsigned int slice, subchan;
01020 switch (items[0].at(1)) {
01021 case 'B':
01022 subd = HcalDcsBarrel;
01023 break;
01024 case 'E':
01025 subd = HcalDcsEndcap;
01026 break;
01027 case 'F':
01028 subd = HcalDcsForward;
01029 break;
01030 case 'O':
01031 subd = HcalDcsOuter;
01032 break;
01033 default:
01034 continue;
01035 }
01036
01037 from_string<int>(sidering, items[1], std::dec);
01038 from_string<unsigned int>(slice, items[2], std::dec);
01039
01040 from_string<unsigned int>(subchan, items[4], std::dec);
01041
01042 HcalDcsDetId newId(subd, sidering, slice,
01043 HcalDcsDetId::DcsTypeFromString(items[3]), subchan);
01044
01045 int LS;
01046 float val,upper,lower;
01047 from_string<int>(LS, items[5], std::dec);
01048 from_string<float>(val, items[6], std::dec);
01049 from_string<float>(upper, items[7], std::dec);
01050 from_string<float>(lower, items[8], std::dec);
01051
01052 HcalDcsValue newVal(newId.rawId(),LS,val,upper,lower);
01053
01054
01055
01056
01057
01058 if (!(fObject->addValue(newVal))) {
01059 edm::LogWarning("Data Error") << "Data from line " << buffer
01060 << "\nwas not added to the HcalDcsValues object." << std::endl;
01061 }
01062
01063 }
01064 fObject->sortAll();
01065 return true;
01066 }
01067
01068 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput,
01069 HcalDcsValues const& fObject) {
01070 fOutput << "# subDet side_ring slice type subChan LS Value UpperLimit LowerLimit DcsId\n";
01071 for(int subd = HcalDcsValues::HcalHB;
01072 subd <= HcalDcsValues::HcalHF; ++subd) {
01073
01074 HcalDcsValues::DcsSet const & vals=
01075 fObject.getAllSubdetValues(HcalDcsValues::DcsSubDet(subd));
01076 for (HcalDcsValues::DcsSet::const_iterator val = vals.begin();
01077 val != vals.end(); ++val) {
01078 HcalDcsDetId valId(val->DcsId());
01079
01080 switch (valId.subdet()) {
01081 case HcalDcsBarrel:
01082 fOutput << "HB ";
01083 break;
01084 case HcalDcsEndcap:
01085 fOutput << "HE ";
01086 break;
01087 case HcalDcsOuter:
01088 fOutput << "HO ";
01089 break;
01090 case HcalDcsForward:
01091 fOutput << "HF ";
01092 break;
01093 default :
01094 fOutput << valId.subdet() << ' ';
01095 }
01096
01097 if (valId.subdet() == HcalDcsOuter)
01098 fOutput << valId.ring() << ' ';
01099 else
01100 fOutput << valId.zside() << ' ';
01101
01102 fOutput << valId.slice() << ' '
01103 << valId.typeString(valId.type()) << ' '
01104 << valId.subchannel() << ' ';
01105 fOutput << val->LS() << ' '
01106 << val->getValue() << ' '
01107 << val->getUpperLimit() << ' '
01108 << val->getLowerLimit() << ' ';
01109 fOutput << std::hex << val->DcsId() << std::dec << '\n';
01110
01111
01112
01113
01114
01115
01116 }
01117 }
01118
01119 return true;
01120 }
01121
01122
01123
01124
01125
01126 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalDcsMap* fObject) {
01127 char buffer [1024];
01128 while (fInput.getline(buffer, 1024)) {
01129 if (buffer [0] == '#') continue;
01130 std::vector <std::string> items = splitString (std::string (buffer));
01131 if (items.size () < 8) {
01132 if (items.size()==0) continue;
01133 else {
01134 edm::LogError("MapFormat") << "HcalDcsMap-> Bad line: " << buffer
01135 << "\n line must contain 8 items: line side_ring slice subchannel subdet ieta iphi depth";
01136 continue;
01137 }
01138 }
01139
01140
01141 int ring = atoi(items[1].c_str());
01142 unsigned int slice = atoi (items [2].c_str());
01143 unsigned int subchannel = atoi (items [3].c_str());
01144 HcalDcsDetId::DcsType type = HcalDcsDetId::DCSUNKNOWN;
01145
01146
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188 HcalOtherSubdetector subdet = HcalOtherEmpty;
01189 if (items[4].find("CALIB")!=std::string::npos){
01190 subdet = HcalCalibration;
01191 }
01192 else if (items[4].find("HB")!=std::string::npos){
01193 subdet = HcalDcsBarrel;
01194 }
01195 else if (items[4].find("HE")!=std::string::npos){
01196 subdet = HcalDcsEndcap;
01197 }
01198 else if (items[4].find("HO")!=std::string::npos){
01199 subdet = HcalDcsOuter;
01200 }
01201 else if (items[4].find("HF")!=std::string::npos){
01202 subdet = HcalDcsForward;
01203 }
01204 else{
01205 edm::LogError("MapFormat") << "HcalDcsMap-> Unknown subdetector, line is not accepted: " << items[5];
01206 continue;
01207 }
01208 HcalDcsDetId dcsId(subdet, ring, slice, type, subchannel);
01209 HcalText2DetIdConverter converter (items [4], items [5], items [6], items [7]);
01210 HcalDetId id(0);
01211 if (converter.isHcalDetId()){
01212 id = converter.getId();
01213 }
01214 else{
01215 edm::LogWarning("Invalid HCAL channel") << "HcalDcsMap-> invalid channel: "
01216 << items [4] << '/'
01217 << items [5] << '/'
01218 << items [6] << '/'
01219 << items [7] << std::endl;
01220 continue;
01221 }
01222 fObject->mapGeomId2DcsId(id, dcsId);
01223 }
01224 fObject->sort ();
01225 return true;
01226 }
01227
01228
01229
01230
01231 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalDcsMap& fObject) {
01232 char buf [1024];
01233 sprintf (buf, "# %7s %10s %6s %8s %7s %5s %5s %6s",
01234 "i", "side_ring", "slice", "subchan", "subdet", "ieta", "iphi", "depth");
01235 fOutput << buf << std::endl;
01236 HcalDcsMap::const_iterator _line;
01237 unsigned int line_counter = 0;
01238 for (_line = fObject.beginById();
01239 _line != fObject.endById();
01240 ++_line) {
01241 HcalDcsDetId dcsId = _line.getHcalDcsDetId();
01242
01243 HcalText2DetIdConverter _converter(_line.getHcalDetId());
01244 sprintf (buf, " %8X %10d %6d %8d %7s %5s %5s %6s",
01245 line_counter,
01246 dcsId.ring(),
01247 dcsId.slice(),
01248 dcsId.subchannel(),
01249 _converter.getFlavor().c_str(),
01250 _converter.getField1().c_str(),
01251 _converter.getField2().c_str(),
01252 _converter.getField3().c_str()
01253 );
01254 fOutput << buf << std::endl;
01255 ++line_counter;
01256 }
01257 return true;
01258 }
01259
01260