REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestRawUSTCToSignalProcess.h
1 /*************************************************************************
2  * This file is part of the REST software framework. *
3  * *
4  * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5  * For more information see http://gifna.unizar.es/trex *
6  * *
7  * REST is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * REST is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have a copy of the GNU General Public License along with *
18  * REST in $REST_PATH/LICENSE. *
19  * If not, see http://www.gnu.org/licenses/. *
20  * For the list of contributors see $REST_PATH/CREDITS. *
21  *************************************************************************/
22 
23 #ifndef RestCore_TRestRawUSTCToSignalProcess
24 #define RestCore_TRestRawUSTCToSignalProcess
25 
26 #include <map>
27 
28 #include "TRestRawToSignalProcess.h"
29 
30 // #define V3_Readout_Format_Long
31 #define V4_Readout_Format
32 // #define Incoherent_Event_Generation
33 
34 #ifdef V3_Readout_Format_Long
35 #define DATA_SIZE 1048
36 #define DATA_OFFSET (DATA_SIZE - 512 * 2 - 4)
37 #define PROTOCOL_SIZE 4
38 #endif
39 
40 #ifdef V3_Readout_Format_Short
41 #define DATA_SIZE 1040
42 #define DATA_OFFSET (DATA_SIZE - 512 * 2 - 4)
43 #define PROTOCOL_SIZE 4
44 #endif
45 
46 #ifdef V4_Readout_Format
47 #define DATA_SIZE 1036
48 #define DATA_OFFSET 6
49 #define HEADER_SIZE 36
50 #define ENDING_SIZE 16
51 #define PROTOCOL_SIZE 4
52 #endif
53 
54 struct USTCDataFrame {
55  // a signal-level data frame
56  // e.g.
57  // EEEE | E0A0 | 246C0686 | 0001 | 2233 | (A098)(A09C)... | FFFF
58  // header | board number | event time | channel id(0~63) | event id | [chip id
59  // + data(0~4095)]*512 | ending
60  USTCDataFrame() {
61  boardId = 0;
62  chipId = 0;
63  readoutType = 0;
64  eventTime = 0;
65  channelId = 0;
66  evId = -1;
67  signalId = 0;
68  }
69  UChar_t data[1048]; // the size of a signal frame
70 
71  Int_t boardId; // 0~n
72  Int_t chipId; // 0~3 aget number
73  Int_t readoutType; // 2:full readout 1:partial readout
74  Long64_t eventTime; // event time in na
75  Int_t channelId; // 0~63 channels
76  Int_t evId; // if equals -1, this data frame is used but have not been
77  // re-filled
78 
79  Int_t signalId;
80  Int_t dataPoint[512];
81 };
82 
85  private:
86 #ifndef __CINT__
87  TRestRawSignal sgnl;
88 
89  UChar_t fHeader[64];
90  UChar_t fEnding[32];
91 
92  std::vector<std::vector<USTCDataFrame>> fEventBuffer;
93  int nBufferedEvent;
94  int fCurrentFile = 0;
95  int fCurrentEvent = -1;
96  int fCurrentBuffer = 0;
97  int fLastBufferedId = 0;
98  std::vector<int> errorevents;
99  int unknownerrors = 0;
100 
101  Long64_t fTimeOffset = 0;
102  std::set<int> fChannelOffset;
103 #endif
104 
105  public:
106  void InitProcess() override;
107  void Initialize() override;
108 
109  TRestEvent* ProcessEvent(TRestEvent* inputEvent) override;
110 
111  void EndProcess() override;
112 
113  bool FillBuffer();
114 
115  bool GetNextFrame(USTCDataFrame&);
116 
117  bool OpenNextFile(USTCDataFrame&);
118 
119  void FixToNextFrame(FILE* f);
120 
121  bool ReadFrameData(USTCDataFrame& Frame);
122 
123  bool AddBuffer(USTCDataFrame& Frame);
124 
125  void ClearBuffer();
126 
127  Bool_t EndReading();
128 
129  // Constructor
131  TRestRawUSTCToSignalProcess(const char* configFilename);
132  // Destructor
134 
135  ClassDefOverride(TRestRawUSTCToSignalProcess, 3);
136 };
137 #endif
A base class for any REST event.
Definition: TRestEvent.h:38
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.
A process to read USTC electronic binary format files generated.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
Process one event.
void EndProcess() override
To be executed at the end of the run (outside event loop)
void InitProcess() override
To be executed at the beginning of the run (outside event loop)
void Initialize() override
Making default settings.