71 #include "TRestRawFEUDreamToSignalProcess.h"
75 #include "TTimeStamp.h"
79 TRestRawFEUDreamToSignalProcess::TRestRawFEUDreamToSignalProcess() { Initialize(); }
81 TRestRawFEUDreamToSignalProcess::TRestRawFEUDreamToSignalProcess(
const char* configFilename)
86 TRestRawFEUDreamToSignalProcess::~TRestRawFEUDreamToSignalProcess() {
96 Nevent = 0, Nbadevent = 0;
102 RESTInfo <<
"TRestRawFEUDreamToSignalProcess::InitProcess" <<
RESTendl;
104 totalBytesReaded = 0;
109 bool badreadfg =
false;
111 RESTDebug <<
"---------------Start of TRestRawFEUDreamToSignalProcess::ProcessEvent------------"
121 badreadfg = ReadFeuHeaders(Feu);
122 RESTDebug <<
"TRestRawFEUDreamToSignalProcess::ProcessEvent: header read, badreadfg " << badreadfg
124 RESTDebug <<
"TRestRawFEUDreamToSignalProcess::ProcessEvent: event to read EventID " << Feu.EventID
125 <<
" Time " << Feu.TimeStamp <<
" isample " << Feu.isample <<
RESTendl;
129 <<
"TRestRawFEUDreamToSignalProcess::ProcessEvent: Error in reading feu header (bad file or "
130 "end of file), trying to go to the next file"
132 if (GoToNextFile()) {
133 badreadfg = ReadFeuHeaders(Feu);
134 RESTDebug <<
"TRestRawFEUDreamToSignalProcess::ProcessEvent: header read, badreadfg "
136 RESTDebug <<
"TRestRawFEUDreamToSignalProcess::ProcessEvent: event to read EventID "
137 << Feu.EventID <<
" Time " << Feu.TimeStamp <<
" isample " << Feu.isample
145 badreadfg = ReadEvent(Feu);
146 RESTDebug <<
"TRestRawFEUDreamToSignalProcess::ProcessEvent: event read, badreadfg " << badreadfg
149 RESTError <<
"TRestRawFEUDreamToSignalProcess::ProcessEvent: Error in event reading at event "
155 if (badreadfg)
break;
156 if (bad_event) Nbadevent++;
157 if ((Nevent % 100) == 0)
158 cout <<
"TRestRawFEUDreamToSignalProcess::ProcessEvent: " << Nevent
159 <<
" events processed in file, and " << Nbadevent <<
" bad events skipped " << endl;
162 RESTInfo <<
"-- TRestRawFEUDreamToSignalProcess::ProcessEvent ---" <<
RESTendl;
163 RESTInfo <<
"Event ID : " << fSignalEvent->GetID() <<
RESTendl;
164 RESTInfo <<
"Time stamp : " << fSignalEvent->GetTimeStamp() <<
RESTendl;
165 RESTInfo <<
"Number of Signals : " << fSignalEvent->GetNumberOfSignals() <<
RESTendl;
166 RESTInfo <<
"Number of Samples : " << (Feu.isample + 1) <<
RESTendl;
167 RESTInfo <<
"-------------------------------------------------" <<
RESTendl;
171 Feu.isample_prev = -2;
175 if (fSignalEvent->GetNumberOfSignals() == 0) {
176 RESTError <<
"TRestRawFEUDreamToSignalProcess::ProcessEvent: no signal in event" <<
RESTendl;
180 RESTDebug <<
"TRestRawFEUDreamToSignalProcess::ProcessEvent: returning signal event fSignalEvent "
190 bool TRestRawFEUDreamToSignalProcess::ReadEvent(FeuReadOut& Feu) {
191 bool badreadfg =
false;
193 while (!Feu.event_completed) {
194 badreadfg = ReadFeuHeaders(Feu);
195 RESTDebug <<
"TRestRawFEUDreamToSignalProcess::ReadEvent: header read, badreadfg " << badreadfg
198 RESTWarning <<
"TRestRawFEUDreamToSignalProcess::ReadEvent: error in reading FEU headers "
203 badreadfg = ReadDreamData(Feu);
204 RESTDebug <<
"TRestRawFEUDreamToSignalProcess::ReadEvent: data read, badreadfg " << badreadfg
207 RESTError <<
"TRestRawFEUDreamToSignalProcess::ReadEvent: error in reading Dream data "
212 badreadfg = ReadFeuTrailer(Feu);
213 RESTDebug <<
"TRestRawFEUDreamToSignalProcess::ReadEvent: trailer read, badreadfg " << badreadfg
216 RESTError <<
"TRestRawFEUDreamToSignalProcess::ReadEvent: error in reading FEU trailer"
222 RESTInfo <<
"TRestRawFEUDreamToSignalProcess::ReadEvent: Event ID " << Feu.EventID
223 <<
" processed successfully, Time " << Feu.TimeStamp <<
" isample " << Feu.isample <<
RESTendl;
228 bool TRestRawFEUDreamToSignalProcess::ReadFeuHeaders(FeuReadOut& Feu) {
229 if (Feu.FeuHeaderLoaded)
return false;
231 if (!Feu.data_to_treat) {
233 int nbytes = fread((
void*)&(Feu.current_data),
sizeof(Feu.current_data), 1, fInputBinFile);
234 totalBytesReaded +=
sizeof(Feu.current_data);
238 <<
"TRestRawFEUDreamToSignalProcess::ReadFeuHeaders: Problem in reading raw file, ferror "
239 << ferror(fInputBinFile) <<
" feof " << feof(fInputBinFile) <<
" fInputBinFile "
245 Feu.current_data.ntohs_();
246 Feu.data_to_treat =
true;
250 if (Feu.FeuHeaderLine < 8 && Feu.current_data.is_Feu_header()) {
251 if (Feu.FeuHeaderLine == 0) {
252 Feu.zs_mode = Feu.current_data.get_zs_mode();
253 Feu.Id = Feu.current_data.get_Feu_ID();
254 RESTDebug <<
"ReadFeuHeaders: header FeuHeaderLine " << Feu.FeuHeaderLine <<
" ZS mode "
255 << Feu.zs_mode <<
" Id " << Feu.Id <<
RESTendl;
257 }
else if (Feu.FeuHeaderLine == 1) {
258 Feu.EventID = Feu.current_data.get_data();
259 RESTDebug <<
"ReadFeuHeaders: header FeuHeaderLine " << Feu.FeuHeaderLine <<
" EventID "
262 }
else if (Feu.FeuHeaderLine == 2) {
263 Feu.TimeStamp = Feu.current_data.get_data();
264 RESTDebug <<
"ReadFeuHeaders: header FeuHeaderLine " << Feu.FeuHeaderLine <<
" TimeStamp "
267 }
else if (Feu.FeuHeaderLine == 3) {
268 Feu.FineTimeStamp = Feu.current_data.get_finetstp();
269 Feu.isample_prev = Feu.isample;
270 Feu.isample = Feu.current_data.get_sample_ID();
272 Feu.FeuHeaderLoaded =
true;
273 if (Feu.isample != Feu.isample_prev + 1) {
274 if (Feu.isample_prev ==
279 <<
"TRestRawFEUDreamToSignalProcess::ReadFeuHeaders: non continuous sample index "
281 << Feu.isample <<
" prev_isample = " << Feu.isample_prev <<
RESTendl;
285 RESTDebug <<
"ReadFeuHeaders: header FeuHeaderLine " << Feu.FeuHeaderLine <<
" FineTimeStamp "
286 << Feu.FineTimeStamp <<
" isample " << Feu.isample <<
RESTendl;
289 }
else if (Feu.FeuHeaderLine == 4) {
290 Feu.EventID_Op = Feu.current_data.get_data();
291 Feu.EventID += (1 << 12) * Feu.EventID_Op;
292 RESTDebug <<
"ReadFeuHeaders: header FeuHeaderLine " << Feu.FeuHeaderLine <<
" EventID_Op "
295 }
else if (Feu.FeuHeaderLine == 5) {
296 Feu.TimeStamp_Op1 = Feu.current_data.get_data();
297 RESTDebug <<
"ReadFeuHeaders: header FeuHeaderLine " << Feu.FeuHeaderLine <<
" TimeStamp_Op1 "
300 }
else if (Feu.FeuHeaderLine == 6) {
301 Feu.TimeStamp_Op2 = Feu.current_data.get_data();
302 RESTDebug <<
"ReadFeuHeaders: header FeuHeaderLine " << Feu.FeuHeaderLine <<
" TimeStamp_Op2 "
305 }
else if (Feu.FeuHeaderLine == 7) {
306 Feu.TimeStamp_Op3 = Feu.current_data.get_TimeStamp_Op();
307 Feu.TimeStamp += ((
long long)1 << 36) * Feu.TimeStamp_Op3 + (1 << 24) * Feu.TimeStamp_Op2 +
308 (1 << 12) * Feu.TimeStamp_Op1;
309 RESTDebug <<
"ReadFeuHeaders: header FeuHeaderLine " << Feu.FeuHeaderLine <<
" TimeStamp_Op3 "
310 << Feu.TimeStamp_Op3 <<
" TimeStamp " << Feu.TimeStamp <<
RESTendl;
313 Feu.data_to_treat =
false;
316 }
else if (Feu.FeuHeaderLine > 8 && Feu.current_data.is_Feu_header()) {
317 RESTError <<
"TRestRawFEUDreamToSignalProcess::ReadFeuHeaders: too long Feu header part "
320 }
else if (Feu.FeuHeaderLine > 3 && !Feu.current_data.is_Feu_header())
323 if (fread((
void*)&(Feu.current_data),
sizeof(Feu.current_data), 1, fInputBinFile) == 0)
return true;
324 totalBytesReaded +=
sizeof(Feu.current_data);
325 Feu.current_data.ntohs_();
326 Feu.data_to_treat =
true;
330 fSignalEvent->SetID(Feu.EventID);
331 fSignalEvent->
SetTime(tStart + Feu.TimeStamp * 8.E-9);
336 bool TRestRawFEUDreamToSignalProcess::ReadDreamData(FeuReadOut& Feu) {
337 bool got_raw_data_header =
false;
338 bool got_channel_id =
false;
341 if (!Feu.FeuHeaderLoaded) {
343 <<
"TRestRawFEUDreamToSignalProcess::ReadDreamData: error in ReadDreamData, Feu header not loaded"
348 if (!Feu.data_to_treat) {
349 int nbytes = fread((
void*)&(Feu.current_data),
sizeof(Feu.current_data), 1, fInputBinFile);
350 totalBytesReaded +=
sizeof(Feu.current_data);
352 perror(
"TRestRawFEUDreamToSignalProcess::ReadDreamData: no Dream data to read in file");
353 RESTError <<
"TRestRawFEUDreamToSignalProcess::ReadDreamData: problem in reading raw data file, "
355 << ferror(fInputBinFile) <<
" feof " << feof(fInputBinFile) <<
" fInputBinFile "
357 fclose(fInputBinFile);
361 Feu.current_data.ntohs_();
362 Feu.data_to_treat =
true;
366 if (Feu.FeuHeaderLine > 3 && !Feu.current_data.is_Feu_header()) {
367 if (Feu.DataHeaderLine < 4 && Feu.current_data.is_data_header()) {
368 if (Feu.DataHeaderLine == 0) {
369 Feu.TriggerID = Feu.current_data.get_data();
370 RESTDebug <<
"ReadDreamData: header DataHeaderLine " << Feu.DataHeaderLine
371 <<
" TriggerID MSB " << Feu.TriggerID <<
RESTendl;
372 }
else if (Feu.DataHeaderLine == 1) {
373 Feu.TriggerID_ISB = Feu.current_data.get_data();
374 RESTDebug <<
"ReadDreamData: header DataHeaderLine " << Feu.DataHeaderLine
375 <<
" TriggerID_ISB " << Feu.TriggerID_ISB <<
RESTendl;
376 }
else if (Feu.DataHeaderLine == 2) {
377 Feu.TriggerID_LSB = Feu.current_data.get_data();
378 Feu.TriggerID *= (1 << 24);
379 Feu.TriggerID += Feu.TriggerID_LSB + (1 << 12) * Feu.TriggerID_ISB;
380 RESTDebug <<
"ReadDreamData: header DataHeaderLine " << Feu.DataHeaderLine
381 <<
" TriggerID_LSB " << Feu.TriggerID_LSB <<
" TriggerID " << Feu.TriggerID
383 }
else if (Feu.DataHeaderLine == 3) {
384 Feu.asicN = Feu.current_data.get_dream_ID();
387 Feu.DataTrailerLine = 0;
389 got_raw_data_header =
true;
390 RESTDebug <<
"ReadDreamData: header DataHeaderLine " << Feu.DataHeaderLine <<
" asicN "
393 Feu.DataHeaderLine++;
394 Feu.data_to_treat =
false;
396 }
else if (Feu.DataHeaderLine > 3 && Feu.current_data.is_data_header()) {
398 RESTError <<
"TRestRawFEUDreamToSignalProcess::ReadDreamData: too many data header lines, "
403 }
else if (Feu.current_data.is_data() &&
405 if (!got_raw_data_header) {
408 <<
"TRestRawFEUDreamToSignalProcess::ReadDreamData: data lines without header in "
412 Feu.channelN = ichannel;
413 if (!bad_event && Feu.channelN > -1 && Feu.channelN < NstripMax &&
414 Feu.isample < fMinPoints) {
415 Feu.physChannel = Feu.asicN * NstripMax + Feu.channelN;
418 if (Feu.physChannel < MaxPhysChannel) {
419 Int_t sgnlIndex = fSignalEvent->GetSignalIndex(Feu.physChannel);
420 if (sgnlIndex == -1) {
421 sgnlIndex = fSignalEvent->GetNumberOfSignals();
423 sgnl.SetSignalID(Feu.physChannel);
424 fSignalEvent->AddSignal(sgnl);
427 Feu.current_data.get_data());
430 <<
"TRestRawFEUDreamToSignalProcess::ReadDreamData: too large physical Channel "
432 "non-ZS mode , Feu.physChannel= "
433 << Feu.physChannel <<
" > MaxPhysChannel " << MaxPhysChannel <<
RESTendl;
434 RESTExtreme <<
"ReadDreamData: nonZS physChannel " << Feu.physChannel <<
" get_data "
435 << Feu.current_data.get_data() <<
RESTendl;
438 Feu.data_to_treat =
false;
440 }
else if (Feu.current_data.is_data_zs() && Feu.zs_mode) {
441 if (got_raw_data_header) {
444 <<
"TRestRawFEUDreamToSignalProcess::ReadDreamData: data lines with header in ZS "
448 if (!got_channel_id && Feu.current_data.is_channel_ID()) {
449 ichannel = Feu.current_data.get_channel_ID();
450 Feu.channelN = ichannel;
451 Feu.asicN = Feu.current_data.get_dream_ID();
452 Feu.physChannel = Feu.asicN * NstripMax + Feu.channelN;
453 got_channel_id =
true;
454 if (Feu.channelN < 0 || Feu.channelN >= NstripMax) {
456 <<
"TRestRawFEUDreamToSignalProcess::ReadDreamData: too large channel number in "
458 "mode , Feu.channelN= "
459 << Feu.channelN <<
" > MaxPhysChannel " << MaxPhysChannel <<
RESTendl;
462 RESTExtreme <<
"ReadDreamData: ZS header physChannel " << Feu.physChannel <<
" asicN "
463 << Feu.asicN <<
" ichannel " << ichannel <<
RESTendl;
465 got_channel_id =
false;
466 if (!bad_event && Feu.channelN > -1 && Feu.channelN < NstripMax &&
467 Feu.isample < fMinPoints) {
468 Feu.channel_data = Feu.current_data.get_data();
470 RESTExtreme <<
"ReadDreamData: ZS data get_data " << Feu.current_data.get_data()
474 if (Feu.physChannel < MaxPhysChannel) {
475 Int_t sgnlIndex = fSignalEvent->GetSignalIndex(Feu.physChannel);
476 if (sgnlIndex == -1) {
477 sgnlIndex = fSignalEvent->GetNumberOfSignals();
479 sgnl.SetSignalID(Feu.physChannel);
480 fSignalEvent->AddSignal(sgnl);
485 <<
"TRestRawFEUDreamToSignalProcess::ReadDreamData: too large physical Channel in ZS "
486 "mode , Feu.physChannel= "
487 << Feu.physChannel <<
" > MaxPhysChannel " << MaxPhysChannel <<
RESTendl;
488 Feu.data_to_treat =
false;
490 }
else if (Feu.current_data.is_data_trailer()) {
492 if (ichannel != NstripMax && !Feu.zs_mode) {
495 <<
"TRestRawFEUDreamToSignalProcess::ReadDreamData: trailer with missing channel "
496 "numbers in non-ZS mode, ichannel "
500 if (got_channel_id && Feu.zs_mode) {
503 <<
"TRestRawFEUDreamToSignalProcess::ReadDreamData: trailer with channel Id without "
504 "channel data in ZS data, got_channel_id true"
509 if (Feu.DataTrailerLine == 0) {
510 Feu.CMN = Feu.current_data.get_data();
511 RESTDebug <<
"ReadDreamData: trailer DataTrailerLine " << Feu.DataTrailerLine <<
" CMN "
513 }
else if (Feu.DataTrailerLine == 1) {
514 Feu.CMN_rest = Feu.current_data.get_data();
515 RESTDebug <<
"ReadDreamData: trailer DataTrailerLine " << Feu.DataTrailerLine
516 <<
" CMN_rest " << Feu.CMN_rest <<
RESTendl;
517 }
else if (Feu.DataTrailerLine == 2) {
518 Feu.Cell_ID_MSB = Feu.current_data.get_data();
519 RESTDebug <<
"ReadDreamData: trailer DataTrailerLine " << Feu.DataTrailerLine
520 <<
" Cell_ID_MSB " << Feu.Cell_ID_MSB <<
RESTendl;
521 }
else if (Feu.DataTrailerLine == 3) {
522 Feu.Cell_ID_ISB = Feu.current_data.get_data();
523 RESTDebug <<
"ReadDreamData: trailer DataTrailerLine " << Feu.DataTrailerLine
524 <<
" Cell_ID_ISB " << Feu.Cell_ID_ISB <<
RESTendl;
525 }
else if (Feu.DataTrailerLine == 4) {
526 Feu.Cell_ID_LSB = Feu.current_data.get_data();
527 Feu.Cell_ID = Feu.Cell_ID_LSB + (1 << 12) * Feu.Cell_ID_ISB +
528 ((
long long)1 << 24) * Feu.Cell_ID_MSB;
529 RESTDebug <<
"ReadDreamData: trailer DataTrailerLine " << Feu.DataTrailerLine
530 <<
" Cell_ID_LSB " << Feu.Cell_ID_LSB <<
" Cell_ID " << Feu.Cell_ID <<
RESTendl;
531 Feu.DataHeaderLine = 0;
532 got_raw_data_header =
false;
535 Feu.DataTrailerLine++;
536 Feu.data_to_treat =
false;
538 }
else if (Feu.DataTrailerLine > 4 && Feu.current_data.is_data_trailer()) {
540 RESTError <<
"TRestRawFEUDreamToSignalProcess::ReadDreamData: too many data trailer lines, "
545 }
else if (Feu.current_data.is_final_trailer())
549 if (fread((
char*)&(Feu.current_data),
sizeof(Feu.current_data), 1, fInputBinFile) == 0)
return true;
550 totalBytesReaded +=
sizeof(Feu.current_data);
551 Feu.current_data.ntohs_();
552 Feu.data_to_treat =
true;
558 bool TRestRawFEUDreamToSignalProcess::ReadFeuTrailer(FeuReadOut& Feu) {
559 if (!Feu.data_to_treat) {
560 int nbytes = fread((
void*)&(Feu.current_data),
sizeof(Feu.current_data), 1, fInputBinFile);
561 totalBytesReaded +=
sizeof(Feu.current_data);
563 perror(
"TRestRawFEUDreamToSignalProcess::ReadFeuTrailer: can't read new data from file");
565 <<
"TRestRawFEUDreamToSignalProcess::ReadFeuTrailer: can't read new data from file, ferror "
566 << ferror(fInputBinFile) <<
" feof " << feof(fInputBinFile) <<
" fInputBinFile "
568 fclose(fInputBinFile);
571 RESTDebug <<
"TRestRawFEUDreamToSignalProcess::ReadFeuTrailer: Reading FeuTrailer ok, nbytes "
573 Feu.current_data.ntohs_();
574 Feu.data_to_treat =
true;
578 if (Feu.current_data.is_final_trailer()) {
579 if (Feu.channelN != 0) {
581 RESTError <<
"TRestRawFEUDreamToSignalProcess::ReadFeuTrailer: channel number not NULL in "
587 if (Feu.current_data.is_end_of_event()) {
588 if (Feu.isample != (fMinPoints - 1)) {
590 <<
"TRestRawFEUDreamToSignalProcess::ReadFeuTrailer: not all samples read at end of "
592 << Feu.isample <<
" MinPoints " << fMinPoints <<
RESTendl;
595 Feu.event_completed =
true;
598 Feu.FeuHeaderLine = 0;
599 Feu.FeuHeaderLoaded =
false;
601 Feu.data_to_treat =
false;
604 int z = fread((
void*)&(Feu.current_data),
sizeof(Feu.current_data), 1, fInputBinFile);
606 RESTError <<
"TRestRawFEUDreamToSignalProcess::ReadFeuTrailer. Error reading file"
608 totalBytesReaded +=
sizeof(Feu.current_data);
612 if (fread((
void*)&(Feu.current_data),
sizeof(Feu.current_data), 1, fInputBinFile) == 0)
return true;
613 totalBytesReaded +=
sizeof(Feu.current_data);
614 Feu.current_data.ntohs_();
615 Feu.data_to_treat =
true;
A base class for any REST event.
void SetTime(Double_t time)
An process to read binary data from FEUDream electronics.
void Initialize() override
Making default settings.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
void AddChargeToSignal(Int_t sgnlID, Int_t bin, Short_t value)
It defines a Short_t array with a physical parameter that evolves in time using a fixed time bin.
A base class for any process reading a binary external file as input to REST.
void Initialize() override
Making default settings.
@ REST_Info
+show most of the information for each steps
@ REST_Debug
+show the defined debug messages