]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCcalibDB.cxx
Adding OCDB entries for the Ion tail
[u/mrichter/AliRoot.git] / TPC / AliTPCcalibDB.cxx
index aa34eb779539d953caa52eca8292e32ae7b1fd41..2091e1c9098ca18eeced2dc4584c422fc40c2798 100644 (file)
@@ -48,7 +48,7 @@
 //          Simulation:      applied in the AliTPC::MakeSector - adding offset
 //          Reconstruction:  AliTPCTransform::Transform() - remove offset
 //                           AliTPCTransform::Transform() - to be called
-//                           in AliTPCtracker::Transform()      
+//                           in AliTPCtrackerMI::Transform()      
 //
 // 
 // 2.)  Space points transformation:
@@ -125,6 +125,7 @@ class AliTPCCalDet;
 #include "AliTPCCalibRaw.h"
 #include "AliTPCParam.h"
 #include "AliTPCCorrection.h"
+#include "AliTPCComposedCorrection.h"
 #include "AliTPCPreprocessorOnline.h"
 
 
@@ -140,7 +141,7 @@ AliTPCcalibDB* AliTPCcalibDB::Instance()
 {
   //
   // Singleton implementation
-  // Returns an instance of this class, it is created if neccessary
+  // Returns an instance of this class, it is created if necessary
   //
   
   if (fgTerminated != kFALSE)
@@ -176,6 +177,7 @@ AliTPCcalibDB::AliTPCcalibDB():
   fTransform(0),
   fExB(0),
   fPadGainFactor(0),
+  fActiveChannelMap(0),
   fDedxGainFactor(0),
   fPadTime0(0),
   fDistortionMap(0),
@@ -186,6 +188,7 @@ AliTPCcalibDB::AliTPCcalibDB():
   fCalibRaw(0),
   fDataQA(0),
   fALTROConfigData(0),
+  fIonTailArray(0),
   fPulserData(0),
   fCEData(0),
   fTemperature(0),
@@ -193,17 +196,19 @@ AliTPCcalibDB::AliTPCcalibDB():
   fParam(0),
   fClusterParam(0),
   fTimeGainSplines(0),
-  fTimeGainSplinesArray(100000),
-  fGRPArray(100000),            //! array of GRPs  -  per run  - JUST for calibration studies
-  fGRPMaps(100000),            //! array of GRPs  -  per run  - JUST for calibration studies
-  fGoofieArray(100000),         //! array of GOOFIE values -per run - Just for calibration studies
-  fVoltageArray(100000),
-  fTemperatureArray(100000),    //! array of temperature sensors - per run - Just for calibration studies
-  fVdriftArray(100000),                 //! array of v drift interfaces
-  fDriftCorrectionArray(100000),  //! array of drift correction
-  fRunList(100000),              //! run list - indicates try to get the run param 
+  fTimeGainSplinesArray(1),
+  fGRPArray(1),            //! array of GRPs  -  per run  - JUST for calibration studies
+  fGRPMaps(1),            //! array of GRPs  -  per run  - JUST for calibration studies
+  fGoofieArray(1),         //! array of GOOFIE values -per run - Just for calibration studies
+  fVoltageArray(1),
+  fTemperatureArray(1),    //! array of temperature sensors - per run - Just for calibration studies
+  fVdriftArray(1),                 //! array of v drift interfaces
+  fDriftCorrectionArray(1),  //! array of drift correction
+  fRunList(1),              //! run list - indicates try to get the run param 
+  fBHasAlignmentOCDB(kFALSE),    // Flag  - has the alignment on the composed correction ?
   fDButil(0),
-  fCTPTimeParams(0)
+  fCTPTimeParams(0),
+  fMode(-1)
 {
   //
   // constructor
@@ -211,6 +216,14 @@ AliTPCcalibDB::AliTPCcalibDB():
   //
   fgInstance=this;
   Update();    // temporary
+  fTimeGainSplinesArray.SetOwner(); //own the keys
+  fGRPArray.SetOwner(); //own the keys
+  fGRPMaps.SetOwner(); //own the keys
+  fGoofieArray.SetOwner(); //own the keys
+  fVoltageArray.SetOwner(); //own the keys
+  fTemperatureArray.SetOwner(); //own the keys
+  fVdriftArray.SetOwner(); //own the keys
+  fDriftCorrectionArray.SetOwner(); //own the keys
 }
 
 AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
@@ -219,6 +232,7 @@ AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
   fTransform(0),
   fExB(0),
   fPadGainFactor(0),
+  fActiveChannelMap(0),
   fDedxGainFactor(0),
   fPadTime0(0),
   fDistortionMap(0),
@@ -229,6 +243,7 @@ AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
   fCalibRaw(0),
   fDataQA(0),
   fALTROConfigData(0),
+  fIonTailArray(0),
   fPulserData(0),
   fCEData(0),
   fTemperature(0),
@@ -236,7 +251,7 @@ AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
   fParam(0),
   fClusterParam(0),
   fTimeGainSplines(0),
-  fTimeGainSplinesArray(100000),
+  fTimeGainSplinesArray(1),
   fGRPArray(0),          //! array of GRPs  -  per run  - JUST for calibration studies
   fGRPMaps(0),          //! array of GRPs  -  per run  - JUST for calibration studies
   fGoofieArray(0),        //! array of GOOFIE values -per run - Just for calibration studies
@@ -245,13 +260,23 @@ AliTPCcalibDB::AliTPCcalibDB(const AliTPCcalibDB& ):
   fVdriftArray(0),         //! array of v drift interfaces
   fDriftCorrectionArray(0), //! array of v drift corrections
   fRunList(0),              //! run list - indicates try to get the run param 
+  fBHasAlignmentOCDB(kFALSE),    // Flag  - has the alignment on the composed correction ?
   fDButil(0),
-  fCTPTimeParams(0)
+  fCTPTimeParams(0),
+  fMode(-1)
 {
   //
   // Copy constructor invalid -- singleton implementation
   //
    Error("copy constructor","invalid -- singleton implementation");
+  fTimeGainSplinesArray.SetOwner(); //own the keys
+  fGRPArray.SetOwner(); //own the keys
+  fGRPMaps.SetOwner(); //own the keys
+  fGoofieArray.SetOwner(); //own the keys
+  fVoltageArray.SetOwner(); //own the keys
+  fTemperatureArray.SetOwner(); //own the keys
+  fVdriftArray.SetOwner(); //own the keys
+  fDriftCorrectionArray.SetOwner(); //own the keys
 }
 
 AliTPCcalibDB& AliTPCcalibDB::operator= (const AliTPCcalibDB& )
@@ -272,6 +297,7 @@ AliTPCcalibDB::~AliTPCcalibDB()
   // destructor
   //
   
+  delete fActiveChannelMap;
 }
 AliTPCCalPad* AliTPCcalibDB::GetDistortionMap(Int_t i) const {
   //
@@ -291,7 +317,7 @@ AliCDBEntry* AliTPCcalibDB::GetCDBEntry(const char* cdbPath)
   AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, fRun); 
   if (!entry) 
   { 
-    sprintf(chinfo,"AliTPCcalibDB: Failed to get entry:\t%s ", cdbPath);
+    snprintf(chinfo,1000,"AliTPCcalibDB: Failed to get entry:\t%s ", cdbPath);
     AliError(chinfo); 
     return 0; 
   }
