1 | #ifndef FACT_EventBuilder
|
---|
2 | #define FACT_EventBuilder
|
---|
3 |
|
---|
4 | #include "FAD.h"
|
---|
5 |
|
---|
6 | /* global variables;
|
---|
7 | to avoid race canoditions, only one thread is allowed to write
|
---|
8 | the name of the variable defines which process shall write it:
|
---|
9 |
|
---|
10 | g_XXX : main control thread
|
---|
11 | gi_XX : input thread (reading from camera)
|
---|
12 | gw_XX : write thread (writing to disk)
|
---|
13 | qp_XX : processing thread(s) (processing data, eg. soft-trig)
|
---|
14 |
|
---|
15 | */
|
---|
16 | extern int g_reset ; //>0 = reset different levels of eventbuilder
|
---|
17 | extern size_t g_maxMem ; //maximum memory allowed for buffer
|
---|
18 |
|
---|
19 | extern FACT_SOCK g_port[NBOARDS] ; // .port = baseport, .addr=string of IP-addr in dotted-decimal "ddd.ddd.ddd.ddd"
|
---|
20 |
|
---|
21 | extern uint gi_NumConnect[NBOARDS]; //4 crates * 10 boards
|
---|
22 |
|
---|
23 | class DrsCalibration;
|
---|
24 |
|
---|
25 | enum FileStatus_t
|
---|
26 | {
|
---|
27 | kFileNotYetOpen,
|
---|
28 | kFileOpen,
|
---|
29 | kFileClosed
|
---|
30 | };
|
---|
31 |
|
---|
32 | enum CloseRequest_t
|
---|
33 | {
|
---|
34 | kRequestNone = 0,
|
---|
35 | kRequestManual = 1,
|
---|
36 | kRequestTimeout = 2,
|
---|
37 | kRequestConnectionChange = 4,
|
---|
38 | kRequestEventCheckFailed = 8
|
---|
39 | };
|
---|
40 |
|
---|
41 |
|
---|
42 | struct RUN_CTRL2
|
---|
43 | {
|
---|
44 | int64_t runId ; // Run number
|
---|
45 |
|
---|
46 | time_t openTime; // Time when first event (first board) was received
|
---|
47 | time_t lastTime; // Time when last event was received (set when first board data received)
|
---|
48 | time_t closeTime; // Time when run should be closed
|
---|
49 | uint32_t night; // night as int as determined for this run
|
---|
50 |
|
---|
51 | uint32_t lastEvt; // number of events received (counted when the first board was received)
|
---|
52 | uint32_t maxEvt; // maximum number which should be written to file
|
---|
53 |
|
---|
54 | uint16_t roi0; // roi for normal pixels
|
---|
55 | uint16_t roi8; // roi for pixels8
|
---|
56 |
|
---|
57 | std::string runType;
|
---|
58 |
|
---|
59 | FileStatus_t fileStat;
|
---|
60 | int closeRequest;
|
---|
61 |
|
---|
62 | std::shared_ptr<DrsCalibration> calib;
|
---|
63 |
|
---|
64 | RUN_CTRL2() : runId(-1), lastTime(0), lastEvt(0), maxEvt(1<<31), fileStat(kFileNotYetOpen), closeRequest(kRequestNone)
|
---|
65 | {
|
---|
66 | // runId = -1;
|
---|
67 | // fileId = kFileNotYetOpen;
|
---|
68 | // lastEvt = 0; // Number of events partially started to read
|
---|
69 | // actEvt = 0; // Number of written events
|
---|
70 | // maxEvt = 1<<31; // max number events allowed (~2400min @ 250Hz)
|
---|
71 |
|
---|
72 | }
|
---|
73 | //~RUN_CTRL2();
|
---|
74 | };
|
---|
75 |
|
---|
76 | struct EVT_CTRL2
|
---|
77 | {
|
---|
78 | int64_t runNum;
|
---|
79 | uint32_t evNum;
|
---|
80 |
|
---|
81 | uint32_t trgNum;
|
---|
82 | uint32_t trgTyp;
|
---|
83 | uint32_t fadLen;
|
---|
84 |
|
---|
85 | uint32_t nBoard;
|
---|
86 | int16_t board[NBOARDS];
|
---|
87 |
|
---|
88 | uint16_t nRoi;
|
---|
89 | uint16_t nRoiTM;
|
---|
90 |
|
---|
91 | timeval time;
|
---|
92 | uint8_t Errors[4];
|
---|
93 |
|
---|
94 | std::shared_ptr<PEVNT_HEADER> FADhead;
|
---|
95 | EVENT *fEvent;
|
---|
96 |
|
---|
97 | std::shared_ptr<RUN_CTRL2> runCtrl;
|
---|
98 |
|
---|
99 | EVT_CTRL2(std::shared_ptr<RUN_CTRL2> run=std::shared_ptr<RUN_CTRL2>()) : runNum(-1), runCtrl(run)
|
---|
100 | {
|
---|
101 | Errors[0] = 0;
|
---|
102 | Errors[1] = 0;
|
---|
103 | Errors[2] = 0;
|
---|
104 | Errors[3] = 0;
|
---|
105 |
|
---|
106 | //flag all boards as unused
|
---|
107 | nBoard = 0;
|
---|
108 | for (int b=0; b<NBOARDS; b++)
|
---|
109 | board[b] = -1;
|
---|
110 | }
|
---|
111 |
|
---|
112 | operator RUN_HEAD() const
|
---|
113 | {
|
---|
114 | RUN_HEAD rh;
|
---|
115 |
|
---|
116 | rh.Nroi = nRoi;
|
---|
117 | rh.NroiTM = nRoiTM;
|
---|
118 | rh.RunTime = time.tv_sec;
|
---|
119 | rh.RunUsec = time.tv_usec;
|
---|
120 |
|
---|
121 | memcpy(rh.FADhead, FADhead.get(), NBOARDS*sizeof(PEVNT_HEADER));
|
---|
122 |
|
---|
123 | return rh;
|
---|
124 | }
|
---|
125 |
|
---|
126 | void initEvent(const std::shared_ptr<PEVNT_HEADER> &mem)
|
---|
127 | {
|
---|
128 | FADhead = mem;
|
---|
129 | fEvent = reinterpret_cast<EVENT*>(mem.get()+NBOARDS);
|
---|
130 |
|
---|
131 | memset(fEvent->Adc_Data, 0, (NPIX+NTMARK)*2*nRoi);
|
---|
132 |
|
---|
133 | //flag all pixels as unused
|
---|
134 | for (int k = 0; k < NPIX; k++)
|
---|
135 | fEvent->StartPix[k] = -1;
|
---|
136 |
|
---|
137 | //flag all TMark as unused
|
---|
138 | for (int k = 0; k < NTMARK; k++)
|
---|
139 | fEvent->StartTM[k] = -1;
|
---|
140 |
|
---|
141 | fEvent->NumBoards = 0;
|
---|
142 | fEvent->SoftTrig = 0;
|
---|
143 | fEvent->PCTime = time.tv_sec;
|
---|
144 | fEvent->PCUsec = time.tv_usec;
|
---|
145 | fEvent->Roi = nRoi;
|
---|
146 | fEvent->RoiTM = nRoiTM;
|
---|
147 | fEvent->EventNum = evNum;
|
---|
148 | fEvent->TriggerNum = trgNum;
|
---|
149 | fEvent->TriggerType = trgTyp;
|
---|
150 | }
|
---|
151 | };
|
---|
152 |
|
---|
153 | #endif
|
---|