Corrected UInt_t <-> Int_t conversion
[u/mrichter/AliRoot.git] / TPC / AliTPCPreprocessor.cxx
index 76e82b9..501ed83 100644 (file)
@@ -40,6 +40,9 @@
 
 const Int_t kValCutTemp = 100;               // discard temperatures > 100 degrees
 const Int_t kDiffCutTemp = 5;               // discard temperature differences > 5 degrees
+const Double_t kHighVoltageDifference = 1e-4; // don't record High Voltage points 
+                                             // differing by less than 1e-4 from
+                                            // previous point.
 const TString kPedestalRunType = "PEDESTAL";  // pedestal run identifier
 const TString kPulserRunType = "PULSER";     // pulser run identifier
 const TString kPhysicsRunType = "PHYSICS";   // physics run identifier
@@ -57,6 +60,8 @@ const char* kPressureSensorNames[kNumPressureSensors] = {
                    "CavernAtmosPressure",
                    "CavernAtmosPressure2",
                    "SurfaceAtmosPressure" };
+const Int_t  kMinCESectors = 32;      // minimum number of sectors (per side)
+                                      // to accept CE calibration
       
 
 //
@@ -244,8 +249,11 @@ UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
   TObject * status;
 
   UInt_t dcsResult=0;
-  if (!dcsAliasMap) dcsResult=1;
-  if (dcsAliasMap->GetEntries() == 0 ) dcsResult=1;  
+  if (!dcsAliasMap) { 
+     dcsResult=1;
+  } else {
+     if (dcsAliasMap->GetEntries() == 0 ) dcsResult=1;
+  }  
   status = new TParameter<int>("dcsResult",dcsResult);
   resultArray->Add(status);
 
@@ -437,7 +445,7 @@ UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
    // only flag error if CE result is missing from LASER runs
    //    -- for PHYSICS run do CE processing if data available
    
-     if ( runType == kLaserRunType && source != "TRY" ) result += ceResult;
+     if ( runType == kLaserRunType && source != "TRY"  && ceResult<10 ) result += ceResult;
      status = new TParameter<int>("ceResult",ceResult);
      resultArray->Add(status);
 
@@ -475,7 +483,9 @@ UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
   metaData.SetResponsible("Haavard Helstrup");
   metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
   metaData.SetComment("Preprocessor AliTPC status.");
-  Store("Calib", "PreprocStatus", resultArray, &metaData, 0, kFALSE);
+  Bool_t storeOK = Store("Calib", "PreprocStatus", resultArray, &metaData, 0,  kFALSE);
+  if (!storeOK) Log ("Unable to store preprocessor status entry");
   resultArray->Delete();
   delete resultArray;
 