@@ -330,7 +356,7 @@ void AliTPCcalibDB::Update(){
     entry->SetOwner(kTRUE);
     fPadGainFactor = (AliTPCCalPad*)entry->GetObject();
   }else{
-    AliFatal("TPC - Missing calibration entry TPC/Calib/PadGainFactor")
+    AliFatal("TPC - Missing calibration entry TPC/Calib/PadGainFactor");
   }
   //
   entry          = GetCDBEntry("TPC/Calib/TimeGain");
@@ -339,7 +365,7 @@ void AliTPCcalibDB::Update(){
     entry->SetOwner(kTRUE);
     fTimeGainSplines = (TObjArray*)entry->GetObject();
   }else{
-    AliFatal("TPC - Missing calibration entry TPC/Calib/Timegain")
+    AliFatal("TPC - Missing calibration entry TPC/Calib/Timegain");
   }
   //
   entry          = GetCDBEntry("TPC/Calib/GainFactorDedx");
@@ -347,7 +373,7 @@ void AliTPCcalibDB::Update(){
     entry->SetOwner(kTRUE);
     fDedxGainFactor = (AliTPCCalPad*)entry->GetObject();
   }else{
-    AliFatal("TPC - Missing calibration entry TPC/Calib/gainFactordEdx")
+    AliFatal("TPC - Missing calibration entry TPC/Calib/gainFactordEdx");
   }
   //
   entry          = GetCDBEntry("TPC/Calib/PadTime0");
@@ -356,7 +382,7 @@ void AliTPCcalibDB::Update(){
     entry->SetOwner(kTRUE);
     fPadTime0 = (AliTPCCalPad*)entry->GetObject();
   }else{
-    AliFatal("TPC - Missing calibration entry")
+    AliFatal("TPC - Missing calibration entry");
   }
 
   entry          = GetCDBEntry("TPC/Calib/Distortion");
@@ -377,7 +403,7 @@ void AliTPCcalibDB::Update(){
     entry->SetOwner(kTRUE);
     fPadNoise = (AliTPCCalPad*)entry->GetObject();
   }else{
-    AliFatal("TPC - Missing calibration entry")
+    AliFatal("TPC - Missing calibration entry");
   }
 
   entry          = GetCDBEntry("TPC/Calib/Pedestals");
