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