60#include "TRestRawAFTERToSignalProcess.h"
64#include "TTimeStamp.h"
124 char runUid[21], initTime[21];
125 int z = fread(runUid, 1, 20, fInputBinFile);
126 if (z == 0) RESTError <<
"TRestRawAFTERToSignalProcess. Problems reading input file." <<
RESTendl;
128 sprintf(initTime,
"%s", runUid);
129 printf(
"File UID is %s \n", initTime);
130 totalbytesRead =
sizeof(runUid);
132 int year, day, month, hour, minute, second;
133 sscanf(runUid,
"R%d.%02d.%02d-%02d:%02d:%02d", &year, &month, &day, &hour, &minute, &second);
134 printf(
"R%d_%02d_%02d-%02d_%02d_%02d\n", year, month, day, hour, minute, second);
135 TTimeStamp tS(year, month, day, hour, minute, second);
136 tStart = tS.AsDouble();
137 cout << tStart << endl;
146 DataPacketHeader pHeader;
152 if (fread(&head,
sizeof(EventHeader), 1, fInputBinFile) != 1) {
153 fclose(fInputBinFile);
154 cout <<
"Error reading event header :-(" << endl;
155 cout <<
"... or end of file found :-)" << endl;
159 head.eventSize = ntohl(head.eventSize);
160 head.eventNumb = ntohl(head.eventNumb);
162 payload = head.eventSize;
163 frameBits =
sizeof(head);
165 RESTDebug <<
"Event number from header --> 0x" << std::hex << head.eventNumb << std::dec <<
RESTendl;
166 RESTDebug <<
" event header size " <<
sizeof(head) <<
RESTendl;
167 RESTDebug <<
" total rawdata size 0x" << std::hex << head.eventSize << std::dec <<
RESTendl;
168 RESTDebug <<
"Payload " << payload <<
RESTendl;
170 fSignalEvent->SetID(head.eventNumb);
179 uint32_t eventTime, deltaTime;
181 int tempAsic1, tempAsic2, sampleCountRead, pay;
189 while (frameBits < payload) {
190 int x = fread(&pHeader,
sizeof(DataPacketHeader), 1, fInputBinFile);
192 RESTError <<
"TRestRawAFTERToSignalProcess::ProcessEvent. Problems reading input file."
194 frameBits +=
sizeof(DataPacketHeader);
198 th = ntohs(pHeader.ts_h);
199 tl = ntohs(pHeader.ts_l);
200 eventTime = th << 16 | tl;
202 if (eventTime > prevTime)
203 deltaTime = eventTime - prevTime;
205 deltaTime = (0xFFFFFFFF - prevTime) + eventTime;
207 reducedTime += deltaTime;
210 fSignalEvent->
SetTime(tStart + reducedTime * 2.E-8);
212 prevTime = eventTime;
215 RESTDebug <<
"Timestamp: " << eventTime <<
RESTendl;
218 RESTDebug <<
"******Event data packet header:******" <<
RESTendl;
220 RESTDebug <<
"Size " << ntohs(pHeader.size) <<
RESTendl;
222 RESTDebug <<
"Event data packet header: " <<
RESTendl;
223 RESTDebug << std::hex <<
"Size 0x" << ntohs(pHeader.size) <<
RESTendl;
224#ifdef NEW_DAQ_T2K_2_X
225 RESTDebug <<
"DCC 0x" << ntohs(pHeader.dcc) <<
RESTendl;
227 RESTDebug <<
"Hdr word 0x" << ntohs(pHeader.hdr) <<
RESTendl;
228 RESTDebug <<
"Args 0x" << ntohs(pHeader.args) <<
RESTendl;
229 RESTDebug <<
"TS_H 0x" << ntohs(pHeader.ts_h) <<
RESTendl;
230 RESTDebug <<
"TS_L 0x" << ntohs(pHeader.ts_l) <<
RESTendl;
231 RESTDebug <<
"Ecnt 0x" << ntohs(pHeader.ecnt) <<
RESTendl;
232 RESTDebug <<
"Scnt 0x" << ntohs(pHeader.scnt) << std::dec <<
RESTendl;
234#ifdef NEW_DAQ_T2K_2_X
235 RESTDebug <<
"RawDCC Head 0x" << std::hex << ntohs(pHeader.dcc) << std::dec <<
" Version "
236 << GET_EVENT_TYPE(ntohs(pHeader.dcc));
237 RESTDebug <<
" Flag " << ((ntohs(pHeader.dcc) & 0x3000) >> 12);
238 RESTDebug <<
" RT " << ((ntohs(pHeader.dcc) & 0x0C00) >> 10) <<
" DCCInd "
239 << ((ntohs(pHeader.dcc) & 0x03F0) >> 4);
240 RESTDebug <<
" FEMInd " << (ntohs(pHeader.dcc) & 0x000F) <<
RESTendl;
242 RESTDebug <<
"FEM0Ind " << ntohs(pHeader.hdr) <<
" Type " << ((ntohs(pHeader.hdr) & 0xF000) >> 12);
243 RESTDebug <<
" L " << ((ntohs(pHeader.hdr) & 0x0800) >> 11);
244 RESTDebug <<
" U " << ((ntohs(pHeader.hdr) & 0x0800) >> 10) <<
" FECFlags "
245 << ((ntohs(pHeader.hdr) & 0x03F0) >> 4);
246 RESTDebug <<
" Index " << (ntohs(pHeader.hdr) & 0x000F) <<
RESTendl;
248 RESTDebug <<
"RawFEM 0x" << std::hex << ntohs(pHeader.args) << std::dec <<
" M "
249 << ((ntohs(pHeader.args) & 0x8000) >> 15);
250 RESTDebug <<
" N " << ((ntohs(pHeader.args) & 0x4000) >> 14) <<
" Zero "
251 << ((ntohs(pHeader.args) & 0x1000) >> 13);
252 RESTDebug <<
" Arg2 " << GET_RB_ARG2(ntohs(pHeader.args)) <<
" Arg2 "
253 << GET_RB_ARG1(ntohs(pHeader.args)) <<
RESTendl;
254 RESTDebug <<
"TimeStampH " << ntohs(pHeader.ts_h) <<
RESTendl;
255 RESTDebug <<
"TimeStampL " << ntohs(pHeader.ts_l) <<
RESTendl;
256 RESTDebug <<
"RawEvType 0x" << std::hex << ntohs(pHeader.ecnt) << std::dec <<
" EvTy "
257 << GET_EVENT_TYPE(ntohs(pHeader.ecnt));
258 RESTDebug <<
" EventCount " << GET_EVENT_COUNT(ntohs(pHeader.ecnt)) <<
RESTendl;
259 RESTDebug <<
"Samples " << ntohs(pHeader.scnt) <<
RESTendl;
262 tempAsic1 = GET_RB_ARG1(ntohs(pHeader.args));
263 tempAsic2 = GET_RB_ARG2(ntohs(pHeader.args));
264 channel = tempAsic1 / 6;
265 asicN = (10 * (tempAsic1 % 6) / 2 + tempAsic2) % 4;
266 fecN = (10 * (tempAsic1 % 6) / 2 + tempAsic2) / 4;
268 RESTDebug <<
" channel " << channel <<
" asic " << asicN <<
" fec " << fecN <<
RESTendl;
270 sampleCountRead = ntohs(pHeader.scnt);
271 pay = sampleCountRead % 2;
274 if (channel > 2 && channel < 15) {
275 physChannel = channel - 3;
276 }
else if (channel > 15 && channel < 28) {
277 physChannel = channel - 4;
278 }
else if (channel > 28 && channel < 53) {
279 physChannel = channel - 5;
280 }
else if (channel > 53 && channel < 66) {
281 physChannel = channel - 6;
282 }
else if (channel > 66) {
283 physChannel = channel - 7;
286 if (physChannel >= 0)
293 physChannel = fecN * 72 * 4 + asicN * 72 + physChannel;
300 if (sampleCountRead < 9) isData =
false;
301 for (
int i = 0; i < sampleCountRead; i++) {
302 int y = fread(&dat,
sizeof(uint16_t), 1, fInputBinFile);
304 RESTError <<
"TRestRawAFTERToSignalProcess::ProcessEvent. Problems reading input file."
306 frameBits +=
sizeof(dat);
309 std::bitset<16> bs(data);
312 if (((data & 0xFE00) >> 9) == 8) {
313 timeBin = GET_CELL_INDEX(data);
314 if (timeBin == 511) isData =
false;
315 RESTDebug << data <<
" Time bin " << timeBin <<
RESTendl;
316 }
else if ((((data & 0xF000) >> 12) == 0) && isData) {
318 RESTDebug <<
"Time bin " << timeBin <<
" ADC: " << data <<
RESTendl;
325 int z = fread(&dat,
sizeof(uint16_t), 1, fInputBinFile);
327 RESTError <<
"TRestRawAFTERToSignalProcess::ProcessEvent. Problems reading input file."
329 frameBits +=
sizeof(uint16_t);
332 int w = fread(&pEnd,
sizeof(DataPacketEnd), 1, fInputBinFile);
334 RESTError <<
"TRestRawAFTERToSignalProcess::ProcessEvent. Problems reading input file."
336 frameBits +=
sizeof(DataPacketEnd);
339 << sampleCountRead *
sizeof(uint16_t) +
sizeof(DataPacketHeader) +
sizeof(DataPacketEnd) +
340 sampleCountRead % 2 *
sizeof(uint16_t)
341 <<
" vs HeadSize " << ntohs(pHeader.size) <<
" Diff "
342 << ntohs(pHeader.size) - (sampleCountRead +
sizeof(DataPacketHeader) +
343 sizeof(DataPacketEnd) + sampleCountRead % 2)
345 RESTDebug <<
"Trailer_H " << ntohs(pEnd.crc1) <<
" Trailer_L " << ntohs(pEnd.crc2) <<
RESTendl;
346 RESTDebug <<
"Trailer " << eventTime <<
"\n" <<
RESTendl;
349 totalbytesRead += frameBits;
354 RESTDebug <<
"End of event " <<
RESTendl;
A base class for any REST event.
void SetTime(Double_t time)
A process to read binary files produced with AFTER electronics.
~TRestRawAFTERToSignalProcess()
Constructor loading data from a config file.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
void InitProcess() override
Process initialization.
TRestRawAFTERToSignalProcess()
Default constructor.
void Initialize() override
Function to initialize input/output event members and define the section name.
void AddChargeToSignal(Int_t sgnlID, Int_t bin, Short_t value)
void Initialize() override
Making default settings.