@@ -557,6 +567,8 @@ UInt_t AliTPCPreprocessor::MapHighVoltage(TMap* dcsAliasMap)
   TMap *map = fHighVoltage->ExtractDCS(dcsAliasMap);
   if (map) {
     fHighVoltage->ClearFit();
+    fHighVoltage->RemoveGraphDuplicates(kHighVoltageDifference);
+               // don't keep new point if too similar to previous one
     fHighVoltage->SetGraph(map);
   } else {
     Log("No high voltage recordings extracted. \n");
@@ -644,26 +656,32 @@ UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
  //  Read pedestal file from file exchage server
  //  Keep original entry from OCDB in case no new pedestals are available
  //
- AliTPCCalPad *calPadPed=0;
+ AliTPCCalPad *calPadPedOCDB=0;
  AliCDBEntry* entry = GetFromOCDB("Calib", "Pedestals");
- if (entry) calPadPed = (AliTPCCalPad*)entry->GetObject();
- if ( calPadPed==NULL ) {
+ if (entry) calPadPedOCDB = (AliTPCCalPad*)entry->GetObject();
+ if ( calPadPedOCDB==NULL ) {
      Log("AliTPCPreprocsessor: No previous TPC pedestal entry available.\n");
-     calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
  }
 
- AliTPCCalPad *calPadRMS=0;
+ AliTPCCalPad *calPadRMSOCDB=0;
  entry = GetFromOCDB("Calib", "PadNoise");
- if (entry) calPadRMS = (AliTPCCalPad*)entry->GetObject();
- if ( calPadRMS==NULL ) {
+ if (entry) calPadRMSOCDB = (AliTPCCalPad*)entry->GetObject();
+ if ( calPadRMSOCDB==NULL ) {
      Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
-     calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
  }
 
+  AliTPCCalPad* calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
+  AliTPCCalPad* calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
+
 
  UInt_t result=0;
 
  Int_t nSectors = fROC->GetNSectors();
+ TVectorD foundSectorsPed(nSectors);
+ foundSectorsPed=0;
+ TVectorD foundSectorsRMS(nSectors);
+ foundSectorsRMS=0;
+
  TList* list = GetFileSources(sourceFXS,"pedestals");
  
  if (list && list->GetEntries()>0) {
@@ -696,15 +714,91 @@ UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
         changed=true;
         for (Int_t sector=0; sector<nSectors; sector++) {
            AliTPCCalROC *rocPed=calPed->GetCalRocPedestal(sector, kFALSE);
-           if ( rocPed )  calPadPed->SetCalROC(rocPed,sector);
+           if ( rocPed ) {
+              AliTPCCalROC* roc=calPadPed->GetCalROC(sector);
+              roc->Add(rocPed,1);
+              foundSectorsPed[sector]++;
+          }
            AliTPCCalROC *rocRMS=calPed->GetCalRocRMS(sector, kFALSE);
-           if ( rocRMS )  calPadRMS->SetCalROC(rocRMS,sector);
+           if ( rocRMS )  {
+               AliTPCCalROC* roc=calPadRMS->GetCalROC(sector);
+              roc->Add(rocRMS,1);
+              foundSectorsRMS[sector]++;
+          } 
         }
         delete calPed; 
         f->Close();
       }
      ++index;
     }  // while(list)
+
+//
+//  Check if calibration is complete -- otherwise take from old OCDB entry
+
+// inner sectors
+    for (Int_t sector=0; sector<nSectors/2; sector++) {
+       if (foundSectorsPed[sector] < 1 ) {
+          if (calPadPedOCDB) {
+            AliTPCCalROC *rocOCDB=calPadPedOCDB->GetCalROC(sector);
+           calPadPed->SetCalROC(rocOCDB,sector);
+         } else {
+           const int mess_length=100;
+            char message[mess_length];
+           snprintf(message,mess_length,"Missing pedestals for sector %d - also not available from previous OCDB entry.\n",
+                    sector);
+           Log (message);
+           result = 2;
+         }
+       }
+       if (foundSectorsRMS[sector] < 1 ) {
+          if (calPadRMSOCDB) {
+            AliTPCCalROC *rocOCDB=calPadRMSOCDB->GetCalROC(sector);
+           calPadRMS->SetCalROC(rocOCDB,sector);
+         } else {
+           const int mess_length=100;
+            char message[mess_length];
+           snprintf(message,mess_length,"Missing pedestal RMS for sector %d - also not available from previous OCDB entry.\n",
+                    sector);
+           Log (message);
+           result = 2;
+         }       
+       }
+    }
+
+// outer sectors -- two updates needed
+
+    for (Int_t sector=nSectors/2; sector<nSectors; sector++) {
+       if (foundSectorsPed[sector] < 2 ) {
+          if (calPadPedOCDB) {
+            AliTPCCalROC *rocOCDB=calPadPedOCDB->GetCalROC(sector);
+           calPadPed->SetCalROC(rocOCDB,sector);
+         } else {
+           const int mess_length=100;
+            char message[mess_length];
+           snprintf(message,mess_length,"Missing pedestals for sector %d - also not available from previous OCDB entry.\n",
+                    sector);
+           Log (message);
+           result = 2;
+         }
+
+       }
+       if (foundSectorsRMS[sector] < 2 ) {
+          if (calPadRMSOCDB) {
+            AliTPCCalROC *rocOCDB=calPadRMSOCDB->GetCalROC(sector);
+           calPadRMS->SetCalROC(rocOCDB,sector);
+         } else {
+           const int mess_length=100;
+            char message[mess_length];
+           snprintf(message,mess_length,"Missing pedestal RMS for sector %d - also not available from previous OCDB entry.\n",
+                    sector);
+           Log (message);
+           result = 2;
+         }       
+
+       }       
+    }
+
+    
 //
 //  Store updated pedestal entry to OCDB
 //
@@ -727,6 +821,8 @@ UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
 
   delete calPadPed;
   delete calPadRMS;
+  delete calPadPedOCDB;
+  delete calPadRMSOCDB;
 
   return result;
 }
@@ -740,37 +836,38 @@ UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
  //  Read pulser calibration file from file exchage server
  //  Keep original entry from OCDB in case no new pulser calibration is available
  //
- TObjArray    *pulserObjects=0;
- AliTPCCalPad *pulserTmean=0;
- AliTPCCalPad *pulserTrms=0;
- AliTPCCalPad *pulserQmean=0;
+ TObjArray *pulserObjects = new TObjArray;
+ TObjArray *pulserObjectsOCDB=0;   
+  
  AliCDBEntry* entry = GetFromOCDB("Calib", "Pulser");
- if (entry) pulserObjects = (TObjArray*)entry->GetObject();
- if ( pulserObjects==NULL ) {
+ if (entry) pulserObjectsOCDB = (TObjArray*)entry->GetObject();
+ if ( pulserObjectsOCDB==NULL ) {
      Log("AliTPCPreprocsessor: No previous TPC pulser entry available.\n");
-     pulserObjects = new TObjArray;    
  }
 
- pulserTmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserTmean");
- if ( !pulserTmean ) {
-    pulserTmean = new AliTPCCalPad("PulserTmean","PulserTmean");
-    pulserObjects->Add(pulserTmean);
- }
- pulserTrms = (AliTPCCalPad*)pulserObjects->FindObject("PulserTrms");
- if ( !pulserTrms )  { 
-    pulserTrms = new AliTPCCalPad("PulserTrms","PulserTrms");
-    pulserObjects->Add(pulserTrms);
- }
- pulserQmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserQmean");
- if ( !pulserQmean )  { 
-    pulserQmean = new AliTPCCalPad("PulserQmean","PulserQmean");
-    pulserObjects->Add(pulserQmean);
- }
+ AliTPCCalPad *pulserTmean = new AliTPCCalPad("PulserTmean","PulserTmean");
+ pulserObjects->Add(pulserTmean);
+ AliTPCCalPad *pulserTrms = new AliTPCCalPad("PulserTrms","PulserTrms");
+ pulserObjects->Add(pulserTrms);
+ AliTPCCalPad *pulserQmean = new AliTPCCalPad("PulserQmean","PulserQmean");
+ pulserObjects->Add(pulserQmean);
 
 
  UInt_t result=0;
 
  Int_t nSectors = fROC->GetNSectors();
+ TVectorD foundTmean(nSectors);
+ foundTmean=0;
+ TVectorD foundTrms(nSectors);
+ foundTrms=0;
+ TVectorD foundQmean(nSectors);
+ foundQmean=0;
+
+
  TList* list = GetFileSources(sourceFXS,"pulser");
  
  if (list && list->GetEntries()>0) {
@@ -803,17 +900,88 @@ UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
         changed=true;
         for (Int_t sector=0; sector<nSectors; sector++) {
            AliTPCCalROC *rocTmean=calPulser->GetCalRocT0(sector);
-           if ( rocTmean )  pulserTmean->SetCalROC(rocTmean,sector);
+           if ( rocTmean ) {
+               AliTPCCalROC* roc=pulserTmean->GetCalROC(sector);
+              roc->Add(rocTmean,1);
+              foundTmean[sector]++;
+           }
            AliTPCCalROC *rocTrms=calPulser->GetCalRocRMS(sector);
-           if ( rocTrms )  pulserTrms->SetCalROC(rocTrms,sector);
+           if ( rocTrms ) {
+               AliTPCCalROC* roc=pulserTrms->GetCalROC(sector);
+              roc->Add(rocTrms,1);
+              foundTrms[sector]++;
+           }
            AliTPCCalROC *rocQmean=calPulser->GetCalRocQ(sector);
-           if ( rocQmean )  pulserQmean->SetCalROC(rocQmean,sector);
+           if ( rocQmean ) {
+               AliTPCCalROC* roc=pulserQmean->GetCalROC(sector);
+              roc->Add(rocQmean,1);
+              foundQmean[sector]++;
+           }
         }
        delete calPulser;
        f->Close();
       }
      ++index;
     }  // while(list)
+
+
+
+
+if (pulserObjectsOCDB) {
+  AliTPCCalPad* pulserTmeanOCDB = (AliTPCCalPad*)pulserObjectsOCDB->FindObject("PulserTmean");
+  AliTPCCalPad* pulserTrmsOCDB  = (AliTPCCalPad*)pulserObjectsOCDB->FindObject("PulserTrms");
+  AliTPCCalPad* pulserQmeanOCDB = (AliTPCCalPad*)pulserObjectsOCDB->FindObject("PulserQmean");
+//
+//  Check if calibration is complete -- otherwise take from old OCDB entry
+
+// inner sectors
+    for (Int_t sector=0; sector<nSectors/2; sector++) {
+       if (foundTmean[sector] < 1 ) {
+         if (pulserTmeanOCDB) {
+          AliTPCCalROC* rocOCDB = pulserTmeanOCDB->GetCalROC(sector);
+          if ( rocOCDB ) pulserTmean->SetCalROC(rocOCDB,sector);
+         }
+       }
+       if (foundTrms[sector] < 1 ) {
+         if (pulserTrmsOCDB) {
+          AliTPCCalROC* rocOCDB = pulserTrmsOCDB->GetCalROC(sector);
+          if ( rocOCDB ) pulserTrms->SetCalROC(rocOCDB,sector);
+         }
+       }
+       if (foundQmean[sector] < 1 ) {
+         if (pulserQmeanOCDB) {
+          AliTPCCalROC* rocOCDB = pulserQmeanOCDB->GetCalROC(sector);
+          if ( rocOCDB ) pulserQmean->SetCalROC(rocOCDB,sector);
+         }
+       }
+    }
+  
+// outer sectors -- two updates needed
+
+    for (Int_t sector=0; sector<nSectors/2; sector++) {
+       if (foundTmean[sector] < 2 ) {
+         if (pulserTmeanOCDB) {
+          AliTPCCalROC* rocOCDB = pulserTmeanOCDB->GetCalROC(sector);
+          if ( rocOCDB ) pulserTmean->SetCalROC(rocOCDB,sector);
+         }
+       }
+       if (foundTrms[sector] < 2 ) {
+         if (pulserTrmsOCDB) {
+          AliTPCCalROC* rocOCDB = pulserTrmsOCDB->GetCalROC(sector);
+          if ( rocOCDB ) pulserTrms->SetCalROC(rocOCDB,sector);
+         }
+       }
+       if (foundQmean[sector] < 2 ) {
+         if (pulserQmeanOCDB) {
+          AliTPCCalROC* rocOCDB = pulserQmeanOCDB->GetCalROC(sector);
+          if ( rocOCDB ) pulserQmean->SetCalROC(rocOCDB,sector);
+         }
+       }
+
+    }
+}
+
 //
 //  Store updated pedestal entry to OCDB
 //
@@ -833,6 +1001,8 @@ UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
   }
   pulserObjects->Delete();
   delete pulserObjects;
