LCOV - code coverage report
Current view: top level - ITS/ITSrec - AliITSOnlineSPDphys.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 169 0.0 %
Date: 2016-06-14 17:26:59 Functions: 0 30 0.0 %

          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. Hitmaps are //
       6             : // stored in this file (AliITSOnlineSPDHitArray).         //
       7             : // Also some general information is stored                //
       8             : // (AliITSOnlineSPDphysInfo).                             //
       9             : ////////////////////////////////////////////////////////////
      10             : 
      11             : #include <math.h>
      12             : #include <TFile.h>
      13             : #include "AliITSOnlineSPDphys.h"
      14             : #include "AliITSOnlineSPDphysInfo.h"
      15             : #include "AliITSOnlineSPDHitArray.h"
      16             : 
      17             : AliITSOnlineSPDphys::AliITSOnlineSPDphys(const Char_t *fileName, Bool_t readFromGridFile) :
      18           0 :   fFile(NULL),
      19           0 :   fWrite(kFALSE),
      20           0 :   fModified(kFALSE),
      21           0 :   fInfoModified(kFALSE),
      22           0 :   fPhysInfo(NULL),
      23           0 :   fFileName(fileName)
      24           0 : {
      25             :   // constructor, open file for reading or writing
      26             :   // look for a previously saved info object 
      27             :   // (if file not found create a new one and return, else read)
      28             : 
      29           0 :   for(Int_t ihs =0; ihs<6; ihs++) fHitArray[ihs]=0x0;
      30             : 
      31           0 :   Bool_t bRead = readFromGridFile;
      32             : 
      33           0 :   if (!bRead) {
      34           0 :     FILE* fp0 = fopen(fFileName.Data(), "r");
      35           0 :     if (fp0 != NULL) {
      36             :       bRead=kTRUE;
      37           0 :       fclose(fp0);
      38             :     }
      39           0 :   }
      40             : 
      41           0 :   if (bRead) { // open file for reading
      42           0 :     fFile = TFile::Open(fFileName.Data(), "READ");
      43           0 :     if (fFile==NULL) { // grid file not found, create new local default file
      44           0 :       printf("ERROR: AliITSOnlineSPDphys: File %s not found! Creating 'test999.root' file instead\n",fFileName.Data());
      45             :       // create default empty file:
      46           0 :       fFileName = "test999.root";
      47           0 :       fPhysInfo = new AliITSOnlineSPDphysInfo();
      48           0 :       fInfoModified=kTRUE;
      49           0 :       fFile = new TFile(fFileName.Data(), "RECREATE");
      50           0 :       fWrite=kTRUE;
      51           0 :       InitHitmap();
      52             :     }
      53             :     else { // read from file (grid or local)
      54           0 :       fWrite=kFALSE;
      55           0 :       fFile->GetObject("AliITSOnlineSPDphysInfo", fPhysInfo);
      56           0 :       ReadHitmap();
      57             :     }
      58             :   }
      59             :   else { // create new local file
      60           0 :     fPhysInfo = new AliITSOnlineSPDphysInfo();
      61           0 :     fInfoModified=kTRUE;
      62           0 :     fFile = new TFile(fFileName.Data(), "RECREATE");
      63           0 :     fWrite=kTRUE;
      64           0 :     InitHitmap();
      65             :   }
      66             : 
      67           0 : }
      68             : 
      69             : AliITSOnlineSPDphys::AliITSOnlineSPDphys(const AliITSOnlineSPDphys& /*phys*/) :
      70           0 :   fFile(NULL),
      71           0 :   fWrite(kFALSE),
      72           0 :   fModified(kFALSE),
      73           0 :   fInfoModified(kFALSE),
      74           0 :   fPhysInfo(NULL),
      75           0 :   fFileName(".")
      76           0 : {
      77           0 :   for(Int_t i=0; i<6; i++) fHitArray[i]=0x0;
      78           0 :   printf("This object should not be copied!");
      79           0 : }
      80             : 
      81           0 : AliITSOnlineSPDphys::~AliITSOnlineSPDphys() {
      82             :   // destructor
      83           0 :   if (fModified) {
      84           0 :     SaveHitmap();
      85             :   }
      86           0 :   for (UInt_t hs=0; hs<6; hs++) {
      87           0 :     if (fHitArray[hs]!=NULL) {
      88           0 :       delete fHitArray[hs];
      89           0 :       fHitArray[hs]=NULL;
      90           0 :     }
      91             :   }
      92           0 :   if (fInfoModified) {
      93           0 :     if (!fWrite) {
      94           0 :       fFile->Close();
      95           0 :       delete fFile;
      96           0 :       fFile = new TFile(fFileName.Data(), "UPDATE");
      97           0 :       fWrite=kTRUE;
      98           0 :     }
      99           0 :     fFile->Delete("AliITSOnlineSPDphysInfo;*");
     100           0 :     fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo");
     101             :   }
     102           0 :   if (fFile!=NULL) {
     103           0 :     delete fFile;
     104             :   }
     105           0 : }
     106             : 
     107             : AliITSOnlineSPDphys& AliITSOnlineSPDphys::operator=(const AliITSOnlineSPDphys& phys) {
     108             :   // assignment operator (should not be used)
     109           0 :   printf("This object should not be copied!");
     110             :   if (this!=&phys) {
     111             :     // still do nothing...
     112             :   }
     113           0 :   return *this;
     114             : }
     115             : 
     116             : void AliITSOnlineSPDphys::ClearThis() {
     117             :   // clear this phys, close file and open new
     118           0 :   for (UInt_t hs=0; hs<6; hs++) {
     119           0 :     if (fHitArray[hs]!=NULL) {
     120           0 :       delete fHitArray[hs];
     121             :     }
     122           0 :     fHitArray[hs] = NULL;
     123             :   }
     124           0 :   InitHitmap();
     125           0 :   fPhysInfo->ClearThis();
     126           0 :   fFile->Close();
     127           0 :   delete fFile;
     128           0 :   fFile = new TFile(fFileName.Data(), "RECREATE");
     129           0 :   fWrite=kTRUE;
     130           0 :   fFile->WriteTObject(fPhysInfo, "AliITSOnlineSPDphysInfo");
     131           0 :   fInfoModified=kTRUE;
     132           0 : }
     133             : 
     134             : void AliITSOnlineSPDphys::InitHitmap() {
     135             :   // init hit arrays and hit events
     136           0 :   for (UInt_t hs=0; hs<6; hs++) {
     137           0 :     fHitArray[hs] = new AliITSOnlineSPDHitArray();
     138             :   }
     139           0 :   fModified=kTRUE;
     140           0 : }
     141             : 
     142             : void AliITSOnlineSPDphys::AddPhys(AliITSOnlineSPDphys* phys2) {
     143             :   // add hitmap and info from another phys object
     144           0 :   if (phys2==NULL) return;
     145           0 :   if (GetEqNr()!=phys2->GetEqNr() && GetEqNr()!=999) {
     146           0 :     printf("AliITSOnlineSPDphys::AddPhys eqNr mismatch!\n");
     147           0 :     return;
     148             :   }
     149           0 :   if (GetEqNr()==999) {
     150           0 :     SetEqNr(phys2->GetEqNr());
     151           0 :   }
     152           0 :   UInt_t nrRuns = phys2->GetNrRuns();
     153           0 :   for (UInt_t i=0; i<nrRuns; i++) {
     154           0 :     AddRunNr(phys2->GetRunNr(i));
     155             :   }
     156           0 :   SetNrEvents(GetNrEvents() + phys2->GetNrEvents());
     157           0 :   for (UInt_t hs=0; hs<6; hs++) {
     158           0 :     for (UInt_t chip=0; chip<10; chip++) {
     159           0 :       for (UInt_t col=0; col<32; col++) {
     160           0 :         for (UInt_t row=0; row<256; row++) {
     161           0 :           SetHits(hs,chip,col,row,GetHits(hs,chip,col,row)+phys2->GetHits(hs,chip,col,row));
     162             :         }
     163             :       }
     164             :     }
     165             :   }
     166           0 : }
     167             : 
     168             : void AliITSOnlineSPDphys::ReadHitmap() {
     169             :   // read hitmap into memory
     170           0 :   for (UInt_t hs=0; hs<6; hs++) {
     171           0 :     TString hName = Form("HitArray_HS%d",hs);
     172           0 :     fFile->GetObject(hName.Data(), fHitArray[hs]);
     173           0 :   }
     174           0 : }
     175             : 
     176             : void AliITSOnlineSPDphys::SaveHitmap() {
     177             :   // save hitmap to file
     178           0 :   if (!fWrite) {
     179           0 :     fFile->Close();
     180           0 :     delete fFile;
     181           0 :     fFile = new TFile(fFileName.Data(), "UPDATE");
     182           0 :     fWrite=kTRUE;
     183           0 :   }
     184           0 :   for (UInt_t hs=0; hs<6; hs++) {
     185           0 :     TString hName = Form("HitArray_HS%d",hs);
     186             :     //TString hDelete = Form("%s;*",hName.Data());
     187             :     //fFile->Delete(hDelete.Data());
     188           0 :     fFile->WriteTObject(fHitArray[hs], hName.Data(),"overwrite");
     189           0 :   }
     190           0 :   fModified=kFALSE;
     191           0 : }
     192             : 
     193             : void AliITSOnlineSPDphys::SetHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi, UInt_t val) {
     194             :   // set nr of hits for pixel
     195           0 :   fHitArray[hs]->SetHits(chipi,coli,rowi,val);
     196           0 :   fModified=kTRUE;
     197           0 : }
     198             : void AliITSOnlineSPDphys::AddHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi, Int_t val) {
     199             :   // add val nr of hits for pixel (val could be negative)
     200           0 :   Int_t summedVal = fHitArray[hs]->GetHits(chipi,coli,rowi)+val;
     201           0 :   if (summedVal>0) {
     202           0 :     fHitArray[hs]->SetHits(chipi,coli,rowi,(UInt_t)summedVal);
     203           0 :   }
     204             :   else {
     205           0 :     fHitArray[hs]->SetHits(chipi,coli,rowi,0);
     206             :   }
     207           0 :   fModified=kTRUE;
     208           0 : }
     209             : void AliITSOnlineSPDphys::IncrementHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
     210             :   // increment nr of hits for pixel
     211           0 :   fHitArray[hs]->IncrementHits(chipi,coli,rowi);
     212           0 :   fModified=kTRUE;
     213           0 : }
     214             : 
     215             : UInt_t AliITSOnlineSPDphys::GetHits(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
     216             :   // get nr of hits for pixel
     217           0 :   return fHitArray[hs]->GetHits(chipi,coli,rowi);
     218             : }
     219             : Float_t AliITSOnlineSPDphys::GetHitsEfficiency(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
     220             :   // get the hit efficiency for pixel
     221           0 :   UInt_t ntr = GetNrEvents();
     222           0 :   if (ntr>0) {
     223           0 :     return ((Float_t)GetHits(hs,chipi,coli,rowi))/ntr;
     224             :   }
     225             :   else {
     226           0 :     return 0;
     227             :   }
     228           0 : }
     229             : Float_t AliITSOnlineSPDphys::GetHitsEfficiencyError(UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
     230             :   // get error in hit efficiency for pixel
     231           0 :   Float_t hits = GetHits(hs,chipi,coli,rowi);
     232           0 :   UInt_t ntr = GetNrEvents();
     233           0 :   return sqrt(hits*(ntr-hits)/ntr)/ntr;
     234             : }
     235             : Float_t AliITSOnlineSPDphys::GetAverageMultiplicity(UInt_t hs, UInt_t chipi) {
     236             :   // get average multiplicity for a chip
     237             :   Float_t nrhits = 0;
     238           0 :   for (UInt_t chip=0;chip<10;chip++) {
     239           0 :     if (chipi==10 || chip==chipi) {
     240           0 :       for (Int_t col=0; col<32; col++) {
     241           0 :         for (Int_t row=0; row<256; row++) {
     242           0 :           nrhits+=GetHits(hs,chip,col,row);
     243             :         }
     244             :       }
     245           0 :     }
     246             :   }
     247           0 :   UInt_t ntr = GetNrEvents();
     248           0 :   if (ntr>0) {
     249           0 :     return nrhits/ntr;
     250             :   }
     251             :   else {
     252           0 :     return 0;
     253             :   }
     254           0 : }
     255             : Float_t AliITSOnlineSPDphys::GetAverageMultiplicityTot(UInt_t hs) {
     256             :   // get average multiplicity for 10 chips
     257           0 :   return GetAverageMultiplicity(hs,10);
     258             : }
     259             : 
     260             : void AliITSOnlineSPDphys::AddRunNr(UInt_t val) {
     261             :   // add a run nr
     262           0 :   fPhysInfo->AddRunNr(val);
     263           0 :   fInfoModified=kTRUE;
     264           0 : }
     265             : void AliITSOnlineSPDphys::SetEqNr(UInt_t val) {
     266             :   // set router nr
     267           0 :   fPhysInfo->SetEqNr(val);
     268           0 :   fInfoModified=kTRUE;
     269           0 : }
     270             : void AliITSOnlineSPDphys::SetNrEvents(UInt_t val) {
     271             :   // set nr of events
     272           0 :   fPhysInfo->SetNrEvents(val);
     273           0 :   fInfoModified=kTRUE;
     274           0 : }
     275             : void AliITSOnlineSPDphys::AddNrEvents(Int_t val) {
     276             :   // add val nr of events (val could be negative)
     277           0 :   fPhysInfo->AddNrEvents(val);
     278           0 :   fInfoModified=kTRUE;
     279           0 : }
     280             : void AliITSOnlineSPDphys::IncrementNrEvents() {
     281             :   // increment nr of events
     282           0 :   fPhysInfo->IncrementNrEvents(); 
     283           0 :   fInfoModified=kTRUE;
     284           0 : }
     285             : 
     286             : 
     287             : UInt_t AliITSOnlineSPDphys::GetNrRuns() const {
     288           0 :   return fPhysInfo->GetNrRuns();
     289             : }
     290             : UInt_t AliITSOnlineSPDphys::GetRunNr(UInt_t posi) const {
     291           0 :   return fPhysInfo->GetRunNr(posi);
     292             : }
     293             : UInt_t AliITSOnlineSPDphys::GetEqNr() const {
     294           0 :   return fPhysInfo->GetEqNr();
     295             : }
     296             : UInt_t AliITSOnlineSPDphys::GetNrEvents() const {
     297           0 :   return fPhysInfo->GetNrEvents();
     298             : }
     299             : 

Generated by: LCOV version 1.11