5#include <boost/program_options.hpp>
16namespace po = boost::program_options;
29 printf(
"Error! Unable to read the trigger channel map!\n");
37 map<TString, TClonesArray*> brName2ptr;
41 auto it = brName2ptr.find(detName);
42 if (it == brName2ptr.end()) {
47 record.branchArrayPtr = ar;
48 brName2ptr.insert(make_pair(detName, ar));
50 record.branchArrayPtr = it->second;
71 printf(
"Error! Unable to read the trigger channel map!\n");
77 map<TString, TClonesArray*> brName2ptr;
81 auto it = brName2ptr.find(detName);
82 if (it == brName2ptr.end()) {
85 BranchRegFun(detName, ar);
88 record.branchArrayPtr = ar;
89 brName2ptr.insert(make_pair(detName, ar));
91 record.branchArrayPtr = it->second;
99 LOGF(info,
"Reading Triggers placement mapping file %s...", PlMapFileName.
Data());
101 pmFile.open(PlMapFileName.
Data());
102 if (!pmFile.is_open()) {
103 cout <<
"Error opening map-file (" << PlMapFileName <<
")!" << endl;
108 UInt_t crateSerial, boardSerial;
112 pmFile >> dummy >> dummy >> dummy >> dummy >> dummy;
114 while (pmFile >> name >> hex >> crateSerial >> dec >> slot >> hex >> boardSerial >> dec >> isT0) {
116 .BoardSerial = boardSerial, .CrateSerial = crateSerial, .Slot = (uint8_t)slot, .IsT0 = (
bool)isT0});
118 .BoardSerial = boardSerial,
119 .CrateSerial = crateSerial,
120 .Slot = (uint8_t)slot,
121 .IsT0 = (
bool)isT0});
123 LOGF(debug,
"Board 0x%08X inserted", newIt->second.BoardSerial);
125 LOGF(error,
"Board 0x%08X duplicate serial in the placement map!", newIt->second.BoardSerial);
136 LOGF(info,
"Reading Triggers strip mapping file %s...",
fMapFileName.Data());
138 vector<string> trc_trigger_bits;
139 vector<string> scalers;
140 vector<string> configuration;
141 vector<string> t0_raw;
144 po::options_description desc(
"Options");
145 desc.add_options()(
"INPUTS.serial", po::value<string>(),
"TRC serial")(
146 "INPUTS.channels", po::value<vector<string>>(&trc_trigger_bits)->multitoken(),
"TRC trigger input signal bits")(
147 "SCALERS.channels", po::value<vector<string>>(&scalers)->multitoken(),
148 "Scaler channels")(
"TDC-CONFIGURATION.channels", po::value<vector<string>>(&configuration)->multitoken(),
149 "TDC configuration")(
"T0-RAW.virt_serial", po::value<string>(),
"T0 virtual serial")(
150 "T0-RAW.channels", po::value<vector<string>>(&t0_raw)->multitoken(),
"TDC configuration");
153 po::variables_map vm;
154 ifstream config_file(
fMapFileName.Data(), ifstream::in);
155 if (!config_file.is_open()) {
156 printf(
"%s - file open error!\n", mappingFile.
Data());
159 po::store(po::parse_config_file(config_file, desc), vm);
163 stringstream hs(vm[
"INPUTS.serial"].as<string>());
170 for (
auto it : trc_trigger_bits) {
171 istringstream ss(it);
172 ss >> tr_name >> bit;
178 uint16_t scalers_ar_size(0);
179 for (
auto it : scalers) {
180 istringstream ss(it);
181 ss >> tr_name >> hex >> ser >> dec >> ch;
182 std::pair p_ser_ch = make_pair(ser, ch);
193 LOGF(debug,
"msc[%15s] = (0x%08X : %2u)", tr_name.data(),
name2scaler_map[tr_name].first,
200 for (
auto it : configuration) {
201 istringstream ss(it);
202 ss >> name >> mod >> hex >> ser >> dec >> ch >> neg;
215 stringstream vs(vm[
"T0-RAW.virt_serial"].as<string>());
216 UInt_t t0_virt_serial;
217 vs >> std::hex >> t0_virt_serial;
218 LOGF(info,
"t0_virt_serial %0X", t0_virt_serial);
219 for (
auto it : t0_raw) {
220 istringstream ss(it);
221 ss >> tr_name >> mod >> ch;
222 fT0Map[make_pair(tr_name, mod)] = ch;
223 LOGF(debug,
"trig[%10s] mod %2u ch %3u", tr_name.data(), mod, ch);
230 LOGF(info,
"Assigning trigger maps...");
233 uint32_t& boardSerial = record.serial;
238 "BoardSeral %08X was not present in the placement map file!\n"
239 " Board sync time will be associated with it's own WR time!\n",
241 auto [newIt, didInsert] =
244 .BoardSerial = boardSerial,
245 .CrateSerial = boardSerial,
250 LOGF(debug,
"Board 0x%08X inserted", newIt->second.BoardSerial);
252 LOGF(error,
"Board 0x%08X duplicate serial in the placement map!", newIt->second.BoardSerial);
255 par = &(newIt->second);
257 par = &(itPar->second);
259 par->
ChannelMap[record.channel] = record.module;
261 par->
NegativeMap[record.channel] = record.isNegative;
274 ff.open((fINLFileName).Data(), ios::in);
276 cout <<
"Error opening INL-file (" << fINLFileName <<
")!" << endl;
279 LOGF(info,
"Open INL file %s", fINLFileName.
Data());
280 TPRegexp reInlHdr(
"\\[.*(inl_corr).*\\]");
286 std::getline(ff, line,
'\n');
287 if (reInlHdr.
MatchB(line)) {
294 printf(
"Incorrect INL file format!\n");
297 uint16_t channelID = 0;
300 std::getline(ff, line,
'\n');
306 istringstream ss(line);
310 while (ss.tellg() != -1) {
312 printf(
"INL File contains too many bins in channel.\n");
316 if (ss.peek() ==
',' || ss.peek() ==
'=') {
319 ss >> par->
INL[channelID][i_bin];
339 for (
auto& val : iValue)
342 for (
auto& val : iValue)
368 for (
auto& val : iValue)
370 uint16_t maxCount = 0;
373 if (cnt > maxCount) {
382 std::vector<Double_t> times;
386 uint16_t iChannel = adcDig->GetChannel();
397 auto it = tsMap.find(adcDig->GetSerial());
398 Long64_t timeShift = (it != tsMap.end()) ? it->second : 0;
410 times.push_back(time);
413 BmnTrigWaveDigit(iMod, move(adcDig->GetValue()), trgTimestamp, adcTimestamp);
432 auto it = tsMap.find(tdcDig->
GetSerial());
433 Long64_t timeShift = (it != tsMap.end()) ? it->second : 0;
444 par.
t[rChannel] = time;
446 if (time < par.
t[rChannel])
448 if (par.
t[rChannel] < 0)
456 par.
t[rChannel] = -1.0;
BmnStatus
Define status code.
const UShort_t kNCHANNELS
#define ADC_CLOCK_TQDC16VS
#define CHANNEL_COUNT_MAX
UChar_t GetHptdcId() const
UChar_t GetChannel() const
Bool_t GetLeading() const
UShort_t GetTrigTimestamp() const
UShort_t GetAdcTimestamp() const
int16_t GetBaselineByMap(vector< int16_t > &iValue)
BmnStatus ReadINLFromFile(BmnTrigParameters *par)
Name2SerCh name2scaler_map
map< std::pair< uint32_t, uint16_t >, uint16_t > scalers2index_map
BmnStatus ReadChannelMap(TString mappingFile)
unordered_map< uint32_t, BmnTrigParameters > fTrigBoardMap
vector< BmnTrigChannelData > fChannelVec
vector< PlacementLine > fPlacementVec
void ProcessWave(vector< int16_t > &iValue, Bool_t &isNeg)
map< uint16_t, uint16_t > trcIdx2scalerIdx
vector< string > scalers_index2name_map
unordered_map< int16_t, uint16_t > fValsMap
SerCh2Name scalers2name_map
vector< TClonesArray * > trigArrays
NameChMap scalers_name2index_map
TString Serial2FileName(TString boardName, UInt_t serial)
BmnStatus FillEvent(TClonesArray *tdc, unordered_map< UInt_t, Long64_t > &tsMap)
BmnStatus ReadPlacementMap(TString mappingFile)
BmnTrigRaw2Digit(uint32_t period, TString mappingFile, TString INLFile, TTree *digiTree=NULL)
class for TQDC data including waveform can be initialized both from an std::vector and raw pointer to...
vector< int16_t > & GetValue()
vector< Double_t > & TdcVector()
void SetName(const char *name)
Int_t GetEntriesFast() const
TObject * At(Int_t idx) const override
Bool_t MatchB(const TString &s, const TString &mods="", Int_t start=0, Int_t nMaxMatch=10)
const char * Data() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
TClonesArray * branchArrayPtr
Double_t t[CHANNEL_COUNT_MAX]
Double_t INL[CHANNEL_COUNT_MAX][TDC_BIN_COUNT]
TClonesArray * branchArrayPtr[CHANNEL_COUNT_MAX]
bool NegativeMap[CHANNEL_COUNT_MAX]
UShort_t ChannelMap[CHANNEL_COUNT_MAX]