Changeset 16380 for trunk/FACT++/src/EventBuilder.h
- Timestamp:
- 05/28/13 13:45:31 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/EventBuilder.h
r16108 r16380 3 3 4 4 #include "FAD.h" 5 6 #include <array> 7 #include <forward_list> 5 8 6 9 /* global variables; … … 32 35 enum CloseRequest_t 33 36 { 34 kRequestNone = 0, 35 kRequestManual = 1, 36 kRequestTimeout = 2, 37 kRequestConnectionChange = 4, 38 kRequestEventCheckFailed = 8 37 kRequestNone = 0, 38 kRequestManual = 1<<1, 39 kRequestTimeout = 1<<2, 40 kRequestConnectionChange = 1<<3, 41 kRequestEventCheckFailed = 1<<4, 42 kRequestMaxEvtsReached = 1<<5, 43 kRequestMaxTimeReached = 1<<6 39 44 }; 40 45 … … 58 63 59 64 FileStatus_t fileStat; 60 int closeRequest;61 65 62 66 std::shared_ptr<DrsCalibration> calib; 67 std::list<std::array<int16_t,1440>> prevStart; // History for start cells of previous events (for step calibration) 63 68 64 RUN_CTRL2() : runId(-1), lastTime(0), lastEvt(0), maxEvt(1<<31), fileStat(kFileNotYetOpen) , closeRequest(kRequestNone)69 RUN_CTRL2() : runId(-1), lastTime(0), lastEvt(0), maxEvt(1<<31), fileStat(kFileNotYetOpen) 65 70 { 66 71 // runId = -1; … … 74 79 }; 75 80 81 #define MAX_HEAD_MEM (NBOARDS * sizeof(PEVNT_HEADER)) 82 #define MAX_TOT_MEM (sizeof(EVENT) + (NPIX+NTMARK)*1024*2 + MAX_HEAD_MEM) 83 84 namespace Memory 85 { 86 extern uint64_t inuse; 87 extern uint64_t allocated; 88 89 extern uint64_t max_inuse; 90 91 extern std::mutex mtx; 92 93 extern std::forward_list<void*> memory; 94 95 extern void *malloc(); 96 extern void free(void *mem); 97 }; 98 76 99 struct EVT_CTRL2 77 100 { 78 int64_t runNum;79 uint32_t evNum; 101 uint32_t runNum; // header->runnumber; 102 uint32_t evNum; // header->fad_evt_counter 80 103 81 uint32_t trgNum; 82 uint32_t trgTyp; 104 uint32_t trgNum; // header->trigger_id 105 uint32_t trgTyp; // header->trigger_type 83 106 uint32_t fadLen; 84 107 85 uint 32_t nBoard;108 uint16_t nBoard; 86 109 int16_t board[NBOARDS]; 87 110 … … 92 115 uint8_t Errors[4]; 93 116 94 std::shared_ptr<PEVNT_HEADER> FADhead; 95 EVENT *fEvent; 117 PEVNT_HEADER *FADhead; // Pointer to the whole allocated memory 118 EVENT *fEvent; // Pointer to the event data itself 119 PEVNT_HEADER *header; // Pointer to a valid header within FADhead 120 121 bool reportMem; // initMemory has reported no memory once (set outside of class) 122 int closeRequest; 96 123 97 124 std::shared_ptr<RUN_CTRL2> runCtrl; 98 125 99 EVT_CTRL2(std::shared_ptr<RUN_CTRL2> run=std::shared_ptr<RUN_CTRL2>()) : runNum(-1), runCtrl(run) 126 // Be carefull with this constructor... writeEvt can seg fault 127 // it gets an empty runCtrl 128 EVT_CTRL2() : nBoard(0), FADhead(0), header(0), reportMem(false), closeRequest(kRequestNone) 100 129 { 101 Errors[0] = 0; 102 Errors[1] = 0; 103 Errors[2] = 0; 104 Errors[3] = 0; 130 //flag all boards as unused 131 std::fill(board, board+NBOARDS, -1); 132 } 133 /* 134 EVT_CTRL2(CloseRequest_t req) : nBoard(0), FADhead(0), header(0), reportMem(false), closeRequest(req), runCtrl(new RUN_CTRL2) 135 { 136 //flag all boards as unused 137 std::fill(board, board+NBOARDS, -1); 138 }*/ 105 139 140 EVT_CTRL2(int req, const std::shared_ptr<RUN_CTRL2> &run) : nBoard(0), FADhead(0), header(0), reportMem(false), closeRequest(req), runCtrl(run) 141 { 106 142 //flag all boards as unused 107 nBoard = 0; 108 for (int b=0; b<NBOARDS; b++) 109 board[b] = -1; 143 std::fill(board, board+NBOARDS, -1); 144 } 145 ~EVT_CTRL2() 146 { 147 Memory::free(FADhead); 110 148 } 111 149 … … 119 157 rh.RunUsec = time.tv_usec; 120 158 121 memcpy(rh.FADhead, FADhead .get(), NBOARDS*sizeof(PEVNT_HEADER));159 memcpy(rh.FADhead, FADhead, NBOARDS*sizeof(PEVNT_HEADER)); 122 160 123 161 return rh; 124 162 } 125 163 126 void initEvent(const std::shared_ptr<PEVNT_HEADER> &mem) 164 bool valid() const { return header; } 165 166 bool initMemory() 127 167 { 128 FADhead = mem; 129 fEvent = reinterpret_cast<EVENT*>(mem.get()+NBOARDS); 168 // We have a valid entry, but no memory has yet been allocated 169 if (FADhead) 170 return true; 171 172 FADhead = (PEVNT_HEADER*)Memory::malloc(); 173 if (!FADhead) 174 return false; 175 176 fEvent = reinterpret_cast<EVENT*>(FADhead+NBOARDS); 130 177 131 178 memset(fEvent->Adc_Data, 0, (NPIX+NTMARK)*2*nRoi); 132 179 133 //flag all pixels as unused 134 for (int k = 0; k < NPIX; k++)135 fEvent->StartPix[k] = -1;180 //flag all pixels as unused, flag all TMark as unused 181 std::fill(fEvent->StartPix, fEvent->StartPix+NPIX, -1); 182 std::fill(fEvent->StartTM, fEvent->StartTM +NTMARK, -1); 136 183 137 //flag all TMark as unused138 for (int k = 0; k < NTMARK; k++)139 fEvent->StartTM[k] = -1;140 141 fEvent->NumBoards = 0;142 184 fEvent->SoftTrig = 0; 143 fEvent->PCTime = time.tv_sec;144 fEvent->PCUsec = time.tv_usec;145 185 fEvent->Roi = nRoi; 146 186 fEvent->RoiTM = nRoiTM; … … 148 188 fEvent->TriggerNum = trgNum; 149 189 fEvent->TriggerType = trgTyp; 190 191 return true; 150 192 } 151 193 };
Note:
See TracChangeset
for help on using the changeset viewer.