81 #include "TRestRawBiPoToSignalProcess.h"
85 #include "TTimeStamp.h"
106 SetLibraryVersion(LIBRARY_VERSION);
119 RESTInfo <<
"TRestRawBiPoToSignalProcess::InitProcess" << RESTendl;
122 char buffer[CTAG_SZ];
123 if (fread(buffer,
sizeof(
char), CTAG_SZ, fInputBinFile) != CTAG_SZ) {
124 printf(
"Error: could not read first prefix.\n");
127 totalBytesReaded += CTAG_SZ *
sizeof(char);
129 if (strcmp(buffer, TAG_RUN_BIPO) != 0) {
130 RESTError <<
"The file " << fInputFileNames[0] <<
" is not BiPo format" << RESTendl;
143 RESTDebug <<
"-------Start of TRestRawBiPoToSignalProcess::ProcessEvent------------" << RESTendl;
145 RESTDebug <<
"--- Starting to process event id: " << fEventCounter << RESTendl;
149 fSignalEvent->SetRunOrigin(fRunOrigin);
150 fSignalEvent->SetSubRunOrigin(fSubRunOrigin);
151 fSignalEvent->SetID(fEventCounter);
153 char buffer[CTAG_SZ];
154 if (fread(buffer,
sizeof(
char), CTAG_SZ, fInputBinFile) != CTAG_SZ) {
155 printf(
"Error: could not read first ACQ prefix.\n");
158 totalBytesReaded += CTAG_SZ *
sizeof(char);
160 if (strcmp(buffer, TAG_RUN_STOP) == 0) {
161 RESTDebug <<
"The run ends" << RESTendl;
167 if (strcmp(buffer, TAG_ACQ) == 0 || strcmp(buffer, TAG_ACQ_2) == 0) {
168 RESTDebug <<
"A new event comes" << RESTendl;
170 std::vector<uint16_t> data;
171 Int_t boardAddress = ReadBiPoEventData(data);
172 Int_t bIndex = GetBoardIndex(boardAddress);
175 RESTError <<
"TRestRawBiPoToSignalProcess::ProcessEvent." << RESTendl;
176 RESTError <<
"Board index not found!" << RESTendl;
180 RESTDebug <<
"Number of channels : " << fMatacqBoard[bIndex].nChannels << RESTendl;
181 for (
int nch = 0; nch < fMatacqBoard[bIndex].nChannels; nch++) {
186 Int_t nBins = fBiPoSettings[bIndex].t1_window + fBiPoSettings[bIndex].t2_window;
188 for (
int b = 0; b < nBins; b++) {
189 Short_t sdata = data[GetBin(bIndex, nch, b)];
190 Short_t v = MATACQ_ZERO - sdata;
191 if (sdata == MATACQ_OVERFLOW) {
194 if (sdata == MATACQ_UNDERFLOW) {
195 v = TMath::Power(2, 12);
201 RESTDebug <<
"Adding signal with id : " << sgnl.
GetID() << RESTendl;
203 fSignalEvent->AddSignal(sgnl);
219 RESTDebug <<
"Entering TRestRawBiPoToSignalProcess::ReadFooter" << RESTendl;
223 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
224 printf(
"Error: could not read timestamp.\n");
227 totalBytesReaded +=
sizeof(int32_t);
228 Double_t runEndTime = (Double_t)tmp;
230 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
231 printf(
"Error: could not read timestamp (us).\n");
234 totalBytesReaded +=
sizeof(int32_t);
235 runEndTime += 1.e-6 * (Double_t)tmp;
237 fRunInfo->SetEndTimeStamp(runEndTime);
246 RESTDebug <<
"Entering TRestRawBiPoToSignalProcess::ReadHeader" << RESTendl;
250 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
251 printf(
"Error: could not read timestamp.\n");
254 totalBytesReaded +=
sizeof(int32_t);
255 Double_t runStartTime = (Double_t)tmp;
257 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
258 printf(
"Error: could not read timestamp (us).\n");
261 totalBytesReaded +=
sizeof(int32_t);
262 runStartTime += 1.e-6 * (Double_t)tmp;
264 fRunInfo->SetStartTimeStamp(runStartTime);
267 if (fread(&nBoards,
sizeof(uint32_t), 1, fInputBinFile) != 1) {
268 printf(
"Error: could not read nBoards.\n");
271 totalBytesReaded +=
sizeof(int32_t);
274 RESTDebug <<
"N boards: " << fNBoards << RESTendl;
276 for (
int n = 0; n < fNBoards; n++) {
280 if (fread(&bipo,
sizeof(int32_t), 1, fInputBinFile) != 1) {
281 printf(
"Error: could not read BiPo flag.\n");
284 totalBytesReaded +=
sizeof(int32_t);
287 RESTError <<
"The file " << fInputFileNames[0] <<
" is not BiPo format" << RESTendl;
301 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
302 printf(
"Error: could not read base matacq address.\n");
305 totalBytesReaded +=
sizeof(int32_t);
308 if (fread(&board.en_ch[0],
sizeof(int32_t), MATACQ_N_CH, fInputBinFile) != MATACQ_N_CH) {
309 printf(
"Error: could not read base matacq en_ch.\n");
312 totalBytesReaded += MATACQ_N_CH *
sizeof(int32_t);
316 for (
int ich = (MATACQ_N_CH - 1); ich >= 0; ich--) {
317 if (board.en_ch[ich] == 1) {
318 board.nChannels = board.nChannels + 1;
319 board.ch_shifts[ich] = cnt;
322 board.ch_shifts[ich] = -1;
326 if (fread(&board.trg_ch[0],
sizeof(int32_t), MATACQ_N_CH, fInputBinFile) != MATACQ_N_CH) {
327 printf(
"Error: could not read base matacq trg_ch.\n");
330 totalBytesReaded += MATACQ_N_CH *
sizeof(int32_t);
332 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
333 printf(
"Error: could not read Trig type.\n");
336 totalBytesReaded +=
sizeof(int32_t);
337 board.Trig_Type = tmp;
339 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
340 printf(
"Error: could not read Threshold.\n");
343 totalBytesReaded +=
sizeof(int32_t);
344 board.Threshold = tmp;
346 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
347 printf(
"Error: could not read Nb_Acq.\n");
350 totalBytesReaded +=
sizeof(int32_t);
353 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
354 printf(
"Error: could not read Posttrig.\n");
357 totalBytesReaded +=
sizeof(int32_t);
358 board.Posttrig = tmp;
360 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
361 printf(
"Error: could not read Time_Tag_On.\n");
364 totalBytesReaded +=
sizeof(int32_t);
365 board.Time_Tag_On = tmp;
367 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
368 printf(
"Error: could not read Sampling_GHz.\n");
371 totalBytesReaded +=
sizeof(int32_t);
372 board.Sampling_GHz = tmp;
374 RESTDebug <<
"MATACQ Base memory address: " << board.
address << RESTendl;
375 RESTDebug <<
"En[0]: " << board.en_ch[0] <<
" En[1]: " << board.en_ch[1] <<
" En[2]: " << board.en_ch[2]
376 <<
" En[3]: " << board.en_ch[3] << RESTendl;
377 RESTDebug <<
"Trg[0]: " << board.trg_ch[0] <<
" Trg[1]: " << board.trg_ch[1]
378 <<
" Trg[2]: " << board.trg_ch[2] <<
" Trg[3]: " << board.trg_ch[3] << RESTendl;
379 RESTDebug <<
" " << RESTendl;
380 RESTDebug <<
"Trigger type: " << board.Trig_Type <<
" Threshold: " << board.Threshold << RESTendl;
381 RESTDebug <<
"Nb_Acq: " << board.Nb_Acq <<
" Posttrig: " << board.Posttrig << RESTendl;
382 RESTDebug <<
"Time_Tag_On: " << board.Time_Tag_On <<
" Sampling_GHz: " << board.Sampling_GHz << RESTendl;
383 RESTDebug <<
" -- " << RESTendl;
385 fMatacqBoard.push_back(board);
396 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
397 printf(
"Error: could not read BiPo trigger address.\n");
400 totalBytesReaded +=
sizeof(int32_t);
401 bipo.trigger_address = tmp;
403 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
404 printf(
"Error: could not read BiPo Win1 Posttrig.\n");
407 totalBytesReaded +=
sizeof(int32_t);
408 bipo.Win1_Posttrig = tmp;
410 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
411 printf(
"Error: could not read BiPo timeout 200KHz.\n");
414 totalBytesReaded +=
sizeof(int32_t);
415 bipo.Timeout_200KHz = tmp;
417 if (fread(&bipo.Trig_Chan[0],
sizeof(int32_t), MATACQ_N_CH, fInputBinFile) != MATACQ_N_CH) {
418 printf(
"Error: could not read Trig_Chan.\n");
421 totalBytesReaded += MATACQ_N_CH *
sizeof(int32_t);
423 if (fread(&bipo.Level1_mV[0],
sizeof(int32_t), MATACQ_N_CH, fInputBinFile) != MATACQ_N_CH) {
424 printf(
"Error: could not read Level1_mV.\n");
427 totalBytesReaded += MATACQ_N_CH *
sizeof(int32_t);
429 if (fread(&bipo.Level2_mV[0],
sizeof(int32_t), MATACQ_N_CH, fInputBinFile) != MATACQ_N_CH) {
430 printf(
"Error: could not read Level2_mV.\n");
433 totalBytesReaded += MATACQ_N_CH *
sizeof(int32_t);
435 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
436 printf(
"Error: could not read BiPo Win1 Posttrig.\n");
439 totalBytesReaded +=
sizeof(int32_t);
440 bipo.t1_window = tmp;
442 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
443 printf(
"Error: could not read BiPo Win1 Posttrig.\n");
446 totalBytesReaded +=
sizeof(int32_t);
447 bipo.t2_window = tmp;
449 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
450 printf(
"Error: could not read BiPo Win1 Posttrig.\n");
453 totalBytesReaded +=
sizeof(int32_t);
454 bipo.t1_t2_timeout = tmp;
456 RESTDebug <<
"BiPo trigger address: " << bipo.trigger_address << RESTendl;
457 RESTDebug <<
"Win1 Posttrig: " << bipo.Win1_Posttrig << RESTendl;
458 RESTDebug <<
"Timeout [200KHz]: " << bipo.Timeout_200KHz << RESTendl;
459 RESTDebug <<
" " << RESTendl;
460 RESTDebug <<
"Trig_Chan[0]: " << bipo.Trig_Chan[0] <<
" Trig_Chan[1]: " << bipo.Trig_Chan[1]
461 <<
" Trig_Chan[2]: " << bipo.Trig_Chan[2] <<
" Trig_Chan[3]: " << bipo.Trig_Chan[3] << RESTendl;
462 RESTDebug <<
"Level1_mV[0]: " << bipo.Level1_mV[0] <<
" Level1_mV[1]: " << bipo.Level1_mV[1]
463 <<
" Level1_mV[2]: " << bipo.Level1_mV[2] <<
" Level1_mV[3]: " << bipo.Level1_mV[3] << RESTendl;
464 RESTDebug <<
"Level2_mV[0]: " << bipo.Level2_mV[0] <<
" Level2_mV[1]: " << bipo.Level2_mV[1]
465 <<
" Level2_mV[2]: " << bipo.Level2_mV[2] <<
" Level2_mV[3]: " << bipo.Level2_mV[3] << RESTendl;
466 RESTDebug <<
" " << RESTendl;
467 RESTDebug <<
"T1 window: " << bipo.t1_window << RESTendl;
468 RESTDebug <<
"T2 window: " << bipo.t2_window << RESTendl;
469 RESTDebug <<
"T1-T2 timeout: " << bipo.t1_t2_timeout << RESTendl;
470 RESTDebug <<
" -- " << RESTendl;
472 fBiPoSettings.push_back(bipo);
487 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
488 printf(
"Error: could not read tmp .\n");
491 totalBytesReaded +=
sizeof(int32_t);
492 Int_t boardAddress = tmp;
494 RESTDebug <<
" Event address --> " << boardAddress << RESTendl;
499 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
500 printf(
"Error: could not read tmp .\n");
503 totalBytesReaded +=
sizeof(int32_t);
505 Double_t timeStamp = tmp;
507 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
508 printf(
"Error: could not read tmp .\n");
511 totalBytesReaded +=
sizeof(int32_t);
512 timeStamp += 1.e-6 * (Double_t)tmp;
514 fSignalEvent->SetTime(timeStamp);
516 RESTDebug <<
"Event time stamp: " << timeStamp << RESTendl;
518 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
519 printf(
"Error: could not read tmp .\n");
522 totalBytesReaded +=
sizeof(int32_t);
523 int32_t data_size = tmp;
524 RESTDebug <<
"Data size --> " << tmp << RESTendl;
526 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
527 printf(
"Error: could not read BiPo trigger address.\n");
530 totalBytesReaded +=
sizeof(int32_t);
531 RESTDebug <<
" T1-T2 distance --> " << tmp << RESTendl;
532 fSignalEvent->SetAuxiliar(tmp);
534 mdata.resize(data_size);
535 if (fread(&mdata[0],
sizeof(uint16_t), data_size, fInputBinFile) != (size_t)data_size) {
536 printf(
"Error: could not read MATACQ data.\n");
539 totalBytesReaded += data_size *
sizeof(uint16_t);
549 for (
unsigned int n = 0; n < fMatacqBoard.size(); n++)
550 if (fMatacqBoard[n].address == address)
return n;
561 return board.ch_shifts[channel] + board.nChannels * bin;
570 RESTMetadata <<
"Number of Matacq boards : " << fNBoards << RESTendl;
571 RESTMetadata <<
" " << RESTendl;
573 for (
int n = 0; n < fNBoards; n++) {
574 RESTMetadata <<
" " << RESTendl;
575 RESTMetadata <<
"Board address: " << fMatacqBoard[n].address << RESTendl;
576 RESTMetadata <<
"----" << RESTendl;
577 RESTMetadata <<
" - Enabled channels: " << fMatacqBoard[n].en_ch[0] <<
" - "
578 << fMatacqBoard[n].en_ch[1] <<
" - " << fMatacqBoard[n].en_ch[2] <<
" - "
579 << fMatacqBoard[n].en_ch[3] << RESTendl;
580 RESTMetadata <<
" - Trigger channels: " << fMatacqBoard[n].trg_ch[0] <<
" - "
581 << fMatacqBoard[n].trg_ch[1] <<
" - " << fMatacqBoard[n].trg_ch[2] <<
" - "
582 << fMatacqBoard[n].trg_ch[3] << RESTendl;
583 RESTMetadata <<
" - Trigger type: " << fMatacqBoard[n].Trig_Type << RESTendl;
584 RESTMetadata <<
" - Threshold: " << fMatacqBoard[n].Threshold << RESTendl;
585 RESTMetadata <<
" - Nb_Acq: " << fMatacqBoard[n].Nb_Acq << RESTendl;
586 RESTMetadata <<
" - Posttrig: " << fMatacqBoard[n].Posttrig << RESTendl;
587 RESTMetadata <<
" - Time_Tag_On: " << fMatacqBoard[n].Time_Tag_On << RESTendl;
588 RESTMetadata <<
" - Sampling_GHz: " << fMatacqBoard[n].Sampling_GHz << RESTendl;
589 RESTMetadata <<
" " << RESTendl;
590 RESTMetadata <<
"BiPo trigger settings. Address : " << fBiPoSettings[n].trigger_address << RESTendl;
591 RESTMetadata <<
"----" << RESTendl;
592 RESTMetadata <<
" - Win1 Posttrig: " << fBiPoSettings[n].Win1_Posttrig << RESTendl;
593 RESTMetadata <<
" - Timeout [200KHz]: " << fBiPoSettings[n].Timeout_200KHz << RESTendl;
594 RESTMetadata <<
" - Trigger channels: " << fBiPoSettings[n].Trig_Chan[0] <<
" - "
595 << fBiPoSettings[n].Trig_Chan[1] <<
" - " << fBiPoSettings[n].Trig_Chan[2] <<
" - "
596 << fBiPoSettings[n].Trig_Chan[3] << RESTendl;
597 RESTMetadata <<
" - Level 1 [mV]: " << fBiPoSettings[n].Level1_mV[0] <<
" - "
598 << fBiPoSettings[n].Level1_mV[1] <<
" - " << fBiPoSettings[n].Level1_mV[2] <<
" - "
599 << fBiPoSettings[n].Level1_mV[3] << RESTendl;
600 RESTMetadata <<
" - Level 2 [mV]: " << fBiPoSettings[n].Level2_mV[0] <<
" - "
601 << fBiPoSettings[n].Level2_mV[2] <<
" - " << fBiPoSettings[n].Level2_mV[2] <<
" - "
602 << fBiPoSettings[n].Level2_mV[3] << RESTendl;
603 RESTMetadata <<
" - T1 window: " << fBiPoSettings[n].t1_window << RESTendl;
604 RESTMetadata <<
" - T2 window: " << fBiPoSettings[n].t2_window << RESTendl;
605 RESTMetadata <<
" - T1-T2 timeout: " << fBiPoSettings[n].t1_t2_timeout << RESTendl;
608 RESTMetadata <<
"+++++++++++++++++++++++++++++++++++++++++++++++++" << RESTendl;
A base class for any REST event.
virtual void Initialize()=0
An process to read binary data from BiPo electronics.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
Int_t GetBin(Int_t boardIndex, Int_t channel, Int_t bin)
It returns the ordered channel value from the Matacq memory buffer for a given board,...
Int_t ReadBiPoEventData(std::vector< uint16_t > &mdata)
This method reads the event data corresponding to one event. The sampled channel data that will be ma...
void ReadBoard()
This method reads the settings of one of the Matacq boards.
void ReadFooter()
This method reads the header data containing the run timestamp, the number of Matacq boards,...
TRestRawBiPoToSignalProcess()
Default constructor.
void ReadHeader()
This method reads the header data containing the run timestamp, the number of Matacq boards,...
UInt_t GetBoardIndex(Int_t address)
It returns the std::vector storage index using the hardware address of the Matacq board.
~TRestRawBiPoToSignalProcess()
Default destructor.
void InitProcess() override
Process initialization. Data members that require initialization just before start processing should ...
void PrintMetadata() override
Prints out the Matacq boards configuration and BiPo setup.
void ReadBiPoSetup()
This method reads the header data corresponding to the BiPo settings of one card.
void Initialize() override
Function to initialize input/output event members and define the section name.
It defines a Short_t array with a physical parameter that evolves in time using a fixed time bin.
Int_t GetID() const
Returns the value of signal ID.
void Initialize()
Initialization of TRestRawSignal members.
void SetSignalID(Int_t sID)
It sets the id number of the signal.
void AddPoint(Short_t)
Adds a new point to the end of the signal data array.
Int_t GetSignalID() const
Returns the value of signal ID.
Int_t GetNumberOfPoints() const
Returns the actual number of points, or size of the signal.
virtual void InitProcess() override
To be executed at the beginning of the run (outside event loop)
void Initialize() override
Making default settings.
@ REST_Debug
+show the defined debug messages
Int_t GetChar(std::string hint="Press a KEY to continue ...")
Helps to pause the program, printing a message before pausing.
A structure to store the BiPo settings.
A structure to store the configuration settings of Matacq board.
int32_t address
The base memory address of the Matacq board.