49 std::vector <std::string>
splitString (
const std::string& fLine) {
50 std::vector <std::string>
result;
53 for (
unsigned i = 0;
i <= fLine.size ();
i++) {
54 if (fLine [
i] ==
' ' ||
i == fLine.size ()) {
56 std::string item (fLine, start,
i-start);
57 result.push_back (item);
63 if (empty) empty =
false;
71 return converter.
getId ();
77 sprintf (buffer,
" %15s %15s %15s %15s",
82 template <
class T,
class S>
84 if (!fObject) fObject =
new T;
86 while (fInput.getline(buffer, 1024)) {
87 if (buffer [0] ==
'#')
continue;
88 std::vector <std::string> items =
splitString (std::string (buffer));
89 if (items.size()==0)
continue;
90 if (items.size () < 8) {
91 edm::LogWarning(
"Format Error") <<
"Bad line: " << buffer <<
"\n line must contain 8 items: eta, phi, depth, subdet, 4x values" << std::endl;
100 fCondObject =
new S(
id, atof (items [4].c_str()), atof (items [5].c_str()),
101 atof (items [6].c_str()), atof (items [7].c_str()));
102 fObject->addValues(*fCondObject);
113 sprintf (buffer,
"# %15s %15s %15s %15s %8s %8s %8s %8s %10s\n",
"eta",
"phi",
"dep",
"det",
"cap0",
"cap1",
"cap2",
"cap3",
"DetId");
115 std::vector<DetId> channels = fObject.getAllChannels ();
117 for (std::vector<DetId>::iterator channel = channels.begin ();
118 channel != channels.end ();
120 const float*
values = fObject.getValues (*channel)->getValues ();
122 dumpId (fOutput, *channel);
123 sprintf (buffer,
" %8.5f %8.5f %8.5f %8.5f %10X\n",
124 values[0], values[1], values[2], values[3], channel->rawId ());
131 template <
class T,
class S>
133 if (!fObject) fObject =
new T;
135 while (fInput.getline(buffer, 1024)) {
136 if (buffer [0] ==
'#')
continue;
137 std::vector <std::string> items =
splitString (std::string (buffer));
138 if (items.size()==0)
continue;
139 if (items.size () < 5) {
140 edm::LogWarning(
"Format Error") <<
"Bad line: " << buffer <<
"\n line must contain 8 items: eta, phi, depth, subdet, value" << std::endl;
149 fCondObject =
new S(
id, atof (items [4].c_str()) );
150 fObject->addValues(*fCondObject);
160 sprintf (buffer,
"# %15s %15s %15s %15s %8s %10s\n",
"eta",
"phi",
"dep",
"det",
"value",
"DetId");
162 std::vector<DetId> channels = fObject.getAllChannels ();
164 for (std::vector<DetId>::iterator channel = channels.begin ();
165 channel != channels.end ();
167 const float value = fObject.getValues (*channel)->getValue ();
168 dumpId (fOutput, *channel);
169 sprintf (buffer,
" %8.5f %10X\n",
170 value, channel->rawId ());
176 template <
class T,
class S>
178 if (!fObject) fObject =
new T;
180 while (fInput.getline(buffer, 1024)) {
181 if (buffer [0] ==
'#')
continue;
182 std::vector <std::string> items =
splitString (std::string (buffer));
183 if (items.size()==0)
continue;
184 if (items.size () < 5) {
185 edm::LogWarning(
"Format Error") <<
"Bad line: " << buffer <<
"\n line must contain 8 items: eta, phi, depth, subdet, value" << std::endl;
194 fCondObject =
new S(
id, atoi (items [4].c_str()) );
195 fObject->addValues(*fCondObject);
205 sprintf (buffer,
"# %15s %15s %15s %15s %8s %10s\n",
"eta",
"phi",
"dep",
"det",
"value",
"DetId");
207 std::vector<DetId> channels = fObject.getAllChannels ();
209 for (std::vector<DetId>::iterator channel = channels.begin ();
210 channel != channels.end ();
212 const int value = fObject.getValues (*channel)->getValue ();
213 dumpId (fOutput, *channel);
214 sprintf (buffer,
" %15d %10X\n",
215 value, channel->rawId ());
234 while (fInput.getline(buffer, 1024)) {
235 std::vector <std::string> items =
splitString (std::string (buffer));
236 if (items.size()==0)
continue;
238 if (items[0] ==
"#U")
240 if (items[1] == (std::string)
"ADC") fObject->
setUnitADC(
true);
241 else if (items[1] == (std::string)
"fC") fObject->
setUnitADC(
false);
244 edm::LogWarning(
"Pedestal Unit Error") <<
"Unrecognized unit for pedestals. Assuming fC." << std::endl;
251 edm::LogWarning(
"Pedestal Unit Missing") <<
"The unit for the pedestals is missing in the txt file." << std::endl;
256 while (fInput.getline(buffer, 1024)) {
257 if (buffer [0] ==
'#')
continue;
258 std::vector <std::string> items =
splitString (std::string (buffer));
259 if (items.size()==0)
continue;
260 if (items.size () < 8) {
261 edm::LogWarning(
"Format Error") <<
"Bad line: " << buffer <<
"\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
262 <<
" or 12 items: eta, phi, depth, subdet, 4x values for mean, 4x values for width"
273 if (items.size() < 12)
276 atof (items [6].c_str()), atof (items [7].c_str()),
284 atof (items [6].c_str()), atof (items [7].c_str()),
285 atof (items [8].c_str()), atof (items [9].c_str()),
286 atof (items [10].c_str()), atof (items [11].c_str()) );
299 if (fObject.
isADC() ) sprintf (buffer,
"#U ADC << this is the unit \n");
300 else sprintf (buffer,
"#U fC << this is the unit \n");
303 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");
307 std::sort (channels.begin(), channels.end(), DetIdLess ());
308 for (std::vector<DetId>::iterator channel = channels.begin ();
309 channel != channels.end ();
313 dumpId (fOutput, *channel);
314 sprintf (buffer,
" %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
315 values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], channel->rawId ());
328 while (fInput.getline(buffer, 1024)) {
329 if (buffer [0] ==
'#')
continue;
330 std::vector <std::string> items =
splitString (std::string (buffer));
331 if (items.size()==0)
continue;
332 if (items.size () < 5) {
333 edm::LogWarning(
"Format Error") <<
"Bad line: " << buffer <<
"\n line must contain 5 items: eta, phi, depth, subdet, GOOD/BAD/HOT/DEAD" << std::endl;
338 if (fObject->
exists(
id) ) {
339 edm::LogWarning(
"Redefining Channel") <<
"line: " << buffer <<
"\n attempts to redefine data. Ignored" << std::endl;
346 if (items[4].substr(0,2)==
"0x") {
347 sscanf(items[4].c_str(),
"%X", &mystatus);
350 else if (isalpha(items[4].c_str()[0])) {
354 sscanf(items[4].c_str(),
"%u", &mystatus);
367 sprintf (buffer,
"# %15s %15s %15s %15s %15s %10s\n",
"eta",
"phi",
"dep",
"det",
"value",
"DetId");
370 std::sort (channels.begin(), channels.end(), DetIdLess ());
371 for (std::vector<DetId>::iterator channel = channels.begin ();
372 channel != channels.end ();
375 dumpId (fOutput, *channel);
376 sprintf (buffer,
" %15X %10X\n",
377 value, channel->rawId ());
390 while (fInput.getline(buffer, 1024)) {
392 std::vector <std::string> items =
splitString (std::string (buffer));
393 if (items.size()==0)
continue;
395 if (items[0] == (std::string)
"#U")
397 if (items[1] == (std::string)
"ADC") fObject->
setUnitADC(
true);
398 else if (items[1] == (std::string)
"fC") fObject->
setUnitADC(
false);
401 edm::LogWarning(
"Pedestal Width Unit Error") <<
"Unrecognized unit for pedestal widths. Assuming fC." << std::endl;
408 edm::LogWarning(
"Pedestal Width Unit Missing") <<
"The unit for the pedestal widths is missing in the txt file." << std::endl;
414 while (fInput.getline(buffer, 1024)) {
416 if (buffer [0] ==
'#')
continue;
417 std::vector <std::string> items =
splitString (std::string (buffer));
418 if (items.size()==0)
continue;
419 if (items.size () < 14) {
420 edm::LogWarning(
"Format Error") <<
"Bad line: " << buffer <<
"\n line number: " << linecounter <<
"\n line must contain 14 items: eta, phi, depth, subdet, 10x correlations"
421 <<
" or 20 items: eta, phi, depth, subdet, 16x correlations"
432 if (items.size() < 20)
435 values.setSigma (0, 0, atof (items [4].c_str()));
436 values.setSigma (1, 0, atof (items [5].c_str()));
437 values.setSigma (1, 1, atof (items [6].c_str()));
438 values.setSigma (2, 0, atof (items [7].c_str()));
439 values.setSigma (2, 1, atof (items [8].c_str()));
440 values.setSigma (2, 2, atof (items [9].c_str()));
441 values.setSigma (3, 0, atof (items [10].c_str()));
442 values.setSigma (3, 1, atof (items [11].c_str()));
443 values.setSigma (3, 2, atof (items [12].c_str()));
444 values.setSigma (3, 3, atof (items [13].c_str()));
445 values.setSigma (0, 1, 0.);
446 values.setSigma (0, 2, 0.);
447 values.setSigma (0, 3, 0.);
448 values.setSigma (1, 2, 0.);
449 values.setSigma (1, 3, 0.);
450 values.setSigma (2, 3, 0.);
456 values.setSigma (0, 0, atof (items [4].c_str()) );
457 values.setSigma (0, 1, atof (items [5].c_str()) );
458 values.setSigma (0, 2, atof (items [6].c_str()) );
459 values.setSigma (0, 3, atof (items [7].c_str()) );
460 values.setSigma (1, 0, atof (items [8].c_str()) );
461 values.setSigma (1, 1, atof (items [9].c_str()) );
462 values.setSigma (1, 2, atof (items [10].c_str()) );
463 values.setSigma (1, 3, atof (items [11].c_str()) );
464 values.setSigma (2, 0, atof (items [12].c_str()) );
465 values.setSigma (2, 1, atof (items [13].c_str()) );
466 values.setSigma (2, 2, atof (items [14].c_str()) );
467 values.setSigma (2, 3, atof (items [15].c_str()) );
468 values.setSigma (3, 0, atof (items [16].c_str()) );
469 values.setSigma (3, 1, atof (items [17].c_str()) );
470 values.setSigma (3, 2, atof (items [18].c_str()) );
471 values.setSigma (3, 3, atof (items [19].c_str()) );
482 if (fObject.
isADC() ) sprintf (buffer,
"#U ADC << this is the unit \n");
483 else sprintf (buffer,
"#U fC << this is the unit \n");
486 sprintf (buffer,
"# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
487 "eta",
"phi",
"dep",
"det",
488 "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",
492 std::sort (channels.begin(), channels.end(), DetIdLess ());
493 for (std::vector<DetId>::iterator channel = channels.begin ();
494 channel != channels.end ();
498 dumpId (fOutput, *channel);
499 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",
514 while (fInput.getline(buffer, 1024)) {
515 if (buffer [0] ==
'#')
continue;
516 std::vector <std::string> items =
splitString (std::string (buffer));
517 if (items.size()<1)
continue;
518 if (items [0] ==
"SHAPE") {
519 if (items.size () < 33) {
520 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;
525 while (--i >= 0) lowEdges [
i] = atof (items [i+1].c_str ());
529 if (items.size () < 36) {
530 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;
542 for (
unsigned capid = 0; capid < 4; capid++) {
543 for (
unsigned range = 0; range < 4; range++) {
544 coder.setOffset (capid, range, atof (items [index++].c_str ()));
547 for (
unsigned capid = 0; capid < 4; capid++) {
548 for (
unsigned range = 0; range < 4; range++) {
549 coder.setSlope (capid, range, atof (items [index++].c_str ()));
562 fOutput <<
"# QIE basic shape: SHAPE 32 x low edge values for first 32 channels" << std::endl;
563 sprintf (buffer,
"SHAPE ");
565 for (
unsigned bin = 0;
bin < 32;
bin++) {
569 fOutput << std::endl;
571 fOutput <<
"# QIE data" << std::endl;
572 sprintf (buffer,
"# %15s %15s %15s %15s %36s %36s %36s %36s %36s %36s %36s %36s\n",
573 "eta",
"phi",
"dep",
"det",
574 "4 x offsets cap0",
"4 x offsets cap1",
"4 x offsets cap2",
"4 x offsets cap3",
575 "4 x slopes cap0",
"4 x slopes cap1",
"4 x slopes cap2",
"4 x slopes cap3");
578 std::sort (channels.begin(), channels.end(), DetIdLess ());
579 for (std::vector<DetId>::iterator channel = channels.begin ();
580 channel != channels.end ();
583 dumpId (fOutput, *channel);
584 for (
unsigned capid = 0; capid < 4; capid++) {
585 for (
unsigned range = 0; range < 4; range++) {
586 sprintf (buffer,
" %8.5f", coder->
offset (capid, range));
590 for (
unsigned capid = 0; capid < 4; capid++) {
591 for (
unsigned range = 0; range < 4; range++) {
592 sprintf (buffer,
" %8.5f", coder->
slope (capid, range));
596 fOutput << std::endl;
604 while (fInput.getline(buffer, 1024)) {
605 if (buffer [0] ==
'#')
continue;
606 std::vector <std::string> items =
splitString (std::string (buffer));
607 if (items.size () < 36) {
608 edm::LogWarning(
"Format Error") <<
"Bad line: " << buffer <<
"\n line must contain 36 items: eta, phi, depth, subdet, 32 bin values" << std::endl;
621 for (
unsigned bin = 0;
bin < 32;
bin++) {
622 values[
bin] = atof (items [index++].c_str ());
624 coder.setMinCharges (values);
634 fOutput <<
"# QIE data in calibration mode" << std::endl;
635 sprintf (buffer,
"# %15s %15s %15s %15s %288s\n",
636 "eta",
"phi",
"dep",
"det",
"32 x charges");
639 std::sort (channels.begin(), channels.end(), DetIdLess ());
640 for (std::vector<DetId>::iterator channel = channels.begin ();
641 channel != channels.end ();
645 dumpId (fOutput, *channel);
647 for (
unsigned bin = 0;
bin < 32;
bin++) {
648 sprintf (buffer,
" %8.5f", lowEdge [
bin]);
651 fOutput << std::endl;
661 while (fInput.getline(buffer, 1024)) {
662 if (buffer [0] ==
'#')
continue;
663 std::vector <std::string> items =
splitString (std::string (buffer));
664 if (items.size () < 12) {
665 if (items.size()==0)
continue;
666 if (items.size()<9) {
667 edm::LogError(
"MapFormat") <<
"CastorElectronicsMap-> line too short: " << buffer;
670 if (items[8]==
"NA" || items[8]==
"NT") {
671 while (items.size()<12) items.push_back(
"");
672 }
else if (items[8]==
"HT") {
673 if (items.size()==11) items.push_back(
"");
675 edm::LogError(
"MapFormat") <<
"CastorElectronicsMap-> Bad line: " << buffer
676 <<
"\n HT line must contain at least 11 items: i cr sl tb dcc spigot fiber fiberchan subdet=HT ieta iphi";
680 edm::LogError(
"MapFormat") <<
"CastorElectronicsMap-> Bad line: " << buffer
681 <<
"\n line must contain 12 items: i cr sl tb dcc spigot fiber fiberchan subdet ieta iphi depth";
686 int crate = atoi (items [1].c_str());
687 int slot = atoi (items [2].c_str());
689 if (items [3] ==
"b") top = 0;
690 int dcc = atoi (items [4].c_str());
691 int spigot = atoi (items [5].c_str());
693 if (items[8] ==
"HT" || items[8] ==
"NT") {
694 int slb = atoi (items [6].c_str());
695 int slbCh = atoi (items [7].c_str());
698 int fiber = atoi (items [6].c_str());
699 int fiberCh = atoi (items [7].c_str());
702 elId.
setHTR (crate, slot, top);
706 if (items [8] ==
"NA") {
708 }
else if (items [8] ==
"NT") {
712 if (converter.isHcalCastorDetId ()) {
716 edm::LogWarning(
"Format Error") <<
"CastorElectronicsMap-> Unknown subdetector: "
717 << items [8] <<
'/' << items [9] <<
'/' << items [10] <<
'/' << items [11] << std::endl;
730 sprintf (buf,
"# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
731 "i",
"cr",
"sl",
"tb",
"dcc",
"spigot",
"fiber/slb",
"fibcha/slbcha",
"subdet",
"ieta",
"iphi",
"depth");
732 fOutput << buf << std::endl;
734 for (
unsigned i = 0; i < eids.size (); i++) {
738 if (trigger.
rawId ()) {
742 sprintf (buf,
" %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
744 converter.getId().rawId(),
748 converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
750 fOutput << buf << std::endl;
754 if (channel.
rawId()) {
758 sprintf (buf,
" %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
760 converter.getId().rawId(),
762 converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
764 fOutput << buf << std::endl;
const std::string & getField2() const
static const HcalDetId Undefined
bool getCastorSingleIntObject(std::istream &fInput, T *fObject, S *fCondObject)
const DetId lookupTrigger(CastorElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
bool operator()(CastorElectronicsId first, CastorElectronicsId second) const
void setUnitADC(bool isADC)
std::vector< std::string > splitString(const std::string &fLine)
int readoutVMECrateId() const
int zside() const
get the z-side of the cell (1/-1)
const CastorQIEShape & getShape() const
get basic shape
void setHTR(int crate, int slot, int tb)
bool getCastorSingleFloatObject(std::istream &fInput, T *fObject, S *fCondObject)
bool addCoder(const CastorCalibrationQIECoder &fCoder)
std::vector< DetId > getAllChannels() const
const CastorCalibrationQIECoder * getCoder(DetId fId) const
get QIE parameters
const float * minCharges() const
int slbSiteNumber() const
void dumpId(std::ostream &fOutput, DetId id)
bool dumpCastorSingleIntObject(std::ostream &fOutput, const T &fObject)
bool mapEId2tId(CastorElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
uint32_t rawId() const
get the raw id
U second(std::pair< T, U > const &p)
const bool exists(DetId fId) const
const DetId lookup(CastorElectronicsId fId) const
lookup the logical detid associated with the given electronics id
int depth() const
get the tower depth
uint32_t getValue() const
bool getCastorObject(std::istream &fInput, T *fObject, S *fCondObject)
float getSigma(int fCapId1, int fCapId2) const
get correlation element for capId1/2 = 0..3
IO for ASCII instances of Castor/HCAL Calibrations.
bool getObject(std::istream &fInput, CastorPedestals *fObject)
bool dumpCastorSingleFloatObject(std::ostream &fOutput, const T &fObject)
const std::string & getField1() const
bool isTriggerChainId() const
const Item * getValues(DetId fId) const
void setUnitADC(bool isADC)
DetId getId(const std::vector< std::string > &items)
int ietaAbs() const
get the absolute value of the cell ieta
int iphi() const
get the cell iphi
const CastorQIECoder * getCoder(DetId fId) const
get QIE parameters
bool dumpObject(std::ostream &fOutput, const CastorPedestals &fObject)
bool operator()(DetId fFirst, DetId fSecond) const
static const HcalTrigTowerDetId Undefined
std::vector< CastorElectronicsId > allElectronicsId() const
float offset(unsigned fCapId, unsigned fRange) const
bool addValues(const Item &myItem)
const std::string & getField3() const
float lowEdge(unsigned fAdc) const
bool mapEId2chId(CastorElectronicsId fElectronicsId, DetId fId)
Readout chain identification for Castor Bits for the readout chain : some names need change! [31:26] ...
bool dumpCastorObject(std::ostream &fOutput, const T &fObject)
const float * getValues() const
get value for all capId = 0..3
HcalGenericSubdetector genericSubdet() const
const std::string & getFlavor() const
float slope(unsigned fCapId, unsigned fRange) const
int slbChannelIndex() const
bool addCoder(const CastorQIECoder &fCoder)