+  if (pulserObjectsOCDB) pulserObjectsOCDB->Delete();
+  delete pulserObjectsOCDB;
 
   return result;
 }
@@ -906,113 +1076,173 @@ UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
 {
  //
  //  Read Central Electrode file from file exchage server
- //  
  //
- AliTPCCalPad *ceTmean=0;
- AliTPCCalPad *ceTrms=0;
- AliTPCCalPad *ceQmean=0;
- TObjArray    *rocTtime=0;  
- TObjArray    *rocQtime=0;  
-
- TObjArray    *ceObjects= new TObjArray;
+ //
+  AliTPCCalPad *ceTmean=0;
+  AliTPCCalPad *ceTrms=0;
+  AliTPCCalPad *ceQmean=0;
+  TObjArray    *rocTtime=0;
+  TObjArray    *rocQtime=0;
+  
+  TObjArray    *ceObjects= new TObjArray;
+  
+  
+  Int_t nSectors = fROC->GetNSectors();
+  
+  ceTmean = new AliTPCCalPad("CETmean","CETmean");
+  ceObjects->Add(ceTmean);
+  
+  ceTrms = new AliTPCCalPad("CETrms","CETrms");
+  ceObjects->Add(ceTrms);
+  
+  ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
+  ceObjects->Add(ceQmean);
+  
+  rocTtime = new TObjArray(nSectors+2);   // also make room for A and C side average
+  rocTtime->SetName("rocTtime");
+  ceObjects->Add(rocTtime);
+  
+  rocQtime = new TObjArray(nSectors);
+  rocQtime->SetName("rocQtime");
+  ceObjects->Add(rocQtime);
+
+  //=== new part
+  TObjArray *arrFitGraphs=new TObjArray;
+  arrFitGraphs->SetName("ceFitsDrift");
+  ceObjects->Add(arrFitGraphs);
   
-
- Int_t nSectors = fROC->GetNSectors();
-
- ceTmean = new AliTPCCalPad("CETmean","CETmean");
- ceObjects->Add(ceTmean);
-
- ceTrms = new AliTPCCalPad("CETrms","CETrms");
- ceObjects->Add(ceTrms);
-
- ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
- ceObjects->Add(ceQmean);
- rocTtime = new TObjArray(nSectors+2);   // also make room for A and C side average
- rocTtime->SetName("rocTtime");
- ceObjects->Add(rocTtime);
- rocQtime = new TObjArray(nSectors);
- rocQtime->SetName("rocQtime");
- ceObjects->Add(rocQtime);
-
 // Temperature maps 
-
- if (fTemp) {
+  
+  if (fTemp) {
     AliTPCSensorTempArray *tempMap = new AliTPCSensorTempArray(*fTemp);
     tempMap->SetNameTitle("TempMap","TempMap");
     ceObjects->Add(tempMap);
- }
-
+  }
+  
 // Pressure maps
-
- if (fPressure) {
-   AliDCSSensor *sensor=0, *sensorCopy=0;
-   for (Int_t isensor=0; isensor<kNumPressureSensors; ++isensor ) {
+  
+  if (fPressure) {
+    AliDCSSensor *sensor=0, *sensorCopy=0;
+    for (Int_t isensor=0; isensor<kNumPressureSensors; ++isensor ) {
       sensor = fPressure->GetSensor(kPressureSensorNames[isensor]);
       if (sensor) {
-       sensorCopy = new AliDCSSensor(*sensor);
-       sensorCopy->SetNameTitle(kPressureSensorNames[isensor],kPressureSensorNames[isensor]);       
-       ceObjects->Add(sensorCopy);
+        sensorCopy = new AliDCSSensor(*sensor);
+        sensorCopy->SetNameTitle(kPressureSensorNames[isensor],kPressureSensorNames[isensor]);
+        ceObjects->Add(sensorCopy);
       }
-   }
- }   
-
- UInt_t result=0;
-
- TList* list = GetFileSources(sourceFXS,"CE");
- if (list && list->GetEntries()>0) {
-
+    }
+  }
+  
+  UInt_t result=0;
+  
+  TList* list = GetFileSources(sourceFXS,"CE");
+  
+  if (list && list->GetEntries()>0) {
+    
 //  loop through all files from LDCs
-
+    
     UInt_t index = 0;
     while (list->At(index)!=NULL) {
-     TObjString* fileNameEntry = (TObjString*) list->At(index);
-     if (fileNameEntry!=NULL) {
+      TObjString* fileNameEntry = (TObjString*) list->At(index);
+      if (fileNameEntry!=NULL) {
         TString fileName = GetFile(sourceFXS, "CE",
-                                        fileNameEntry->GetString().Data());
-        TFile *f = TFile::Open(fileName);
-        if (!f) {
-         Log ("Error opening central electrode file.");
-         result =2;
-         break;
-       }
-        AliTPCCalibCE *calCE;
-       f->GetObject("tpcCalibCE",calCE);
-
+                                   fileNameEntry->GetString().Data());
+        AliTPCCalibCE *calCE=AliTPCCalibCE::ReadFromFile(fileName.Data());        
+        
         if (!calCE) {
-         Log ("No valid calibCE object.");
-         result=2;
-         break;
-       }
+          Log ("No valid calibCE object.");
+          result=2;
+          break;
+        }
         //  replace entries for the sectors available in the present file
-
+        
         for (Int_t sector=0; sector<nSectors; sector++) {
-           AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
-           if ( rocTmean )  ceTmean->SetCalROC(rocTmean,sector);
-           AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
-           if ( rocTrms )  ceTrms->SetCalROC(rocTrms,sector);
-           AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
-          if ( rocQmean )  ceQmean->SetCalROC(rocQmean,sector);
-          TGraph *grT=calCE->MakeGraphTimeCE(sector,0,2); // T time graph
-           if ( grT ) rocTtime->AddAt(grT,sector);         
-          TGraph *grQ=calCE->MakeGraphTimeCE(sector,0,3); // Q time graph
-           if ( grQ ) rocQtime->AddAt(grQ,sector);         
+          AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
+          if ( rocTmean )  ceTmean->SetCalROC(rocTmean,sector);
+          AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
+          if ( rocTrms )  ceTrms->SetCalROC(rocTrms,sector);
+          AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
+          if ( rocQmean )  ceQmean->SetCalROC(rocQmean,sector);
+          TGraph *grT=calCE->MakeGraphTimeCE(sector,0,2); // T time graph
+          if ( grT ) rocTtime->AddAt(grT,sector);
+          TGraph *grQ=calCE->MakeGraphTimeCE(sector,0,3); // Q time graph
+          if ( grQ ) rocQtime->AddAt(grQ,sector);
+        }
+        
+        TGraph *grT=calCE->MakeGraphTimeCE(-1,0,2); // A side average
+        if ( grT ) {
+          rocTtime->AddAt(grT,nSectors);
+        } else {
+          result=10;
+        }
+        grT=calCE->MakeGraphTimeCE(-2,0,2); // C side average
+        if ( grT ) {
+          rocTtime->AddAt(grT,nSectors+1);
+        } else {
+          result=10;
         }
 
-       TGraph *grT=calCE->MakeGraphTimeCE(-1,0,2); // A side average
-       if ( grT ) rocTtime->AddAt(grT,nSectors);         
-       grT=calCE->MakeGraphTimeCE(-2,0,2); // C side average
-       if ( grT ) rocTtime->AddAt(grT,nSectors+1);         
-
-
-       delete calCE;
-       f->Close();
+        delete calCE;
       }
-     ++index;
+      ++index;
     }  // while(list)
 //
+//   Check number of calibrated sectors per side
+// 
+    Int_t aside=0, cside=0;
+    for (Int_t ind=0; ind<nSectors/4; ind++ ) {
+        TGraph *grT=(TGraph*)rocTtime->At(ind);
+       if (grT) aside++;
+       grT=(TGraph*)rocTtime->At(ind+nSectors/2);
+       if (grT) aside++;
+       grT=(TGraph*)rocTtime->At(ind+nSectors/4);
+       if (grT) cside++;
+       grT=(TGraph*)rocTtime->At(ind+3*nSectors/4);
+       if (grT) cside++;
+     }
+     if ( (aside<kMinCESectors) && (cside<kMinCESectors) ) {
+        Log (Form("ExtractCE: Too few fitted sectors: Aside =%d, Cside=%d\n",
+            aside, cside)) ;
+       result=10;
+     }
+
+    //
+    //=== New CE part
+    //    if it is validated this part needs to be modified again
+    //    currently its only processed if there is a valid standard CE object
+    //
+    list = GetFileSources(sourceFXS,"CEnew");
+    
+    if (result==0 && list && list->GetEntries()>0) {
+      
+//  loop through all files from LDCs
+      
+      UInt_t index2 = 0;
+      while (list->At(index2)!=NULL) {
+        TObjString* fileNameEntry = (TObjString*) list->At(index2);
+        if (fileNameEntry!=NULL) {
+          TString fileName = GetFile(sourceFXS, "CEnew",
+                                     fileNameEntry->GetString().Data());
+          AliTPCCalibCE *calCE=AliTPCCalibCE::ReadFromFile(fileName.Data());        
+          
+          if (!calCE) {
+            Log ("No valid new calibCE object.");
+//             result=2;
+            break;
+          }
+
+          TIter nextObj(calCE->GetArrFitGraphs());
+          TObject *obj=0x0;
+          while ( (obj=nextObj()) ){
+            arrFitGraphs->Add(obj->Clone());
+          }
+          delete calCE;
+        }
+        ++index2;
+      }
+    }
+    
+//
 //  Store updated pedestal entry to OCDB
 //
     AliCDBMetaData metaData;
@@ -1020,15 +1250,18 @@ UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
     metaData.SetResponsible("Haavard Helstrup");
     metaData.SetAliRootVersion(ALIROOT_SVN_BRANCH);
     metaData.SetComment("Preprocessor AliTPC data base entries.");
-
-    Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE);
-    if ( !storeOK ) ++result;
     
+    if ( result == 0 ) {
+      Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE);
+      if ( !storeOK ) ++result;
+    } else {
+      Log ("Warning: Average time graphs not available - no OCDB entry written");
+    }
   } else {
     Log ("Error: no CE entries available from FXS!");
     result = 1;
   }
