54 return a.GetValue() < b.GetValue();
96 return HptdcId * 8 + channel;
112 LOGF(debug,
"Loading the placement map...");
115 if (pLoadedPlacement == 0) {
120 vector<UniValue*> tdcmap_array;
121 pLoadedPlacement->
GetValue(tdcmap_array);
124 for (
size_t i = 0;
i < tdcmap_array.size();
i++) {
132 LOGF(debug,
"\t\tLoaded %d TDCs", (
int)tdcmap_array.size());
135 if (!tdcmap_array.empty())
136 for (
size_t i = 0;
i < tdcmap_array.size();
i++)
137 delete tdcmap_array[
i];
138 delete pLoadedPlacement;
151 LOGF(debug,
"Loading strip map...");
154 if (pLoadedStr == 0) {
159 vector<UniValue*> stripmap_array;
160 pLoadedStr->
GetValue(stripmap_array);
162 for (
size_t i = 0;
i < stripmap_array.size();
i++) {
166 if (TDCPair ==
TDCMap.end()) {
179 if (tempstrMap->
value.at(2) == 0)
181 else if (tempstrMap->
value.at(2) == 1)
189 LOGF(debug,
"\t\tLoaded %d strips", (
int)stripmap_array.size());
191 if (!stripmap_array.empty())
192 for (
size_t i = 0;
i < stripmap_array.size();
i++)
193 delete stripmap_array[
i];
208 LOGF(debug,
"Loading the INL correction from DB... ");
210 "TOF1",
"TOF1_inl", nPeriod, nRun);
211 if (pLoadedInl == NULL) {
216 vector<UniValue*> inl_array;
223 while (tdcs !=
TDCMap.end()) {
224 serialtemp = tdcs->first;
228 for (
size_t iv = 0; iv < inl_array.size(); iv++) {
230 if (tempInl->
serial == serialtemp) {
231 LOGF(debug,
"\t\tINL for %08X are found", serialtemp);
235 (tdcs->second).INL[ich][ibin] = tempInl->
inl[ich][ibin];
238 if (flagtemp ==
false) {
244 (tdcs->second).INL[ich][ibin] = 0.;
250 LOGF(debug,
"\t\tLoading INL for TOF400 complete. %d records uploaded", inl_array.size());
252 if (!inl_array.empty())
253 for (
size_t i = 0;
i < inl_array.size();
i++)
267 placementMapFile.
Data(), mapFile.
Data());
268 UInt_t fcrate, fserial, fslot, fchan, fplane, fstrip;
274 ff.open(placementMapFile.
Data(), std::fstream::in);
279 LOGF(debug,
"Reading TOF400 PlacementMap file %s", placementMapFile.
Data());
281 ff >> std::hex >> fcrate >> std::dec >> fslot >> std::hex >> fserial >> std::dec;
288 LOGF(debug,
"\t\tLoaded %d TDCs", (
int)
TDCMap.size());
302 ff.open(mapFile.
Data(), std::fstream::in);
307 LOGF(debug,
"Reading TOF400 StripMap file %s", mapFile.
Data());
309 ff >> std::hex >> fserial >> std::dec >> fchan >> fplane >> fstrip >> side_c;
315 if (TDCPair ==
TDCMap.end()) {
318 BmnTof1Map2* elem = &((TDCPair->second).ChannelMap[fchan]);
319 elem->
plane = fplane;
320 elem->
strip = fstrip;
323 }
else if (side_c ==
'R') {
330 LOGF(debug,
"\t\tLoaded %d strips", nLines);
344 ff.open(placementMapFile.c_str(), std::fstream::out);
346 cerr <<
"Cannot open the file " << placementMapFile << endl;
352 ff << std::hex << std::setfill(
'0') << std::setw(8) << plit->first.first <<
'\t';
353 ff << std::dec << int(plit->first.second) <<
'\t';
354 ff << std::hex << std::setfill(
'0') << std::setw(8) << plit->second << endl;
360 ff.open(mapFile.c_str(), std::fstream::out);
362 cerr <<
"Cannot open the file " << mapFile << endl;
367 while (mapit !=
TDCMap.end()) {
369 ff << std::hex << std::setfill(
'0') << std::setw(8) << mapit->first << std::setfill(
' ') <<
'\t';
370 ff << std::dec <<
i <<
'\t';
371 ff << mapit->second.ChannelMap[
i].plane <<
'\t';
372 ff << mapit->second.ChannelMap[
i].strip <<
'\t';
373 bool side = mapit->second.ChannelMap[
i].side;
379 cerr <<
"Side is not bool." << endl;
391 fstream ff(INLFile.c_str(), std::fstream::in);
393 cerr <<
"Failed to open " << INLFile << endl;
396 unsigned int TDCSerial;
401 ff >> std::hex >> TDCSerial >> std::dec;
402 ff.ignore(1000,
'\n');
406 if (TDCPair ==
TDCMap.end()) {
407 cerr <<
"Tof400: TDC " << std::setfill(
'0') << std::setw(8) << std::hex << TDCSerial << std::setfill(
' ')
409 cerr <<
" isn't in the placement map." << endl;
414 unsigned int chan_id = 0;
415 unsigned int lines_num = 0;
421 std::getline(ff, line,
'\n');
428 istringstream ss(line);
430 ss >> chan_id >> dummy;
432 cerr <<
"Tof400: Wrong INL file format." << endl;
437 cerr <<
"Tof400: Wrong channel in in the INL file" << endl;
442 double* INLelem = (TDCPair->second).INL[chan_id];
444 unsigned int i_bin = 0;
445 while (ss.tellg() != -1) {
447 cerr <<
"Tof400: INL File contains too many bins in channel." << endl;
451 if (ss.peek() ==
',') {
454 ss >> INLelem[i_bin];
458 cout <<
"Warning: wrong number of bins in the INL file for channel " << chan_id <<
" (" << i_bin <<
")"
465 cout <<
"Warning: wrong number of lines in the INL file (" << lines_num << endl;
467 cout <<
"Tof400: INL for TDC " << std::setfill(
'0') << std::setw(8) << std::hex << TDCSerial << std::setfill(
' ')
468 << std::dec <<
" loaded succesfully from INL file." << endl;
477 if (TDCPair ==
TDCMap.end()) {
478 cerr <<
"Tof400: TDC " << std::setfill(
'0') << std::setw(8) << std::hex << TDCSerial << std::setfill(
' ')
480 cerr <<
" isn't in the placement map." << endl;
484 fstream ff(INLFile.c_str(), std::fstream::out);
485 ff <<
"[TDC-" << std::setfill(
'0') << std::setw(8) << std::hex << TDCSerial << std::dec << std::setfill(
' ')
486 <<
"-inl_corr]" << endl;
490 double* INLelem = (TDCPair->second).INL[chan];
511 while (tdci !=
TDCMap.end()) {
513 (tdci->second).t[
i] = -1;
526 multiset<BmnTDCDigit, _Tof1TDCCompare> temp;
532 while (it != data->
end()) {
546 multiset<BmnTDCDigit, _Tof1TDCCompare>::iterator si = temp.begin();
548 while (si != temp.end()) {
555 parPair =
PlacementMap.find(std::make_pair<UInt_t, UChar_t>(si->GetSerial(), si->GetSlot()));
566 if (parPair->second == si->GetSerial())
585 if (itTS == mapTS->end()) {
593 UInt_t TDC_Serial = parPair->second;
597 if (TDCPair ==
TDCMap.end()) {
600 cerr <<
"Warning: TDC with ID " << std::hex << TDC_Serial << std::dec <<
": no data" << endl;
628 if (si->GetLeading()) {
630 par->
t[rchan] = timeFromDigit;
633 if (par->
t[rchan] != -1) {
636 if (timeFromDigit < (par->
t[rchan]) &&
fVerbose >= 2) {
641 cout <<
"Error: negative dt" << endl;
644 multiset<BmnTDCDigit, _Tof1TDCCompare>::iterator si2 = temp.begin();
645 while (si2 != temp.end()) {
646 cout << std::hex << si2->GetSerial() <<
" " << int(si2->GetSlot()) <<
" " << std::dec
647 << int(si2->GetHptdcId()) <<
" " << int(si2->GetChannel()) <<
" "
648 << (si2->GetLeading() ?
"L" :
"T") << si2->GetValue() << endl;
652 cout <<
"Error at: " << endl;
653 cout << std::hex << si->GetSerial() <<
" " << int(si->GetSlot()) <<
" " << std::dec
654 << int(si->GetHptdcId()) <<
" " << int(si->GetChannel()) <<
" "
655 << (si->GetLeading() ?
"L" :
"T") << si->GetValue() << endl;
656 cout << std::hex << TDC_Serial << std::dec <<
" " << rchan <<
" " << (par->
t[rchan]) <<
"--"
657 << timeFromDigit << endl;
670 timeFromDigit - (par->
t[rchan]));
681 LOGF(debug,
"TOF400 : %d digits", nOut);
std::map< std::pair< UInt_t, UChar_t >, UInt_t >::iterator Tof1PlMapIter
std::pair< UInt_t, UChar_t > Tof1PlMapKey
int Tof1GlobalNameCounter
std::map< UInt_t, BmnTof1TDCParameters >::iterator Tof1TDCMapIter
std::pair< UInt_t, BmnTof1TDCParameters > Tof1TDCMapElem
std::map< std::pair< UInt_t, UChar_t >, UInt_t > PlacementMap
Bool_t setRun(Int_t nPerion, Int_t nRun)
void saveINLToFile(std::string INLFile, unsigned int TDCSerial)
virtual ~BmnTof1Raw2Digit()
static UShort_t ToGlobalChannel(UChar_t HptdcId, UChar_t channel)
Bool_t setMapFromFile(TString placementMapFile, TString mapFile)
void plmap_insert(UInt_t Serial, UChar_t Slot, UInt_t TDCSerial)
void setINLFromFile(std::string INLFile)
void FillEvent(TClonesArray *data, unordered_map< UInt_t, Long64_t > *mapTS, TClonesArray *tof1digit)
std::map< UInt_t, BmnTof1TDCParameters > TDCMap
void saveMapToFile(std::string placementMapFile, std::string mapFile)
Int_t GetEntries() const override
const char * Data() const
int GetValue(vector< UniValue * > ¶meter_value)
get value of detector parameter presented by an array
static UniDetectorParameter * GetDetectorParameter(int value_id)
get detector parameter from the database
#define TOF1_CHANNEL_NUMBER
BmnTof1Map2 ChannelMap[TOF1_CHANNEL_NUMBER]
double t[TOF1_CHANNEL_NUMBER]
double INL[TOF1_CHANNEL_NUMBER][TOF1_BIN_NUMBER]
bool operator()(const BmnTDCDigit &a, const BmnTDCDigit &b) const