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
183unsigned char cur_fr[MAX_EVENT_SIZE];
185#include "TRestRawMultiFEMINOSToSignalProcess.h"
189#include "TTimeStamp.h"
195TRestRawMultiFEMINOSToSignalProcess::TRestRawMultiFEMINOSToSignalProcess() {
Initialize(); }
197TRestRawMultiFEMINOSToSignalProcess::TRestRawMultiFEMINOSToSignalProcess(
const char* configFilename)
202TRestRawMultiFEMINOSToSignalProcess::~TRestRawMultiFEMINOSToSignalProcess() {}
204void 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();
237 if (fread(&sh,
sizeof(
unsigned short), 1, fInputBinFile) != 1) {
238 printf(
"Error: could not read first prefix.\n");
241 totalbytesRead +=
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 totalbytesRead +=
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 totalbytesRead +=
sizeof(char);
274 printf(
"Run string: %s\n", &(run_str[0]));
280 cout <<
"TRestRawMultiFEMINOSToSignalProcess::ProcessEvent" << endl;
285 sh = (
unsigned short*)&(cur_fr[2]);
292 Bool_t endOfEvent =
false;
296 fSignalEvent->SetRunOrigin(fRunOrigin);
297 fSignalEvent->SetSubRunOrigin(fSubRunOrigin);
299 while (!endOfEvent) {
303 if (fread(sh,
sizeof(
unsigned short), 1, fInputBinFile) != 1) {
304 RESTDebug <<
"End of file reached." <<
RESTendl;
309 totalbytesRead +=
sizeof(
unsigned short);
311 if ((*sh & PFX_0_BIT_CONTENT_MASK) == PFX_START_OF_BUILT_EVENT) {
313 printf(
"***** Start of Built Event *****\n");
315 }
else if ((*sh & PFX_0_BIT_CONTENT_MASK) == PFX_END_OF_BUILT_EVENT) {
317 printf(
"***** End of Built Event *****\n\n");
321 }
else if ((*sh & PFX_0_BIT_CONTENT_MASK) == PFX_SOBE_SIZE) {
323 if (fread((sh + 1),
sizeof(
unsigned short), 2, fInputBinFile) != 2) {
324 printf(
"Error: could not read two short words.\n");
327 totalbytesRead +=
sizeof(
unsigned short) * 2;
330 fr_sz = (int)(((*(sh + 2)) << 16) | (*(sh + 1)));
338 }
else if (((*sh & PFX_9_BIT_CONTENT_MASK) == PFX_START_OF_DFRAME) ||
339 ((*sh & PFX_9_BIT_CONTENT_MASK) == PFX_START_OF_CFRAME) ||
340 ((*sh & PFX_9_BIT_CONTENT_MASK) == PFX_START_OF_MFRAME)) {
342 if (fread((sh + 1),
sizeof(
unsigned short), 1, fInputBinFile) != 1) {
343 printf(
"Error: could not read short word.\n");
346 totalbytesRead +=
sizeof(
unsigned short);
349 fr_sz = (int)*(sh + 1);
358 printf(
"Error: cannot interpret short word 0x%x\n", *sh);
365 if (fread(&(cur_fr[fr_offset]),
sizeof(
unsigned short), nb_sh, fInputBinFile) != nb_sh) {
366 printf(
"Error: could not read %d bytes.\n", (nb_sh * 2));
369 totalbytesRead +=
sizeof(
unsigned short) * nb_sh;
376 endOfEvent = ReadFrame((
void*)&(cur_fr[2]), fr_sz);
380 if (fSignalEvent->GetID() == 0 && fLastEventId != 0) {
381 fSignalEvent->SetID(fLastEventId);
382 fSignalEvent->
SetTime(fLastTimeStamp);
387 cout <<
"------------------------------------------" << endl;
388 cout <<
"Event ID : " << fSignalEvent->GetID() << endl;
389 cout <<
"Time stamp : " << fSignalEvent->GetTimeStamp() << endl;
390 cout <<
"Number of Signals : " << fSignalEvent->GetNumberOfSignals() << endl;
391 cout <<
"------------------------------------------" << endl;
394 for (Int_t n = 0; n < fSignalEvent->GetNumberOfSignals(); n++)
395 cout <<
"Signal N : " << n <<
" daq id : " << fSignalEvent->GetSignal(n)->
GetID() << endl;
400 if (fSignalEvent->GetNumberOfSignals() != 0) {
403 RESTWarning <<
"blank event " << fSignalEvent->GetID() <<
"! skipping..." <<
RESTendl;
411Bool_t TRestRawMultiFEMINOSToSignalProcess::ReadFrame(
void* fr,
int fr_sz) {
412 Bool_t endOfEvent =
false;
416 unsigned short r0, r1, r2;
417 unsigned short n0, n1;
418 unsigned short cardNumber, chipNumber, daqChannel;
423 p = (
unsigned short*)fr;
429 printf(
"ReadFrame: Frame payload: %d bytes\n", fr_sz);
437 if ((*p & PFX_14_BIT_CONTENT_MASK) == PFX_CARD_CHIP_CHAN_HIT_IX) {
439 fSignalEvent->AddSignal(sgnl);
441 cardNumber = GET_CARD_IX(*p);
442 chipNumber = GET_CHIP_IX(*p);
443 daqChannel = GET_CHAN_IX(*p);
445 if (daqChannel >= 0) {
446 daqChannel += cardNumber * 4 * 72 + chipNumber * 72;
451 printf(
"ReadFrame: Card %02d Chip %01d Daq Channel %02d\n", cardNumber, chipNumber,
461 else if ((*p & PFX_12_BIT_CONTENT_MASK) == PFX_ADC_SAMPLE) {
462 r0 = GET_ADC_DATA(*p);
464 if (showSamples > 0) printf(
"ReadFrame: %03d 0x%04x (%4d)\n", si, r0, r0);
472 else if ((*p & PFX_4_BIT_CONTENT_MASK) == PFX_START_OF_EVENT) {
473 r0 = GET_EVENT_TYPE(*p);
475 printf(
"ReadFrame: -- Start of Event (Type %01d) --\n", r0);
491 printf(
"ReadFrame: Time 0x%04x 0x%04x 0x%04x\n", r2, r1, r0);
492 printf(
"Timestamp: 0x%04x 0x%04x 0x%04x\n", r2, r1, r0);
493 cout <<
"TimeStamp " << tStart + (2147483648 * r2 + 32768 * r1 + r0) * 2e-8 << endl;
506 tmp = (((
unsigned int)n1) << 16) | ((
unsigned int)n0);
508 printf(
"ReadFrame: Event_Count 0x%08x (%d)\n", tmp, tmp);
515 if (fSignalEvent->GetID() == 0) {
516 if (fLastEventId == 0) {
517 fSignalEvent->SetID(tmp);
518 fSignalEvent->
SetTime(tStart + (2147483648 * r2 + 32768 * r1 + r0) * 2e-8);
520 fSignalEvent->SetID(fLastEventId);
521 fSignalEvent->
SetTime(fLastTimeStamp);
526 fLastTimeStamp = tStart + (2147483648 * r2 + 32768 * r1 + r0) * 2e-8;
530 fRunInfo->SetStartTimeStamp(fLastTimeStamp);
534 fRunInfo->SetEndTimeStamp(fLastTimeStamp);
537 fSignalEvent->SetRunOrigin(fRunOrigin);
538 fSignalEvent->SetSubRunOrigin(fSubRunOrigin);
539 }
else if ((*p & PFX_4_BIT_CONTENT_MASK) == PFX_END_OF_EVENT) {
540 tmp = ((
unsigned int)GET_EOE_SIZE(*p)) << 16;
542 tmp = tmp + (
unsigned int)*p;
545 printf(
"ReadFrame: ----- End of Event ----- (size %d bytes)\n", tmp);
548 if (fElectronicsType ==
"SingleFeminos") endOfEvent =
true;
552 else if ((*p & PFX_0_BIT_CONTENT_MASK) == PFX_END_OF_FRAME) {
554 fSignalEvent->AddSignal(sgnl);
557 printf(
"ReadFrame: ----- End of Frame -----\n");
560 }
else if (*p == PFX_START_OF_BUILT_EVENT) {
562 printf(
"ReadFrame: ***** Start of Built Event *****\n");
564 }
else if (*p == PFX_END_OF_BUILT_EVENT) {
566 printf(
"ReadFrame: ***** End of Built Event *****\n\n");
568 }
else if (*p == PFX_SOBE_SIZE) {
578 tmp_i[0] = (int)((r1 << 16) | (r0));
581 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.