81#include "TRestRawBiPoToSignalProcess.h"
85#include "TTimeStamp.h"
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 totalbytesRead += 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;
149 fSignalEvent->SetRunOrigin(fRunOrigin);
150 fSignalEvent->SetSubRunOrigin(fSubRunOrigin);
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 totalbytesRead += 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;
175 RESTError <<
"TRestRawBiPoToSignalProcess::ProcessEvent." <<
RESTendl;
176 RESTError <<
"Board index not found!" <<
RESTendl;
181 for (
int nch = 0; nch <
fMatacqBoard[bIndex].nChannels; nch++) {
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 totalbytesRead +=
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 totalbytesRead +=
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 totalbytesRead +=
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 totalbytesRead +=
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 totalbytesRead +=
sizeof(int32_t);
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 totalbytesRead +=
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 totalbytesRead +=
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 totalbytesRead += 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 totalbytesRead += 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 totalbytesRead +=
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 totalbytesRead +=
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 totalbytesRead +=
sizeof(int32_t);
353 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
354 printf(
"Error: could not read Posttrig.\n");
357 totalbytesRead +=
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 totalbytesRead +=
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 totalbytesRead +=
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;
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;
396 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
397 printf(
"Error: could not read BiPo trigger address.\n");
400 totalbytesRead +=
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 totalbytesRead +=
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 totalbytesRead +=
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 totalbytesRead += 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 totalbytesRead += 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 totalbytesRead += 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 totalbytesRead +=
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 totalbytesRead +=
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 totalbytesRead +=
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;
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;
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;
487 if (fread(&tmp,
sizeof(int32_t), 1, fInputBinFile) != 1) {
488 printf(
"Error: could not read tmp .\n");
491 totalbytesRead +=
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 totalbytesRead +=
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 totalbytesRead +=
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 totalbytesRead +=
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 totalbytesRead +=
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 totalbytesRead += data_size *
sizeof(uint16_t);
561 return board.ch_shifts[channel] + board.nChannels * bin;
573 for (
int n = 0; n <
fNBoards; n++) {
577 RESTMetadata <<
" - Enabled channels: " <<
fMatacqBoard[n].en_ch[0] <<
" - "
580 RESTMetadata <<
" - Trigger channels: " <<
fMatacqBoard[n].trg_ch[0] <<
" - "
594 RESTMetadata <<
" - Trigger channels: " <<
fBiPoSettings[n].Trig_Chan[0] <<
" - "
597 RESTMetadata <<
" - Level 1 [mV]: " <<
fBiPoSettings[n].Level1_mV[0] <<
" - "
600 RESTMetadata <<
" - Level 2 [mV]: " <<
fBiPoSettings[n].Level2_mV[0] <<
" - "
608 RESTMetadata <<
"+++++++++++++++++++++++++++++++++++++++++++++++++" <<
RESTendl;
TRestRun * fRunInfo
< Pointer to TRestRun object where to find metadata.
A base class for any REST event.
void SetTime(Double_t time)
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,...
std::vector< BiPoSettings > fBiPoSettings
A vector of BiPo settings.
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.
Int_t fNBoards
The number of Matacq boards present on the setup.
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.
Int_t fEventCounter
A temporary counter used to define the event id.
std::vector< MatacqBoard > fMatacqBoard
A vector of Matacq boards that contain the information of each card.
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.