]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - T0/AliT0CalibData.cxx
Fixes for memory leaks (Chiara)
[u/mrichter/AliRoot.git] / T0 / AliT0CalibData.cxx
index 68c952f400d2f6e937cdd032b036abb0dce56c54..2a6635384220003297c23c727da0220c615165f3 100644 (file)
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
-// class for T0 calibration                       TM-AC-AM_6-02-2006         //
+// class for T0 calibration                       TM--AM_6-02-2006         //
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-#include <iostream>
-#include <fstream>
-#include <iomanip>
-#include <string>
-#include <TCanvas.h>
-
 #include "AliT0CalibData.h"
-#include "TObjArray.h"
-#include "TGraph.h"
-#include "TFile.h"
+#include "AliT0LookUpValue.h"
+#include "AliT0LookUpKey.h"
 #include "AliLog.h"
-#include "TObjString.h"
-
-#include "TAxis.h"
-#include "TH2F.h"
 
+#include <Riostream.h>
 
+//#include <string>
 
+using std::ifstream;
 ClassImp(AliT0CalibData)
 
 //________________________________________________________________
-  AliT0CalibData::AliT0CalibData():   TNamed()
+  AliT0CalibData::AliT0CalibData():   TNamed(),
+                                     fLookup(0),
+                                     fNumberOfTRMs(0)
 
 {
   //
 }
 
 //________________________________________________________________
