]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALCalibMapAPD.cxx
- removing obsolote classes
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALCalibMapAPD.cxx
index 8f8573e48e9070cf198b55a5a9215b35c51ece52..82b888bea95f078f7b5897c80191d86e6cc17ca0 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <fstream>
 #include <TString.h>
+#include <TFile.h>
+#include <TTree.h>
 
 #include "AliEMCALCalibMapAPD.h"
 
@@ -28,16 +30,20 @@ using namespace std;
 ClassImp(AliEMCALCalibMapAPD)
 
 //____________________________________________________________________________
-AliEMCALCalibMapAPD::AliEMCALCalibMapAPD() : 
-  fNSuperModule(0),
-  fSuperModuleData(0)
+AliEMCALCalibMapAPD::AliEMCALCalibMapAPD(const int nSM) : 
+  fNSuperModule(nSM),
+  fSuperModuleData()
 {
   //Default constructor.
+  for (int i=0; i<fNSuperModule; i++) {
+    fSuperModuleData.Add(new AliEMCALSuperModuleCalibMapAPD(i));
+  }
+  fSuperModuleData.Compress(); // compress the TObjArray
 }
 
 //____________________________________________________________________________
-void AliEMCALCalibMapAPD::ReadCalibMapAPDInfo(Int_t nSM, const TString &txtFileName,
-                                     Bool_t swapSides)
+void AliEMCALCalibMapAPD::ReadTextCalibMapAPDInfo(Int_t nSM, const TString &txtFileName,
+                                                 Bool_t swapSides)
 {
   //Read data from txt file. ; coordinates given on SuperModule basis
 
@@ -48,39 +54,37 @@ void AliEMCALCalibMapAPD::ReadCalibMapAPDInfo(Int_t nSM, const TString &txtFileN
   }
 
   fNSuperModule = nSM;
-  if (fSuperModuleData) delete [] fSuperModuleData;
-  fSuperModuleData = new AliEMCALSuperModuleCalibMapAPD[fNSuperModule];
 
   Int_t iSM = 0; // SuperModule index
   Int_t iCol = 0;
   Int_t iRow = 0;
   // list of values to be read
   Int_t iHW = 0;
-  Int_t APDNum = 0;
-  Float_t V30 = 0;     
-  Float_t Par[3] = {0};   
-  Float_t ParErr[3] = {0}; 
-  Int_t BreakDown = 0;
-  Float_t DarkCurrent = 0; 
+  Int_t iAPDNum = 0;
+  Float_t v30 = 0;     
+  Float_t par[3] = {0};   
+  Float_t parErr[3] = {0}; 
+  Int_t iBreakDown = 0;
+  Float_t darkCurrent = 0; 
   // end - all values
 
   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
 
   for (Int_t i = 0; i < fNSuperModule; i++) {
-    AliEMCALSuperModuleCalibMapAPD &t = fSuperModuleData[i];
+    AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[i];
     if (!inputFile) {
       printf("AliEMCALCalibMapAPD::ReadCalibMapAPDInfo - Error while reading input file; likely EOF..");
       return;
     }
     inputFile >> iSM;
-    t.fSuperModuleNum = iSM;
+    t->SetSuperModuleNum(iSM);
 
     for (Int_t j=0; j<nAPDPerSM; j++) {
       inputFile >> iCol >> iRow >> iHW 
-               >> APDNum >> V30 
-               >> Par[0] >> Par[1] >> Par[2]
-               >> ParErr[0] >> ParErr[1] >> ParErr[2]
-               >> BreakDown >> DarkCurrent;
+               >> iAPDNum >> v30 
+               >> par[0] >> par[1] >> par[2]
+               >> parErr[0] >> parErr[1] >> parErr[2]
+               >> iBreakDown >> darkCurrent;
 
       // assume that this info is already swapped and done for this basis?
       if (swapSides) {
@@ -89,19 +93,19 @@ void AliEMCALCalibMapAPD::ReadCalibMapAPDInfo(Int_t nSM, const TString &txtFileN
        iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
       }
 
-      AliEMCALCalibMapAPDVal &v = t.fAPDVal[iCol][iRow];
-
-      v.fHardWareId = iHW;
-      v.fAPDNum = APDNum;
-      v.fV30 = V30;
-      v.fPar[0] = Par[0];
-      v.fPar[1] = Par[1];
-      v.fPar[2] = Par[2];
-      v.fParErr[0] = ParErr[0];
-      v.fParErr[1] = ParErr[1];
-      v.fParErr[2] = ParErr[2];
-      v.fBreakDown = BreakDown;
-      v.fDarkCurrent = DarkCurrent;
+      AliEMCALCalibMapAPDVal * v = t->GetAPDVal(iCol, iRow);
+
+      v->SetHardWareId(iHW);
+      v->SetAPDNum(iAPDNum);
+      v->SetV30(v30);
+      v->SetPar(0, par[0]);
+      v->SetPar(1, par[1]);
+      v->SetPar(2, par[2]);
+      v->SetParErr(0, parErr[0]);
+      v->SetParErr(1, parErr[1]);
+      v->SetParErr(2, parErr[2]);
+      v->SetBreakDown(iBreakDown);
+      v->SetDarkCurrent(darkCurrent);
     }
 
   } // i, SuperModule
@@ -112,8 +116,8 @@ void AliEMCALCalibMapAPD::ReadCalibMapAPDInfo(Int_t nSM, const TString &txtFileN
 }
 
 //____________________________________________________________________________
-void AliEMCALCalibMapAPD::WriteCalibMapAPDInfo(const TString &txtFileName,
-                                      Bool_t swapSides)
+void AliEMCALCalibMapAPD::WriteTextCalibMapAPDInfo(const TString &txtFileName,
+                                                  Bool_t swapSides)
 {
   // write data to txt file. ; coordinates given on SuperModule basis
 
@@ -129,14 +133,14 @@ void AliEMCALCalibMapAPD::WriteCalibMapAPDInfo(const TString &txtFileName,
   Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
 
   for (Int_t i = 0; i < fNSuperModule; i++) {
-    AliEMCALSuperModuleCalibMapAPD &t = fSuperModuleData[i];
-    outputFile << t.fSuperModuleNum << endl;
+    AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[i];
+    outputFile << t->GetSuperModuleNum() << endl;
 
     for (Int_t j=0; j<nAPDPerSM; j++) {
       iCol = j / AliEMCALGeoParams::fgkEMCALRows;
       iRow = j % AliEMCALGeoParams::fgkEMCALRows;
 
-      AliEMCALCalibMapAPDVal &v = t.fAPDVal[iCol][iRow];
+      AliEMCALCalibMapAPDVal * v = t->GetAPDVal(iCol, iRow);
 
       if (swapSides) {
        // C side, oriented differently than A side: swap is requested
@@ -144,11 +148,11 @@ void AliEMCALCalibMapAPD::WriteCalibMapAPDInfo(const TString &txtFileName,
        iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
       }
 
-      outputFile << iCol << " " << iRow << " " << v.fHardWareId 
-                << " " << v.fAPDNum << " " << v.fV30 
-                << " " << v.fPar[0] << " " << v.fPar[1] << " " << v.fPar[2]
-                << " " << v.fParErr[0] << " " << v.fParErr[1] << " " << v.fParErr[2]
-                << " " << v.fBreakDown << " " << v.fDarkCurrent << endl;
+      outputFile << iCol << " " << iRow << " " << v->GetHardWareId() 
+                << " " << v->GetAPDNum() << " " << v->GetV30() 
+                << " " << v->GetPar(0) << " " << v->GetPar(1) << " " << v->GetPar(2)
+                << " " << v->GetParErr(0) << " " << v->GetParErr(1) << " " << v->GetParErr(2)
+                << " " << v->GetBreakDown() << " " << v->GetDarkCurrent() << endl;
     }
 
   } // i, SuperModule
@@ -159,34 +163,178 @@ void AliEMCALCalibMapAPD::WriteCalibMapAPDInfo(const TString &txtFileName,
 }
 
 //____________________________________________________________________________
-AliEMCALCalibMapAPD::~AliEMCALCalibMapAPD()
+void AliEMCALCalibMapAPD::ReadRootCalibMapAPDInfo(const TString &rootFileName,
+                                                 Bool_t swapSides)
 {
-  delete [] fSuperModuleData;
+  //Read data from root file. ; coordinates given on SuperModule basis
+  TFile inputFile(rootFileName, "read");  
+
+  TTree *tree = (TTree*) inputFile.Get("tree");
+
+  ReadTreeCalibMapAPDInfo(tree, swapSides);
+
+  inputFile.Close();
+
+  return;
 }
 
 //____________________________________________________________________________
-AliEMCALCalibMapAPD::AliEMCALSuperModuleCalibMapAPD AliEMCALCalibMapAPD::GetSuperModuleCalibMapAPDId(Int_t supModIndex)const
+void AliEMCALCalibMapAPD::ReadTreeCalibMapAPDInfo(TTree *tree,
+                                                 Bool_t swapSides)
 {
-  AliEMCALSuperModuleCalibMapAPD t;  // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
-  if (!fSuperModuleData)
-    return t;
+  // how many SuperModule's worth of entries / APDs do we have?
+  Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
+  fNSuperModule = tree->GetEntries() / nAPDPerSM;
+
+  Int_t iSM = 0; // SuperModule index
+  Int_t iCol = 0;
+  Int_t iRow = 0;
+  // list of values to be read
+  Int_t iHW = 0;
+  Int_t iAPDNum = 0;
+  Float_t v30 = 0;     
+  Float_t par[3] = {0};   
+  Float_t parErr[3] = {0}; 
+  Int_t iBreakDown = 0;
+  Float_t darkCurrent = 0; 
+  // end - all values
+
+  // declare the branches
+  tree->SetBranchAddress("iSM", &iSM);
+  tree->SetBranchAddress("iCol", &iCol);
+  tree->SetBranchAddress("iRow", &iRow);
+  tree->SetBranchAddress("iHW", &iHW);
+  tree->SetBranchAddress("APDNum", &iAPDNum);
+  tree->SetBranchAddress("V30", &v30);
+  tree->SetBranchAddress("Par", par);
+  tree->SetBranchAddress("ParErr", parErr);
+  tree->SetBranchAddress("BreakDown", &iBreakDown);
+  tree->SetBranchAddress("DarkCurrent", &darkCurrent);
+
+  for (int ient=0; ient<tree->GetEntries(); ient++) {
+    tree->GetEntry(ient);
+
+    // assume the index SuperModules come in order: i=iSM
+    AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[iSM];
+    t->SetSuperModuleNum(iSM);
+
+    // assume that this info is already swapped and done for this basis?
+    if (swapSides) {
+      // C side, oriented differently than A side: swap is requested
+      iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
+      iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
+    }
+
+    AliEMCALCalibMapAPDVal * v = t->GetAPDVal(iCol, iRow);
+
+    v->SetHardWareId(iHW);
+    v->SetAPDNum(iAPDNum);
+    v->SetV30(v30);
+    v->SetPar(0, par[0]);
+    v->SetPar(1, par[1]);
+    v->SetPar(2, par[2]);
+    v->SetParErr(0, parErr[0]);
+    v->SetParErr(1, parErr[1]);
+    v->SetParErr(2, parErr[2]);
+    v->SetBreakDown(iBreakDown);
+    v->SetDarkCurrent(darkCurrent);
+  } // 
+
+  return;
+}
+
+//____________________________________________________________________________
+void AliEMCALCalibMapAPD::WriteRootCalibMapAPDInfo(const TString &rootFileName,
+                                      Bool_t swapSides)
+{
+  // write data to root file. ; coordinates given on SuperModule basis
+  TFile destFile(rootFileName, "recreate");  
+  if (destFile.IsZombie()) {
+    return;
+  }  
+  destFile.cd();
+
+  TTree *tree = new TTree("tree","");
 
-  return fSuperModuleData[supModIndex];
+  // variables for filling the TTree
+  Int_t iSM = 0; // SuperModule index
+  Int_t iHW = 0;
+  Int_t iAPDNum = 0;
+  Float_t v30 = 0;     
+  Float_t par[3] = {0};   
+  Float_t parErr[3] = {0}; 
+  Int_t iBreakDown = 0;
+  Float_t darkCurrent = 0; 
+  //
+  Int_t iCol = 0;
+  Int_t iRow = 0;
+  // declare the branches
+  tree->Branch("iSM", &iSM, "iSM/I");
+  tree->Branch("iCol", &iCol, "iCol/I");
+  tree->Branch("iRow", &iRow, "iRow/I");
+  tree->Branch("iHW", &iHW, "iHW/I");
+  tree->Branch("APDNum", &iAPDNum, "APDNum/I");
+  tree->Branch("V30", &v30, "V30/F");
+  tree->Branch("Par", &par, "Par[3]/F");
+  tree->Branch("ParErr", &parErr, "ParErr[3]/F");
+  tree->Branch("BreakDown", &iBreakDown, "BreakDown/I");
+  tree->Branch("DarkCurrent", &darkCurrent, "DarkCurrent/F");
+
+  Int_t nAPDPerSM = AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows;
+
+  for (iSM = 0; iSM < fNSuperModule; iSM++) {
+    AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD *) fSuperModuleData[iSM];
+
+    for (Int_t j=0; j<nAPDPerSM; j++) {
+      iCol = j / AliEMCALGeoParams::fgkEMCALRows;
+      iRow = j % AliEMCALGeoParams::fgkEMCALRows;
+
+      AliEMCALCalibMapAPDVal * v = t->GetAPDVal(iCol, iRow);
+
+      if (swapSides) {
+       // C side, oriented differently than A side: swap is requested
+       iCol = AliEMCALGeoParams::fgkEMCALCols-1 - iCol;
+       iRow = AliEMCALGeoParams::fgkEMCALRows-1 - iRow;
+      }
+
+      iHW = v->GetHardWareId(); 
+      iAPDNum = v->GetAPDNum();
+      v30 = v->GetV30();
+      for (int k=0; k<3; k++) {
+       par[k] = v->GetPar(k);
+       parErr[k] = v->GetParErr(k);
+      } 
+      iBreakDown = v->GetBreakDown();
+      darkCurrent = v->GetDarkCurrent();
+
+      tree->Fill();
+    }
+
+  } // i, SuperModule
+
+  tree->Write();
+  destFile.Close();
+
+  return;
 }
 
 //____________________________________________________________________________
-AliEMCALCalibMapAPD::AliEMCALSuperModuleCalibMapAPD AliEMCALCalibMapAPD::GetSuperModuleCalibMapAPDNum(Int_t supModIndex)const
+AliEMCALCalibMapAPD::~AliEMCALCalibMapAPD()
 {
-  AliEMCALSuperModuleCalibMapAPD t;  // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
-  if (!fSuperModuleData)
-    return t;
+  fSuperModuleData.Delete();
+}
 
+//____________________________________________________________________________
+AliEMCALSuperModuleCalibMapAPD * AliEMCALCalibMapAPD::GetSuperModuleCalibMapAPDNum(Int_t supModIndex)const
+{
   for (int i=0; i<fNSuperModule; i++) {
-    if (fSuperModuleData[i].fSuperModuleNum == supModIndex) {
-      return fSuperModuleData[i];
+    AliEMCALSuperModuleCalibMapAPD * t = (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[i];
+    if (t->GetSuperModuleNum() == supModIndex) {
+      return t;
     }
   }
 
-  return t;
+  // if we arrived here, then nothing was found.. just return a NULL pointer 
+  return NULL;
 }