BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnMscRaw2Digit.cxx
Go to the documentation of this file.
1#include "BmnMscRaw2Digit.h"
2
3#include "ElogRecord.h"
4#include "FairLogger.h"
5#include "UniParser.h"
6#include "UniRun.h"
7#include "UniSearchCondition.h"
8
9BmnMscRaw2Digit::BmnMscRaw2Digit(Int_t period, Int_t run, TString MapFile, TTree* spillTree, TTree* digiSpillTree)
10{
11 fBmnSetup = MapFile.Contains("SRC") ? kSRCSETUP : kBMNSETUP;
12 fPeriodId = period;
13 fRunId = run;
14 SetRawSpillTree(spillTree);
15 SetDigSpillTree(digiSpillTree);
16 ReadChannelMap(MapFile);
17 if ((fBmnSetup == kSRCSETUP) && (fPeriodId == 7)) { // @TODO extend for BM@N
19 fBmnSetup == kSRCSETUP ? "$VMCWORKDIR/database/uni_db/macros/parse_schemes/spill_run7/SRC_Data.txt"
20 : "$VMCWORKDIR/database/uni_db/macros/parse_schemes/spill_run7/summary_corr_v2.txt",
22 ? "$VMCWORKDIR/database/uni_db/macros/parse_schemes/spill_run7/spill_run7_src_full.xslt"
23 : "$VMCWORKDIR/database/uni_db/macros/parse_schemes/spill_run7/spill_run7_bmn_full.xslt");
24 isValidSpillLog = (status == kBMNSUCCESS);
25 }
26}
27
29{
30 fMapFileName = TString(getenv("VMCWORKDIR")) + TString("/input/") + mappingFile;
31 LOG(info) << "Reading MSC16 channel mapping file " << fMapFileName << "...";
32 fMapFile.open((fMapFileName).Data());
33 if (!fMapFile.is_open()) {
34 fprintf(stderr, "Error opening map-file (%s)!\n", fMapFileName.Data());
35 return kBMNERROR;
36 }
37 TString dummy;
38 TString name;
39 UInt_t ser;
40 UShort_t slot, bt, btnbusy, l0, tp, bc1, bc2, bc3, BC1H, BC1BP, BC1xBC2, BC1nBusy, IntTrig, SRCTrig, TrignBusy;
41
42 fMapFile >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy
43 >> dummy >> dummy >> dummy >> dummy;
44 fMapFile >> dummy;
45 while (fMapFile >> hex >> ser >> dec >> slot >> bt >> btnbusy >> l0 >> tp >> bc1 >> bc2 >> bc3 >> BC1H >> BC1BP
46 >> BC1xBC2 >> BC1nBusy >> IntTrig >> SRCTrig >> TrignBusy)
47 {
48 MscMap record;
49 record.serial = ser;
50 record.slot = slot;
51 record.BT = bt;
52 record.BTnBusy = btnbusy;
53 record.L0 = l0;
54 record.TriggerProtection = tp;
55 record.BC1 = bc1;
56 record.BC2 = bc2;
57 record.BC3 = bc3;
58 record.BC1H = BC1H;
59 record.BC1BP = BC1BP;
60 record.BC1xBC2 = BC1xBC2;
61 record.BC1nBusy = BC1nBusy;
62 record.IntTrig = IntTrig;
63 record.SRCTrig = SRCTrig;
64 record.TrignBusy = TrignBusy;
65 fMap.push_back(record);
66 }
67 fMapFile.close();
68 if (fMap.size() == 0) {
69 fprintf(stderr, "Map file is empty!\n");
70 return kBMNERROR;
71 }
72 return kBMNSUCCESS;
73}
74
76{
77 TString beam = "";
78 TString target = "";
79 Int_t log_shift_bmn = 6;
80 Int_t log_shift_src = -3;
81 fLogShift = fBmnSetup == kBMNSETUP ? log_shift_bmn : log_shift_src;
82
83 map<TDatime, vector<Int_t>> temp_spill_map;
84 UniParser parser;
85 vector<structParseValue*> parse_values;
86 vector<structParseSchema> vecElements;
87 int res_code = parser.ParseTxt2Struct(LogName, SchemeName, parse_values, vecElements, fVerbose);
88 if (res_code != 0) {
89 cout << endl << "Error: parser error (" << res_code << ")" << endl;
90 return kBMNERROR;
91 }
92
93 if (parse_values.size() < 1) {
94 cout << endl << "Error: there are no lines to parse" << endl;
95 return kBMNERROR;
96 }
97
98 // TObjArray* pRunArray = NULL;
99 // select only with a given condition, e.g. target particle
100 TObjArray arrayConditions;
101 arrayConditions.SetOwner(kTRUE);
102
103 UniSearchCondition* searchCondition =
105 arrayConditions.Add((TObject*)searchCondition);
106 if (target != "") {
107 searchCondition =
109 target); // one can choose any condition: beam, energy...
110 arrayConditions.Add((TObject*)searchCondition);
111 }
112 if (beam != "") {
113 searchCondition =
115 arrayConditions.Add((TObject*)searchCondition);
116 }
117
118 int sum_size = parse_values[0]->arrValues.size();
119
120 for (size_t ind = 0; ind < parse_values.size(); ind++) {
121 structParseValue* st = parse_values.at(ind);
122 vector<Int_t> vals;
123 for (Int_t iValue = 0; iValue < sum_size; iValue++)
124 vals.push_back(boost::any_cast<Int_t>(st->arrValues[iValue]));
126 temp_spill_map.insert(pair<TDatime, vector<Int_t>>(st->dtSpillEnd, vals));
127 }
128
129 vector<Long64_t> total_columns;
130 for (int i_total = 0; i_total < sum_size; i_total++)
131 total_columns.push_back(0);
132 // get run time
134 if (pRun == NULL) {
135 cout << endl << "Error: no experimental run was found " << fPeriodId << " : " << fRunId << endl;
136 return kBMNERROR;
137 }
138 dtStart = pRun->GetStartDatetime();
139 TDatime* dateEnd = pRun->GetEndDatetime();
140 if (dateEnd == NULL) {
141 cout << "Error: no end datetime in the database for this run" << endl;
142 delete pRun;
143 return kBMNERROR;
144 }
145 dtEnd = *dateEnd;
146 delete pRun;
147 // fSpillMapIter = spill_map.lower_bound(dtStart);
148 // check for presence in ELOG
150 if (recs == NULL) {
151 fprintf(stderr, "ELOG Error!\n");
152 return kBMNERROR;
153 } else if (recs->GetEntries() == 0) {
154 fprintf(stderr, "Run %d not found in ELOG!\n", fRunId);
155 return kBMNERROR;
156 }
157 printf("Run %d %s", fRunId, dtStart.AsSQLString());
158 printf(" - %s\n", dtEnd.AsSQLString());
159 spill_map.insert(temp_spill_map.lower_bound(dtStart), temp_spill_map.upper_bound(dtEnd));
160
161 return kBMNSUCCESS;
162}
163
165{
166 if (rh) {
167 rh->SetBT(fBT);
168 rh->SetBTnBusy(fBTnBusy);
171 rh->SetL0(fL0);
172 rh->SetRawMSC(move(fBoardSums));
173 // printf("map len %lu\n",fBoardSums.size());
174 }
175}
176
178{
179 // UInt_t iEv = 0; // hdr->GetEventId();
180 // for (Int_t iAdc = 0; iAdc < msc->GetEntriesFast(); ++iAdc) {
181 // BmnMSCDigit<UChar_t>* dig = (BmnMSCDigit<UChar_t>*)msc->At(iAdc);
182 // // fVerbose = 1;
183 // if (fVerbose)
184 // printf("iAdc %d Spill %u last event %u Curent evId %u \n", iAdc, iSpill, dig->GetLastEventId(), iEv);
185 // auto it = fBoardSums.find(dig->GetSerial());
186 // if (it == fBoardSums.end()) {
187 // vector<uint64_t> v(dig->GetValue().begin(), dig->GetValue().end());
188 // fBoardSums.insert(make_pair(dig->GetSerial(), move(v)));
189 // } else {
190 // for (uint8_t i = 0; i < MSC_N_COUNTERS; i++)
191 // it->second[i] += dig->GetValue()[i];
192 // }
193 // }
194 return kBMNSUCCESS;
195}
196
197// for period 7
198
200{
201 sh->Clear();
202 if (fRawSpillTree->GetEntriesFast() <= iSpill)
203 return kBMNERROR;
204 BmnTrigInfo& ti = hdr->GetTrigInfo();
205 // if (msc->GetEntriesFast() == 0)
206 // fTempTI = BmnTrigInfo(hdr->GetTrigInfo());
207 UInt_t iEv = hdr->GetEventId();
208 for (Int_t iAdc = 0; iAdc < msc->GetEntriesFast(); ++iAdc) {
209 BmnMSCDigit<UInt_t>* dig = (BmnMSCDigit<UInt_t>*)msc->At(iAdc);
210 if (dig->GetLastEventId() > iEv)
211 return kBMNFINISH;
212 if ((dig->GetLastEventId() < iEv) && (dig->GetLastEventId() > 0)) {
213 fprintf(stderr, "Spill %u last event %u lost! Curent evId %u \n", iSpill, dig->GetLastEventId(), iEv);
214 fRawSpillTree->GetEntry(++iSpill);
215 ++iSpillMap;
216 nPedEvBySpill = 0;
217 return kBMNERROR;
218 }
219 fVerbose = 1;
220 if (fVerbose)
221 printf("Spill %u last event %u Curent evId %u \n", iSpill, dig->GetLastEventId(), iEv);
222 auto& arr = dig->GetValue();
223 UInt_t serial = dig->GetSerial();
224 for (auto& mRec : fMap) {
225 if (mRec.serial == serial) {
226 fBT += arr[mRec.BT];
227 fBTnBusy += arr[mRec.BTnBusy];
228 fProtection += arr[mRec.TriggerProtection];
229 fL0 += arr[mRec.L0];
230 UInt_t AcceptedReal = ti.GetTrigAccepted() - nPedEvBySpill;
231 if ((fBmnSetup == kSRCSETUP) && (fPeriodId == 7) && (isValidSpillLog)) {
232 if (iSpillMap < spill_map.size()) {
233 map<TDatime, vector<Int_t>>::iterator SpillMapIter = spill_map.begin();
234 advance(SpillMapIter, iSpillMap);
235 if (fVerbose)
236 printf(" spill %s\n", SpillMapIter->first.AsSQLString());
237 vector<Int_t> v = SpillMapIter->second;
238 /** flux ~= sum [BT * (DAQ_Busy -peds)/ (DAQ_TRigger - peds)]*/
239 Double_t BT = v[15];
240 Double_t DAQ_Busy = v[21];
241 Double_t DAQ_Trigger = v[22];
242 if (DAQ_Trigger - nPedEvBySpill != 0)
243 fBTAccepted += BT * (DAQ_Busy - nPedEvBySpill) / (DAQ_Trigger - nPedEvBySpill);
244 if (fVerbose)
245 printf("BT %f DAQ_Busy %f DAQ_Trigger %f flux %f\n", BT, DAQ_Busy, DAQ_Trigger,
247 }
248 } else { // BM@N setup or U40 is present
249 UInt_t den = AcceptedReal + ti.GetTrigBefo() + ti.GetTrigAfter();
250 if (den > 0)
251 fBTAccepted += arr[mRec.BTnBusy] * AcceptedReal / (Double_t)den;
252 }
253 fAccepted += AcceptedReal;
254 if (fDigSpillTree) {
255 // BM@N MSC16
256 sh->SetBC1(arr[mRec.BC1]);
257 sh->SetBC2(arr[mRec.BC2]);
258 sh->SetBC3(arr[mRec.BC3]);
259 sh->SetBT(arr[mRec.BT]);
260 sh->SetBTnBusy(arr[mRec.BTnBusy]);
261 sh->SetL0(arr[mRec.L0]);
262 sh->SetProt(arr[mRec.TriggerProtection]);
263 // // SRC MSC16
264 // sh->SetBC1H(arr[mRec.BC1H]);
265 // sh->SetBC1BP(arr[mRec.BC1BP]);
266 // sh->SetBC1xBC2(arr[mRec.BC1xBC2]);
267 // sh->SetBC1nBusy(arr[mRec.BC1nBusy]);
268 // sh->SetIntTrig(arr[mRec.IntTrig]);
269 // sh->SetSRCTrig(arr[mRec.SRCTrig]);
270 // sh->SetTrignBusy(arr[mRec.TrignBusy]);
271 // U40
272 sh->SetAccepted(AcceptedReal);
273 sh->SetAfter(ti.GetTrigAfter());
274 sh->SetBefo(ti.GetTrigBefo());
275 sh->SetCand(ti.GetTrigCand());
276 sh->SetAll(ti.GetTrigAll());
277 sh->SetAvail(ti.GetTrigAvail());
278 sh->SetRjct(ti.GetTrigRjct());
279
280 sh->SetLastEventId(iEv);
281 sh->SetPeriodId(hdr->GetPeriodId());
282 sh->SetStopTS(hdr->GetEventTimeTS());
283 fDigSpillTree->Fill();
284 }
285
286 if (fVerbose) {
287 printf("iSpill %4u last EvId %7u pedestals %d\n", iSpill, dig->GetLastEventId(), nPedEvBySpill);
288 hdr->GetEventTimeTS().Print();
289 printf(ANSI_COLOR_BLUE " MSC16:" ANSI_COLOR_RESET "\t"
290 "BC1 %7u, BC2 %7u, BC3 %4u, BeamTrigger %7u, L0 %7u, "
291 "TrigProtection %7u, BT&Busy %7u\n"
292 "\tBC1H %7u, BC1BP %7u, BC1xBC2 %4u, BC1nBusy %7u, IntTrig %7u, "
293 "SRCTrig %7u, TrignBusy %7u\n",
294 arr[mRec.BC1], arr[mRec.BC2], arr[mRec.BC3], arr[mRec.BT], arr[mRec.L0],
295 arr[mRec.TriggerProtection], arr[mRec.BTnBusy], arr[mRec.BC1H], arr[mRec.BC1BP],
296 arr[mRec.BC1xBC2], arr[mRec.BC1nBusy], arr[mRec.IntTrig], arr[mRec.SRCTrig],
297 arr[mRec.TrignBusy]); // BM@N
298 printf(ANSI_COLOR_BLUE
299 " U40VE:" ANSI_COLOR_RESET
300 "\tcand %7u, acc %7u, before %4u, after %6u, rjct %6u, all %7u, avail %7u\n\n",
302 ti.GetTrigRjct(), ti.GetTrigAll(), ti.GetTrigAvail());
303 }
304 ++iSpill;
305 ++iSpillMap;
306 Int_t r = fRawSpillTree->GetEntry(iSpill);
307 // printf("Get entry %u returned %d\n", iSpill, r);
308 if (r <= 0) {
309 // fprintf(stderr, "Spill %u read error!\n", iSpill);
310 return kBMNFINISH;
311 }
312 nPedEvBySpill = 0;
313 break;
314 }
315 }
316 }
317 return kBMNSUCCESS;
318}
__m128 v
Definition P4_F32vec4.h:1
unsigned short UShort_t
int Int_t
double Double_t
constexpr Bool_t kTRUE
BmnStatus
Define status code.
Definition BmnEnums.h:93
@ kBMNFINISH
Definition BmnEnums.h:97
@ kBMNERROR
Error.
Definition BmnEnums.h:95
@ kBMNSUCCESS
Success.
Definition BmnEnums.h:94
@ kSRCSETUP
Definition BmnEnums.h:167
@ kBMNSETUP
Definition BmnEnums.h:166
#define ANSI_COLOR_RESET
Definition BmnMath.h:18
#define ANSI_COLOR_BLUE
Definition BmnMath.h:17
UInt_t GetPeriodId()
Get the period ID for this event.
UInt_t GetEventId()
Get the event ID for this event.
TTimeStamp GetEventTimeTS()
Get the time for this event.
BmnTrigInfo & GetTrigInfo()
Get the spill statistics.
UInt_t GetSerial() const
Definition BmnMSCDigit.h:61
UInt_t GetLastEventId() const
Definition BmnMSCDigit.h:71
std::array< IntType, MSC_N_COUNTERS > & GetValue()
Definition BmnMSCDigit.h:65
unordered_map< UInt_t, vector< uint64_t > > fBoardSums
vector< MscMap > fMap
BmnStatus SumEvent7(TClonesArray *msc, BmnEventHeader *hdr, BmnSpillHeader *sh, UInt_t &nPedEvBySpill)
BmnStatus ParseTxtSpillLog(TString LogName, TString SchemeName)
BmnStatus SumEvent(TClonesArray *msc, BmnEventHeader *hdr, BmnSpillHeader *sh, UInt_t &nPedEvBySpill)
map< TDatime, vector< Int_t > > spill_map
void FillRunHeader(DigiRunHeader *rh)
void SetRawSpillTree(TTree *tree)
BmnStatus ReadChannelMap(TString mappingFile)
void SetDigSpillTree(TTree *tree)
void SetBC3(UInt_t _v)
void SetBC2(UInt_t _v)
void SetBT(UInt_t _v)
void SetLastEventId(UInt_t event_id)
Set the last event ID for the spill.
void SetAccepted(UInt_t _v)
void SetBC1(UInt_t _v)
void SetBTnBusy(UInt_t _v)
void SetStopTS(const TTimeStamp &ts)
Set the time for spill stop.
void SetAvail(UInt_t _v)
void SetProt(UInt_t _v)
void SetAll(UInt_t _v)
void SetBefo(UInt_t _v)
void SetL0(UInt_t _v)
void SetCand(UInt_t _v)
void SetRjct(UInt_t _v)
void SetPeriodId(UInt_t period_id)
Set the period ID.
void SetAfter(UInt_t _v)
Class BmnTrigInfo Trigger counters of the current spill from U40VE card.
Definition BmnTrigInfo.h:15
UInt_t GetTrigAvail()
Definition BmnTrigInfo.h:50
UInt_t GetTrigAfter()
Definition BmnTrigInfo.h:38
UInt_t GetTrigRjct()
Definition BmnTrigInfo.h:42
UInt_t GetTrigAll()
Definition BmnTrigInfo.h:46
UInt_t GetTrigBefo()
Definition BmnTrigInfo.h:34
UInt_t GetTrigAccepted()
Definition BmnTrigInfo.h:30
UInt_t GetTrigCand()
Definition BmnTrigInfo.h:26
void SetL0(uint64_t cntr)
Set the L0 counter.
void SetBT(uint64_t cntr)
Set the Beam Trigger counter.
void SetBTnBusy(uint64_t cntr)
Set the BT and Busy counter.
void SetAccepted(uint64_t cntr)
Set the Accepted counter.
void SetBTAccepted(Double_t cntr)
Set the (BT and not Busy) by live time.
void SetRawMSC(unordered_map< uint32_t, vector< uint64_t > > v)
Set the raw MSC counters.
static TObjArray * GetRecords(int period_number, int run_number, int findNeighbourRun=0)
get array of ElogRecord-s for a given or a neighbour run (the same period) from the database if findN...
virtual void SetOwner(Bool_t enable=kTRUE)
void Set()
UInt_t Convert(Bool_t toGMT=kFALSE) const
Int_t GetEntriesFast() const
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
void Add(TObject *obj) override
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
void Print(const Option_t *option="") const
int ParseTxt2Struct(TString txtName, TString schemaPath, vector< structParseValue * > &parse_values, vector< structParseSchema > &vecElements, int iVerbose=1)
UniRun.h Class for the table: run_.
Definition UniRun.h:21
static UniRun * GetRun(int period_number, int run_number)
get run from the database
Definition UniRun.cxx:161
TDatime * GetEndDatetime()
get end datetime of the current run
Definition UniRun.h:101
TDatime GetStartDatetime()
get start datetime of the current run
Definition UniRun.h:99
UShort_t L0
UShort_t BC1nBusy
UShort_t BTnBusy
(BeamTrigger & !Busy)
UInt_t serial
UShort_t BT
BeamTrigger index.
UShort_t TrignBusy
Trigger * !Busy.
UShort_t BC3
UShort_t BC1xBC2
UShort_t TriggerProtection
UShort_t IntTrig
UShort_t SRCTrig
UShort_t BC1BP
BC1 (before protection).
UShort_t BC1
UShort_t slot
UShort_t BC1H
BC1 (high threshold).
UShort_t BC2
TDatime dtSpillEnd
Definition UniParser.h:92
vector< boost::any > arrValues
Definition UniParser.h:93