]>
Commit | Line | Data |
---|---|---|
b15de2d2 | 1 | //////////////////////////////////////////////////////////// |
2 | // Author: Henrik Tydesjo // | |
3 | // Interface class to the containers of an online scan. // | |
4 | // Directly connected to a TFile with all containers. // | |
5 | // Handles reading and writing of this TFile. // | |
6 | // Hitmaps and information on nr of events with hits // | |
7 | // is stored in this file (AliITSOnlineSPDHitArray and // | |
8 | // AliITSOnlineSPDHitEvent). Also some general // | |
9 | // information is stored (AliITSOnlineSPDscanInfo). // | |
10 | // When switching between different steps of the scan, // | |
11 | // the previous step is automatically stored on the file. // | |
12 | // With this scheme there is no risk of running out of // | |
13 | // memory. // | |
14 | //////////////////////////////////////////////////////////// | |
15 | ||
a1e17193 | 16 | #include <math.h> |
17 | ||
b15de2d2 | 18 | #include <TFile.h> |
19 | #include "AliITSOnlineSPDscan.h" | |
20 | #include "AliITSOnlineSPDscanInfo.h" | |
21 | #include "AliITSOnlineSPDHitArray.h" | |
22 | #include "AliITSOnlineSPDHitEvent.h" | |
23 | ||
53ae21ce | 24 | AliITSOnlineSPDscan::AliITSOnlineSPDscan(const Char_t *fileName) : |
b15de2d2 | 25 | fFile(NULL), |
26 | fWrite(kFALSE), | |
27 | fCurrentStep(-1), | |
28 | fModified(kFALSE), | |
29 | fInfoModified(kFALSE), | |
53ae21ce | 30 | fScanInfo(NULL), |
31 | fFileName(fileName) | |
b15de2d2 | 32 | { |
33 | // constructor, open file for reading or writing | |
b15de2d2 | 34 | // look for a previously saved info object |
35 | // (if file not found create a new one and return, else read) | |
53ae21ce | 36 | FILE* fp0 = fopen(fFileName.Data(), "r"); |
b15de2d2 | 37 | if (fp0 == NULL) { |
38 | fScanInfo = new AliITSOnlineSPDscanInfo(); | |
53ae21ce | 39 | fFile = new TFile(fFileName.Data(), "RECREATE"); |
b15de2d2 | 40 | fWrite=kTRUE; |
41 | } | |
42 | else { | |
43 | fclose(fp0); | |
53ae21ce | 44 | fFile = new TFile(fFileName.Data(), "READ"); |
b15de2d2 | 45 | fWrite=kFALSE; |
46 | fFile->GetObject("AliITSOnlineSPDscanInfo", fScanInfo); | |
47 | } | |
48 | Init(); | |
49 | } | |
50 | ||
51 | AliITSOnlineSPDscan::AliITSOnlineSPDscan(const AliITSOnlineSPDscan& /*scan*/) : | |
52 | fFile(NULL), | |
53 | fWrite(kFALSE), | |
54 | fCurrentStep(-1), | |
55 | fModified(kFALSE), | |
56 | fInfoModified(kFALSE), | |
53ae21ce | 57 | fScanInfo(NULL), |
58 | fFileName(".") | |
b15de2d2 | 59 | { |
60 | printf("This object should not be copied!"); | |
61 | } | |
62 | ||
63 | AliITSOnlineSPDscan::~AliITSOnlineSPDscan() { | |
64 | // destructor | |
65 | if (fModified) { | |
66 | SaveCurrentStep(); | |
67 | } | |
68 | for (UInt_t hs=0; hs<6; hs++) { | |
69 | if (fCurrentHitArray[hs]!=NULL) { | |
70 | delete fCurrentHitArray[hs]; | |
71 | fCurrentHitArray[hs]=NULL; | |
72 | } | |
73 | if (fCurrentHitEvent[hs]!=NULL) { | |
74 | delete fCurrentHitEvent[hs]; | |
75 | fCurrentHitEvent[hs]=NULL; | |
76 | } | |
77 | } | |
78 | if (fInfoModified) { | |
79 | if (!fWrite) { | |
80 | fFile->Close(); | |
81 | delete fFile; | |
53ae21ce | 82 | fFile = new TFile(fFileName.Data(), "UPDATE"); |
b15de2d2 | 83 | fWrite=kTRUE; |
84 | } | |
85 | fFile->Delete("AliITSOnlineSPDscanInfo;*"); | |
86 | fFile->WriteTObject(fScanInfo, "AliITSOnlineSPDscanInfo"); | |
08ed0911 | 87 | } |
88 | if (fFile!=NULL) { | |
b15de2d2 | 89 | delete fFile; |
90 | } | |
91 | } | |
92 | ||
93 | AliITSOnlineSPDscan& AliITSOnlineSPDscan::operator=(const AliITSOnlineSPDscan& scan) { | |
94 | // assignment operator (should not be used) | |
95 | printf("This object should not be copied!"); | |
96 | if (this!=&scan) { | |
97 | // still do nothing... | |
98 | } | |
99 | return *this; | |
100 | } | |
101 | ||
b15de2d2 | 102 | void AliITSOnlineSPDscan::ClearThis() { |
103 | // clear this scan, close file and open new | |
104 | for (UInt_t hs=0; hs<6; hs++) { | |
105 | if (fCurrentHitArray[hs]!=NULL) { | |
106 | delete fCurrentHitArray[hs]; | |
107 | } | |
108 | fCurrentHitArray[hs] = NULL; | |
109 | if (fCurrentHitEvent[hs]!=NULL) { | |
110 | delete fCurrentHitEvent[hs]; | |
111 | } | |
112 | fCurrentHitEvent[hs] = NULL; | |
113 | } | |
114 | fScanInfo->ClearThis(); | |
115 | fFile->Close(); | |
116 | delete fFile; | |
53ae21ce | 117 | fFile = new TFile(fFileName.Data(), "RECREATE"); |
b15de2d2 | 118 | fWrite=kTRUE; |
119 | fFile->WriteTObject(fScanInfo, "AliITSOnlineSPDscanInfo"); | |
120 | fInfoModified=kTRUE; | |
121 | } | |
122 | ||
123 | void AliITSOnlineSPDscan::Init() { | |
124 | // init hit arrays and hit events | |
125 | for (UInt_t hs=0; hs<6; hs++) { | |
126 | fCurrentHitArray[hs]=NULL; | |
127 | fCurrentHitEvent[hs]=NULL; | |
128 | } | |
129 | ||
130 | } | |
131 | ||
132 | UInt_t AliITSOnlineSPDscan::AddScanStep() { | |
133 | // add a new scan step | |
134 | CreateNewStep(); | |
135 | return fScanInfo->AddScanStep(); | |
136 | } | |
137 | ||
138 | void AliITSOnlineSPDscan::CreateNewStep() { | |
139 | // create a new step | |
140 | // save current step to file (if modified) | |
141 | if (fModified) { | |
142 | SaveCurrentStep(); | |
143 | } | |
144 | // create new step | |
145 | for (UInt_t hs=0; hs<6; hs++) { | |
146 | if (fCurrentHitArray[hs]!=NULL) { | |
147 | delete fCurrentHitArray[hs]; | |
148 | } | |
149 | fCurrentHitArray[hs] = new AliITSOnlineSPDHitArray(); | |
150 | if (fCurrentHitEvent[hs]!=NULL) { | |
151 | delete fCurrentHitEvent[hs]; | |
152 | } | |
153 | fCurrentHitEvent[hs] = new AliITSOnlineSPDHitEvent(); | |
154 | } | |
155 | fCurrentStep = fScanInfo->GetNSteps(); | |
156 | fModified=kTRUE; | |
157 | fInfoModified=kTRUE; | |
158 | } | |
159 | ||
160 | void AliITSOnlineSPDscan::SwitchToStep(UInt_t nsi) { | |
161 | // switch to step nsi (save current step first if needed) | |
162 | if ((Int_t)nsi!=fCurrentStep) { | |
163 | if (fModified) { | |
164 | SaveCurrentStep(); | |
165 | } | |
166 | for (UInt_t hs=0; hs<6; hs++) { | |
167 | if (fCurrentHitArray[hs]!=NULL) { | |
168 | delete fCurrentHitArray[hs]; | |
169 | fCurrentHitArray[hs]=NULL; | |
170 | } | |
171 | if (fCurrentHitEvent[hs]!=NULL) { | |
172 | delete fCurrentHitEvent[hs]; | |
173 | fCurrentHitEvent[hs]=NULL; | |
174 | } | |
175 | } | |
176 | if (nsi>=GetNSteps()) { | |
177 | FillGap(nsi); // makes fCurrentStep = nsi | |
178 | } | |
179 | else { | |
180 | fCurrentStep=nsi; | |
181 | ReadCurrentStep(); | |
182 | } | |
183 | } | |
184 | } | |
185 | ||
186 | void AliITSOnlineSPDscan::FillGap(UInt_t nsi) { | |
187 | //create new steps until nsi is reached | |
188 | while (nsi>=GetNSteps()) { | |
189 | fCurrentStep = AddScanStep(); | |
190 | } | |
191 | } | |
192 | ||
193 | void AliITSOnlineSPDscan::ReadCurrentStep() { | |
194 | // read current step index into memory | |
195 | for (UInt_t hs=0; hs<6; hs++) { | |
53ae21ce | 196 | TString stepName = Form("HitArray_HS%d_Step%d",hs,fCurrentStep); |
197 | fFile->GetObject(stepName.Data(), fCurrentHitArray[hs]); | |
198 | TString stepName2 = Form("HitEvent_HS%d_Step%d",hs,fCurrentStep); | |
b15de2d2 | 199 | fFile->GetObject(stepName2, fCurrentHitEvent[hs]); |
200 | } | |
201 | } | |
202 | ||
203 | void AliITSOnlineSPDscan::SaveCurrentStep() { | |
204 | // save current step to file | |
205 | if (!fWrite) { | |
206 | fFile->Close(); | |
207 | delete fFile; | |
53ae21ce | 208 | fFile = new TFile(fFileName.Data(), "UPDATE"); |
b15de2d2 | 209 | fWrite=kTRUE; |
210 | } | |
211 | for (UInt_t hs=0; hs<6; hs++) { | |
53ae21ce | 212 | TString stepName = Form("HitArray_HS%d_Step%d",hs,fCurrentStep); |
213 | TString stepDelete = Form("%s;*",stepName.Data()); | |
214 | fFile->Delete(stepDelete.Data()); | |
215 | fFile->WriteTObject(fCurrentHitArray[hs], stepName.Data()); | |
216 | TString stepName2 = Form("HitEvent_HS%d_Step%d",hs,fCurrentStep); | |
217 | TString stepDelete2 = Form("%s;*",stepName2.Data()); | |
218 | fFile->Delete(stepDelete2.Data()); | |
219 | fFile->WriteTObject(fCurrentHitEvent[hs], stepName2.Data()); | |
b15de2d2 | 220 | } |
221 | fModified=kFALSE; | |
222 | } | |
223 | ||
224 | void AliITSOnlineSPDscan::SetHits(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi, UInt_t val) { | |
225 | // set nr of hits for pixel | |
226 | SwitchToStep(nsi); | |
227 | fCurrentHitArray[hs]->SetHits(chipi,coli,rowi,val); | |
228 | fModified=kTRUE; | |
229 | } | |
230 | void AliITSOnlineSPDscan::IncrementHits(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) { | |
231 | // increment nr of hits for pixel | |
232 | SwitchToStep(nsi); | |
233 | fCurrentHitArray[hs]->IncrementHits(chipi,coli,rowi); | |
234 | fModified=kTRUE; | |
235 | } | |
236 | void AliITSOnlineSPDscan::SetHitEvents(UInt_t nsi, UInt_t hs, UInt_t chipi, Int_t val) { | |
237 | // set nr of hit events for a chip | |
238 | SwitchToStep(nsi); | |
239 | fCurrentHitEvent[hs]->SetHitEvent(chipi,val); | |
240 | fModified=kTRUE; | |
241 | } | |
242 | void AliITSOnlineSPDscan::SetHitEventsTot(UInt_t nsi, UInt_t hs, Int_t val) { | |
243 | // set nr of hit events for 10 chips together | |
244 | SetHitEvents(nsi,hs,10,val); | |
245 | } | |
246 | void AliITSOnlineSPDscan::IncrementHitEvents(UInt_t nsi, UInt_t hs, UInt_t chipi) { | |
247 | // increment nr of hit events for a chip | |
248 | SwitchToStep(nsi); | |
249 | fCurrentHitEvent[hs]->IncrementHitEvent(chipi); | |
250 | fModified=kTRUE; | |
251 | } | |
252 | void AliITSOnlineSPDscan::IncrementHitEventsTot(UInt_t nsi, UInt_t hs) { | |
253 | // increment nr of hit events for 10 chips | |
254 | IncrementHitEvents(nsi,hs,10); | |
255 | } | |
256 | ||
257 | ||
258 | UInt_t AliITSOnlineSPDscan::GetHits(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) { | |
259 | // get nr of hits for pixel | |
260 | if (nsi<GetNSteps()) { | |
261 | SwitchToStep(nsi); | |
262 | return fCurrentHitArray[hs]->GetHits(chipi,coli,rowi); | |
263 | } | |
264 | else { | |
265 | return 0; | |
266 | } | |
267 | } | |
268 | Float_t AliITSOnlineSPDscan::GetHitsEfficiency(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) { | |
269 | // get the hit efficiency for pixel | |
270 | UInt_t ntr = GetTriggers(nsi); | |
271 | if (ntr>0) { | |
272 | return ((Float_t)GetHits(nsi,hs,chipi,coli,rowi))/ntr; | |
273 | } | |
274 | else { | |
275 | return 0; | |
276 | } | |
277 | } | |
278 | Float_t AliITSOnlineSPDscan::GetHitsEfficiencyError(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) { | |
279 | // get error in hit efficiency for pixel | |
280 | Float_t hits = GetHits(nsi,hs,chipi,coli,rowi); | |
281 | UInt_t ntr = GetTriggers(nsi); | |
282 | return sqrt(hits*(ntr-hits)/ntr)/ntr; | |
283 | } | |
284 | UInt_t AliITSOnlineSPDscan::GetHitEvents(UInt_t nsi, UInt_t hs, UInt_t chipi) { | |
285 | // get nr of hit events for a chip | |
286 | if (nsi<GetNSteps()) { | |
287 | SwitchToStep(nsi); | |
288 | return fCurrentHitEvent[hs]->GetHitEvent(chipi); | |
289 | } | |
290 | else { | |
291 | return 0; | |
292 | } | |
293 | } | |
294 | UInt_t AliITSOnlineSPDscan::GetHitEventsTot(UInt_t nsi, UInt_t hs) { | |
295 | // get nr of hit events for 10 chips | |
296 | return GetHitEvents(nsi,hs,10); | |
297 | } | |
298 | Float_t AliITSOnlineSPDscan::GetHitEventsEfficiency(UInt_t nsi, UInt_t hs, UInt_t chipi) { | |
299 | // get the hit events efficiency for a chip | |
300 | UInt_t ntr = GetTriggers(nsi); | |
301 | if (ntr>0) { | |
302 | return ((Float_t)GetHitEvents(nsi,hs,chipi))/ntr; | |
303 | } | |
304 | else { | |
305 | return 0; | |
306 | } | |
307 | } | |
308 | Float_t AliITSOnlineSPDscan::GetHitEventsTotEfficiency(UInt_t nsi, UInt_t hs) { | |
309 | // get the hit events efficiency for 10 chips | |
310 | return GetHitEventsEfficiency(nsi,hs,10); | |
311 | } | |
312 | Float_t AliITSOnlineSPDscan::GetHitEventsEfficiencyError(UInt_t nsi, UInt_t hs, UInt_t chipi) { | |
313 | // get error in hit events efficiency for a chip | |
314 | Float_t hitevents = (Float_t) GetHitEvents(nsi,hs,chipi); | |
315 | UInt_t ntr = GetTriggers(nsi); | |
316 | return sqrt(hitevents*(ntr-hitevents)/ntr)/ntr; | |
317 | } | |
318 | Float_t AliITSOnlineSPDscan::GetHitEventsTotEfficiencyError(UInt_t nsi, UInt_t hs) { | |
319 | // get error in hit events efficiency for 10 chips | |
320 | return GetHitEventsEfficiencyError(nsi,hs,10); | |
321 | } | |
322 | Float_t AliITSOnlineSPDscan::GetAverageMultiplicity(UInt_t nsi, UInt_t hs, UInt_t chipi) { | |
323 | // get average multiplicity for a chip | |
324 | Float_t nrhits = 0; | |
325 | for (UInt_t chip=0;chip<10;chip++) { | |
326 | if (chipi==10 || chip==chipi) { | |
327 | for (Int_t col=0; col<32; col++) { | |
328 | for (Int_t row=0; row<256; row++) { | |
329 | nrhits+=GetHits(nsi,hs,chip,col,row); | |
330 | } | |
331 | } | |
332 | } | |
333 | } | |
334 | UInt_t ntr = GetTriggers(nsi); | |
335 | if (ntr>0) { | |
336 | return nrhits/ntr; | |
337 | } | |
338 | else { | |
339 | return 0; | |
340 | } | |
341 | } | |
342 | Float_t AliITSOnlineSPDscan::GetAverageMultiplicityTot(UInt_t nsi, UInt_t hs) { | |
343 | // get average multiplicity for 10 chips | |
344 | return GetAverageMultiplicity(nsi,hs,10); | |
345 | } | |
346 | ||
347 | ||
348 | void AliITSOnlineSPDscan::SetType(UInt_t val) { | |
349 | // set type | |
350 | fScanInfo->SetType(val); | |
351 | fInfoModified=kTRUE; | |
352 | } | |
353 | void AliITSOnlineSPDscan::SetRunNr(UInt_t val) { | |
354 | // set run nr | |
355 | fScanInfo->SetRunNr(val); | |
356 | fInfoModified=kTRUE; | |
357 | } | |
358 | void AliITSOnlineSPDscan::SetRouterNr(UInt_t val) { | |
359 | // set router nr | |
360 | fScanInfo->SetRouterNr(val); | |
361 | fInfoModified=kTRUE; | |
362 | } | |
ad18504e | 363 | void AliITSOnlineSPDscan::SetHalfStaveScanned(UInt_t val, Bool_t b) { |
364 | // set half stave scanned | |
365 | fScanInfo->SetHalfStaveScanned(val,b); | |
366 | fInfoModified=kTRUE; | |
367 | } | |
368 | void AliITSOnlineSPDscan::SetDataFormat(UInt_t val) { | |
369 | // set data format (0=normal 1=histogram) | |
370 | fScanInfo->SetDataFormat(val); | |
371 | fInfoModified=kTRUE; | |
372 | } | |
b15de2d2 | 373 | void AliITSOnlineSPDscan::SetTriggers(UInt_t nsi, UInt_t val) { |
374 | // set nr of triggers | |
3db5f733 | 375 | SwitchToStep(nsi); |
b15de2d2 | 376 | fScanInfo->SetTriggers(nsi,val); |
377 | fInfoModified=kTRUE; | |
378 | } | |
379 | void AliITSOnlineSPDscan::SetChipPresent(UInt_t hs, UInt_t chipi, Bool_t val){ | |
380 | // set chip present | |
381 | fScanInfo->SetChipPresent(hs,chipi,val); | |
382 | fInfoModified=kTRUE; | |
383 | } | |
384 | void AliITSOnlineSPDscan::SetRowStart(UInt_t val){ | |
385 | // set row start | |
386 | fScanInfo->SetRowStart(val); | |
387 | fInfoModified=kTRUE; | |
388 | } | |
389 | void AliITSOnlineSPDscan::SetRowEnd(UInt_t val){ | |
390 | // set row end | |
391 | fScanInfo->SetRowEnd(val); | |
392 | fInfoModified=kTRUE; | |
393 | } | |
394 | void AliITSOnlineSPDscan::SetDacStart(UInt_t val){ | |
395 | // set dac start | |
396 | fScanInfo->SetDacStart(val); | |
397 | fInfoModified=kTRUE; | |
398 | } | |
399 | void AliITSOnlineSPDscan::SetDacEnd(UInt_t val){ | |
400 | // set dac end | |
401 | fScanInfo->SetDacEnd(val); | |
402 | fInfoModified=kTRUE; | |
403 | } | |
404 | void AliITSOnlineSPDscan::SetDacStep(UInt_t val){ | |
405 | // set dac step | |
406 | fScanInfo->SetDacStep(val); | |
407 | fInfoModified=kTRUE; | |
408 | } | |
53ae21ce | 409 | void AliITSOnlineSPDscan::SetDCSVersion(UInt_t val){ |
410 | // set dcs db version | |
411 | fScanInfo->SetDCSVersion(val); | |
412 | fInfoModified=kTRUE; | |
413 | } | |
b15de2d2 | 414 | void AliITSOnlineSPDscan::IncrementTriggers(UInt_t nsi) { |
415 | // increment nr of triggers | |
3db5f733 | 416 | SwitchToStep(nsi); |
b15de2d2 | 417 | fScanInfo->IncrementTriggers(nsi); |
418 | fInfoModified=kTRUE; | |
419 | } | |
420 | ||
421 | ||
422 | ||
423 | UInt_t AliITSOnlineSPDscan::GetNSteps() const { | |
424 | return fScanInfo->GetNSteps(); | |
425 | } | |
426 | UInt_t AliITSOnlineSPDscan::GetType() const { | |
427 | return fScanInfo->GetType(); | |
428 | } | |
429 | UInt_t AliITSOnlineSPDscan::GetRunNr() const { | |
430 | return fScanInfo->GetRunNr(); | |
431 | } | |
432 | UInt_t AliITSOnlineSPDscan::GetRouterNr() const { | |
433 | return fScanInfo->GetRouterNr(); | |
434 | } | |
ad18504e | 435 | Bool_t AliITSOnlineSPDscan::GetHalfStaveScanned(UInt_t val) const { |
436 | return fScanInfo->GetHalfStaveScanned(val); | |
437 | } | |
438 | UInt_t AliITSOnlineSPDscan::GetDataFormat() const { | |
439 | return fScanInfo->GetDataFormat(); | |
440 | } | |
b15de2d2 | 441 | UInt_t AliITSOnlineSPDscan::GetTriggers(UInt_t nsi) const { |
442 | return fScanInfo->GetTriggers(nsi); | |
443 | } | |
444 | Bool_t AliITSOnlineSPDscan::GetChipPresent(UInt_t hs, UInt_t chipi) const { | |
445 | return fScanInfo->GetChipPresent(hs,chipi); | |
446 | } | |
447 | UInt_t AliITSOnlineSPDscan::GetRowStart() const { | |
448 | return fScanInfo->GetRowStart(); | |
449 | } | |
450 | UInt_t AliITSOnlineSPDscan::GetRowEnd() const { | |
451 | return fScanInfo->GetRowEnd(); | |
452 | } | |
453 | UInt_t AliITSOnlineSPDscan::GetDacStart() const { | |
454 | return fScanInfo->GetDacStart(); | |
455 | } | |
456 | UInt_t AliITSOnlineSPDscan::GetDacEnd() const { | |
457 | return fScanInfo->GetDacEnd(); | |
458 | } | |
459 | UInt_t AliITSOnlineSPDscan::GetDacStep() const { | |
460 | return fScanInfo->GetDacStep(); | |
461 | } | |
53ae21ce | 462 | UInt_t AliITSOnlineSPDscan::GetDCSVersion() const { |
463 | return fScanInfo->GetDCSVersion(); | |
464 | } |