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