12 #include "dictionaries.h"
15 #include "ConfigParameters.hh"
24 ConfigParameters::ConfigParameters() {
30 ConfigParameters::ConfigParameters(
string filename) {
32 readConfigParameterFile(filename);
37 void ConfigParameters::initialize() {
38 fReadTbParameters = fReadTbmParameters = fReadDacParameters = fReadRocPixelConfig = fReadReadbackCal =
false;
45 fI2cAddresses.clear();
50 fKeithleyRemote =
false;
55 fEmptyReadoutLength = 54;
56 fEmptyReadoutLengthADC = 64;
57 fEmptyReadoutLengthADCDual = 40;
60 fDACParametersFileName =
"defaultDACParameters";
61 fTbmParametersFileName =
"defaultTBMParameters";
62 fTBParametersFileName =
"defaultTBParameters.dat";
63 fTrimParametersFileName =
"defaultTrimParameters";
64 fTestParametersFileName =
"defaultTestParameters.dat";
65 fMaskFileName =
"defaultMaskFile.dat";
66 fLogFileName =
"log.txt";
67 fDebugFileName =
"debug.log";
68 fRootFileName =
"expert.root";
69 fGainPedestalParameterFileName =
"phCalibrationFitTanH";
70 fGainPedestalFileName =
"phCalibration";
71 fReadbackCalFileName =
"readbackCal";
83 rocZeroAnalogCurrent = 0.0;
84 fRocType =
"psi46digv21respin";
99 void ConfigParameters::readAllConfigParameterFiles() {
101 readRocPixelConfig();
109 void ConfigParameters::writeAllFiles() {
110 writeConfigParameterFile();
111 writeTbParameterFile();
126 bool ConfigParameters::readConfigParameterFile(
string file) {
127 ifstream _input(file.c_str());
128 if (!_input.is_open())
130 LOG(logINFO) <<
"Can not open file '" << file <<
"' to read Config Parameters.";
136 for (
string _line; _input.good();)
138 getline(_input, _line);
143 ||
'-' == _line[0])
continue;
145 istringstream _istring(_line);
149 _istring >> _name >> _value;
152 if (_istring.fail() || !_name.length())
continue;
154 int _ivalue = atoi(_value.c_str());
155 double dvalue = atof(_value.c_str());
157 if (0 == _name.compare(
"testboardName")) { fTBName = _value; }
158 else if (0 == _name.compare(
"directory")) { fDirectory = _value; }
160 else if (0 == _name.compare(
"tbParameters")) { setTBParameterFileName(_value); }
161 else if (0 == _name.compare(
"tbmParameters")) { setTbmParameterFileName(_value); }
162 else if (0 == _name.compare(
"testParameters")) { setTestParameterFileName(_value); }
163 else if (0 == _name.compare(
"dacParameters")) { setDACParameterFileName(_value); }
164 else if (0 == _name.compare(
"rootFileName")) { setRootFileName(_value); }
165 else if (0 == _name.compare(
"trimParameters")) { setTrimParameterFileName(_value); }
166 else if (0 == _name.compare(
"maskFile")) { setMaskFileName(_value); }
168 else if (0 == _name.compare(
"nModules")) { fnModules = _ivalue; }
169 else if (0 == _name.compare(
"nRocs")) { readNrocs(_istring.str()); }
170 else if (0 == _name.compare(
"nTbms")) { fnTbms = _ivalue; }
171 else if (0 == _name.compare(
"hubId")) { fHubId = _ivalue; }
172 else if (0 == _name.compare(
"halfModule")) { fHalfModule = _ivalue; }
173 else if (0 == _name.compare(
"emptyReadoutLength")) { fEmptyReadoutLength = _ivalue; }
174 else if (0 == _name.compare(
"emptyReadoutLengthADC")) { fEmptyReadoutLengthADC = _ivalue; }
175 else if (0 == _name.compare(
"emptyReadoutLengthADCDual")) { fEmptyReadoutLengthADCDual = _ivalue; }
176 else if (0 == _name.compare(
"hvOn")) { fHvOn = (_ivalue>0); }
177 else if (0 == _name.compare(
"keithleyRemote")) { fKeithleyRemote = (_ivalue>0); }
178 else if (0 == _name.compare(
"tbmEnable")) { fTbmEnable = (_ivalue>0); }
179 else if (0 == _name.compare(
"tbmEmulator")) { fTbmEmulator = (_ivalue>0); }
180 else if (0 == _name.compare(
"tbmChannel")) { fTbmChannel = _ivalue; }
182 else if (0 == _name.compare(
"ia")) { ia =
static_cast<float>((dvalue > 1000.?.001:1.) * dvalue); }
183 else if (0 == _name.compare(
"id")) {
id =
static_cast<float>((dvalue > 1000.?.001:1.) * dvalue); }
184 else if (0 == _name.compare(
"va")) { va =
static_cast<float>((dvalue > 1000.?.001:1.) * dvalue); }
185 else if (0 == _name.compare(
"vd")) { vd =
static_cast<float>((dvalue > 1000.?.001:1.) * dvalue); }
187 else if (0 == _name.compare(
"rocZeroAnalogCurrent")) { rocZeroAnalogCurrent =
static_cast<float>(.001 *
static_cast<float>(_ivalue)); }
189 else if (0 == _name.compare(
"rocType")) { fRocType = _value; }
190 else if (0 == _name.compare(
"tbmType")) { fTbmType = _value; }
191 else if (0 == _name.compare(
"hdiType")) { fHdiType = _value; }
193 else if (0 == _name.compare(
"probeA1")) { fProbeA1 = _value; }
194 else if (0 == _name.compare(
"probeA2")) { fProbeA2 = _value; }
195 else if (0 == _name.compare(
"probeD1")) { fProbeD1 = _value; }
196 else if (0 == _name.compare(
"probeD2")) { fProbeD2 = _value; }
199 else { LOG(logINFO) <<
"Did not understand '" << _name <<
"'."; }
204 fTbPowerSettings.push_back(make_pair(
"ia", ia));
205 fTbPowerSettings.push_back(make_pair(
"id",
id));
206 fTbPowerSettings.push_back(make_pair(
"va", va));
207 fTbPowerSettings.push_back(make_pair(
"vd", vd));
214 vector<pair<string, uint8_t> > ConfigParameters::readDacFile(
string fname) {
215 vector<pair<string, uint8_t> > rocDacs;
218 vector<string> lines;
220 LOG(logINFO) <<
" reading " << fname;
221 ifstream is(fname.c_str());
222 while (is.getline(buffer, 200,
'\n')) {
223 lines.push_back(
string(buffer));
228 unsigned int ival(0);
232 string::size_type s1, s2;
233 string str1, str2, str3;
234 for (
unsigned int i = 0; i < lines.size(); ++i) {
237 cleanupString(lines[i]);
238 if (lines[i].length() < 2)
continue;
239 s1 = lines[i].find(
" ");
240 s2 = lines[i].rfind(
" ");
243 str1 = lines[i].substr(0, s1);
244 str2 = lines[i].substr(s1+1, s2-s1-1);
245 str3 = lines[i].substr(s2+1);
248 str2 = lines[i].substr(0, s1);
249 str3 = lines[i].substr(s1+1);
252 if (string::npos != str3.find(
"0x")) {
253 sscanf(str3.c_str(),
"%x", &ival);
255 ival = atoi(str3.c_str());
258 rocDacs.push_back(make_pair(str2, uval));
266 vector<pair<string, uint8_t> > ConfigParameters::getTbParameters() {
267 if (!fReadTbParameters) {
270 return fTbParameters;
275 void ConfigParameters::readTbParameters() {
276 if (!fReadTbParameters) {
277 string filename = fDirectory +
"/" + fTBParametersFileName;
278 fTbParameters = readDacFile(filename);
280 for (
unsigned int i = 0; i < fTbParameters.size(); ++i) {
282 LOG(logINFO) <<
" " << fTbParameters[i].first <<
": " << (int)fTbParameters[i].second;
284 fReadTbParameters =
true;
289 vector<pair<string, double> > ConfigParameters::getTbPowerSettings() {
290 vector<pair<string, double> > v;
292 LOG(logINFO) <<
"Read config files first!" << endl;
295 return fTbPowerSettings;
299 vector<pair<string, uint8_t> > ConfigParameters::getTbSigDelays() {
300 vector<pair<string, uint8_t> > a;
303 vector<string> sigdelays = dict->getAllDTBNames();
305 if (!fReadTbParameters) readTbParameters();
306 for (
unsigned int i = 0; i < fTbParameters.size(); ++i) {
307 for (
unsigned int j = 0; j < sigdelays.size(); ++j) {
308 if (0 == fTbParameters[i].first.compare(sigdelays[j])) a.push_back(make_pair(sigdelays[j], fTbParameters[i].second));
316 vector<pair<std::string, uint8_t> > ConfigParameters::getTbPgSettings() {
318 vector<pair<std::string, uint8_t> > a;
321 vector<vector<pair<string, uint8_t> > > dacs = getRocDacs();
322 for (
unsigned int idac = 0; idac < dacs[0].size(); ++idac) {
323 if (!dacs[0][idac].first.compare(
"wbc")) {
324 wbc = dacs[0][idac].second;
329 a.push_back(make_pair(
"resetroc",25));
330 a.push_back(make_pair(
"calibrate",wbc+6));
331 a.push_back(make_pair(
"trigger",16));
332 a.push_back(make_pair(
"token",0));
334 a.push_back(std::make_pair(
"resetroc",15));
335 a.push_back(std::make_pair(
"calibrate",wbc+6));
336 a.push_back(std::make_pair(
"trigger;sync",0));
344 vector<vector<pxar::pixelConfig> > ConfigParameters::getRocPixelConfig() {
345 if (!fReadRocPixelConfig) {
346 readRocPixelConfig();
348 return fRocPixelConfigs;
352 vector<pxar::pixelConfig> ConfigParameters::getRocPixelConfig(
int i) {
353 if (!fReadRocPixelConfig) {
354 readRocPixelConfig();
356 return fRocPixelConfigs[i];
362 void ConfigParameters::readRocPixelConfig() {
365 filename = fDirectory +
"/" + fMaskFileName;
366 vector<bool> rocmasked;
367 for (
unsigned int i = 0; i < fnRocs; ++i) rocmasked.push_back(
false);
369 vector<vector<pair<int, int> > > vmask = readMaskFile(filename);
370 for (
unsigned int i = 0; i < vmask.size(); ++i) {
371 vector<pair<int, int> > v = vmask[i];
374 for (
unsigned int j = 0; j < v.size(); ++j) {
375 LOG(logINFO) <<
"MASKED Roc " << i <<
" col/row: " << v[j].first <<
" " << v[j].second;
381 for (
unsigned int i = 0; i < fnRocs; ++i) {
382 vector<pxar::pixelConfig> v;
383 for (uint8_t ic = 0; ic < fnCol; ++ic) {
384 for (uint8_t ir = 0; ir < fnRow; ++ir) {
387 vector<pair<int, int> > v = vmask[i];
388 for (
unsigned int j = 0; j < v.size(); ++j) {
389 if (v[j].first == ic && v[j].second == ir) {
390 LOG(logINFO) <<
" masking Roc " << i <<
" col/row: " << v[j].first <<
" " << v[j].second;
398 std::stringstream fname;
399 fname << fDirectory <<
"/" << fTrimParametersFileName << fTrimVcalSuffix <<
"_C" << i <<
".dat";
400 readTrimFile(fname.str(), v);
401 fRocPixelConfigs.push_back(v);
404 fReadRocPixelConfig =
true;
409 void ConfigParameters::readTrimFile(
string fname, vector<pxar::pixelConfig> &v) {
412 vector<string> lines;
414 LOG(logINFO) <<
" reading " << fname;
415 ifstream is(fname.c_str());
416 while (is.getline(buffer, 200,
'\n')) {
417 lines.push_back(
string(buffer));
422 unsigned int ival(0), irow(0), icol(0);
425 string::size_type s1, s2;
426 string str1, str2, str3;
427 for (
unsigned int i = 0; i < lines.size(); ++i) {
429 replaceAll(lines[i],
"\t",
" ");
430 replaceAll(lines[i],
"Pix",
" ");
431 string::iterator new_end = unique(lines[i].begin(), lines[i].end(), bothAreSpaces);
432 lines[i].erase(new_end, lines[i].end());
433 if (0 == lines[i].length())
continue;
434 if (lines[i].substr(0, 1) ==
string(
" ")) lines[i].erase(0, 1);
435 if (lines[i].substr(lines[i].length()-1, 1) ==
string(
" ")) lines[i].erase(lines[i].length()-1, 1);
436 s1 = lines[i].find(
" ");
437 s2 = lines[i].rfind(
" ");
439 str1 = lines[i].substr(0, s1);
440 str2 = lines[i].substr(s1+1, s2-s1);
441 str3 = lines[i].substr(s2+1);
443 LOG(logINFO) <<
"could not read line -->" << lines[i] <<
"<--";
446 ival = atoi(str1.c_str());
447 icol = atoi(str2.c_str());
448 irow = atoi(str3.c_str());
450 unsigned int index = icol*80+irow;
451 if (index <= v.size()) {
452 v[index].setTrim(uval);
454 LOG(logINFO) <<
" not matching entry in trim vector found for row/col = " << irow <<
"/" << icol;
463 vector<vector<pair<int, int> > > ConfigParameters::readMaskFile(
string fname) {
465 vector<vector<pair<int, int> > > v;
466 vector<pair<int, int> > a;
467 for (
unsigned int i = 0; i < fnRocs; ++i) {
472 vector<string> lines;
474 LOG(logINFO) <<
" reading " << fname;
475 ifstream is(fname.c_str());
476 while (is.getline(buffer, 200,
'\n')) {
477 lines.push_back(
string(buffer));
482 unsigned int iroc(0), irow(0), icol(0);
484 string::size_type s1, s2, s3;
485 string str1, str2, str3;
486 for (
unsigned int i = 0; i < lines.size(); ++i) {
488 if (lines[i].substr(0, 1) == string(
"#"))
continue;
490 cleanupString(lines[i]);
491 if (0 == lines[i].length())
continue;
493 s1 = lines[i].find(
"roc");
494 if (string::npos != s1) {
495 str3 = lines[i].substr(s1+4);
496 iroc = atoi(str3.c_str());
499 for (uint8_t ic = 0; ic < fnCol; ++ic) {
500 for (uint8_t ir = 0; ir < fnRow; ++ir) {
501 v[iroc].push_back(make_pair(ic, ir));
505 LOG(logINFO) <<
"illegal ROC coordinates in line " << i <<
": " << lines[i];
510 s1 = lines[i].find(
"row");
511 if (string::npos != s1) {
513 s2 = lines[i].find(
" ", s1) + 1;
514 iroc = atoi(lines[i].substr(s1, s2-s1-1).c_str());
515 irow = atoi(lines[i].substr(s2).c_str());
517 if (iroc < fnRocs && irow < fnRow) {
518 for (
unsigned int ic = 0; ic < fnCol; ++ic) {
519 v[iroc].push_back(make_pair(ic, irow));
522 LOG(logINFO) <<
"illegal ROC/row coordinates in line " << i <<
": " << lines[i];
527 s1 = lines[i].find(
"col");
528 if (string::npos != s1) {
530 s2 = lines[i].find(
" ", s1) + 1;
531 iroc = atoi(lines[i].substr(s1, s2-s1-1).c_str());
532 icol = atoi(lines[i].substr(s2).c_str());
534 if (iroc < fnRocs && icol < fnCol) {
535 for (
unsigned int ir = 0; ir < fnRow; ++ir) {
536 v[iroc].push_back(make_pair(icol, ir));
539 LOG(logINFO) <<
"illegal ROC/col coordinates in line " << i <<
": " << lines[i];
544 s1 = lines[i].find(
"pix");
545 if (string::npos != s1) {
547 s2 = lines[i].find(
" ", s1) + 1;
548 s3 = lines[i].find(
" ", s2) + 1;
549 iroc = atoi(lines[i].substr(s1, s2-s1-1).c_str());
550 icol = atoi(lines[i].substr(s2, s3-s2-1).c_str());
551 irow = atoi(lines[i].substr(s3).c_str());
553 if (iroc < fnRocs && icol < fnCol && irow < fnRow) {
554 v[iroc].push_back(make_pair(icol, irow));
556 LOG(logINFO) <<
"illegal ROC/row/col coordinates in line " << i <<
": " << lines[i];
567 bool ConfigParameters::writeMaskFile(vector<vector<pair<int, int> > > v,
string name) {
568 std::stringstream fname;
569 if (!name.compare(
"")) {
570 fname << fDirectory <<
"/" << fMaskFileName;
572 if (string::npos == name.find(
"/")) {
573 fname << fDirectory <<
"/" << name;
580 OutputFile.open((fname.str()).c_str());
581 if (!OutputFile.is_open()) {
582 LOG(logERROR) <<
"failed to open " << fname.str().c_str() <<
" as mask file";
585 LOG(logDEBUG) <<
"write masked pixels into " << fname.str();
588 OutputFile <<
"# mask file generated by maskHotPixels" << endl;
590 for (
unsigned int iroc = 0; iroc < v.size(); ++iroc) {
591 vector<pair<int, int> > a = v[iroc];
592 for (
unsigned int ipix = 0; ipix < a.size(); ++ipix) {
593 OutputFile <<
"pix " << iroc <<
" "
594 << a[ipix].first <<
" " << a[ipix].second
607 vector<vector<pair<string, uint8_t> > > ConfigParameters::getRocDacs() {
608 if (!fReadDacParameters) {
611 return fDacParameters;
616 vector<string> ConfigParameters::getDacs() {
617 if (!fReadDacParameters) {
620 vector<string> names;
621 vector<std::pair<std::string, uint8_t> > dacs = fDacParameters[0];
622 for (
unsigned int i = 0; i < dacs.size(); ++i) {
623 names.push_back(dacs[i].first);
630 void ConfigParameters::readRocDacs() {
631 if (!fReadDacParameters) {
632 for (
unsigned int i = 0; i < fnRocs; ++i) {
633 stringstream filename;
634 filename << fDirectory <<
"/" << fDACParametersFileName << fTrimVcalSuffix <<
"_C" << i <<
".dat";
635 vector<pair<string, uint8_t> > rocDacs = readDacFile(filename.str());
636 fDacParameters.push_back(rocDacs);
638 fReadDacParameters =
true;
644 vector<vector<pair<string, uint8_t> > > ConfigParameters::getTbmDacs() {
645 if (!fReadTbmParameters) {
648 return fTbmParameters;
652 void ConfigParameters::readTbmDacs() {
653 if (!fReadTbmParameters) {
655 for (
unsigned int i = 0; i < fnTbms; ++i) {
656 for (
unsigned int ic = 0; ic < 2; ++ic) {
657 stringstream filename;
658 filename << fDirectory <<
"/" << fTbmParametersFileName <<
"_C" << i << (ic==0?
"a":
"b") <<
".dat";
659 vector<pair<string, uint8_t> > rocDacs = readDacFile(filename.str());
660 fTbmParameters.push_back(rocDacs);
663 fReadTbmParameters =
true;
669 bool ConfigParameters::setTbParameter(std::string var, uint8_t val,
bool appendIfNotFound) {
670 for (
unsigned int i = 0; i < fTbParameters.size(); ++i) {
671 if (!fTbParameters[i].first.compare(var)) {
672 fTbParameters[i].second = val;
676 if (appendIfNotFound) {
677 fTbParameters.push_back(make_pair(var, val));
685 bool ConfigParameters::setTbmDac(std::string var, uint8_t val,
int itbm) {
687 for (
unsigned int i = 0; i < fTbmParameters.size(); ++i) {
688 if (itbm < 0 || itbm == static_cast<int>(i)) {
689 for (
unsigned int idac = 0; idac < fTbmParameters[i].size(); ++idac) {
690 if (!fTbmParameters[i][idac].first.compare(var)) {
691 fTbmParameters[i][idac].second = val;
706 bool ConfigParameters::setRocDac(std::string var, uint8_t val,
int iroc) {
708 for (
unsigned int i = 0; i < fDacParameters.size(); ++i) {
709 if (iroc < 0 || iroc == static_cast<int>(i)) {
710 for (
unsigned int idac = 0; idac < fDacParameters[i].size(); ++idac) {
711 if (!fDacParameters[i][idac].first.compare(var)) {
712 fDacParameters[i][idac].second = val;
727 bool ConfigParameters::setTbPowerSettings(std::string var,
double val) {
729 for (
unsigned int i = 0; i < fTbPowerSettings.size(); ++i) {
730 if (!fTbPowerSettings[i].first.compare(var)) {
731 fTbPowerSettings[i].second = val;
741 bool ConfigParameters::setTrimBits(
int trim) {
742 for (
unsigned int iroc = 0; iroc < fRocPixelConfigs.size(); ++iroc) {
743 for (
unsigned int ipix = 0; ipix < fRocPixelConfigs[iroc].size(); ++ipix) {
744 fRocPixelConfigs[iroc][ipix].setTrim(trim);
752 bool ConfigParameters::writeConfigParameterFile() {
754 sprintf(filename,
"%s/configParameters.dat", fDirectory.c_str());
755 FILE * file = fopen(filename,
"w");
758 LOG(logINFO) <<
"Can not open file '" << filename <<
"' to write configParameters.";
762 LOG(logINFO) <<
"Writing Config-Parameters to '" << filename <<
"'.";
764 fprintf(file,
"testboardName %s\n\n", fTBName.c_str());
766 fprintf(file,
"-- parameter files\n\n");
768 fprintf(file,
"tbParameters %s\n", fTBParametersFileName.c_str());
769 fprintf(file,
"dacParameters %s\n", fDACParametersFileName.c_str());
770 fprintf(file,
"tbmParameters %s\n", fTbmParametersFileName.c_str());
771 fprintf(file,
"trimParameters %s\n", fTrimParametersFileName.c_str());
772 fprintf(file,
"maskFile %s\n", fMaskFileName.c_str());
773 fprintf(file,
"testParameters %s\n", fTestParametersFileName.c_str());
774 fprintf(file,
"rootFileName %s\n\n", fRootFileName.c_str());
776 fprintf(file,
"-- configuration\n\n");
778 fprintf(file,
"nModules %i\n", fnModules);
779 fprintf(file,
"nRocs %i\n", fnRocs);
780 fprintf(file,
"nTbms %i\n", fnTbms);
781 fprintf(file,
"hubId %i\n", fHubId);
782 fprintf(file,
"tbmEnable %i\n", fTbmEnable);
783 fprintf(file,
"tbmEmulator %i\n", fTbmEmulator);
784 fprintf(file,
"hvOn %i\n", fHvOn);
785 fprintf(file,
"tbmChannel %i\n", fTbmChannel);
786 fprintf(file,
"rocType %s\n", fRocType.c_str());
787 if (fnTbms > 0) fprintf(file,
"tbmType %s\n", fTbmType.c_str());
788 fprintf(file,
"hdiType %s\n", fHdiType.c_str());
791 fprintf(file,
"-- voltages and current limits\n\n");
793 fprintf(file,
"ia %i\n" , static_cast<int>(ia * 1000));
794 fprintf(file,
"id %i\n" , static_cast<int>(
id * 1000));
795 fprintf(file,
"va %i\n" , static_cast<int>(va * 1000));
796 fprintf(file,
"vd %i\n\n", static_cast<int>(vd * 1000));
798 fprintf(file,
"probeA1 %s\n", fProbeA1.c_str());
799 fprintf(file,
"probeA2 %s\n", fProbeA2.c_str());
800 fprintf(file,
"probeD1 %s\n", fProbeD1.c_str());
801 fprintf(file,
"probeD2 %s\n", fProbeD2.c_str());
809 bool ConfigParameters::writeTrimFile(
int iroc, vector<pixelConfig> v) {
810 std::stringstream fname;
811 fname << fDirectory <<
"/" << fTrimParametersFileName << fTrimVcalSuffix <<
"_C" << iroc <<
".dat";
814 OutputFile.open((fname.str()).c_str());
815 if (!OutputFile.is_open()) {
818 LOG(logDEBUG) <<
"write trim parameters into " << fname.str();
821 for (std::vector<pixelConfig>::iterator ipix = v.begin(); ipix != v.end(); ++ipix) {
822 OutputFile << setw(2) << static_cast<int>(ipix->trim())
823 <<
" Pix " << setw(2)
824 <<
static_cast<int>(ipix->column()) <<
" " << setw(2) <<
static_cast<int>(ipix->row())
834 bool ConfigParameters::writeDacParameterFile(
int iroc, vector<pair<string, uint8_t> > v) {
836 std::stringstream fname;
837 fname << fDirectory <<
"/" << getDACParameterFileName() << fTrimVcalSuffix <<
"_C" << iroc <<
".dat";
840 OutputFile.open((fname.str()).c_str());
841 if (!OutputFile.is_open()) {
844 LOG(logDEBUG) <<
"write dac parameters into " << fname.str();
848 for (std::vector<std::pair<std::string,uint8_t> >::iterator idac = v.begin(); idac != v.end(); ++idac) {
850 OutputFile << right << setw(3) << static_cast<int>(a->getRegister(idac->first, ROC_REG)) <<
" " << left
851 << setw(10) << idac->first <<
" " << setw(3) <<
static_cast<int>(idac->second)
861 bool ConfigParameters::writeTbmParameterFile(
int itbm, vector<pair<string, uint8_t> > vA, vector<pair<string, uint8_t> > vB) {
863 vector<pair<string, uint8_t> > v;
864 for (
unsigned int ic = 0; ic < 2; ++ic) {
866 fname << fDirectory <<
"/" << fTbmParametersFileName <<
"_C" << itbm << (ic==0?
"a":
"b") <<
".dat";
869 OutputFile.open((fname.str()).c_str());
870 if (!OutputFile.is_open()) {
873 LOG(logDEBUG) <<
"write tbm parameters into " << (fname.str()).c_str();
883 for (std::vector<std::pair<std::string, uint8_t> >::iterator idac = v.begin(); idac != v.end(); ++idac) {
884 OutputFile << right << setw(3) << setfill('0') << static_cast<int>(a->getRegister(idac->first, TBM_REG)) <<
" "
886 <<
" 0x" << setw(2) << setfill(
'0') << hex << static_cast<int>(idac->second)
897 bool ConfigParameters::writeTbParameterFile() {
898 string fname = fDirectory +
"/" + getTBParameterFileName();
902 OutputFile.open(fname.c_str());
903 if (!OutputFile.is_open()) {
906 LOG(logDEBUG) <<
"write dtb parameters into " << fname.c_str();
910 for (
unsigned int idac = 0; idac < fTbParameters.size(); ++idac) {
911 data = fTbParameters[idac].first;
912 std::transform(data.begin(), data.end(), data.begin(), ::tolower);
913 OutputFile << right << setw(3) << static_cast<int>(a->getRegister(fTbParameters[idac].first, DTB_REG)) <<
" "
914 << setw(15) << fTbParameters[idac].first <<
" " << std::setw(3) <<
static_cast<int>(fTbParameters[idac].second)
924 bool ConfigParameters::writeTestParameterFile(
string whichTest) {
925 string bla =
"no implementation for dumping test parameters " + whichTest;
932 void ConfigParameters::readGainPedestalParameters() {
934 string bname = getGainPedestalParameterFileName();
936 fGainPedestalParameters.clear();
939 vector<string> lines;
942 vector<gainPedestalParameters> rocPar;
943 for (
unsigned int iroc = 0; iroc < fnRocs; ++iroc) {
946 std::stringstream fname;
947 fname.str(std::string());
948 fname << fDirectory <<
"/" << bname << fTrimVcalSuffix <<
"_C" << iroc <<
".dat";
949 LOG(logINFO) <<
" reading " << (fname.str());
950 is.open((fname.str()).c_str());
952 LOG(logERROR) <<
"cannot open " << (fname.str()) <<
" for reading PH calibration constants";
956 while (is.getline(buffer, 200,
'\n')) {
957 lines.push_back(
string(buffer));
962 double p0, p1, p2, p3;
966 for (
unsigned int i = 3; i < lines.size(); ++i) {
967 istringstream istring(lines[i]);
968 istring >> p0 >> p1 >> p2 >> p3 >> pix >> icol >> irow;
972 fGainPedestalParameters.push_back(rocPar);
977 void ConfigParameters::writeGainPedestalParameters() {
981 for (
unsigned int iroc = 0; iroc < fGainPedestalParameters.size(); ++iroc) {
982 fname.str(std::string());
983 fname << fDirectory <<
"/" << getGainPedestalParameterFileName() << fTrimVcalSuffix <<
"_C" << iroc <<
".dat";
985 OutputFile.open((fname.str()).c_str());
986 if (!OutputFile.is_open()) {
987 LOG(logERROR) <<
"Could not open " << fname.str();
990 LOG(logDEBUG) <<
"write gain/ped parameters into " << fname.str();
993 OutputFile <<
"Parameters of the vcal vs. pulse height fits" << endl;
994 OutputFile <<
"par[3] + par[2] * TMath::TanH(par[0]*x[0] - par[1])" << endl << endl;
996 vector<gainPedestalParameters> pars = fGainPedestalParameters[iroc];
997 for (
unsigned ipix = 0; ipix < pars.size(); ++ipix) {
998 OutputFile << scientific
999 << pars[ipix].p0 <<
" "
1000 << pars[ipix].p1 <<
" "
1001 << pars[ipix].p2 <<
" "
1003 OutputFile.unsetf(ios::fixed | ios::scientific);
1004 OutputFile <<
" Pix "
1005 << setw(2) << ipix/80 <<
" " << setw(2) << ipix%80
1014 void ConfigParameters::setGainPedestalParameters(vector<vector<gainPedestalParameters> >v) {
1015 fGainPedestalParameters.clear();
1016 for (
unsigned int i = 0; i < v.size(); ++i) {
1017 fGainPedestalParameters.push_back(v[i]);
1022 std::vector<std::vector<gainPedestalParameters> > ConfigParameters::getGainPedestalParameters() {
1023 if (fGainPedestalParameters.size() == 0) {
1024 readGainPedestalParameters();
1026 return fGainPedestalParameters;
1030 void ConfigParameters::setProbe(std::string probe, std::string value) {
1032 std::transform(probe.begin(), probe.end(), probe.begin(), ::tolower);
1034 if (probe ==
"a1") fProbeA1 = value;
1035 else if (probe ==
"a2") fProbeA2 = value;
1036 else if (probe ==
"d1") fProbeD1 = value;
1037 else if (probe ==
"d2") fProbeD2 = value;
1041 std::string ConfigParameters::getProbe(std::string probe) {
1042 std::transform(probe.begin(), probe.end(), probe.begin(), ::tolower);
1043 if (probe ==
"a1")
return fProbeA1;
1044 else if (probe ==
"a2")
return fProbeA2;
1045 else if (probe ==
"d1")
return fProbeD1;
1046 else if (probe ==
"d2")
return fProbeD2;
1052 void ConfigParameters::cleanupString(
string &s) {
1053 replaceAll(s,
"\t",
" ");
1054 string::size_type s1 = s.find(
"#");
1055 if (string::npos != s1) s.erase(s1);
1056 if (0 == s.length())
return;
1057 string::iterator new_end = unique(s.begin(), s.end(), bothAreSpaces);
1058 s.erase(new_end, s.end());
1059 if (s.substr(0, 1) == string(
" ")) s.erase(0, 1);
1060 if (s.substr(s.length()-1, 1) ==
string(
" ")) s.erase(s.length()-1, 1);
1064 bool ConfigParameters::bothAreSpaces(
char lhs,
char rhs) {
1065 return (lhs == rhs) && (lhs ==
' ');
1069 void ConfigParameters::replaceAll(
string& str,
const string& from,
const string& to) {
1070 if (from.empty())
return;
1071 size_t start_pos = 0;
1072 while((start_pos = str.find(from, start_pos)) != string::npos) {
1073 str.replace(start_pos, from.length(), to);
1074 start_pos += to.length();
1079 void ConfigParameters::readNrocs(
string line) {
1080 cleanupString(line);
1081 string::size_type s0 = line.find(
" ");
1082 string nrocs = line.substr(s0);
1083 fnRocs = atoi(nrocs.c_str());
1084 string::size_type s1 = line.find(
"i2c:");
1085 if (string::npos == s1) {
1088 string i2cstring = line.substr(s1+5);
1089 s0 = i2cstring.find(
",");
1090 string i2c(
""), leftover(
"");
1091 while (string::npos != s0) {
1092 i2c = i2cstring.substr(0, s0);
1093 fI2cAddresses.push_back(atoi(i2c.c_str()));
1094 i2cstring = i2cstring.substr(s0+1);
1095 s0 = i2cstring.find(
",");
1098 fI2cAddresses.push_back(atoi(i2cstring.c_str()));
1099 if (fnRocs != fI2cAddresses.size()) {
1100 LOG(logWARNING) <<
"mismatch between number of i2c addresses and nRocs! Resetting nRocs to "
1101 << fI2cAddresses.size();
1102 fnRocs = fI2cAddresses.size();
1108 void ConfigParameters::readReadbackCal() {
1109 if (!fReadReadbackCal) {
1110 for (
unsigned int i = 0; i < fnRocs; ++i) {
1111 stringstream filename;
1112 filename << fDirectory <<
"/" << fReadbackCalFileName <<
"_C" << i <<
".dat";
1113 vector<pair<string, double> > rbCal = readReadbackFile(filename.str());
1114 fReadbackCal.push_back(rbCal);
1116 fReadReadbackCal =
true;
1121 vector<pair<string, double> > ConfigParameters::readReadbackFile(
string fname) {
1122 vector<pair<string, double> > rocRb;
1125 vector<string> lines;
1127 LOG(logINFO) <<
" reading " << fname;
1128 ifstream is(fname.c_str());
1129 while (is.getline(buffer, 200,
'\n')) {
1130 lines.push_back(
string(buffer));
1139 string::size_type s1;
1141 for (
unsigned int i = 0; i < lines.size(); ++i) {
1144 cleanupString(lines[i]);
1145 if (lines[i].length() < 2)
continue;
1146 s1 = lines[i].find(
" ");
1147 str1 = lines[i].substr(0, s1);
1148 str2 = lines[i].substr(s1+1);
1150 std::transform(str1.begin(), str1.end(), str1.begin(), ::tolower);
1151 ival = atof(str2.c_str());
1154 rocRb.push_back(make_pair(str1, uval));
1162 vector<vector<pair<string, double> > > ConfigParameters::getReadbackCal() {
1163 if (!fReadReadbackCal) {
1166 return fReadbackCal;
1170 bool ConfigParameters::writeReadbackFile(
int iroc, vector<pair<string, double> > v) {
1172 std::stringstream fname;
1173 fname << fDirectory <<
"/" << fReadbackCalFileName <<
"_C" << iroc <<
".dat";
1175 ofstream OutputFile;
1176 OutputFile.open((fname.str()).c_str());
1177 if (!OutputFile.is_open()) {
1180 LOG(logDEBUG) <<
"write readback calibration parameters into " << fname.str();
1184 for (std::vector<std::pair<std::string,double> >::iterator idac = v.begin(); idac != v.end(); ++idac) {
1185 OutputFile << left << setw(3) << idac->first <<
" " << setw(3) <<
static_cast<double>(idac->second)
1195 void ConfigParameters::setTrimVcalSuffix(
string name,
bool nocheck) {
1198 fTrimVcalSuffix = name;
1202 std::stringstream fname;
1204 fname << fDirectory <<
"/" << fTrimParametersFileName << name <<
"_C0.dat";
1206 InputFile.open((fname.str()).c_str());
1209 if (!InputFile.is_open()) {
1210 LOG(logERROR) <<
"Did not find file " << fname.str() <<
", no trim VCAL value used";
1211 fTrimVcalSuffix =
"";
1213 fTrimVcalSuffix = name;