00001
00002
00003
00004
00005 #include <vector>
00006 #include <string>
00007 #include <cstdio>
00008
00009 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00010 #include "DataFormats/HcalDetId/interface/CastorElectronicsId.h"
00011 #include "CalibFormats/CastorObjects/interface/CastorText2DetIdConverter.h"
00012
00013 #include "CondFormats/CastorObjects/interface/AllObjects.h"
00014 #include "CalibCalorimetry/CastorCalib/interface/CastorDbASCIIIO.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016
00017 namespace CastorDbASCIIIO {
00018 class DetIdLess {
00019 public:
00020 bool operator () (DetId fFirst, DetId fSecond) const {
00021 HcalGenericDetId first (fFirst);
00022 HcalGenericDetId second (fSecond);
00023 if (first.genericSubdet () != second.genericSubdet ()) return first.genericSubdet () < second.genericSubdet ();
00024 if (first.isHcalDetId ()) {
00025 HcalDetId f1 (first);
00026 HcalDetId s1 (second);
00027 return f1.zside () != s1.zside () ? f1.zside () < s1.zside () :
00028 f1.iphi () != s1.iphi () ? f1.iphi () < s1.iphi () :
00029 f1.ietaAbs () != s1.ietaAbs () ? f1.ietaAbs () < s1.ietaAbs () :
00030 f1.depth () < s1.depth ();
00031 }
00032 else {
00033 return first.rawId() < second.rawId();
00034 }
00035 }
00036 };
00037 class CastorElectronicsIdLess {
00038 public:
00039 bool operator () (CastorElectronicsId first, CastorElectronicsId second) const {
00040 return
00041 first.readoutVMECrateId () != second.readoutVMECrateId () ? first.readoutVMECrateId () < second.readoutVMECrateId () :
00042 first.htrSlot () != second.htrSlot () ? first.htrSlot () < second.htrSlot () :
00043 first.htrTopBottom () != second.htrTopBottom () ? first.htrTopBottom () < second.htrTopBottom () :
00044 first.fiberIndex () != second.fiberIndex () ? first.fiberIndex () < second.fiberIndex () :
00045 first.fiberChanId () < second.fiberChanId ();
00046 }
00047 };
00048
00049 std::vector <std::string> splitString (const std::string& fLine) {
00050 std::vector <std::string> result;
00051 int start = 0;
00052 bool empty = true;
00053 for (unsigned i = 0; i <= fLine.size (); i++) {
00054 if (fLine [i] == ' ' || i == fLine.size ()) {
00055 if (!empty) {
00056 std::string item (fLine, start, i-start);
00057 result.push_back (item);
00058 empty = true;
00059 }
00060 start = i+1;
00061 }
00062 else {
00063 if (empty) empty = false;
00064 }
00065 }
00066 return result;
00067 }
00068
00069 DetId getId (const std::vector <std::string> & items) {
00070 CastorText2DetIdConverter converter (items [3], items [0], items [1], items [2]);
00071 return converter.getId ();
00072 }
00073
00074 void dumpId (std::ostream& fOutput, DetId id) {
00075 CastorText2DetIdConverter converter (id);
00076 char buffer [1024];
00077 sprintf (buffer, " %15s %15s %15s %15s",
00078 converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str (),converter.getFlavor ().c_str ());
00079 fOutput << buffer;
00080 }
00081
00082 template <class T,class S>
00083 bool getCastorObject (std::istream& fInput, T* fObject, S* fCondObject) {
00084 if (!fObject) fObject = new T;
00085 char buffer [1024];
00086 while (fInput.getline(buffer, 1024)) {
00087 if (buffer [0] == '#') continue;
00088 std::vector <std::string> items = splitString (std::string (buffer));
00089 if (items.size()==0) continue;
00090 if (items.size () < 8) {
00091 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values" << std::endl;
00092 continue;
00093 }
00094 DetId id = getId (items);
00095
00096
00097
00098
00099
00100 fCondObject = new S(id, atof (items [4].c_str()), atof (items [5].c_str()),
00101 atof (items [6].c_str()), atof (items [7].c_str()));
00102 fObject->addValues(*fCondObject);
00103 delete fCondObject;
00104
00105 }
00106
00107 return true;
00108 }
00109
00110 template <class T>
00111 bool dumpCastorObject (std::ostream& fOutput, const T& fObject) {
00112 char buffer [1024];
00113 sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %10s\n", "eta", "phi", "dep", "det", "cap0", "cap1", "cap2", "cap3", "DetId");
00114 fOutput << buffer;
00115 std::vector<DetId> channels = fObject.getAllChannels ();
00116
00117 for (std::vector<DetId>::iterator channel = channels.begin ();
00118 channel != channels.end ();
00119 channel++) {
00120 const float* values = fObject.getValues (*channel)->getValues ();
00121 if (values) {
00122 dumpId (fOutput, *channel);
00123 sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %10X\n",
00124 values[0], values[1], values[2], values[3], channel->rawId ());
00125 fOutput << buffer;
00126 }
00127 }
00128 return true;
00129 }
00130
00131 template <class T,class S>
00132 bool getCastorSingleFloatObject (std::istream& fInput, T* fObject, S* fCondObject) {
00133 if (!fObject) fObject = new T;
00134 char buffer [1024];
00135 while (fInput.getline(buffer, 1024)) {
00136 if (buffer [0] == '#') continue;
00137 std::vector <std::string> items = splitString (std::string (buffer));
00138 if (items.size()==0) continue;
00139 if (items.size () < 5) {
00140 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 5 items: eta, phi, depth, subdet, value" << std::endl;
00141 continue;
00142 }
00143 DetId id = getId (items);
00144
00145
00146
00147
00148
00149 fCondObject = new S(id, atof (items [4].c_str()) );
00150 fObject->addValues(*fCondObject);
00151 delete fCondObject;
00152
00153 }
00154 return true;
00155 }
00156
00157 template <class T>
00158 bool dumpCastorSingleFloatObject (std::ostream& fOutput, const T& fObject) {
00159 char buffer [1024];
00160 sprintf (buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
00161 fOutput << buffer;
00162 std::vector<DetId> channels = fObject.getAllChannels ();
00163 std::sort (channels.begin(), channels.end(), DetIdLess ());
00164 for (std::vector<DetId>::iterator channel = channels.begin ();
00165 channel != channels.end ();
00166 channel++) {
00167 const float value = fObject.getValues (*channel)->getValue ();
00168 dumpId (fOutput, *channel);
00169 sprintf (buffer, " %8.5f %10X\n",
00170 value, channel->rawId ());
00171 fOutput << buffer;
00172 }
00173 return true;
00174 }
00175
00176 template <class T,class S>
00177 bool getCastorSingleIntObject (std::istream& fInput, T* fObject, S* fCondObject) {
00178 if (!fObject) fObject = new T;
00179 char buffer [1024];
00180 while (fInput.getline(buffer, 1024)) {
00181 if (buffer [0] == '#') continue;
00182 std::vector <std::string> items = splitString (std::string (buffer));
00183 if (items.size()==0) continue;
00184 if (items.size () < 5) {
00185 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 5 items: eta, phi, depth, subdet, value" << std::endl;
00186 continue;
00187 }
00188 DetId id = getId (items);
00189
00190
00191
00192
00193
00194 fCondObject = new S(id, atoi (items [4].c_str()) );
00195 fObject->addValues(*fCondObject);
00196 delete fCondObject;
00197
00198 }
00199 return true;
00200 }
00201
00202 template <class T>
00203 bool dumpCastorSingleIntObject (std::ostream& fOutput, const T& fObject) {
00204 char buffer [1024];
00205 sprintf (buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
00206 fOutput << buffer;
00207 std::vector<DetId> channels = fObject.getAllChannels ();
00208 std::sort (channels.begin(), channels.end(), DetIdLess ());
00209 for (std::vector<DetId>::iterator channel = channels.begin ();
00210 channel != channels.end ();
00211 channel++) {
00212 const int value = fObject.getValues (*channel)->getValue ();
00213 dumpId (fOutput, *channel);
00214 sprintf (buffer, " %15d %10X\n",
00215 value, channel->rawId ());
00216 fOutput << buffer;
00217 }
00218 return true;
00219 }
00220
00221
00222 bool getObject (std::istream& fInput, CastorGains* fObject) {return getCastorObject (fInput, fObject, new CastorGain);}
00223 bool dumpObject (std::ostream& fOutput, const CastorGains& fObject) {return dumpCastorObject (fOutput, fObject);}
00224 bool getObject (std::istream& fInput, CastorGainWidths* fObject) {return getCastorObject (fInput, fObject, new CastorGainWidth);}
00225 bool dumpObject (std::ostream& fOutput, const CastorGainWidths& fObject) {return dumpCastorObject (fOutput, fObject);}
00226
00227
00228
00229
00230 bool getObject (std::istream& fInput, CastorPedestals* fObject) {
00231 if (!fObject) fObject = new CastorPedestals(false);
00232 char buffer [1024];
00233
00234 while (fInput.getline(buffer, 1024)) {
00235 std::vector <std::string> items = splitString (std::string (buffer));
00236 if (items.size()==0) continue;
00237 else {
00238 if (items[0] == "#U")
00239 {
00240 if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
00241 else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
00242 else
00243 {
00244 edm::LogWarning("Pedestal Unit Error") << "Unrecognized unit for pedestals. Assuming fC." << std::endl;
00245 fObject->setUnitADC(false);
00246 }
00247 break;
00248 }
00249 else
00250 {
00251 edm::LogWarning("Pedestal Unit Missing") << "The unit for the pedestals is missing in the txt file." << std::endl;
00252 return false;
00253 }
00254 }
00255 }
00256 while (fInput.getline(buffer, 1024)) {
00257 if (buffer [0] == '#') continue;
00258 std::vector <std::string> items = splitString (std::string (buffer));
00259 if (items.size()==0) continue;
00260 if (items.size () < 8) {
00261 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
00262 << " or 12 items: eta, phi, depth, subdet, 4x values for mean, 4x values for width"
00263 << std::endl;
00264 continue;
00265 }
00266 DetId id = getId (items);
00267
00268
00269
00270
00271
00272
00273 if (items.size() < 12)
00274 {
00275 CastorPedestal* fCondObject = new CastorPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
00276 atof (items [6].c_str()), atof (items [7].c_str()),
00277 0., 0., 0., 0. );
00278 fObject->addValues(*fCondObject);
00279 delete fCondObject;
00280 }
00281 else
00282 {
00283 CastorPedestal* fCondObject = new CastorPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
00284 atof (items [6].c_str()), atof (items [7].c_str()),
00285 atof (items [8].c_str()), atof (items [9].c_str()),
00286 atof (items [10].c_str()), atof (items [11].c_str()) );
00287 fObject->addValues(*fCondObject);
00288 delete fCondObject;
00289 }
00290
00291
00292 }
00293 return true;
00294 }
00295
00296
00297 bool dumpObject (std::ostream& fOutput, const CastorPedestals& fObject) {
00298 char buffer [1024];
00299 if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
00300 else sprintf (buffer, "#U fC << this is the unit \n");
00301 fOutput << buffer;
00302
00303 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");
00304 fOutput << buffer;
00305
00306 std::vector<DetId> channels = fObject.getAllChannels ();
00307 std::sort (channels.begin(), channels.end(), DetIdLess ());
00308 for (std::vector<DetId>::iterator channel = channels.begin ();
00309 channel != channels.end ();
00310 channel++) {
00311 const float* values = fObject.getValues (*channel)->getValues ();
00312 if (values) {
00313 dumpId (fOutput, *channel);
00314 sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
00315 values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], channel->rawId ());
00316 fOutput << buffer;
00317 }
00318 }
00319 return true;
00320 }
00321
00322
00323
00324 bool getObject (std::istream& fInput, CastorChannelQuality* fObject)
00325 {
00326 if (!fObject) fObject = new CastorChannelQuality;
00327 char buffer [1024];
00328 while (fInput.getline(buffer, 1024)) {
00329 if (buffer [0] == '#') continue;
00330 std::vector <std::string> items = splitString (std::string (buffer));
00331 if (items.size()==0) continue;
00332 if (items.size () < 5) {
00333 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 5 items: eta, phi, depth, subdet, GOOD/BAD/HOT/DEAD" << std::endl;
00334 continue;
00335 }
00336 DetId id = getId (items);
00337
00338 if (fObject->exists(id) ) {
00339 edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
00340 continue;
00341 }
00342
00343
00344 uint32_t mystatus;
00345 CastorChannelStatus* fCondObject = NULL;
00346 if (items[4].substr(0,2)=="0x") {
00347 sscanf(items[4].c_str(),"%X", &mystatus);
00348 fCondObject = new CastorChannelStatus(id,mystatus);
00349 }
00350 else if (isalpha(items[4].c_str()[0])) {
00351 fCondObject = new CastorChannelStatus(id, items[4]);
00352 }
00353 else {
00354 sscanf(items[4].c_str(),"%u", &mystatus);
00355 fCondObject = new CastorChannelStatus(id,mystatus);
00356 }
00357 fObject->addValues(*fCondObject);
00358 delete fCondObject;
00359
00360 }
00361 return true;
00362 }
00363
00364
00365 bool dumpObject (std::ostream& fOutput, const CastorChannelQuality& fObject) {
00366 char buffer [1024];
00367 sprintf (buffer, "# %15s %15s %15s %15s %15s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
00368 fOutput << buffer;
00369 std::vector<DetId> channels = fObject.getAllChannels ();
00370 std::sort (channels.begin(), channels.end(), DetIdLess ());
00371 for (std::vector<DetId>::iterator channel = channels.begin ();
00372 channel != channels.end ();
00373 channel++) {
00374 const int value = fObject.getValues (*channel)->getValue ();
00375 dumpId (fOutput, *channel);
00376 sprintf (buffer, " %15X %10X\n",
00377 value, channel->rawId ());
00378 fOutput << buffer;
00379 }
00380 return true;
00381 }
00382
00383
00384
00385 bool getObject (std::istream& fInput, CastorPedestalWidths* fObject) {
00386 if (!fObject) fObject = new CastorPedestalWidths(false);
00387 char buffer [1024];
00388 int linecounter = 0;
00389
00390 while (fInput.getline(buffer, 1024)) {
00391 linecounter++;
00392 std::vector <std::string> items = splitString (std::string (buffer));
00393 if (items.size()==0) continue;
00394 else {
00395 if (items[0] == (std::string)"#U")
00396 {
00397 if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
00398 else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
00399 else
00400 {
00401 edm::LogWarning("Pedestal Width Unit Error") << "Unrecognized unit for pedestal widths. Assuming fC." << std::endl;
00402 fObject->setUnitADC(false);
00403 }
00404 break;
00405 }
00406 else
00407 {
00408 edm::LogWarning("Pedestal Width Unit Missing") << "The unit for the pedestal widths is missing in the txt file." << std::endl;
00409 return false;
00410 }
00411 }
00412 }
00413
00414 while (fInput.getline(buffer, 1024)) {
00415 linecounter++;
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 () < 14) {
00420 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line number: " << linecounter << "\n line must contain 14 items: eta, phi, depth, subdet, 10x correlations"
00421 << " or 20 items: eta, phi, depth, subdet, 16x correlations"
00422 << std::endl;
00423 continue;
00424 }
00425 DetId id = getId (items);
00426
00427
00428
00429
00430
00431
00432 if (items.size() < 20)
00433 {
00434 CastorPedestalWidth values(id);
00435 values.setSigma (0, 0, atof (items [4].c_str()));
00436 values.setSigma (1, 0, atof (items [5].c_str()));
00437 values.setSigma (1, 1, atof (items [6].c_str()));
00438 values.setSigma (2, 0, atof (items [7].c_str()));
00439 values.setSigma (2, 1, atof (items [8].c_str()));
00440 values.setSigma (2, 2, atof (items [9].c_str()));
00441 values.setSigma (3, 0, atof (items [10].c_str()));
00442 values.setSigma (3, 1, atof (items [11].c_str()));
00443 values.setSigma (3, 2, atof (items [12].c_str()));
00444 values.setSigma (3, 3, atof (items [13].c_str()));
00445 values.setSigma (0, 1, 0.);
00446 values.setSigma (0, 2, 0.);
00447 values.setSigma (0, 3, 0.);
00448 values.setSigma (1, 2, 0.);
00449 values.setSigma (1, 3, 0.);
00450 values.setSigma (2, 3, 0.);
00451 fObject->addValues(values);
00452 }
00453 else
00454 {
00455 CastorPedestalWidth values(id);
00456 values.setSigma (0, 0, atof (items [4].c_str()) );
00457 values.setSigma (0, 1, atof (items [5].c_str()) );
00458 values.setSigma (0, 2, atof (items [6].c_str()) );
00459 values.setSigma (0, 3, atof (items [7].c_str()) );
00460 values.setSigma (1, 0, atof (items [8].c_str()) );
00461 values.setSigma (1, 1, atof (items [9].c_str()) );
00462 values.setSigma (1, 2, atof (items [10].c_str()) );
00463 values.setSigma (1, 3, atof (items [11].c_str()) );
00464 values.setSigma (2, 0, atof (items [12].c_str()) );
00465 values.setSigma (2, 1, atof (items [13].c_str()) );
00466 values.setSigma (2, 2, atof (items [14].c_str()) );
00467 values.setSigma (2, 3, atof (items [15].c_str()) );
00468 values.setSigma (3, 0, atof (items [16].c_str()) );
00469 values.setSigma (3, 1, atof (items [17].c_str()) );
00470 values.setSigma (3, 2, atof (items [18].c_str()) );
00471 values.setSigma (3, 3, atof (items [19].c_str()) );
00472 fObject->addValues(values);
00473 }
00474
00475
00476 }
00477 return true;
00478 }
00479
00480 bool dumpObject (std::ostream& fOutput, const CastorPedestalWidths& fObject) {
00481 char buffer [1024];
00482 if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
00483 else sprintf (buffer, "#U fC << this is the unit \n");
00484 fOutput << buffer;
00485
00486 sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
00487 "eta", "phi", "dep", "det",
00488 "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",
00489 "DetId");
00490 fOutput << buffer;
00491 std::vector<DetId> channels = fObject.getAllChannels ();
00492 std::sort (channels.begin(), channels.end(), DetIdLess ());
00493 for (std::vector<DetId>::iterator channel = channels.begin ();
00494 channel != channels.end ();
00495 channel++) {
00496 const CastorPedestalWidth* item = fObject.getValues (*channel);
00497 if (item) {
00498 dumpId (fOutput, *channel);
00499 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",
00500 item->getSigma (0,0), item->getSigma (0,1), item->getSigma (0,2), item->getSigma (0,3),
00501 item->getSigma (1,0), item->getSigma (1,1), item->getSigma (1,2), item->getSigma (1,3),
00502 item->getSigma (2,0), item->getSigma (2,1), item->getSigma (2,2), item->getSigma (2,3),
00503 item->getSigma (3,0), item->getSigma (3,1), item->getSigma (3,2), item->getSigma (3,3), channel->rawId ());
00504 fOutput << buffer;
00505 }
00506 }
00507 return true;
00508 }
00509
00510
00511
00512 bool getObject (std::istream& fInput, CastorQIEData* fObject) {
00513 char buffer [1024];
00514 while (fInput.getline(buffer, 1024)) {
00515 if (buffer [0] == '#') continue;
00516 std::vector <std::string> items = splitString (std::string (buffer));
00517 if (items.size()<1) continue;
00518 if (items [0] == "SHAPE") {
00519 if (items.size () < 33) {
00520 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;
00521 continue;
00522 }
00523
00524
00525
00526
00527 }
00528 else {
00529 if (items.size () < 36) {
00530 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;
00531 continue;
00532 }
00533 DetId id = getId (items);
00534 fObject->sort ();
00535
00536
00537
00538
00539
00540 CastorQIECoder coder (id.rawId ());
00541 int index = 4;
00542 for (unsigned capid = 0; capid < 4; capid++) {
00543 for (unsigned range = 0; range < 4; range++) {
00544 coder.setOffset (capid, range, atof (items [index++].c_str ()));
00545 }
00546 }
00547 for (unsigned capid = 0; capid < 4; capid++) {
00548 for (unsigned range = 0; range < 4; range++) {
00549 coder.setSlope (capid, range, atof (items [index++].c_str ()));
00550 }
00551 }
00552 fObject->addCoder (coder);
00553
00554 }
00555 }
00556 fObject->sort ();
00557 return true;
00558 }
00559
00560 bool dumpObject (std::ostream& fOutput, const CastorQIEData& fObject) {
00561 char buffer [1024];
00562 fOutput << "# QIE basic shape: SHAPE 32 x low edge values for first 32 channels" << std::endl;
00563 sprintf (buffer, "SHAPE ");
00564 fOutput << buffer;
00565 for (unsigned bin = 0; bin < 32; bin++) {
00566 sprintf (buffer, " %8.5f", fObject.getShape ().lowEdge (bin));
00567 fOutput << buffer;
00568 }
00569 fOutput << std::endl;
00570
00571 fOutput << "# QIE data" << std::endl;
00572 sprintf (buffer, "# %15s %15s %15s %15s %36s %36s %36s %36s %36s %36s %36s %36s\n",
00573 "eta", "phi", "dep", "det",
00574 "4 x offsets cap0", "4 x offsets cap1", "4 x offsets cap2", "4 x offsets cap3",
00575 "4 x slopes cap0", "4 x slopes cap1", "4 x slopes cap2", "4 x slopes cap3");
00576 fOutput << buffer;
00577 std::vector<DetId> channels = fObject.getAllChannels ();
00578 std::sort (channels.begin(), channels.end(), DetIdLess ());
00579 for (std::vector<DetId>::iterator channel = channels.begin ();
00580 channel != channels.end ();
00581 channel++) {
00582 const CastorQIECoder* coder = fObject.getCoder (*channel);
00583 dumpId (fOutput, *channel);
00584 for (unsigned capid = 0; capid < 4; capid++) {
00585 for (unsigned range = 0; range < 4; range++) {
00586 sprintf (buffer, " %8.5f", coder->offset (capid, range));
00587 fOutput << buffer;
00588 }
00589 }
00590 for (unsigned capid = 0; capid < 4; capid++) {
00591 for (unsigned range = 0; range < 4; range++) {
00592 sprintf (buffer, " %8.5f", coder->slope (capid, range));
00593 fOutput << buffer;
00594 }
00595 }
00596 fOutput << std::endl;
00597 }
00598 return true;
00599 }
00600
00601
00602 bool getObject (std::istream& fInput, CastorCalibrationQIEData* fObject) {
00603 char buffer [1024];
00604 while (fInput.getline(buffer, 1024)) {
00605 if (buffer [0] == '#') continue;
00606 std::vector <std::string> items = splitString (std::string (buffer));
00607 if (items.size () < 36) {
00608 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 36 items: eta, phi, depth, subdet, 32 bin values" << std::endl;
00609 continue;
00610 }
00611 DetId id = getId (items);
00612 fObject->sort ();
00613
00614
00615
00616
00617
00618 CastorCalibrationQIECoder coder (id.rawId ());
00619 int index = 4;
00620 float values [32];
00621 for (unsigned bin = 0; bin < 32; bin++) {
00622 values[bin] = atof (items [index++].c_str ());
00623 }
00624 coder.setMinCharges (values);
00625 fObject->addCoder (coder);
00626
00627 }
00628 fObject->sort ();
00629 return true;
00630 }
00631
00632 bool dumpObject (std::ostream& fOutput, const CastorCalibrationQIEData& fObject) {
00633 char buffer [1024];
00634 fOutput << "# QIE data in calibration mode" << std::endl;
00635 sprintf (buffer, "# %15s %15s %15s %15s %288s\n",
00636 "eta", "phi", "dep", "det", "32 x charges");
00637 fOutput << buffer;
00638 std::vector<DetId> channels = fObject.getAllChannels ();
00639 std::sort (channels.begin(), channels.end(), DetIdLess ());
00640 for (std::vector<DetId>::iterator channel = channels.begin ();
00641 channel != channels.end ();
00642 channel++) {
00643 const CastorCalibrationQIECoder* coder = fObject.getCoder (*channel);
00644 if (coder) {
00645 dumpId (fOutput, *channel);
00646 const float* lowEdge = coder->minCharges ();
00647 for (unsigned bin = 0; bin < 32; bin++) {
00648 sprintf (buffer, " %8.5f", lowEdge [bin]);
00649 fOutput << buffer;
00650 }
00651 fOutput << std::endl;
00652 }
00653 }
00654 return true;
00655 }
00656
00657
00658
00659 bool getObject (std::istream& fInput, CastorElectronicsMap* fObject) {
00660 char buffer [1024];
00661 while (fInput.getline(buffer, 1024)) {
00662 if (buffer [0] == '#') continue;
00663 std::vector <std::string> items = splitString (std::string (buffer));
00664 if (items.size () < 12) {
00665 if (items.size()==0) continue;
00666 if (items.size()<9) {
00667 edm::LogError("MapFormat") << "CastorElectronicsMap-> line too short: " << buffer;
00668 continue;
00669 }
00670 if (items[8]=="NA" || items[8]=="NT") {
00671 while (items.size()<12) items.push_back("");
00672 } else if (items[8]=="HT") {
00673 if (items.size()==11) items.push_back("");
00674 else {
00675 edm::LogError("MapFormat") << "CastorElectronicsMap-> Bad line: " << buffer
00676 << "\n HT line must contain at least 11 items: i cr sl tb dcc spigot fiber fiberchan subdet=HT ieta iphi";
00677 continue;
00678 }
00679 } else {
00680 edm::LogError("MapFormat") << "CastorElectronicsMap-> Bad line: " << buffer
00681 << "\n line must contain 12 items: i cr sl tb dcc spigot fiber fiberchan subdet ieta iphi depth";
00682 continue;
00683 }
00684 }
00685
00686 int crate = atoi (items [1].c_str());
00687 int slot = atoi (items [2].c_str());
00688 int top = 1;
00689 if (items [3] == "b") top = 0;
00690 int dcc = atoi (items [4].c_str());
00691 int spigot = atoi (items [5].c_str());
00692 CastorElectronicsId elId;
00693 if (items[8] == "HT" || items[8] == "NT") {
00694 int slb = atoi (items [6].c_str());
00695 int slbCh = atoi (items [7].c_str());
00696 elId=CastorElectronicsId(slbCh, slb, spigot, dcc,crate,slot,top);
00697 } else {
00698 int fiber = atoi (items [6].c_str());
00699 int fiberCh = atoi (items [7].c_str());
00700
00701 elId=CastorElectronicsId(fiberCh, fiber, spigot, dcc);
00702 elId.setHTR (crate, slot, top);
00703 }
00704
00705
00706 if (items [8] == "NA") {
00707 fObject->mapEId2chId (elId, DetId (HcalDetId::Undefined));
00708 } else if (items [8] == "NT") {
00709 fObject->mapEId2tId (elId, DetId (HcalTrigTowerDetId::Undefined));
00710 } else {
00711 CastorText2DetIdConverter converter (items [8], items [9], items [10], items [11]);
00712 if (converter.isHcalCastorDetId ()) {
00713 fObject->mapEId2chId (elId, converter.getId ());
00714 }
00715 else {
00716 edm::LogWarning("Format Error") << "CastorElectronicsMap-> Unknown subdetector: "
00717 << items [8] << '/' << items [9] << '/' << items [10] << '/' << items [11] << std::endl;
00718 }
00719 }
00720 }
00721 fObject->sort ();
00722 return true;
00723 }
00724
00725 bool dumpObject (std::ostream& fOutput, const CastorElectronicsMap& fObject) {
00726 std::vector<CastorElectronicsId> eids = fObject.allElectronicsId ();
00727 char buf [1024];
00728
00729
00730 sprintf (buf, "# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
00731 "i", "cr", "sl", "tb", "dcc", "spigot", "fiber/slb", "fibcha/slbcha", "subdet", "ieta", "iphi", "depth");
00732 fOutput << buf << std::endl;
00733
00734 for (unsigned i = 0; i < eids.size (); i++) {
00735 CastorElectronicsId eid = eids[i];
00736 if (eid.isTriggerChainId()) {
00737 DetId trigger = fObject.lookupTrigger (eid);
00738 if (trigger.rawId ()) {
00739 CastorText2DetIdConverter converter (trigger);
00740
00741
00742 sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
00743
00744 converter.getId().rawId(),
00745
00746
00747 eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.slbSiteNumber(), eid.slbChannelIndex(),
00748 converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
00749 );
00750 fOutput << buf << std::endl;
00751 }
00752 } else {
00753 DetId channel = fObject.lookup (eid);
00754 if (channel.rawId()) {
00755 CastorText2DetIdConverter converter (channel);
00756
00757
00758 sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
00759
00760 converter.getId().rawId(),
00761 eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
00762 converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
00763 );
00764 fOutput << buf << std::endl;
00765 }
00766 }
00767 }
00768 return true;
00769 }
00770
00771 bool getObject (std::istream& fInput, CastorRecoParams* fObject) {
00772 if (!fObject) fObject = new CastorRecoParams();
00773 char buffer [1024];
00774 while (fInput.getline(buffer, 1024)) {
00775 if (buffer [0] == '#') continue;
00776 std::vector <std::string> items = splitString (std::string (buffer));
00777 if (items.size()==0) continue;
00778 if (items.size () < 6) {
00779 edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, firstSample, samplesToAdd" << std::endl;
00780 continue;
00781 }
00782 DetId id = getId (items);
00783
00784 CastorRecoParam* fCondObject = new CastorRecoParam(id, atoi (items [4].c_str()), atoi (items [5].c_str()) );
00785 fObject->addValues(*fCondObject);
00786 delete fCondObject;
00787 }
00788 return true;
00789 }
00790
00791 bool dumpObject (std::ostream& fOutput, const CastorRecoParams& fObject) {
00792 char buffer [1024];
00793 sprintf (buffer, "# %15s %15s %15s %15s %18s %15s %10s\n", "eta", "phi", "dep", "det", "firstSample", "samplesToAdd", "DetId");
00794 fOutput << buffer;
00795 std::vector<DetId> channels = fObject.getAllChannels ();
00796 std::sort (channels.begin(), channels.end(), DetIdLess ());
00797 for (std::vector<DetId>::iterator channel = channels.begin();channel != channels.end();channel++) {
00798 dumpId (fOutput, *channel);
00799 sprintf (buffer, " %15d %15d %16X\n",
00800 fObject.getValues (*channel)->firstSample(), fObject.getValues (*channel)->samplesToAdd(), channel->rawId ());
00801 fOutput << buffer;
00802 }
00803 return true;
00804 }
00805
00806 }