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