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;
69 DetId getId (
const std::vector <std::string> & items) {
71 return converter.getId ();
77 sprintf (buffer,
" %15s %15s %15s %15s",
78 converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str (),converter.getFlavor ().c_str ());
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 5 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 5 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 ());
237 while (fInput.getline(buffer, 1024)) {
238 std::vector <std::string> items =
splitString (std::string (buffer));
239 if (items.size()==0)
continue;
241 if (items[0] ==
"#U")
243 if (items[1] == (std::string)
"ADC") fObject->
setUnitADC(
true);
244 else if (items[1] == (std::string)
"fC") fObject->
setUnitADC(
false);
247 edm::LogWarning(
"Pedestal Unit Error") <<
"Unrecognized unit for pedestals. Assuming fC." << std::endl;
254 edm::LogWarning(
"Pedestal Unit Missing") <<
"The unit for the pedestals is missing in the txt file." << std::endl;
259 while (fInput.getline(buffer, 1024)) {
260 if (buffer [0] ==
'#')
continue;
261 std::vector <std::string> items =
splitString (std::string (buffer));
262 if (items.size()==0)
continue;
263 if (items.size () < 8) {
264 edm::LogWarning(
"Format Error") <<
"Bad line: " << buffer <<
"\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
265 <<
" or 12 items: eta, phi, depth, subdet, 4x values for mean, 4x values for width"
276 if (items.size() < 12)
279 atof (items [6].c_str()), atof (items [7].c_str()),
287 atof (items [6].c_str()), atof (items [7].c_str()),
288 atof (items [8].c_str()), atof (items [9].c_str()),
289 atof (items [10].c_str()), atof (items [11].c_str()) );
302 if (fObject.
isADC() ) sprintf (buffer,
"#U ADC << this is the unit \n");
303 else sprintf (buffer,
"#U fC << this is the unit \n");
306 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");
310 std::sort (channels.begin(), channels.end(), DetIdLess ());
311 for (std::vector<DetId>::iterator channel = channels.begin ();
312 channel != channels.end ();
316 dumpId (fOutput, *channel);
317 sprintf (buffer,
" %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
318 values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], channel->rawId ());
331 while (fInput.getline(buffer, 1024)) {
332 if (buffer [0] ==
'#')
continue;
333 std::vector <std::string> items =
splitString (std::string (buffer));
334 if (items.size()==0)
continue;
335 if (items.size () < 5) {
336 edm::LogWarning(
"Format Error") <<
"Bad line: " << buffer <<
"\n line must contain 5 items: eta, phi, depth, subdet, GOOD/BAD/HOT/DEAD" << std::endl;
341 if (fObject->
exists(
id) ) {
342 edm::LogWarning(
"Redefining Channel") <<
"line: " << buffer <<
"\n attempts to redefine data. Ignored" << std::endl;
349 if (items[4].substr(0,2)==
"0x") {
350 sscanf(items[4].c_str(),
"%X", &mystatus);
353 else if (isalpha(items[4].c_str()[0])) {
357 sscanf(items[4].c_str(),
"%u", &mystatus);
370 sprintf (buffer,
"# %15s %15s %15s %15s %15s %10s\n",
"eta",
"phi",
"dep",
"det",
"value",
"DetId");
373 std::sort (channels.begin(), channels.end(), DetIdLess ());
374 for (std::vector<DetId>::iterator channel = channels.begin ();
375 channel != channels.end ();
378 dumpId (fOutput, *channel);
379 sprintf (buffer,
" %15X %10X\n",
380 value, channel->rawId ());
393 while (fInput.getline(buffer, 1024)) {
395 std::vector <std::string> items =
splitString (std::string (buffer));
396 if (items.size()==0)
continue;
398 if (items[0] == (std::string)
"#U")
400 if (items[1] == (std::string)
"ADC") fObject->
setUnitADC(
true);
401 else if (items[1] == (std::string)
"fC") fObject->
setUnitADC(
false);
404 edm::LogWarning(
"Pedestal Width Unit Error") <<
"Unrecognized unit for pedestal widths. Assuming fC." << std::endl;
411 edm::LogWarning(
"Pedestal Width Unit Missing") <<
"The unit for the pedestal widths is missing in the txt file." << std::endl;
417 while (fInput.getline(buffer, 1024)) {
419 if (buffer [0] ==
'#')
continue;
420 std::vector <std::string> items =
splitString (std::string (buffer));
421 if (items.size()==0)
continue;
422 if (items.size () < 14) {
423 edm::LogWarning(
"Format Error") <<
"Bad line: " << buffer <<
"\n line number: " << linecounter <<
"\n line must contain 14 items: eta, phi, depth, subdet, 10x correlations"
424 <<
" or 20 items: eta, phi, depth, subdet, 16x correlations"
435 if (items.size() < 20)
438 values.setSigma (0, 0, atof (items [4].c_str()));
439 values.setSigma (1, 0, atof (items [5].c_str()));
440 values.setSigma (1, 1, atof (items [6].c_str()));
441 values.setSigma (2, 0, atof (items [7].c_str()));
442 values.setSigma (2, 1, atof (items [8].c_str()));
443 values.setSigma (2, 2, atof (items [9].c_str()));
444 values.setSigma (3, 0, atof (items [10].c_str()));
445 values.setSigma (3, 1, atof (items [11].c_str()));
446 values.setSigma (3, 2, atof (items [12].c_str()));
447 values.setSigma (3, 3, atof (items [13].c_str()));
448 values.setSigma (0, 1, 0.);
449 values.setSigma (0, 2, 0.);
450 values.setSigma (0, 3, 0.);
451 values.setSigma (1, 2, 0.);
452 values.setSigma (1, 3, 0.);
453 values.setSigma (2, 3, 0.);
459 values.setSigma (0, 0, atof (items [4].c_str()) );
460 values.setSigma (0, 1, atof (items [5].c_str()) );
461 values.setSigma (0, 2, atof (items [6].c_str()) );
462 values.setSigma (0, 3, atof (items [7].c_str()) );
463 values.setSigma (1, 0, atof (items [8].c_str()) );
464 values.setSigma (1, 1, atof (items [9].c_str()) );
465 values.setSigma (1, 2, atof (items [10].c_str()) );
466 values.setSigma (1, 3, atof (items [11].c_str()) );
467 values.setSigma (2, 0, atof (items [12].c_str()) );
468 values.setSigma (2, 1, atof (items [13].c_str()) );
469 values.setSigma (2, 2, atof (items [14].c_str()) );
470 values.setSigma (2, 3, atof (items [15].c_str()) );
471 values.setSigma (3, 0, atof (items [16].c_str()) );
472 values.setSigma (3, 1, atof (items [17].c_str()) );
473 values.setSigma (3, 2, atof (items [18].c_str()) );
474 values.setSigma (3, 3, atof (items [19].c_str()) );
485 if (fObject.
isADC() ) sprintf (buffer,
"#U ADC << this is the unit \n");
486 else sprintf (buffer,
"#U fC << this is the unit \n");
489 sprintf (buffer,
"# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
490 "eta",
"phi",
"dep",
"det",
491 "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",
495 std::sort (channels.begin(), channels.end(), DetIdLess ());
496 for (std::vector<DetId>::iterator channel = channels.begin ();
497 channel != channels.end ();
501 dumpId (fOutput, *channel);
502 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",
517 while (fInput.getline(buffer, 1024)) {
518 if (buffer [0] ==
'#')
continue;
519 std::vector <std::string> items =
splitString (std::string (buffer));
520 if (items.size()<1)
continue;
521 if (items [0] ==
"SHAPE") {
522 if (items.size () < 33) {
523 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;
532 if (items.size () < 36) {
533 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;
545 for (
unsigned capid = 0; capid < 4; capid++) {
546 for (
unsigned range = 0; range < 4; range++) {
547 coder.setOffset (capid, range, atof (items [index++].c_str ()));
550 for (
unsigned capid = 0; capid < 4; capid++) {
551 for (
unsigned range = 0; range < 4; range++) {
552 coder.setSlope (capid, range, atof (items [index++].c_str ()));
565 fOutput <<
"# QIE basic shape: SHAPE 32 x low edge values for first 32 channels" << std::endl;
566 sprintf (buffer,
"SHAPE ");
568 for (
unsigned bin = 0;
bin < 32;
bin++) {
572 fOutput << std::endl;
574 fOutput <<
"# QIE data" << std::endl;
575 sprintf (buffer,
"# %15s %15s %15s %15s %36s %36s %36s %36s %36s %36s %36s %36s\n",
576 "eta",
"phi",
"dep",
"det",
577 "4 x offsets cap0",
"4 x offsets cap1",
"4 x offsets cap2",
"4 x offsets cap3",
578 "4 x slopes cap0",
"4 x slopes cap1",
"4 x slopes cap2",
"4 x slopes cap3");
581 std::sort (channels.begin(), channels.end(), DetIdLess ());
582 for (std::vector<DetId>::iterator channel = channels.begin ();
583 channel != channels.end ();
586 dumpId (fOutput, *channel);
587 for (
unsigned capid = 0; capid < 4; capid++) {
588 for (
unsigned range = 0; range < 4; range++) {
589 sprintf (buffer,
" %8.5f", coder->
offset (capid, range));
593 for (
unsigned capid = 0; capid < 4; capid++) {
594 for (
unsigned range = 0; range < 4; range++) {
595 sprintf (buffer,
" %8.5f", coder->
slope (capid, range));
599 fOutput << std::endl;
607 while (fInput.getline(buffer, 1024)) {
608 if (buffer [0] ==
'#')
continue;
609 std::vector <std::string> items =
splitString (std::string (buffer));
610 if (items.size () < 36) {
611 edm::LogWarning(
"Format Error") <<
"Bad line: " << buffer <<
"\n line must contain 36 items: eta, phi, depth, subdet, 32 bin values" << std::endl;
624 for (
unsigned bin = 0;
bin < 32;
bin++) {
625 values[
bin] = atof (items [index++].c_str ());
627 coder.setMinCharges (values);
637 fOutput <<
"# QIE data in calibration mode" << std::endl;
638 sprintf (buffer,
"# %15s %15s %15s %15s %288s\n",
639 "eta",
"phi",
"dep",
"det",
"32 x charges");
642 std::sort (channels.begin(), channels.end(), DetIdLess ());
643 for (std::vector<DetId>::iterator channel = channels.begin ();
644 channel != channels.end ();
648 dumpId (fOutput, *channel);
650 for (
unsigned bin = 0;
bin < 32;
bin++) {
651 sprintf (buffer,
" %8.5f", lowEdge [
bin]);
654 fOutput << std::endl;
664 while (fInput.getline(buffer, 1024)) {
665 if (buffer [0] ==
'#')
continue;
666 std::vector <std::string> items =
splitString (std::string (buffer));
667 if (items.size () < 12) {
668 if (items.size()==0)
continue;
669 if (items.size()<9) {
670 edm::LogError(
"MapFormat") <<
"CastorElectronicsMap-> line too short: " << buffer;
673 if (items[8]==
"NA" || items[8]==
"NT") {
674 while (items.size()<12) items.push_back(
"");
675 }
else if (items[8]==
"HT") {
676 if (items.size()==11) items.push_back(
"");
678 edm::LogError(
"MapFormat") <<
"CastorElectronicsMap-> Bad line: " << buffer
679 <<
"\n HT line must contain at least 11 items: i cr sl tb dcc spigot fiber fiberchan subdet=HT ieta iphi";
683 edm::LogError(
"MapFormat") <<
"CastorElectronicsMap-> Bad line: " << buffer
684 <<
"\n line must contain 12 items: i cr sl tb dcc spigot fiber fiberchan subdet ieta iphi depth";
689 int crate = atoi (items [1].c_str());
690 int slot = atoi (items [2].c_str());
692 if (items [3] ==
"b") top = 0;
693 int dcc = atoi (items [4].c_str());
694 int spigot = atoi (items [5].c_str());
696 if (items[8] ==
"HT" || items[8] ==
"NT") {
697 int slb = atoi (items [6].c_str());
698 int slbCh = atoi (items [7].c_str());
701 int fiber = atoi (items [6].c_str());
702 int fiberCh = atoi (items [7].c_str());
705 elId.
setHTR (crate, slot, top);
709 if (items [8] ==
"NA") {
711 }
else if (items [8] ==
"NT") {
715 if (converter.isHcalCastorDetId ()) {
719 edm::LogWarning(
"Format Error") <<
"CastorElectronicsMap-> Unknown subdetector: "
720 << items [8] <<
'/' << items [9] <<
'/' << items [10] <<
'/' << items [11] << std::endl;
733 sprintf (buf,
"# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
734 "i",
"cr",
"sl",
"tb",
"dcc",
"spigot",
"fiber/slb",
"fibcha/slbcha",
"subdet",
"ieta",
"iphi",
"depth");
735 fOutput << buf << std::endl;
737 for (
unsigned i = 0;
i < eids.size ();
i++) {
741 if (trigger.
rawId ()) {
745 sprintf (buf,
" %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
747 converter.getId().rawId(),
751 converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
753 fOutput << buf << std::endl;
757 if (channel.
rawId()) {
761 sprintf (buf,
" %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
763 converter.getId().rawId(),
765 converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
767 fOutput << buf << std::endl;
777 while (fInput.getline(buffer, 1024)) {
778 if (buffer [0] ==
'#')
continue;
779 std::vector <std::string> items =
splitString (std::string (buffer));
780 if (items.size()==0)
continue;
781 if (items.size () < 6) {
782 edm::LogWarning(
"Format Error") <<
"Bad line: " << buffer <<
"\n line must contain 6 items: eta, phi, depth, subdet, firstSample, samplesToAdd" << std::endl;
796 sprintf (buffer,
"# %15s %15s %15s %15s %18s %15s %10s\n",
"eta",
"phi",
"dep",
"det",
"firstSample",
"samplesToAdd",
"DetId");
799 std::sort (channels.begin(), channels.end(), DetIdLess ());
800 for (std::vector<DetId>::iterator channel = channels.begin();channel != channels.end();channel++) {
801 dumpId (fOutput, *channel);
802 sprintf (buffer,
" %15d %15d %16X\n",
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
unsigned int samplesToAdd() const
IO for ASCII instances of Castor/HCAL Calibrations.
bool getObject(std::istream &fInput, CastorPedestals *fObject)
bool dumpCastorSingleFloatObject(std::ostream &fOutput, const T &fObject)
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
unsigned int firstSample() const
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)
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
float slope(unsigned fCapId, unsigned fRange) const
int slbChannelIndex() const
bool addCoder(const CastorQIECoder &fCoder)