-AliT0CalibData::AliT0CalibData(const char* name):TNamed(),fTimeDelayTVD(0),fWalk(),fSlewingLED(),fSlewingRec()
+AliT0CalibData::AliT0CalibData(const char* name):TNamed(),
+                                     fLookup(0),
+                                     fNumberOfTRMs(0)
 {
   TString namst = "Calib_";
   namst += name;
@@ -60,7 +56,10 @@ AliT0CalibData::AliT0CalibData(const char* name):TNamed(),fTimeDelayTVD(0),fWalk
 
 //________________________________________________________________
 AliT0CalibData::AliT0CalibData(const AliT0CalibData& calibda) :
-  TNamed(calibda),fTimeDelayTVD(0),fWalk(),fSlewingLED(),fSlewingRec()
+  TNamed(calibda),             
+  fLookup(0),
+  fNumberOfTRMs(0)
+
 {
 // copy constructor
   SetName(calibda.GetName());
@@ -82,118 +81,106 @@ AliT0CalibData &AliT0CalibData::operator =(const AliT0CalibData& calibda)
 //________________________________________________________________
 AliT0CalibData::~AliT0CalibData()
 {
-
+  //
 }
 //________________________________________________________________
-void AliT0CalibData::Reset()
+void  AliT0CalibData::PrintLookup(Option_t*, Int_t iTRM, Int_t iTDC, Int_t iChannel) const
 {
-    memset(fTimeDelayCFD,1,24*sizeof(Float_t));
-    memset(fTimeDelayLED,1,24*sizeof(Float_t));
-    memset(fGain,1,24*sizeof(Float_t));
+  // print lookup table
+
+  AliT0LookUpKey* lookkey; //= new AliT0LookUpKey();
+  AliT0LookUpValue*  lookvalue= new AliT0LookUpValue();
+  printf("Number Of TRMs in setup %i\n",GetNumberOfTRMs());
+
+  iTRM=0; iTDC=0; Int_t chain=0; iChannel=0;
+
+  for (Int_t ik=0; ik<105; ik++){
+    lookvalue->SetTRM(iTRM);
+    lookvalue->SetTDC(iTDC);
+    lookvalue->SetChain(chain);
+    lookvalue->SetChannel(iChannel);
+    
+    if (iChannel<6) iChannel +=2;
+    else {iChannel = 0; iTDC++;}
+    if(ik==57) { iTDC=0; iChannel=0; iTRM=1;}
+   
+  printf(" AliT0CalibData::PrintLookup ::start GetValue %i %i %i %i\n",iTRM, iTDC,chain, iChannel);
+    lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
+    //    TString name= lookkey->GetChannelName();
+    // cout<<name.Data()<<endl;
+    if (lookkey)
+      {
+       TString name= lookkey->GetChannelName();
+       /*      cout<<" lookup KEY!!! "<<name.Data()<<" "<<lookkey->GetKey()<<" VALUE "<<lookvalue->GetTRM()<<" "
+           <<lookvalue->GetTDC()<<" "
+           << lookvalue->GetChain()<<" "
+           <<lookvalue->GetChannel()<<endl;*/
+      }
+  }
+  
 }
-
-
 //________________________________________________________________
-void  AliT0CalibData::Print(Option_t*) const
+
+void AliT0CalibData::ReadAsciiLookup(const Char_t *filename)
 {
+  // read lookup table from ascii file
 
-  printf("\n   ----    PM Arrays       ----\n\n");
-  printf(" Time delay CFD \n");
-  for (Int_t i=0; i<24; i++) printf("  %f",fTimeDelayCFD[i]);
-  printf(" \n LED \n");
-  for (Int_t i=0; i<24; i++) printf("  %f",fTimeDelayLED[i]);
-  printf(" \n Gain \n");
-  for (Int_t i=0; i<24; i++) printf("  %f",fGain[i]);
-  printf(" \n");
-} 
+  Int_t key, trm, tdc, chain, channel;
 
+  if(filename == 0){
+    AliError(Form("Please, specify file with database")) ;
+    return ;
+  }
 
 
-//________________________________________________________________
-void AliT0CalibData::SetTimeDelayCFD(Float_t* TimeDelay)
-{
-  if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayCFD[t] = TimeDelay[t];
-  //  else for(int t=0; t<24; t++) fTimeDelay[t] = 0.;
+  ifstream lookup;
+  lookup.open(filename);
+  if(!lookup)
+    {
+     AliError(Form("!!!!!!!!!!!!!!No look up table in CDB!" ));
+    }
+  Char_t varname[11];
+  Int_t ntrms;
+  if(lookup)
+    {
+      lookup>>ntrms;
+      //      fNumberOfTRMs=ntrms;
+      SetNumberOfTRMs(ntrms);
+       while(!lookup.eof())
+       {
+         AliT0LookUpKey * lookkey= new AliT0LookUpKey();
+         AliT0LookUpValue * lookvalue= new AliT0LookUpValue();
+         
+         lookup>>varname>>key>>trm>>chain>>tdc>>channel;
+         lookvalue->SetTRM(trm);
+         lookvalue->SetTDC(tdc);
+         lookvalue->SetChain(chain);
+         lookvalue->SetChannel(channel);
+         lookkey->SetKey(key);
+         lookkey->SetChannelName(varname);
+         
+         fLookup.Add((TObject*)lookvalue,(TObject*)lookkey);
+         
+       }
+      
+      lookup.close();
+      
+    }
 }
 //________________________________________________________________
-void AliT0CalibData::SetTimeDelayLED(Float_t* TimeDelay)
-{
-  if(TimeDelay) for(int t=0; t<24; t++) fTimeDelayLED[t] = TimeDelay[t];
-  //  else for(int t=0; t<24; t++) fTimeDelay[t] = 0.;
-}
 
-//________________________________________________________________
-void AliT0CalibData::SetGain(Float_t* Gain)
+Int_t AliT0CalibData::GetChannel(Int_t trm,  Int_t tdc, Int_t chain, Int_t channel)
 {
-  if(Gain) for(int t=0; t<24; t++) fGain[t] = Gain[t];
-  // else for(int t=0; t<24; t++) fGain[t] = 0.;
-}
+  // read number of channel according physical addres 
 
 
-//________________________________________________________________
-void AliT0CalibData::SetWalk(Int_t ipmt, const Char_t *filename)
-{
+  AliT0LookUpKey * lookkey;//= new AliT0LookUpKey();
+  AliT0LookUpValue * lookvalue= new AliT0LookUpValue(trm,tdc,chain,channel);
 
-  TFile *file = new TFile(filename);
-  char funcname[256];
-  sprintf(funcname,"CFD%i",ipmt+1);
-  TF1* gr = (TF1*)file->Get(funcname);
-  fWalk.AddAtAndExpand(gr,ipmt);
-  file->Close();
-}
-
-
-//________________________________________________________________
-
-void AliT0CalibData::SetSlewingLED(Int_t ipmt,const Char_t *filename)
-{
-  Float_t mv, ps; 
-  Float_t x[100], y[100];
-  string buffer;
-  
-  ifstream inFile(filename);
-  if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
-  
-  inFile >> mv>>ps;
-  Int_t i=0;
-  
-  while(getline(inFile,buffer)){
-    x[i]=mv; y[i]=ps;  
-    inFile >> mv >> ps;
-    i++;
-  }
-  inFile.close();
-  TGraph* gr = new TGraph(i,x,y);
-  fSlewingLED.AddAtAndExpand(gr,ipmt);
-   
-}
+  lookkey = (AliT0LookUpKey*) fLookup.GetValue((TObject*)lookvalue);
 
-//________________________________________________________________
+  return lookkey->GetKey();
 
-void AliT0CalibData::SetSlewingRec(Int_t ipmt,const Char_t *filename)
-{
-  Float_t mv, ps; 
-  Float_t x[100], y[100];
-  string buffer;
-  
-  ifstream inFile(filename);
-  if(!inFile) {AliError(Form("Cannot open file %s !",filename));}
-  
-  inFile >> mv>>ps;
-  Int_t i=0;
-  
-  while(getline(inFile,buffer)){
-    x[i]=mv; y[i]=ps;  
-    inFile >> mv >> ps;
-    i++;
-  }
-  inFile.close();
-  Float_t y1[100], x1[100];
-  for (Int_t ir=0; ir<i; ir++){
-    y1[ir]=y[i-ir]; x1[ir]=x[i-ir];}
-  TGraph* gr = new TGraph(i,y1,x1);
-  fSlewingRec.AddAtAndExpand(gr,ipmt);
-  
 }
 
-