@@ -398,17 +424,17 @@ void AliTPCcalibDB::Update(){
   if (entry){
     //if (fPadNoise) delete fPadNoise;
     entry->SetOwner(kTRUE);
-    fParam = (AliTPCParam*)(entry->GetObject()->Clone());
+    fParam = (AliTPCParam*)(entry->GetObject());
   }else{
-    AliFatal("TPC - Missing calibration entry TPC/Calib/Parameters")
+    AliFatal("TPC - Missing calibration entry TPC/Calib/Parameters");
   }
 
   entry          = GetCDBEntry("TPC/Calib/ClusterParam");
   if (entry){
     entry->SetOwner(kTRUE);
-    fClusterParam = (AliTPCClusterParam*)(entry->GetObject()->Clone());
+    fClusterParam = (AliTPCClusterParam*)(entry->GetObject());
   }else{
-    AliFatal("TPC - Missing calibration entry")
+    AliFatal("TPC - Missing calibration entry");
   }
 
   //ALTRO configuration data
@@ -417,7 +443,7 @@ void AliTPCcalibDB::Update(){
     entry->SetOwner(kTRUE);
     fALTROConfigData=(TObjArray*)(entry->GetObject());
   }else{
-    AliFatal("TPC - Missing calibration entry")
+    AliFatal("TPC - Missing calibration entry");
   }
   
   //Calibration Pulser data
@@ -427,6 +453,14 @@ void AliTPCcalibDB::Update(){
     fPulserData=(TObjArray*)(entry->GetObject());
   }
   
+   //Calibration ION tail data
+ //  entry          = GetCDBEntry("TPC/Calib/IonTail");
+//   if (entry){
+//     entry->SetOwner(kTRUE);
+//     fIonTailArray=(TObjArray*)(entry->GetObject());
+//   }
+
+
   //CE data
   entry          = GetCDBEntry("TPC/Calib/CE");
   if (entry){
@@ -435,7 +469,7 @@ void AliTPCcalibDB::Update(){
   }
   //RAW calibration data
  //  entry          = GetCDBEntry("TPC/Calib/Raw");
-  
+
   entry          = GetCDBEntry("TPC/Calib/Mapping");
   if (entry){
     //if (fPadNoise) delete fPadNoise;
@@ -455,7 +489,7 @@ void AliTPCcalibDB::Update(){
     //entry->SetOwner(kTRUE);
     fCTPTimeParams=dynamic_cast<AliCTPTimeParams*>(entry->GetObject());
   }else{
-    AliError("TPC - Missing calibration entry")
+    AliError("TPC - Missing calibration entry");
   }  
   //TPC space point correction data
   entry          = GetCDBEntry("TPC/Calib/Correction");
@@ -466,20 +500,31 @@ void AliTPCcalibDB::Update(){
     fComposedCorrectionArray=dynamic_cast<TObjArray*>(entry->GetObject());
     if (fComposedCorrectionArray){
       for (Int_t i=0; i<fComposedCorrectionArray->GetEntries(); i++){
-       AliTPCCorrection* composedCorrection= dynamic_cast<AliTPCCorrection*>(fComposedCorrectionArray->At(i));
-       if (composedCorrection) composedCorrection->Init();
+       AliTPCComposedCorrection* composedCorrection= dynamic_cast<AliTPCComposedCorrection*>(fComposedCorrectionArray->At(i));
+       if (composedCorrection) {
+         composedCorrection->Init();
+         if (composedCorrection->GetCorrections()){
+           if (composedCorrection->GetCorrections()->FindObject("FitAlignTPC")){
+             fBHasAlignmentOCDB=kTRUE;
+           }
+         }
+       }
       }
-    }
+    }  
   }else{
-    AliError("TPC - Missing calibration entry-  TPC/Calib/Correction")
-  }  
-
+    AliError("TPC - Missing calibration entry-  TPC/Calib/Correction");
+  } 
+  //RCU trigger config mode
+  fMode=GetRCUTriggerConfig();
   //
   if (!fTransform) {
     fTransform=new AliTPCTransform(); 
     fTransform->SetCurrentRun(AliCDBManager::Instance()->GetRun());
   }
 
+  // Create Dead Channel Map
+  InitDeadMap();
+
   //
   AliCDBManager::Instance()->SetCacheFlag(cdbCache); // reset original CDB cache
 }
@@ -504,10 +549,10 @@ void AliTPCcalibDB::UpdateNonRec(){
     fDataQA=dynamic_cast<AliTPCdataQA*>(entry->GetObject());
   }
   // High voltage
-  if (fRun>=0){
+  if (fRun>=0 && !fVoltageArray.GetValue(Form("%i",fRun))){
     entry = AliCDBManager::Instance()->Get("TPC/Calib/HighVoltage",fRun);
     if (entry)  {
-      fVoltageArray.AddAt(entry->GetObject(),fRun);
+      fVoltageArray.Add(new TObjString(Form("%i",fRun)),entry->GetObject());
     }
   }
 
@@ -607,7 +652,153 @@ void AliTPCcalibDB::CreateObjectList(const Char_t *filename, TObjArray *calibObj
    }
 }
 
