5#include <boost/program_options.hpp>
11#include "BmnTDCDigit.h"
12#include "BmnTQDCADCDigit.h"
13#include "BmnTrigDigit.h"
14#include "BmnTrigWaveDigit.h"
16namespace po = boost::program_options;
41 printf(
"Error! Unable to read the trigger channel map!\n");
49 map<TString, TClonesArray*> brName2ptr;
53 auto it = brName2ptr.find(detName);
54 if (it == brName2ptr.end()) {
59 record.branchArrayPtr = ar;
60 brName2ptr.insert(make_pair(detName, ar));
62 record.branchArrayPtr = it->second;
68 map<PlMapKey, BmnTrigParameters*>::iterator itPar =
fPlacementMap.find(
PlMapKey(record.serial, record.slot));
70 printf(
"CrateSeral %08X slot %u not found in the placement map!\n", record.serial, record.slot);
73 par->
name = record.name;
78 par->
ChannelMap[record.channel] = record.module;
80 par->
NegativeMap[record.channel] = record.isNegative;
101 printf(
"Error! Unable to read the trigger channel map!\n");
107 map<TString, TClonesArray*> brName2ptr;
109 TString& detName = record.name;
111 auto it = brName2ptr.find(detName);
112 if (it == brName2ptr.end()) {
115 BranchRegFun(detName, ar);
118 record.branchArrayPtr = ar;
119 brName2ptr.insert(make_pair(detName, ar));
121 record.branchArrayPtr = it->second;
126 map<PlMapKey, BmnTrigParameters*>::iterator itPar =
fPlacementMap.find(
PlMapKey(record.serial, record.slot));
128 printf(
"CrateSeral %08X slot %u not found in the placement map!\n", record.serial, record.slot);
131 par->
name = record.name;
136 par->
ChannelMap[record.channel] = record.module;
138 par->
NegativeMap[record.channel] = record.isNegative;
149 LOGF(info,
"Reading Triggers placement mapping file %s...", PlMapFileName.
Data());
151 pmFile.open(PlMapFileName.
Data());
152 if (!pmFile.is_open()) {
153 cout <<
"Error opening map-file (" << PlMapFileName <<
")!" << endl;
158 UInt_t crateSerial, boardSerial;
162 pmFile >> dummy >> dummy >> dummy >> dummy >> dummy;
164 while (pmFile >> name >> hex >> crateSerial >> dec >> slot >> hex >> boardSerial >> dec >> isT0) {
181 LOGF(info,
"Reading Triggers strip mapping file %s...",
fMapFileName.Data());
183 vector<string> trc_trigger_bits;
184 vector<string> scalers;
185 vector<string> configuration;
186 vector<string> t0_raw;
189 po::options_description desc(
"Options");
190 desc.add_options()(
"INPUTS.serial", po::value<string>(),
"TRC serial")(
191 "INPUTS.channels", po::value<vector<string>>(&trc_trigger_bits)->multitoken(),
"TRC trigger input signal bits")(
192 "SCALERS.channels", po::value<vector<string>>(&scalers)->multitoken(),
193 "Scaler channels")(
"TDC-CONFIGURATION.channels", po::value<vector<string>>(&configuration)->multitoken(),
194 "TDC configuration")(
"T0-RAW.virt_serial", po::value<string>(),
"T0 virtual serial")(
195 "T0-RAW.channels", po::value<vector<string>>(&t0_raw)->multitoken(),
"TDC configuration");
198 po::variables_map vm;
199 ifstream config_file(
fMapFileName.Data(), ifstream::in);
200 if (!config_file.is_open()) {
201 printf(
"%s - file open error!\n", mappingFile.
Data());
204 po::store(po::parse_config_file(config_file, desc), vm);
208 stringstream hs(vm[
"INPUTS.serial"].as<string>());
215 for (
auto it : trc_trigger_bits) {
216 istringstream ss(it);
217 ss >> tr_name >> bit;
224 uint16_t scalers_ar_size(0);
225 for (
auto it : scalers) {
226 istringstream ss(it);
227 ss >> tr_name >> hex >> ser >> dec >> ch;
228 std::pair p_ser_ch = make_pair(ser, ch);
239 LOGF(debug,
"msc[%15s] = (0x%08X : %2u)", tr_name.data(),
name2scaler_map[tr_name].first,
246 for (
auto it : configuration) {
247 istringstream ss(it);
248 ss >> name >> mod >> hex >> ser >> dec >> slot >> ch >> neg;
259 fMap.push_back(record);
262 stringstream vs(vm[
"T0-RAW.virt_serial"].as<string>());
263 UInt_t t0_virt_serial;
264 vs >> std::hex >> t0_virt_serial;
265 LOGF(info,
"t0_virt_serial %0X", t0_virt_serial);
266 for (
auto it : t0_raw) {
267 istringstream ss(it);
268 ss >> tr_name >> mod >> ch;
269 fT0Map[make_pair(tr_name, mod)] = ch;
270 LOGF(debug,
"trig[%10s] mod %2u ch %3u", tr_name.data(), mod, ch);
280 ff.open((fINLFileName).Data(), ios::in);
282 cout <<
"Error opening INL-file (" << fINLFileName <<
")!" << endl;
285 LOGF(info,
"Open INL file %s", fINLFileName.
Data());
286 TPRegexp reInlHdr(
"\\[.*(inl_corr).*\\]");
292 std::getline(ff, line,
'\n');
293 if (reInlHdr.
MatchB(line)) {
300 printf(
"Incorrect INL file format!\n");
303 uint16_t channelID = 0;
306 std::getline(ff, line,
'\n');
312 istringstream ss(line);
316 while (ss.tellg() != -1) {
318 printf(
"INL File contains too many bins in channel.\n");
322 if (ss.peek() ==
',' || ss.peek() ==
'=') {
325 ss >> par->
INL[channelID][i_bin];
345 for (
auto& val : iValue)
348 for (
auto& val : iValue)
374 for (
auto& val : iValue)
376 uint16_t maxCount = 0;
379 if (cnt > maxCount) {
388 std::vector<Double_t> times;
389 std::vector<Double_t> diff;
394 uint16_t iChannel = adcDig->GetChannel();
404 Double_t boardShift = par->
IsT0 ? 0 : tsMap[adcDig->GetSerial()];
415 times.push_back(time);
418 BmnTrigWaveDigit(iMod, move(adcDig->GetValue()), trgTimestamp, adcTimestamp);
430 el.second->t[
i] = -1.0;
446 par->
t[rChannel] = time;
448 if (time < par->t[rChannel])
450 if (par->
t[rChannel] < 0)
458 par->
t[rChannel] = -1.0;
BmnStatus
Define status code.
std::pair< uint32_t, uint16_t > PlMapKey
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)
map< std::pair< uint32_t, uint16_t >, uint16_t > scalers2index_map
vector< BmnTrigChannelData > fMap
map< int16_t, uint16_t > fValsMap
Name2SerCh name2scaler_map
vector< string > scalers_index2name_map
BmnStatus ReadChannelMap(TString mappingFile)
map< PlMapKey, BmnTrigParameters * > fPlacementMap
map< uint16_t, uint16_t > trcIdx2scalerIdx
void ProcessWave(vector< int16_t > &iValue, Bool_t &isNeg)
SerCh2Name scalers2name_map
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)
vector< TClonesArray * > trigArrays
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)
const UShort_t kNCHANNELS
#define ADC_CLOCK_TQDC16VS
#define CHANNEL_COUNT_MAX
TClonesArray * branchArrayPtr
Double_t INL[CHANNEL_COUNT_MAX][TDC_BIN_COUNT]
Bool_t NegativeMap[CHANNEL_COUNT_MAX]
TClonesArray * branchArrayPtr[CHANNEL_COUNT_MAX]
UShort_t ChannelMap[CHANNEL_COUNT_MAX]
Double_t t[CHANNEL_COUNT_MAX]