68 #define PFX_8_BIT_CONTENT_MASK 0xFF00
69 #define PFX_ASCII_MSG_LEN 0x0100
73 #define PFX_9_BIT_CONTENT_MASK 0xFE00
74 #define PFX_TIME_BIN_IX 0x0E00
75 #define PFX_HISTO_BIN_IX 0x0C00
76 #define PFX_PEDTHR_LIST 0x0A00
77 #define PFX_START_OF_DFRAME 0x0800
78 #define PFX_START_OF_MFRAME 0x0600
79 #define PFX_START_OF_CFRAME 0x0400
83 #define GET_ASCII_LEN(w) (((w)&0x00FF) >> 0)
84 #define PUT_ASCII_LEN(w) (PFX_ASCII_MSG_LEN | ((w)&0x00FF))
88 #define PFX_0_BIT_CONTENT_MASK 0xFFFF
89 #define PFX_END_OF_FRAME 0x000F
90 #define PFX_DEADTIME_HSTAT_BINS 0x000E
91 #define PFX_PEDESTAL_HSTAT 0x000D
92 #define PFX_PEDESTAL_H_MD 0x000C
93 #define PFX_SHISTO_BINS 0x000B
94 #define PFX_CMD_STATISTICS 0x000A
95 #define PFX_START_OF_BUILT_EVENT 0x0009
96 #define PFX_END_OF_BUILT_EVENT 0x0008
97 #define PFX_EVPERIOD_HSTAT_BINS 0x0007
98 #define PFX_SOBE_SIZE 0x0006
99 #define PFX_NULL_CONTENT 0x0000
103 #define PFX_14_BIT_CONTENT_MASK 0xC000
104 #define PFX_CARD_CHIP_CHAN_HIT_IX 0xC000
105 #define PFX_CARD_CHIP_CHAN_HIT_CNT 0x8000
106 #define PFX_CARD_CHIP_CHAN_HISTO 0x4000
110 #define PFX_12_BIT_CONTENT_MASK 0xF000
111 #define PFX_ADC_SAMPLE 0x3000
112 #define PFX_LAT_HISTO_BIN 0x2000
113 #define PFX_CHIP_LAST_CELL_READ 0x1000
117 #define PFX_4_BIT_CONTENT_MASK 0xFFF0
118 #define PFX_START_OF_EVENT 0x00F0
119 #define PFX_END_OF_EVENT 0x00E0
124 #define GET_EVENT_TYPE(w) (((w)&0x0007) >> 0)
125 #define GET_EOE_SIZE(w) (((w)&0x000F) >> 0)
130 #define GET_CARD_IX(w) (((w)&0x3E00) >> 9)
131 #define GET_CHIP_IX(w) (((w)&0x0180) >> 7)
132 #define GET_CHAN_IX(w) (((w)&0x007F) >> 0)
137 #define GET_ADC_DATA(w) (((w)&0x0FFF) >> 0)
138 #define GET_LAT_HISTO_BIN(w) (((w)&0x0FFF) >> 0)
139 #define PUT_LAT_HISTO_BIN(w) (PFX_LAT_HISTO_BIN | (((w)&0x0FFF) >> 0))
140 #define GET_LST_READ_CELL(w) (((w)&0x03FF) >> 0)
141 #define GET_LST_READ_CELL_CHIP_IX(w) (((w)&0x0C00) >> 10)
146 #define GET_TIME_BIN(w) (((w)&0x01FF) >> 0)
147 #define GET_HISTO_BIN(w) (((w)&0x01FF) >> 0)
148 #define GET_PEDTHR_LIST_FEM(w) (((w)&0x01F0) >> 4)
149 #define GET_PEDTHR_LIST_ASIC(w) (((w)&0x000C) >> 2)
150 #define GET_PEDTHR_LIST_MODE(w) (((w)&0x0002) >> 1)
151 #define GET_PEDTHR_LIST_TYPE(w) (((w)&0x0001) >> 0)
152 #define PUT_FVERSION_FEMID(w, fv, id) (((w)&0xFE00) | (((fv)&0x0003) << 7) | (((id)&0x001F) << 0))
153 #define GET_FRAMING_VERSION(w) (((w)&0x0180) >> 7)
154 #define GET_FEMID(w) (((w)&0x001F) >> 0)
157 #define FRAME_PRINT_ALL 0x00000001
158 #define FRAME_PRINT_SIZE 0x00000002
159 #define FRAME_PRINT_HIT_CH 0x00000004
160 #define FRAME_PRINT_HIT_CNT 0x00000008
161 #define FRAME_PRINT_CHAN_DATA 0x00000010
162 #define FRAME_PRINT_HISTO_BINS 0x00000020
163 #define FRAME_PRINT_ASCII 0x00000040
164 #define FRAME_PRINT_FRBND 0x00000080
165 #define FRAME_PRINT_EVBND 0x00000100
166 #define FRAME_PRINT_NULLW 0x00000200
167 #define FRAME_PRINT_HISTO_STAT 0x00000400
168 #define FRAME_PRINT_LISTS 0x00000800
169 #define FRAME_PRINT_LAST_CELL_READ_0 0x00001000
170 #define FRAME_PRINT_LAST_CELL_READ_1 0x00002000
171 #define FRAME_PRINT_LAST_CELL_READ_2 0x00004000
172 #define FRAME_PRINT_LAST_CELL_READ_3 0x00008000
173 #define FRAME_PRINT_EBBND 0x00010000
175 #define MAX_FRAME_SIZE 8192
180 #define MAX_EVENT_SIZE (24 * 4 * 80 * 512 * 2)
182 #define ORIGINAL_MCLIENT 0
183 unsigned char cur_fr[MAX_EVENT_SIZE];
185 #include "TRestRawMultiFEMINOSToSignalProcess.h"
189 #include "TTimeStamp.h"
195 TRestRawMultiFEMINOSToSignalProcess::TRestRawMultiFEMINOSToSignalProcess() { Initialize(); }
197 TRestRawMultiFEMINOSToSignalProcess::TRestRawMultiFEMINOSToSignalProcess(
const char* configFilename)
202 TRestRawMultiFEMINOSToSignalProcess::~TRestRawMultiFEMINOSToSignalProcess() {}
204 void TRestRawMultiFEMINOSToSignalProcess::LoadDetectorSetupData() {
206 cout <<
"'fRunInfo' is nullptr" << endl;
219 RESTDebug <<
"TRestRawMultiFeminos::InitProcess" <<
RESTendl;
224 RESTError <<
"The input file extension should be .aqs" <<
RESTendl;
225 RESTError <<
"Filename : " << fInputFileNames[0] <<
RESTendl;
229 LoadDetectorSetupData();
234 totalBytesReaded = 0;
237 if (fread(&sh,
sizeof(
unsigned short), 1, fInputBinFile) != 1) {
238 printf(
"Error: could not read first prefix.\n");
241 totalBytesReaded +=
sizeof(
unsigned short);
246 if ((sh & PFX_8_BIT_CONTENT_MASK) != PFX_ASCII_MSG_LEN) {
247 printf(
"Error: missing string prefix in 0x%x\n", sh);
250 al = GET_ASCII_LEN(sh);
252 if (!ORIGINAL_MCLIENT) {
254 int z = fread(&tt,
sizeof(
int), 1, fInputBinFile);
256 RESTError <<
"TRestRawMultiFEMINOSToSignalProcess::InitProcess. Problem reading from inputfile"
258 totalBytesReaded +=
sizeof(int);
261 RESTDebug <<
"Timestamp : " << tt <<
" - " << tStart <<
RESTendl;
264 if (ORIGINAL_MCLIENT) {
267 if (fread(&(run_str[0]),
sizeof(
char), al, fInputBinFile) != al) {
268 printf(
"Error: could not read %d characters.\n", al);
271 totalBytesReaded +=
sizeof(char);
274 printf(
"Run string: %s\n", &(run_str[0]));
280 cout <<
"TRestRawMultiFEMINOSToSignalProcess::ProcessEvent" << endl;
284 sh = (
unsigned short*)&(cur_fr[2]);
291 Bool_t endOfEvent =
false;
295 fSignalEvent->SetRunOrigin(fRunOrigin);
296 fSignalEvent->SetSubRunOrigin(fSubRunOrigin);
298 while (!endOfEvent) {
302 if (fread(sh,
sizeof(
unsigned short), 1, fInputBinFile) != 1) {
303 RESTDebug <<
"End of file reached." <<
RESTendl;
308 totalBytesReaded +=
sizeof(
unsigned short);
310 if ((*sh & PFX_0_BIT_CONTENT_MASK) == PFX_START_OF_BUILT_EVENT) {
312 printf(
"***** Start of Built Event *****\n");
314 }
else if ((*sh & PFX_0_BIT_CONTENT_MASK) == PFX_END_OF_BUILT_EVENT) {
316 printf(
"***** End of Built Event *****\n\n");
320 }
else if ((*sh & PFX_0_BIT_CONTENT_MASK) == PFX_SOBE_SIZE) {
322 if (fread((sh + 1),
sizeof(
unsigned short), 2, fInputBinFile) != 2) {
323 printf(
"Error: could not read two short words.\n");
326 totalBytesReaded +=
sizeof(
unsigned short) * 2;
329 fr_sz = (int)(((*(sh + 2)) << 16) | (*(sh + 1)));
337 }
else if (((*sh & PFX_9_BIT_CONTENT_MASK) == PFX_START_OF_DFRAME) ||
338 ((*sh & PFX_9_BIT_CONTENT_MASK) == PFX_START_OF_CFRAME) ||
339 ((*sh & PFX_9_BIT_CONTENT_MASK) == PFX_START_OF_MFRAME)) {
341 if (fread((sh + 1),
sizeof(
unsigned short), 1, fInputBinFile) != 1) {
342 printf(
"Error: could not read short word.\n");
345 totalBytesReaded +=
sizeof(
unsigned short);
348 fr_sz = (int)*(sh + 1);
357 printf(
"Error: cannot interpret short word 0x%x\n", *sh);
364 if (fread(&(cur_fr[fr_offset]),
sizeof(
unsigned short), nb_sh, fInputBinFile) != nb_sh) {
365 printf(
"Error: could not read %d bytes.\n", (nb_sh * 2));
368 totalBytesReaded +=
sizeof(
unsigned short) * nb_sh;
375 endOfEvent = ReadFrame((
void*)&(cur_fr[2]), fr_sz);
379 if (fSignalEvent->GetID() == 0 && fLastEventId != 0) {
380 fSignalEvent->SetID(fLastEventId);
381 fSignalEvent->
SetTime(fLastTimeStamp);
386 cout <<
"------------------------------------------" << endl;
387 cout <<
"Event ID : " << fSignalEvent->GetID() << endl;
388 cout <<
"Time stamp : " << fSignalEvent->GetTimeStamp() << endl;
389 cout <<
"Number of Signals : " << fSignalEvent->GetNumberOfSignals() << endl;
390 cout <<
"------------------------------------------" << endl;
393 for (Int_t n = 0; n < fSignalEvent->GetNumberOfSignals(); n++)
394 cout <<
"Signal N : " << n <<
" daq id : " << fSignalEvent->GetSignal(n)->
GetID() << endl;
399 if (fSignalEvent->GetNumberOfSignals() != 0) {
402 RESTWarning <<
"blank event " << fSignalEvent->GetID() <<
"! skipping..." <<
RESTendl;
410 Bool_t TRestRawMultiFEMINOSToSignalProcess::ReadFrame(
void* fr,
int fr_sz) {
411 Bool_t endOfEvent =
false;
415 unsigned short r0, r1, r2;
416 unsigned short n0, n1;
417 unsigned short cardNumber, chipNumber, daqChannel;
422 p = (
unsigned short*)fr;
428 printf(
"ReadFrame: Frame payload: %d bytes\n", fr_sz);
436 if ((*p & PFX_14_BIT_CONTENT_MASK) == PFX_CARD_CHIP_CHAN_HIT_IX) {
438 fSignalEvent->AddSignal(sgnl);
440 cardNumber = GET_CARD_IX(*p);
441 chipNumber = GET_CHIP_IX(*p);
442 daqChannel = GET_CHAN_IX(*p);
444 if (daqChannel >= 0) {
445 daqChannel += cardNumber * 4 * 72 + chipNumber * 72;
450 printf(
"ReadFrame: Card %02d Chip %01d Daq Channel %02d\n", cardNumber, chipNumber,
460 else if ((*p & PFX_12_BIT_CONTENT_MASK) == PFX_ADC_SAMPLE) {
461 r0 = GET_ADC_DATA(*p);
463 if (showSamples > 0) printf(
"ReadFrame: %03d 0x%04x (%4d)\n", si, r0, r0);
471 else if ((*p & PFX_4_BIT_CONTENT_MASK) == PFX_START_OF_EVENT) {
472 r0 = GET_EVENT_TYPE(*p);
474 printf(
"ReadFrame: -- Start of Event (Type %01d) --\n", r0);
490 printf(
"ReadFrame: Time 0x%04x 0x%04x 0x%04x\n", r2, r1, r0);
491 printf(
"Timestamp: 0x%04x 0x%04x 0x%04x\n", r2, r1, r0);
492 cout <<
"TimeStamp " << tStart + (2147483648 * r2 + 32768 * r1 + r0) * 2e-8 << endl;
505 tmp = (((
unsigned int)n1) << 16) | ((
unsigned int)n0);
507 printf(
"ReadFrame: Event_Count 0x%08x (%d)\n", tmp, tmp);
514 if (fSignalEvent->GetID() == 0) {
515 if (fLastEventId == 0) {
516 fSignalEvent->SetID(tmp);
517 fSignalEvent->
SetTime(tStart + (2147483648 * r2 + 32768 * r1 + r0) * 2e-8);
519 fSignalEvent->SetID(fLastEventId);
520 fSignalEvent->
SetTime(fLastTimeStamp);
525 fLastTimeStamp = tStart + (2147483648 * r2 + 32768 * r1 + r0) * 2e-8;
529 fRunInfo->SetStartTimeStamp(fLastTimeStamp);
533 fRunInfo->SetEndTimeStamp(fLastTimeStamp);
536 fSignalEvent->SetRunOrigin(fRunOrigin);
537 fSignalEvent->SetSubRunOrigin(fSubRunOrigin);
538 }
else if ((*p & PFX_4_BIT_CONTENT_MASK) == PFX_END_OF_EVENT) {
539 tmp = ((
unsigned int)GET_EOE_SIZE(*p)) << 16;
541 tmp = tmp + (
unsigned int)*p;
544 printf(
"ReadFrame: ----- End of Event ----- (size %d bytes)\n", tmp);
547 if (fElectronicsType ==
"SingleFeminos") endOfEvent =
true;
551 else if ((*p & PFX_0_BIT_CONTENT_MASK) == PFX_END_OF_FRAME) {
553 fSignalEvent->AddSignal(sgnl);
556 printf(
"ReadFrame: ----- End of Frame -----\n");
559 }
else if (*p == PFX_START_OF_BUILT_EVENT) {
561 printf(
"ReadFrame: ***** Start of Built Event *****\n");
563 }
else if (*p == PFX_END_OF_BUILT_EVENT) {
565 printf(
"ReadFrame: ***** End of Built Event *****\n\n");
567 }
else if (*p == PFX_SOBE_SIZE) {
577 tmp_i[0] = (int)((r1 << 16) | (r0));
580 printf(
"ReadFrame: ***** Start of Built Event - Size = %d bytes *****\n", tmp_i[0]);
TRestRun * fRunInfo
< Pointer to TRestRun object where to find metadata.
A base class for any REST event.
void SetTime(Double_t time)
A process to read Feminos acquisition cards in single or TCM mode.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
void Initialize() override
Making default settings.
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.
A base class for any process reading a binary external file as input to REST.
virtual void InitProcess() override
To be executed at the beginning of the run (outside event loop)
Int_t fShowSamples
true if need to open all raw files at the beginning
@ REST_Info
+show most of the information for each steps
@ 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.