+Int_t AliTPCcalibDB::InitDeadMap() {
+  // Initialize DeadChannel Map 
+  // Source of information:
+  // -  HV < HVnominal -delta
+  // -  Altro disabled channels. Noisy channels.
+  // -  DDL list
+
+  // check necessary information
+  Int_t run=AliCDBManager::Instance()->GetRun();
+  if (run<0){
+    AliError("run not set in CDB manager. Cannot create active channel map");
+    return 0;
+  }
+  AliDCSSensorArray* voltageArray = AliTPCcalibDB::Instance()->GetVoltageSensors(run);
+  AliTPCCalPad*          altroMap = GetALTROMasked();
+  TMap*                    mapddl = GetDDLMap();
+
+  if (!voltageArray && !altroMap && !mapddl) {
+    AliError("All necessary information to create the activate channel are map missing.");
+    return 0;
+  }
+  
+  if (!fActiveChannelMap) fActiveChannelMap=new AliTPCCalPad("ActiveChannelMap","ActiveChannelMap");
+  
+  //=============================================================
+  //get map of bad ROCs from VOLTAGE deviations
+  //
+  Bool_t badVoltage[AliTPCCalPad::kNsec]={kFALSE};
+  Double_t maxVdiff=100.;
+
+  if (voltageArray){
+    //1. get median of median of all chambers
+    Double_t chamberMedian[AliTPCCalPad::kNsec]={0.};
+    for (Int_t iROC=0;iROC<AliTPCCalPad::kNsec;++iROC){
+      TString sensorName="";
+      Char_t sideName='A';
+      if ((iROC/18)%2==1) sideName='C';
+      if (iROC<36) sensorName=Form("TPC_ANODE_I_%c%02d_VMEAS",sideName,iROC%18);
+      else         sensorName=Form("TPC_ANODE_O_%c%02d_0_VMEAS",sideName,iROC%18);
+
+      AliDCSSensor *sensor = voltageArray->GetSensor(sensorName);
+      if (!sensor) continue;
+
+      chamberMedian[iROC]=0;
+      TGraph *gr=sensor->GetGraph();
+      AliSplineFit *fit=sensor->GetFit();
+      if ( gr && gr->GetN()>0 ){
+        chamberMedian[iROC]=TMath::Median(gr->GetN(),gr->GetY());
+      } else if (fit && fit->GetKnots()>0) {
+        chamberMedian[iROC]=TMath::Median(fit->GetKnots(), fit->GetY0());
+      }
+    }
+    Double_t medianIROC=TMath::Median( 36, chamberMedian );
+    Double_t medianOROC=TMath::Median( 36, chamberMedian+36 );
+
+    //2. check if 90% of the knots (points) are out of a given threshold
+    for (Int_t iROC=0;iROC<AliTPCCalPad::kNsec;++iROC){
+      badVoltage[iROC]=kFALSE;
+      TString sensorName="";
+      Char_t sideName='A';
+      Double_t median=medianIROC;
+      if ((iROC/18)%2==1) sideName='C';
+      if (iROC<36) sensorName=Form("TPC_ANODE_I_%c%02d_VMEAS",sideName,iROC%18);
+      else           {sensorName=Form("TPC_ANODE_O_%c%02d_0_VMEAS",sideName,iROC%18); median=medianOROC; }
+
+      AliDCSSensor *sensor = voltageArray->GetSensor(sensorName);
+      if (!sensor) continue;
+
+      chamberMedian[iROC]=0;
+      TGraph *gr=sensor->GetGraph();
+      AliSplineFit *fit=sensor->GetFit();
+      Int_t nmax=1;
+      Int_t nout=0;
+      if ( gr && gr->GetN()>0 ){
+        nmax=gr->GetN();
+        for (Int_t i=0; i<gr->GetN(); ++i)
+          if ( TMath::Abs( gr->GetY()[i]-median ) > maxVdiff ) ++nout;
+      } else if (fit && fit->GetKnots()>0) {
+        nmax=fit->GetKnots();
+        for (Int_t i=0; i<fit->GetKnots(); ++i)
+          if ( TMath::Abs( fit->GetY0()[i]-median ) > maxVdiff ) ++nout;
+      }
+      if ( (Double_t)nout/(Double_t)nmax > 0.9 ) badVoltage[iROC]=kTRUE;
+      //     printf("%d, %d, %d, %f\n",iROC, nout, nmax, median);
+    }
+
+  } else {
+    AliError("Voltage Array missing. ActiveChannelMap can only be created with parts of the information.");
+  }
+  // Voltage map is done
+  //=============================================================
+
+  //=============================================================
+  // Setup DDL map
+
+  Bool_t ddlMap[216]={0};
+  for (Int_t iddl=0; iddl<216; ++iddl) ddlMap[iddl]=1;
+  if (mapddl){
+    TObjString *s = (TObjString*)mapddl->GetValue("DDLArray");
+    if (s){
+      for (Int_t iddl=0; iddl<216; ++iddl) ddlMap[iddl]=TString(s->GetString()(iddl))!="0";
+    }
+  } else {
+    AliError("DDL map missing. ActiveChannelMap can only be created with parts of the information.");
+  }
+  // Setup DDL map done
+  // ============================================================
+
+  //=============================================================
+  // Setup active chnnel map
+  //
+
+  AliTPCmapper map(gSystem->ExpandPathName("$ALICE_ROOT/TPC/mapping/"));
 
+  if (!altroMap) AliError("ALTRO dead channel map missing. ActiveChannelMap can only be created with parts of the information.");
+  
+  for (Int_t iROC=0;iROC<AliTPCCalPad::kNsec;++iROC){
+    AliTPCCalROC *roc=fActiveChannelMap->GetCalROC(iROC);
+    if (!roc){
+      AliError(Form("No ROC %d in active channel map",iROC));
+      continue;
+    }
+    
+    // check for bad voltage
+    if (badVoltage[iROC]){
+      roc->Multiply(0.);
+      continue;
+    }
+    
+    AliTPCCalROC *masked=0x0;
+    if (altroMap) masked=altroMap->GetCalROC(iROC);
+    
+    for (UInt_t irow=0; irow<roc->GetNrows(); ++irow){
+      for (UInt_t ipad=0; ipad<roc->GetNPads(irow); ++ipad){
+        //per default the channel is on
+        roc->SetValue(irow,ipad,1);
+        // apply altro dead channel mask (inverse logik, it is not active, but inactive channles)
+        if (masked && masked->GetValue(irow, ipad)) roc->SetValue(irow, ipad ,0);
+        // mask channels if a DDL is inactive
+        Int_t ddlId=map.GetEquipmentID(iROC, irow, ipad)-768;
+        if (ddlId>=0 && !ddlMap[ddlId]) roc->SetValue(irow, ipad ,0);
+      }
+    }
+  }
+  
+  return 1;
+}
 
 void AliTPCcalibDB::MakeTree(const char * fileName, TObjArray * array, const char * mapFileName, AliTPCCalPad* outlierPad, Float_t ltmFraction) {
   //
@@ -841,9 +1032,8 @@ Bool_t AliTPCcalibDB::IsTrgL0()
   //
   // return if the FEE readout was triggered on L0
   //
-  Int_t mode=GetRCUTriggerConfig();
-  if (mode<0) return kFALSE;
-  return (mode==1);
+  if (fMode<0) return kFALSE;
+  return (fMode==1);
 }
 
 Bool_t AliTPCcalibDB::IsTrgL1()
