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 //
14 ////////////////////////////////////////////////////////////
19 #include "AliITSOnlineSPDscan.h"
20 #include "AliITSOnlineSPDscanInfo.h"
21 #include "AliITSOnlineSPDHitArray.h"
22 #include "AliITSOnlineSPDHitEvent.h"
24 AliITSOnlineSPDscan::AliITSOnlineSPDscan(const Char_t *fileName, Bool_t readFromGridFile) :
29 fInfoModified(kFALSE),
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)
37 for(Int_t ihs=0; ihs<6; ihs++){
38 fCurrentHitArray[ihs]=0x0;
39 fCurrentHitEvent[ihs]=0x0;
42 Bool_t bRead = readFromGridFile;
45 FILE* fp0 = fopen(fFileName.Data(), "r");
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();
60 fFile = new TFile(fFileName.Data(), "RECREATE");
63 else { // read from file (grid or local)
65 fFile->GetObject("AliITSOnlineSPDscanInfo", fScanInfo);
68 else { // create new local file
69 fScanInfo = new AliITSOnlineSPDscanInfo();
71 fFile = new TFile(fFileName.Data(), "RECREATE");
78 AliITSOnlineSPDscan::AliITSOnlineSPDscan(const AliITSOnlineSPDscan& /*scan*/) :
83 fInfoModified(kFALSE),
88 for(Int_t ihs=0; ihs<6; ihs++){
89 fCurrentHitArray[ihs]=0x0;
90 fCurrentHitEvent[ihs]=0x0;
93 printf("This object should not be copied!");
96 AliITSOnlineSPDscan::~AliITSOnlineSPDscan() {
101 for (UInt_t hs=0; hs<6; hs++) {
102 if (fCurrentHitArray[hs]!=NULL) {
103 delete fCurrentHitArray[hs];
104 fCurrentHitArray[hs]=NULL;
106 if (fCurrentHitEvent[hs]!=NULL) {
107 delete fCurrentHitEvent[hs];
108 fCurrentHitEvent[hs]=NULL;
115 fFile = new TFile(fFileName.Data(), "UPDATE");
118 fFile->Delete("AliITSOnlineSPDscanInfo;*");
119 fFile->WriteTObject(fScanInfo, "AliITSOnlineSPDscanInfo");
126 AliITSOnlineSPDscan& AliITSOnlineSPDscan::operator=(const AliITSOnlineSPDscan& scan) {
127 // assignment operator (should not be used)
128 printf("This object should not be copied!");
130 // still do nothing...
135 void 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];
141 fCurrentHitArray[hs] = NULL;
142 if (fCurrentHitEvent[hs]!=NULL) {
143 delete fCurrentHitEvent[hs];
145 fCurrentHitEvent[hs] = NULL;
147 fScanInfo->ClearThis();
150 fFile = new TFile(fFileName.Data(), "RECREATE");
152 fFile->WriteTObject(fScanInfo, "AliITSOnlineSPDscanInfo");
156 void 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;
165 UInt_t AliITSOnlineSPDscan::AddScanStep() {
166 // add a new scan step
168 return fScanInfo->AddScanStep();
171 void AliITSOnlineSPDscan::CreateNewStep() {
173 // save current step to file (if modified)
178 for (UInt_t hs=0; hs<6; hs++) {
179 if (fCurrentHitArray[hs]!=NULL) {
180 delete fCurrentHitArray[hs];
182 fCurrentHitArray[hs] = new AliITSOnlineSPDHitArray();
183 if (fCurrentHitEvent[hs]!=NULL) {
184 delete fCurrentHitEvent[hs];
186 fCurrentHitEvent[hs] = new AliITSOnlineSPDHitEvent();
188 fCurrentStep = fScanInfo->GetNSteps();
193 void AliITSOnlineSPDscan::SwitchToStep(UInt_t nsi) {
194 // switch to step nsi (save current step first if needed)
195 if ((Int_t)nsi!=fCurrentStep) {
199 for (UInt_t hs=0; hs<6; hs++) {
200 if (fCurrentHitArray[hs]!=NULL) {
201 delete fCurrentHitArray[hs];
202 fCurrentHitArray[hs]=NULL;
204 if (fCurrentHitEvent[hs]!=NULL) {
205 delete fCurrentHitEvent[hs];
206 fCurrentHitEvent[hs]=NULL;
209 if (nsi>=GetNSteps()) {
210 FillGap(nsi); // makes fCurrentStep = nsi
219 void AliITSOnlineSPDscan::FillGap(UInt_t nsi) {
220 //create new steps until nsi is reached
221 while (nsi>=GetNSteps()) {
222 fCurrentStep = AddScanStep();
226 void AliITSOnlineSPDscan::ReadCurrentStep() {
227 // read current step index into memory
228 for (UInt_t hs=0; hs<6; hs++) {
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);
232 fFile->GetObject(stepName2, fCurrentHitEvent[hs]);
236 void AliITSOnlineSPDscan::SaveCurrentStep() {
237 // save current step to file
241 fFile = new TFile(fFileName.Data(), "UPDATE");
244 for (UInt_t hs=0; hs<6; hs++) {
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());
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
260 fCurrentHitArray[hs]->SetHits(chipi,coli,rowi,val);
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
266 fCurrentHitArray[hs]->IncrementHits(chipi,coli,rowi);
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
272 fCurrentHitEvent[hs]->SetHitEvent(chipi,val);
275 void 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);
279 void AliITSOnlineSPDscan::IncrementHitEvents(UInt_t nsi, UInt_t hs, UInt_t chipi) {
280 // increment nr of hit events for a chip
282 fCurrentHitEvent[hs]->IncrementHitEvent(chipi);
285 void AliITSOnlineSPDscan::IncrementHitEventsTot(UInt_t nsi, UInt_t hs) {
286 // increment nr of hit events for 10 chips
287 IncrementHitEvents(nsi,hs,10);
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 if (nsi<GetNSteps()) {
295 return fCurrentHitArray[hs]->GetHits(chipi,coli,rowi);
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 UInt_t ntr = GetTriggers(nsi);
305 return ((Float_t)GetHits(nsi,hs,chipi,coli,rowi))/ntr;
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 Float_t hits = GetHits(nsi,hs,chipi,coli,rowi);
314 UInt_t ntr = GetTriggers(nsi);
315 return sqrt(hits*(ntr-hits)/ntr)/ntr;
317 UInt_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()) {
321 return fCurrentHitEvent[hs]->GetHitEvent(chipi);
327 UInt_t AliITSOnlineSPDscan::GetHitEventsTot(UInt_t nsi, UInt_t hs) {
328 // get nr of hit events for 10 chips
329 return GetHitEvents(nsi,hs,10);
331 Float_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);
335 return ((Float_t)GetHitEvents(nsi,hs,chipi))/ntr;
341 Float_t AliITSOnlineSPDscan::GetHitEventsTotEfficiency(UInt_t nsi, UInt_t hs) {
342 // get the hit events efficiency for 10 chips
343 return GetHitEventsEfficiency(nsi,hs,10);
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 Float_t hitevents = (Float_t) GetHitEvents(nsi,hs,chipi);
348 UInt_t ntr = GetTriggers(nsi);
349 return sqrt(hitevents*(ntr-hitevents)/ntr)/ntr;
351 Float_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);
355 Float_t AliITSOnlineSPDscan::GetAverageMultiplicity(UInt_t nsi, UInt_t hs, UInt_t chipi) {
356 // get average multiplicity for a chip
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);
367 UInt_t ntr = GetTriggers(nsi);
375 Float_t AliITSOnlineSPDscan::GetAverageMultiplicityTot(UInt_t nsi, UInt_t hs) {
376 // get average multiplicity for 10 chips
377 return GetAverageMultiplicity(nsi,hs,10);
381 void AliITSOnlineSPDscan::SetType(UInt_t val) {
383 fScanInfo->SetType(val);
386 void AliITSOnlineSPDscan::SetRunNr(UInt_t val) {
388 fScanInfo->SetRunNr(val);
391 void AliITSOnlineSPDscan::SetRouterNr(UInt_t val) {
393 fScanInfo->SetRouterNr(val);
396 void AliITSOnlineSPDscan::SetHalfStaveScanned(UInt_t val, Bool_t b) {
397 // set half stave scanned
398 fScanInfo->SetHalfStaveScanned(val,b);
401 void AliITSOnlineSPDscan::SetDataFormat(UInt_t val) {
402 // set data format (0=normal 1=histogram)
403 fScanInfo->SetDataFormat(val);
406 void AliITSOnlineSPDscan::SetTriggers(UInt_t nsi, UInt_t val) {
407 // set nr of triggers
409 fScanInfo->SetTriggers(nsi,val);
412 void AliITSOnlineSPDscan::SetChipPresent(UInt_t hs, UInt_t chipi, Bool_t val){
414 fScanInfo->SetChipPresent(hs,chipi,val);
417 void AliITSOnlineSPDscan::SetRowStart(UInt_t val){
419 fScanInfo->SetRowStart(val);
422 void AliITSOnlineSPDscan::SetRowEnd(UInt_t val){
424 fScanInfo->SetRowEnd(val);
427 void AliITSOnlineSPDscan::SetDacStart(UInt_t val){
429 fScanInfo->SetDacStart(val);
432 void AliITSOnlineSPDscan::SetDacEnd(UInt_t val){
434 fScanInfo->SetDacEnd(val);
437 void AliITSOnlineSPDscan::SetDacStep(UInt_t val){
439 fScanInfo->SetDacStep(val);
442 void AliITSOnlineSPDscan::SetDCSVersion(UInt_t val){
443 // set dcs db version
444 fScanInfo->SetDCSVersion(val);
447 void AliITSOnlineSPDscan::IncrementTriggers(UInt_t nsi) {
448 // increment nr of triggers
450 fScanInfo->IncrementTriggers(nsi);
456 UInt_t AliITSOnlineSPDscan::GetNSteps() const {
457 return fScanInfo->GetNSteps();
459 UInt_t AliITSOnlineSPDscan::GetType() const {
460 return fScanInfo->GetType();
462 UInt_t AliITSOnlineSPDscan::GetRunNr() const {
463 return fScanInfo->GetRunNr();
465 UInt_t AliITSOnlineSPDscan::GetRouterNr() const {
466 return fScanInfo->GetRouterNr();
468 Bool_t AliITSOnlineSPDscan::GetHalfStaveScanned(UInt_t val) const {
469 return fScanInfo->GetHalfStaveScanned(val);
471 UInt_t AliITSOnlineSPDscan::GetDataFormat() const {
472 return fScanInfo->GetDataFormat();
474 UInt_t AliITSOnlineSPDscan::GetTriggers(UInt_t nsi) const {
475 return fScanInfo->GetTriggers(nsi);
477 Bool_t AliITSOnlineSPDscan::GetChipPresent(UInt_t hs, UInt_t chipi) const {
478 return fScanInfo->GetChipPresent(hs,chipi);
480 UInt_t AliITSOnlineSPDscan::GetRowStart() const {
481 return fScanInfo->GetRowStart();
483 UInt_t AliITSOnlineSPDscan::GetRowEnd() const {
484 return fScanInfo->GetRowEnd();
486 UInt_t AliITSOnlineSPDscan::GetDacStart() const {
487 return fScanInfo->GetDacStart();
489 UInt_t AliITSOnlineSPDscan::GetDacEnd() const {
490 return fScanInfo->GetDacEnd();
492 UInt_t AliITSOnlineSPDscan::GetDacStep() const {
493 return fScanInfo->GetDacStep();
495 UInt_t AliITSOnlineSPDscan::GetDCSVersion() const {
496 return fScanInfo->GetDCSVersion();