-
+  
   ceObjects->Delete();
   delete ceObjects;
   
@@ -1048,7 +1281,7 @@ UInt_t AliTPCPreprocessor::ExtractQA(Int_t sourceFXS)
  
  if (list && list->GetEntries()>0) {
 
-//  only one QA objetc should be available!
+//  only one QA object should be available!
 
     AliTPCdataQA *calQA;
 
@@ -1190,9 +1423,10 @@ UInt_t AliTPCPreprocessor::ExtractAltro(Int_t sourceFXS, TMap* dcsMap)
 
 // extract list of active DDLs
 
+ if (dcsMap) {
   Bool_t found; 
   TString arrDDL(kNumDDL);
-  arrDDL.Append('0',kNumDDL);
+  arrDDL.Append('x',kNumDDL);
   for ( Int_t iDDL = 0; iDDL<kNumDDL; iDDL++ ) {
     TString stringID = Form (kAmandaDDL.Data(),iDDL+kFirstDDL);
     TPair *pair = (TPair*)dcsMap->FindObject(stringID.Data());
@@ -1201,14 +1435,16 @@ UInt_t AliTPCPreprocessor::ExtractAltro(Int_t sourceFXS, TMap* dcsMap)
         TObjArray *valueSet=(TObjArray*)pair->Value();
         if ( valueSet) { 
          AliDCSValue *val = (AliDCSValue*)valueSet->At(0);
-         if (val) found = val->GetBool();
+         if (val) { 
+             found = val->GetBool();
+             if (found){
+               arrDDL[iDDL] = '1';
+              } else { 
+               arrDDL[iDDL] = '0';
+              }
+         }    
        }
     } 
-    if (found){
-      arrDDL[iDDL] = '1';
-    } else { 
-      arrDDL[iDDL] = '0';
-    }    
   }
   TObjString *ddlArray = new TObjString;
   ddlArray->SetString(arrDDL);
@@ -1218,7 +1454,10 @@ UInt_t AliTPCPreprocessor::ExtractAltro(Int_t sourceFXS, TMap* dcsMap)
   activeDDL->Add(key,ddlArray);
   altroObjects->Add(activeDDL);
   changed=true;
-  
+ } else {
+   Log ("ExtractAltro: No DCS map available. Active DDL list cannot be obtained.");
+   result = 3;
+ }        
 
 // extract Altro configuration files
 
@@ -1237,8 +1476,9 @@ UInt_t AliTPCPreprocessor::ExtractAltro(Int_t sourceFXS, TMap* dcsMap)
                                         fileNameEntry->GetString().Data());
         TFile *f = TFile::Open(fileName);
         if (!f) {
-          char message[40];
-         sprintf(message,"Error opening Altro configuration file, id = %d",id);
+         const int mess_length=40;
+          char message[mess_length];
+         snprintf(message,mess_length,"Error opening Altro configuration file, id = %d",id);
          Log (message);
          result =2;
          break;