@@ -851,9 +1041,8 @@ Bool_t AliTPCcalibDB::IsTrgL1()
   //
   // return if the FEE readout was triggered on L1
   //
-  Int_t mode=GetRCUTriggerConfig();
-  if (mode<0) return kFALSE;
-  return (mode==0);
+  if (fMode<0) return kFALSE;
+  return (fMode==0);
 }
 
 void AliTPCcalibDB::RegisterExB(Int_t index, Float_t bz, Bool_t bdelete){
@@ -912,25 +1101,16 @@ void  AliTPCcalibDB::SetExBField(const AliMagF*   bmap){
 
 
 
-
-
 void AliTPCcalibDB::UpdateRunInformations( Int_t run, Bool_t force){
   //
   // - > Don't use it for reconstruction - Only for Calibration studies
   //
   if (run<=0) return;
+  TObjString runstr(Form("%i",run));
   fRun=run;
   AliCDBEntry * entry = 0;
   if (run>= fRunList.fN){
     fRunList.Set(run*2+1);
-    fGRPArray.Expand(run*2+1);
-    fGRPMaps.Expand(run*2+1);
-    fGoofieArray.Expand(run*2+1);
-    fVoltageArray.Expand(run*2+1); 
-    fTemperatureArray.Expand(run*2+1);
-    fVdriftArray.Expand(run*2+1);
-    fDriftCorrectionArray.Expand(run*2+1);
-    fTimeGainSplinesArray.Expand(run*2+1);
     //
     //
     fALTROConfigData->Expand(run*2+1);    // ALTRO configuration data
@@ -954,36 +1134,50 @@ void AliTPCcalibDB::UpdateRunInformations( Int_t run, Bool_t force){
        //grpRun->ReadValuesFromMap(map);
        grpRun =  MakeGRPObjectFromMap(map);
 
-       fGRPMaps.AddAt(map,run);
+       fGRPMaps.Add(new TObjString(runstr),map);
       }
     }
-    fGRPArray.AddAt(grpRun,run);
+    fGRPArray.Add(new TObjString(runstr),grpRun);
   }
   entry = AliCDBManager::Instance()->Get("TPC/Calib/Goofie",run);
   if (entry){
-    fGoofieArray.AddAt(entry->GetObject(),run);
+    fGoofieArray.Add(new TObjString(runstr),entry->GetObject());
   }
   //
   
   //
   entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeGain",run);
   if (entry)  {
-    fTimeGainSplinesArray.AddAt(entry->GetObject(),run);
+    fTimeGainSplinesArray.Add(new TObjString(runstr),entry->GetObject());
   }else{
-    AliFatal("TPC - Missing calibration entry TimeGain")
+    AliFatal("TPC - Missing calibration entry TimeGain");
   }
   //
   entry = AliCDBManager::Instance()->Get("TPC/Calib/TimeDrift",run);
   if (entry)  {
-    fDriftCorrectionArray.AddAt(entry->GetObject(),run);
+    TObjArray * timeArray = (TObjArray*)entry->GetObject();    
+    fDriftCorrectionArray.Add(new TObjString(runstr),entry->GetObject());  
+    AliTPCCorrection * correctionTime = (AliTPCCorrection *)timeArray->FindObject("FitCorrectionTime");
+    if (correctionTime && fComposedCorrectionArray){
+      correctionTime->Init();
+      if (fComposedCorrectionArray->GetEntriesFast()<4) fComposedCorrectionArray->Expand(40);
+      fComposedCorrectionArray->AddAt(correctionTime,4); //add time dependent correction to the list of available corrections
+    }
   }else{
-    AliFatal("TPC - Missing calibration entry TimeDrift")
+    AliFatal("TPC - Missing calibration entry TimeDrift");
   }
   //
   entry = AliCDBManager::Instance()->Get("TPC/Calib/Temperature",run);
   if (entry)  {
-    fTemperatureArray.AddAt(entry->GetObject(),run);
+    fTemperatureArray.Add(new TObjString(runstr),entry->GetObject());
   }
+
+  // High voltage
+  entry = AliCDBManager::Instance()->Get("TPC/Calib/HighVoltage",run);
+  if (!fVoltageArray.GetValue(runstr.GetName()) && entry)  {
+    fVoltageArray.Add(new TObjString(runstr),entry->GetObject());
+  }
+
   //apply fDButil filters
 
   fDButil->UpdateFromCalibDB();
@@ -996,7 +1190,7 @@ void AliTPCcalibDB::UpdateRunInformations( Int_t run, Bool_t force){
     accept = fDButil->FilterTemperature(temp)>0.1;
   }
   if (press) {
-    const Double_t kMinP=950.;
+    const Double_t kMinP=900.;
     const Double_t kMaxP=1050.;
     const Double_t kMaxdP=10.;
     const Double_t kSigmaCut=4.;
@@ -1006,7 +1200,7 @@ void AliTPCcalibDB::UpdateRunInformations( Int_t run, Bool_t force){
 
   if (press && temp &&accept){
     AliTPCCalibVdrift * vdrift = new AliTPCCalibVdrift(temp, press,0);
-    fVdriftArray.AddAt(vdrift,run);
+    fVdriftArray.Add(new TObjString(runstr),vdrift);
   }
 
   fDButil->FilterCE(120., 3., 4.,0);
@@ -1053,13 +1247,10 @@ AliGRPObject *AliTPCcalibDB::GetGRP(Int_t run){
   //
   // Get GRP object for given run 
   //
-  if (run>= ((Instance()->fGRPArray)).GetEntriesFast()){
-    Instance()->UpdateRunInformations(run);    
-  }
-  AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>((Instance()->fGRPArray).At(run));
+  AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>((Instance()->fGRPArray).GetValue(Form("%i",run)));
   if (!grpRun) {
     Instance()->UpdateRunInformations(run);
-    grpRun = dynamic_cast<AliGRPObject *>(Instance()->fGRPArray.At(run));
+    grpRun = dynamic_cast<AliGRPObject *>(Instance()->fGRPArray.GetValue(Form("%i",run)));
     if (!grpRun) return 0; 
   }
   return grpRun;
@@ -1069,10 +1260,10 @@ TMap *  AliTPCcalibDB::GetGRPMap(Int_t run){
   //
   // Get GRP map for given run
   //
-  TMap * grpRun = dynamic_cast<TMap *>((Instance()->fGRPMaps).At(run));
+  TMap * grpRun = dynamic_cast<TMap *>((Instance()->fGRPMaps).GetValue(Form("%i",run)));
   if (!grpRun) {
     Instance()->UpdateRunInformations(run);
-    grpRun = dynamic_cast<TMap *>(Instance()->fGRPMaps.At(run));
+    grpRun = dynamic_cast<TMap *>(Instance()->fGRPMaps.GetValue(Form("%i",run)));
     if (!grpRun) return 0; 
   }
   return grpRun;
@@ -1101,10 +1292,10 @@ AliDCSSensor * AliTPCcalibDB::GetPressureSensor(Int_t run, Int_t type){
   //
   // If not map try to get it from the GRPObject
   //
-  AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run)); 
+  AliGRPObject * grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.GetValue(Form("%i",run))); 
   if (!grpRun) {
     UpdateRunInformations(run);
-    grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.At(run));
+    grpRun = dynamic_cast<AliGRPObject *>(fGRPArray.GetValue(Form("%i",run)));
     if (!grpRun) return 0; 
   }
   AliDCSSensor * sensor = grpRun->GetCavernAtmosPressure();
@@ -1116,10 +1307,10 @@ AliTPCSensorTempArray * AliTPCcalibDB::GetTemperatureSensor(Int_t run){
   //
   // Get temperature sensor array
   //
-  AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
+  AliTPCSensorTempArray * tempArray = (AliTPCSensorTempArray *)fTemperatureArray.GetValue(Form("%i",run));
   if (!tempArray) {
     UpdateRunInformations(run);
-    tempArray = (AliTPCSensorTempArray *)fTemperatureArray.At(run);
+    tempArray = (AliTPCSensorTempArray *)fTemperatureArray.GetValue(Form("%i",run));
   }
   return tempArray;
 }
@@ -1129,10 +1320,10 @@ TObjArray * AliTPCcalibDB::GetTimeGainSplinesRun(Int_t run){
   //
   // Get temperature sensor array
   //
-  TObjArray * gainSplines = (TObjArray *)fTimeGainSplinesArray.At(run);
+  TObjArray * gainSplines = (TObjArray *)fTimeGainSplinesArray.GetValue(Form("%i",run));
   if (!gainSplines) {
     UpdateRunInformations(run);
-    gainSplines = (TObjArray *)fTimeGainSplinesArray.At(run);
+    gainSplines = (TObjArray *)fTimeGainSplinesArray.GetValue(Form("%i",run));
   }
   return gainSplines;
 }
@@ -1141,10 +1332,10 @@ TObjArray * AliTPCcalibDB::GetTimeVdriftSplineRun(Int_t run){
   //
   // Get drift spline array
   //
-  TObjArray * driftSplines = (TObjArray *)fDriftCorrectionArray.At(run);
+  TObjArray * driftSplines = (TObjArray *)fDriftCorrectionArray.GetValue(Form("%i",run));
   if (!driftSplines) {
     UpdateRunInformations(run);
-    driftSplines = (TObjArray *)fDriftCorrectionArray.At(run);
+    driftSplines = (TObjArray *)fDriftCorrectionArray.GetValue(Form("%i",run));
   }
   return driftSplines;
 }
@@ -1153,10 +1344,10 @@ AliDCSSensorArray * AliTPCcalibDB::GetVoltageSensors(Int_t run){
   //
   // Get temperature sensor array
   //
-  AliDCSSensorArray * voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
+  AliDCSSensorArray * voltageArray = (AliDCSSensorArray *)fVoltageArray.GetValue(Form("%i",run));
   if (!voltageArray) {
     UpdateRunInformations(run);
-    voltageArray = (AliDCSSensorArray *)fVoltageArray.At(run);
+    voltageArray = (AliDCSSensorArray *)fVoltageArray.GetValue(Form("%i",run));
   }
   return voltageArray;
 }
@@ -1165,10 +1356,10 @@ AliDCSSensorArray * AliTPCcalibDB::GetGoofieSensors(Int_t run){
   //
   // Get temperature sensor array
   //
-  AliDCSSensorArray * goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
+  AliDCSSensorArray * goofieArray = (AliDCSSensorArray *)fGoofieArray.GetValue(Form("%i",run));
   if (!goofieArray) {
     UpdateRunInformations(run);
-    goofieArray = (AliDCSSensorArray *)fGoofieArray.At(run);
+    goofieArray = (AliDCSSensorArray *)fGoofieArray.GetValue(Form("%i",run));
   }
   return goofieArray;
 }
@@ -1179,11 +1370,10 @@ AliTPCCalibVdrift *     AliTPCcalibDB::GetVdrift(Int_t run){
   //
   // Get the interface to the the vdrift 
   //
-  if (run>=fVdriftArray.GetEntriesFast())  UpdateRunInformations(run);
-  AliTPCCalibVdrift  * vdrift = (AliTPCCalibVdrift*)fVdriftArray.At(run);
+  AliTPCCalibVdrift  * vdrift = (AliTPCCalibVdrift*)fVdriftArray.GetValue(Form("%i",run));
   if (!vdrift) {
     UpdateRunInformations(run);
-    vdrift= (AliTPCCalibVdrift*)fVdriftArray.At(run);
+    vdrift= (AliTPCCalibVdrift*)fVdriftArray.GetValue(Form("%i",run));
   }
   return vdrift;
 }
@@ -1346,11 +1536,11 @@ Float_t AliTPCcalibDB::GetChamberHighVoltage(Int_t run, Int_t sector, Int_t time
     if (sector<36){
       //IROC
       sensorName=Form("TPC_ANODE_I_%c%02d_IMEAS",sideName,sector%18);
-  }else{
+    }else{
       //OROC
       sensorName=Form("TPC_ANODE_O_%c%02d_0_IMEAS",sideName,sector%18);
     }
-
+    
   }
   if (timeStamp==-1){
     val=AliTPCcalibDB::GetDCSSensorMeanValue(voltageArray, sensorName.Data(),sigDigits);
@@ -1713,7 +1903,7 @@ Bool_t AliTPCcalibDB::CreateGUITree(const char* filename){
   
   //
   TString file(filename);
-  if (file.IsNull()) file=Form("guiTreeRun_%lld.root",fRun);
+  if (file.IsNull()) file=Form("guiTreeRun_%i.root",fRun);
   prep.DumpToFile(file.Data());
   return kTRUE;
 }
@@ -1868,6 +2058,7 @@ Double_t AliTPCcalibDB::GetVDriftCorrectionGy(Int_t timeStamp, Int_t run, Int_t
 
   // use TPC-ITS if present
   TGraphErrors *gr= (TGraphErrors*)array->FindObject("ALIGN_ITSB_TPC_VDGY");
+  if (!gr) gr = (TGraphErrors*)array->FindObject("ALIGN_TOFB_TPC_VDGY");
   if(gr) { 
     result = AliTPCcalibDButil::EvalGraphConst(gr,timeStamp);
 
@@ -1911,7 +2102,7 @@ AliTPCCalPad* AliTPCcalibDB::MakeDeadMap(Double_t notInMap, const char* nameMapp
   TFile *fileMapping = new TFile(nameMappingFile, "read");
   AliTPCmapper *mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
   if (!mapping) {
-    sprintf(chinfo,"Failed to get mapping object from %s.  ...\n", nameMappingFile);
+    snprintf(chinfo,1000,"Failed to get mapping object from %s.  ...\n", nameMappingFile);
     AliError (chinfo);
     return 0;
   }
@@ -1945,8 +2136,11 @@ AliTPCCalPad* AliTPCcalibDB::MakeDeadMap(Double_t notInMap, const char* nameMapp
   Double_t active;
   for (Int_t i=0; i<mapping->GetNumDdl(); i++) {
     idDDL= i+offset;
+    if (idDDL<0) continue;
     Int_t patch = mapping->GetPatchFromEquipmentID(idDDL);   
+    if (patch<0) continue;
     Int_t roc=mapping->GetRocFromEquipmentID(idDDL);
+    if (roc<0) continue;
     AliTPCCalROC *calRoc=deadMap->GetCalROC(roc);
     if (calRoc) {
      for ( Int_t branch = 0; branch < 2; branch++ ) {
@@ -1977,11 +2171,38 @@ AliTPCCalPad* AliTPCcalibDB::MakeDeadMap(Double_t notInMap, const char* nameMapp
 AliTPCCorrection * AliTPCcalibDB::GetTPCComposedCorrection(Float_t field) const{
   //
   // GetComposed correction for given field setting
-  //
+  // If not specific correction for field used return correction for all field
+  //        - Complication needed to gaurantee OCDB back compatibility 
+  //        - Not neeeded for the new space point correction 
   if (!fComposedCorrectionArray) return 0;
-  if (field>0.1) return (AliTPCCorrection *)fComposedCorrectionArray->At(1);
-  if (field<-0.1) return (AliTPCCorrection *)fComposedCorrectionArray->At(2);
+  if (field>0.1 && fComposedCorrectionArray->At(1)) {   
+    return (AliTPCCorrection *)fComposedCorrectionArray->At(1);
+  }
+  if (field<-0.1 &&fComposedCorrectionArray->At(2)) {
+    return (AliTPCCorrection *)fComposedCorrectionArray->At(2);
+  }
   return (AliTPCCorrection *)fComposedCorrectionArray->At(0);
   
 }
 
+
+AliTPCCorrection * AliTPCcalibDB::GetTPCComposedCorrectionDelta() const{
+  //
+  // GetComposedCorrection delta
+  // Delta is time dependent - taken form the CalibTime OCDB entry
+  //
+  if (!fComposedCorrectionArray) return 0;
+  if (fRun<0) return 0;
+  if (fDriftCorrectionArray.GetValue(Form("%i",fRun))==0) return 0;
+  if (fComposedCorrectionArray->GetEntriesFast()<=4) {
+    fComposedCorrectionArray->Expand(5);
+    TObjArray * timeArray =(TObjArray*)(fDriftCorrectionArray.GetValue(Form("%i",fRun)));
+     AliTPCCorrection * correctionTime = (AliTPCCorrection *)timeArray->FindObject("FitCorrectionTime");
+     if (correctionTime){
+       correctionTime->Init();
+       fComposedCorrectionArray->AddAt(correctionTime,4); //add time dependent c
+     }
+  }
+  return (AliTPCCorrection *)fComposedCorrectionArray->At(4);  //
+}
+