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