]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDPreprocessor.cxx
Add newline
[u/mrichter/AliRoot.git] / TRD / AliTRDPreprocessor.cxx
index 27f07047538536fcccb185e0b0a5012369440dfc..eb66cfd98063802a9b255ea5fec9424d86141fc2 100644 (file)
 // and stores both reference data and spline fits results                 //
 // in the CDB                                                             //
 //                                                                        //
-// Author                                                               //
+// Authors:                                                               //
 //   R. Bailhache (R.Bailhache@gsi.de)                                    //
 //   W. Monange   (w.monange@gsi.de)                                      //
+//   F. Kramer    (kramer@ikf.uni-frankfurt.de)                           //
 //                                                                        //
 ////////////////////////////////////////////////////////////////////////////
 
-#include "AliTRDPreprocessor.h"
+#include <fstream>
 
 #include <TFile.h>
 #include <TProfile2D.h>
-#include <TStopwatch.h>
 #include <TObjString.h>
 #include <TString.h>
 #include <TList.h>
-#include <TCollection.h>
+#include <TSAXParser.h>
 
 #include "AliCDBMetaData.h"
 #include "AliLog.h"
 
+#include "AliTRDPreprocessor.h"
 #include "AliTRDSensorArray.h"
 #include "AliTRDCalibraFit.h"
 #include "AliTRDCalibraMode.h"
 #include "AliTRDCalibPadStatus.h"
-#include "Cal/AliTRDCalDet.h"
+#include "AliTRDSaxHandler.h"
+#include "AliTRDgeometry.h"
+#include "Cal/AliTRDCalPad.h"
 #include "Cal/AliTRDCalPadStatus.h"
+#include "Cal/AliTRDCalDCS.h"
+#include "Cal/AliTRDCalSingleChamberStatus.h"
+#include "Cal/AliTRDCalROC.h"
 
 ClassImp(AliTRDPreprocessor)
 
 //______________________________________________________________________________________________
 AliTRDPreprocessor::AliTRDPreprocessor(AliShuttleInterface *shuttle)
-  :AliPreprocessor("TRD", shuttle),
-   fVdriftHLT(0)
+  :AliPreprocessor("TRD", shuttle)
+  ,fVdriftHLT(0)
 {
   //
   // Constructor
   //
 
+  AddRunType("PHYSICS");
+  AddRunType("STANDALONE");
+  AddRunType("PEDESTAL");
+  AddRunType("DAQ");
+  
 }
 
 //______________________________________________________________________________________________
@@ -94,48 +105,65 @@ UInt_t AliTRDPreprocessor::Process(TMap* dcsAliasMap)
   TString runType = GetRunType();
   Log(Form("runtype %s\n",runType.Data()));
   
-  if (runType=="PEDESTAL_RUN"){
+  // always process the configuration data
+  Int_t DCSConfigReturn = ProcessDCSConfigData();
+  if(DCSConfigReturn) return DCSConfigReturn; 
+  
+  if (runType=="PEDESTAL"){
     if(ExtractPedestals()) return 1;
     return 0;
   } 
 
-  //
-  // DCS
-  //
-  
-  if(ProcessDCS(dcsAliasMap)) return 1;
-
-  //
-  // Process the calibration data for the HLT and DAQ part
-  //
-  
-  if (runType=="PHYSICS"){
-    //TString runPar = GetRunParameter("HLTStatus")
-    //if(runPar=="1") {
-    if(ExtractHLT()) return 1;
-    //if (fResult > 0) return fResult;
-    //} 
-    if(!fVdriftHLT) {
-      if(ExtractDriftVelocityDAQ()) return 1;
+  if ((runType=="PHYSICS") || (runType=="STANDALONE") || (runType=="DAQ")){
+    // DCS
+    if(ProcessDCS(dcsAliasMap)) return 1; 
+    if(runType=="PHYSICS"){
+      // HLT if On
+      //TString runPar = GetRunParameter("HLTStatus");
+      //if(runPar=="1") {
+      if(GetHLTStatus()) {
+       if(ExtractHLT()) return 1; // for testing!
+      } 
+      // DAQ if HLT failed
+      if(!fVdriftHLT) {
+       if(ExtractDriftVelocityDAQ()) return 1; // for testing!
+      }
     }
   }
   
   return 0;  
   
+}
+//______________________________________________________________________________
+Bool_t AliTRDPreprocessor::ProcessDCS()
+{
+  //
+  // Default process DCS method
+  //
+
+  TString runType = GetRunType();
+  if ((runType == "PHYSICS") || (runType == "STANDALONE")) {
+    return kTRUE;
+  }
+  return kFALSE;
+
 }
 
 //______________________________________________________________________________
-Bool_t AliTRDPreprocessor::ProcessDCS(TMap * dcsAliasMap)
+Bool_t AliTRDPreprocessor::ProcessDCS(TMap *dcsAliasMap)
 {
-  Bool_t error=kFALSE;
+  //
+  // Process DCS method
+  //
+
+  Bool_t error = kFALSE;
 
   AliCDBMetaData metaData;
   metaData.SetBeamPeriod(0);
   metaData.SetResponsible("Wilfried Monange/Raphaelle Bailhache");
   metaData.SetComment("TRD calib test");
-       
-       
-  Log ("****** DCS ******\n");
+
+  Log("****** DCS ******\n");
        
   TObjArray * list=AliTRDSensorArray::GetList ();
        
@@ -158,7 +186,7 @@ Bool_t AliTRDPreprocessor::ProcessDCS(TMap * dcsAliasMap)
     oneTRDDCS->SetStartTime (TTimeStamp (fStartTime));
     oneTRDDCS->SetEndTime (TTimeStamp (fEndTime));
                        
-    Log (Form("Processing DCS : \"%s\"", oneTRDDCS->GetStoreName ().Data ()));
+    Log(Form("Processing DCS : \"%s\"", oneTRDDCS->GetStoreName ().Data ()));
                        
     TMap * map;
 
@@ -169,22 +197,21 @@ Bool_t AliTRDPreprocessor::ProcessDCS(TMap * dcsAliasMap)
     if (nGraph [iAlias] == 0) {
       Log("No TGraph for this dcsDatapointAlias : not stored");
       results [iAlias] = kFALSE;
+      //error  = kTRUE;
       continue;
     }
                
     oneTRDDCS->SetGraph(map);
-    results[iAlias]=Store("Calib", oneTRDDCS->GetStoreName().Data(), oneTRDDCS, &metaData, 0, kTRUE); 
+    results[iAlias]=Store("Calib", oneTRDDCS->GetStoreName().Data(), oneTRDDCS, &metaData, 0, kFALSE); 
     delete map;                
 
     //results [iAlias] = StoreReferenceData("Calib", oneTRDDCS->GetStoreName ().Data (), oneTRDDCS, &metaData); 
 
-
     if (!results[iAlias]) {
       AliError("Problem during StoreRef DCS");
-      error=kTRUE;
+      //error=kTRUE;
     }
 
-
     //BEGIN TEST (should not be removed ...)
     /*
     oneTRDDCS->ClearGraph();
@@ -217,9 +244,17 @@ Bool_t AliTRDPreprocessor::ProcessDCS(TMap * dcsAliasMap)
     */    
     //END TEST
 
-      
-      
   }
+
+  // Check errors
+  Int_t nbCount = 0;
+  for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
+    if (results[iAlias]) {
+      nbCount++;
+    }
+  }
+  if(nbCount == 0) error = kTRUE;
+
                
   Log ("         Summury of DCS :\n");
   Log (Form("%30s %10s %10s", "dcsDatapointAlias", "Stored ?", "# graph"));
@@ -236,6 +271,7 @@ Bool_t AliTRDPreprocessor::ProcessDCS(TMap * dcsAliasMap)
   delete nGraph;
 
   return error;
+
 }
 
 //______________________________________________________________________________________________
@@ -244,7 +280,15 @@ Bool_t AliTRDPreprocessor::ExtractPedestals()
   //
   // Pedestal running on LDCs at the DAQ
   //
+
+  //
+  // The reference data are stored in:
+  // PadStatus1 for sm-00-01-02-09-10-11
+  // PadStatus2 for sm-03-04-05-12-13-14
+  // PadStatus3 for sm-06-07-08-15-16-17
+  // PadStatus0 if nothing found..means problems
+  //
+
   Bool_t error = kFALSE;
 
   // Init a AliTRDCalibPadStatus
@@ -262,8 +306,7 @@ Bool_t AliTRDPreprocessor::ExtractPedestals()
     return kTRUE;
   }
   
-  // loop through all files from LDCs
-  
+  // loop through all files from LDCs  
   UInt_t index = 0;
   while (listpad->At(index)!=NULL) {
     TObjString* fileNameEntry = (TObjString*) listpad->At(index);
@@ -283,41 +326,136 @@ Bool_t AliTRDPreprocessor::ExtractPedestals()
        
        if(calPed){
          
+         Int_t ldc = 0; 
+
          // analyse
-         calPed->AnalyseHisto();
-         
+         //calPed->AnalyseHisto();
+                 
+         // Add to the calPedSum
+         for (Int_t idet=0; idet<540; idet++) {
+           AliTRDCalROC *rocMean  = calPed->GetCalRocMean(idet, kFALSE);
+           if ( rocMean )  {
+             calPedSum.SetCalRocMean(rocMean,idet);
+             ldc = (Int_t) (idet / 30);
+           }
+           AliTRDCalROC *rocRMS = calPed->GetCalRocRMS(idet, kFALSE);
+           if ( rocRMS )  {
+             calPedSum.SetCalRocRMS(rocRMS,idet);
+           }
+           AliTRDCalROC *rocMeand  = calPed->GetCalRocMeand(idet, kFALSE);
+           if ( rocMeand )  {
+             calPedSum.SetCalRocMeand(rocMeand,idet);
+           }
+           AliTRDCalROC *rocRMSd = calPed->GetCalRocRMSd(idet, kFALSE);
+           if ( rocRMSd )  {
+             calPedSum.SetCalRocRMSd(rocRMSd,idet);
+           }
+         }// det loop
+
+         if((ldc==0) || (ldc==1) || (ldc==2)) ldc = 1;
+         if((ldc==3) || (ldc==4) || (ldc==5)) ldc = 2;
+         if((ldc==6) || (ldc==7) || (ldc==8)) ldc = 3;
+         if((ldc==9) || (ldc==10) || (ldc==11)) ldc = 4;
+         if((ldc==12) || (ldc==13) || (ldc==14)) ldc = 5;
+         if((ldc==15) || (ldc==16) || (ldc==17)) ldc = 6;
+       
          // store as reference data
          TString name("PadStatus");
-         name += (Int_t)index;
+         name += ldc;
          if(!StoreReferenceData("DAQData",(const char *)name,(TObject *) calPed,&metaData)){
            Log(Form("Error storing AliTRDCalibPadStatus object %d as reference data",(Int_t)index));
            error = kTRUE;
          }
-         
-         
-         // Add to the calPedSum
-         for (Int_t idet=0; idet<540; idet++) {
-           AliTRDCalROC *rocMean  = calPed->GetCalRocMean(idet, kFALSE);
-           if ( rocMean )  calPedSum.SetCalRocMean(rocMean,idet);
-           AliTRDCalROC *rocRMS = calPed->GetCalRocRMS(idet, kFALSE);
-           if ( rocRMS )  calPedSum.SetCalRocRMS(rocRMS,idet);
-         }// det loop
+
        } // calPed
       } // fileNameEntry
     ++index;
   }// while (list)
+
   Log(Form("%d elements found in the list for the pedestal",(Int_t)index));
   if(index==0){
     delete listpad;
     return kTRUE;
   }
+
   //
-  // Store pedestal entry to OCDB
+  // Create pedestal 
   //
-  
-  
+    
   // Create Pad Status
   AliTRDCalPadStatus *calPadStatus = calPedSum.CreateCalPadStatus();
+  // Create Noise 
+  //Make the AliTRDCalPad
+  AliTRDCalPad *calPad2 = calPedSum.CreateCalPad();
+  //Make the AliTRDCalDet correspondant
+  AliTRDCalDet *calDet = calPedSum.CreateCalDet();
+  //
+  // Take the noise and Pad status from the previous OCDB
+  //
+
+  AliTRDCalPad *calPadPrevious=0;
+  AliCDBEntry* entry = GetFromOCDB("Calib", "PadNoise");
+  if (entry) calPadPrevious = (AliTRDCalPad*)entry->GetObject();
+  if ( calPadPrevious==NULL ) {
+     Log("AliTRDPreprocsessor: No previous TRD pad noise entry available.\n");
+     calPadPrevious = new AliTRDCalPad("PadNoise", "PadNoise");
+  }
+
+  AliTRDCalPadStatus *calPadStatusPrevious=0;
+  entry = GetFromOCDB("Calib", "PadStatus");
+  if (entry) calPadStatusPrevious = (AliTRDCalPadStatus*)entry->GetObject();
+  if ( calPadStatusPrevious==NULL ) {
+    Log("AliTRDPreprocsessor: No previous TRD pad status entry available.\n");
+    calPadStatusPrevious = new AliTRDCalPadStatus("padstatus", "padstatus");
+    for (Int_t idet=0; idet<540; ++idet)
+      {
+       AliTRDCalSingleChamberStatus *calROC = calPadStatusPrevious->GetCalROC(idet);
+       for(Int_t k = 0; k < calROC->GetNchannels(); k++){
+         calROC->SetStatus(k,AliTRDCalPadStatus::kMasked);
+       }
+      }
+  }
+
+  
+  // Loop over detectors for check
+  for (Int_t det=0; det<AliTRDgeometry::kNdet; ++det)  {
+    
+    // noise
+    AliTRDCalROC *calROCPreviousNoise = calPadPrevious->GetCalROC(det);
+    AliTRDCalROC *calROCNoise         = calPad2->GetCalROC(det);
+
+    // padstatus
+    AliTRDCalSingleChamberStatus *calROCPreviousStatus = calPadStatusPrevious->GetCalROC(det);
+    AliTRDCalSingleChamberStatus *calROCStatus         = calPadStatus->GetCalROC(det);
+    
+    
+    // loop over first half and second half chamber
+    for(Int_t half = 0; half < 2; half++){
+
+      Bool_t data         = AreThereDataPedestal(calROCStatus,(Bool_t)half);
+      //printf("There are data for the detector %d the half %d: %d\n",det,half,data);
+      if(!data){
+       // look if data in the OCDB
+       Bool_t dataPrevious = AreThereDataPedestal(calROCPreviousStatus,(Bool_t)half);
+       // if no data at all, set to default value
+       if(!dataPrevious){
+         SetDefaultStatus(*calROCStatus,(Bool_t)half);
+         SetDefaultNoise(*calROCNoise,(Bool_t)half);
+       }
+       else{
+         // if data, set to previous value
+         SetStatus(*calROCStatus,calROCPreviousStatus,(Bool_t)half);
+         SetNoise(*calROCNoise,calROCPreviousNoise,(Bool_t)half);
+       }
+      }
+    }
+  }
+  
+  //
+  // Store  
+  //  
+
   AliCDBMetaData md3; 
   md3.SetObjectClassName("AliTRDCalPadStatus");
   md3.SetResponsible("Raphaelle Bailhache");
@@ -328,10 +466,149 @@ Bool_t AliTRDPreprocessor::ExtractPedestals()
     delete listpad;
     return kTRUE;
   }
+
+  AliCDBMetaData md4; 
+  md4.SetObjectClassName("AliTRDCalPad");
+  md4.SetResponsible("Raphaelle Bailhache");
+  md4.SetBeamPeriod(1);
+  md4.SetComment("TRD calib test");
+  if(!Store("Calib","PadNoise"    ,(TObject *)calPad2, &md4, 0, kTRUE)){
+    Log("Error storing the pedestal");
+    delete listpad;
+    return kTRUE;
+  }
   
+  AliCDBMetaData md5; 
+  md5.SetObjectClassName("AliTRDCalDet");
+  md5.SetResponsible("Raphaelle Bailhache");
+  md5.SetBeamPeriod(1);
+  md5.SetComment("TRD calib test");
+  if(!Store("Calib","DetNoise"    ,(TObject *)calDet, &md5, 0, kTRUE)){
+    Log("Error storing the pedestal");
+    delete listpad;
+    return kTRUE;
+  }  
+
   delete listpad;
   return error; 
+  
+}
+
+//__________________________________________________________________
+Bool_t AliTRDPreprocessor::AreThereDataPedestal(AliTRDCalSingleChamberStatus * const calROCStatus
+                                              , Bool_t second)
+{
+
+  //
+  // Data for this half chamber
+  //
+
+  Bool_t data         = kFALSE;
+  Int_t nCols         = calROCStatus->GetNcols();
+  Int_t nCol0         = 0;
+  Int_t nColE         = (Int_t) nCols/2 - 2;
+  if(second) {
+    nCol0 = nColE + 4;
+    nColE = nCols;
+  }
+
+  Int_t totalnumberofpads = 0;
+  Int_t totalnumberofdata = 0; 
+
+  for(Int_t col = nCol0; col < nColE; col++){
+    for(Int_t row = 0; row < calROCStatus->GetNrows(); row++){
+      totalnumberofpads++;
+      //printf("ismasked %d\n",(Int_t)calROCStatus->IsMasked(col,row));
+      if(!calROCStatus->GetStatus(col,row)) {
+       data = kTRUE;
+       totalnumberofdata++;
+      }
+    }
+  }
+  if(totalnumberofdata < (Int_t)(totalnumberofpads/2)) data = kFALSE;
 
+  return data;
+  
+}
+//__________________________________________________________________
+void AliTRDPreprocessor::SetDefaultStatus(AliTRDCalSingleChamberStatus &calROCStatus, Bool_t second){
+
+  //
+  // default status for this half chamber
+  //
+
+  Int_t nCols         = calROCStatus.GetNcols();
+  Int_t nCol0         = 0;
+  Int_t nColE         = (Int_t) nCols/2;
+  if(second) {
+    nCol0 = nColE;
+    nColE = nCols;
+  }
+  for(Int_t col = nCol0; col < nColE; col++){
+    for(Int_t row = 0; row < calROCStatus.GetNrows(); row++){
+      calROCStatus.SetStatus(col,row,0);
+    }
+  }
+}
+//__________________________________________________________________
+void AliTRDPreprocessor::SetStatus(AliTRDCalSingleChamberStatus &calROCStatus, AliTRDCalSingleChamberStatus *calROCStatusPrevious,Bool_t second){
+
+  //
+  // previous status for this half chamber
+  //
+
+  Int_t nCols         = calROCStatus.GetNcols();
+  Int_t nCol0         = 0;
+  Int_t nColE         = (Int_t) nCols/2;
+  if(second) {
+    nCol0 = nColE;
+    nColE = nCols;
+  }
+  for(Int_t col = nCol0; col < nColE; col++){
+    for(Int_t row = 0; row < calROCStatus.GetNrows(); row++){
+      calROCStatus.SetStatus(col,row,calROCStatusPrevious->GetStatus(col,row));
+    }
+  }
+}
+//__________________________________________________________________
+void AliTRDPreprocessor::SetDefaultNoise(AliTRDCalROC &calROCNoise, Bool_t second){
+
+  //
+  // default noise for this half chamber
+  //
+
+  Int_t nCols         = calROCNoise.GetNcols();
+  Int_t nCol0         = 0;
+  Int_t nColE         = (Int_t) nCols/2;
+  if(second) {
+    nCol0 = nColE;
+    nColE = nCols;
+  }
+  for(Int_t col = nCol0; col < nColE; col++){
+    for(Int_t row = 0; row < calROCNoise.GetNrows(); row++){
+      calROCNoise.SetValue(col,row,0.12);
+    }
+  }
+}
+//__________________________________________________________________
+void AliTRDPreprocessor::SetNoise(AliTRDCalROC &calROCNoise, AliTRDCalROC *calROCNoisePrevious, Bool_t second){
+
+  //
+  // previous noise for this half chamber
+  //
+
+  Int_t nCols         = calROCNoise.GetNcols();
+  Int_t nCol0         = 0;
+  Int_t nColE         = (Int_t) nCols/2;
+  if(second) {
+    nCol0 = nColE;
+    nColE = nCols;
+  }
+  for(Int_t col = nCol0; col < nColE; col++){
+    for(Int_t row = 0; row < calROCNoise.GetNrows(); row++){
+      calROCNoise.SetValue(col,row,calROCNoisePrevious->GetValue(col,row));
+    }
+  }
 }
 //______________________________________________________________________________________________
 Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
@@ -361,9 +638,6 @@ Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
   md2.SetBeamPeriod(0);
   md2.SetComment("TRD calib test");
 
-
-
-
   // Take the file from the DAQ file exchange server
   TList *listdaq = GetFileSources(kDAQ,"VDRIFT");
   if (!listdaq) {
@@ -409,8 +683,10 @@ Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
       
       // if enough statistics store the results
       if ((nbtg >                  0) && 
-         (nbfit        >= 0.95*nbE)) {
+         (nbfit        >= 0.5*nbE)) {
        // create the cal objects
+       calibra->PutMeanValueOtherVectorFit(1,kTRUE);
+       calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
        TObjArray object      = calibra->GetVectorFit();
        AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
        TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
@@ -446,12 +722,13 @@ Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
   return error; 
   
 }
+
 //______________________________________________________________________________________________
 Bool_t AliTRDPreprocessor::ExtractHLT()
 {
   //
   // Gain, vdrift and PRF calibration running on HLT
-  // return kFALSE if NULL pointer to the list
+  // return kTRUE if NULL pointer to the list
   //
 
   Bool_t error = kFALSE;
@@ -474,7 +751,6 @@ Bool_t AliTRDPreprocessor::ExtractHLT()
   md2.SetResponsible("Raphaelle Bailhache");
   md2.SetBeamPeriod(0);
   md2.SetComment("TRD calib test");
-
   
   // Take the file from the HLT file exchange server
   TList *listhlt = GetFileSources(kHLT,"GAINDRIFTPRF");
@@ -501,7 +777,6 @@ Bool_t AliTRDPreprocessor::ExtractHLT()
     // Take the file
     TFile *filehlt = TFile::Open(fileName);
     
-    
     // gain
     TH2I *histogain = (TH2I *) filehlt->Get("CH2d");
     histogain->SetDirectory(0);
@@ -513,7 +788,7 @@ Bool_t AliTRDPreprocessor::ExtractHLT()
       }
       // analyse
       Log("Take the CH reference data. Now we will try to fit\n");
-      calibra->SetMinEntries(1000); // If there is less than 1000 entries in the histo: no fit
+      calibra->SetMinEntries(800); // If there is less than 1000 entries in the histo: no fit
       calibra->AnalyseCH(histogain);
       Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
        + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
@@ -521,10 +796,11 @@ Bool_t AliTRDPreprocessor::ExtractHLT()
       Int_t nbE         = calibra->GetNumberEnt();
       // enough statistics
       if ((nbtg >                  0) && 
-         (nbfit        >= 0.95*nbE)) {
+         (nbfit        >= 0.5*nbE)) {
        // create the cal objects
+       calibra->PutMeanValueOtherVectorFit(1,kTRUE);
        TObjArray object           = calibra->GetVectorFit();
-       AliTRDCalDet *objgaindet   = calibra->CreateDetObjectGain(&object,calibra->GetScaleFitFactor(),kTRUE);
+       AliTRDCalDet *objgaindet   = calibra->CreateDetObjectGain(&object);
        TObject *objgainpad        = calibra->CreatePadObjectGain();
        // store them
        if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet         ,&md1,0,kTRUE)){
@@ -539,8 +815,6 @@ Bool_t AliTRDPreprocessor::ExtractHLT()
       calibra->ResetVectorFit();
     }// if histogain
     
-    
-    
     // vdrift
     fVdriftHLT = kFALSE;
     TProfile2D *histodriftvelocity = (TProfile2D *) filehlt->Get("PH2d");
@@ -553,7 +827,7 @@ Bool_t AliTRDPreprocessor::ExtractHLT()
       }
       // analyse
       Log("Take the PH reference data. Now we will try to fit\n");
-      calibra->SetMinEntries(1000*20); // If there is less than 20000
+      calibra->SetMinEntries(800*20); // If there is less than 20000
       calibra->AnalysePH(histodriftvelocity);
       Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
        + 6*  18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
@@ -561,8 +835,10 @@ Bool_t AliTRDPreprocessor::ExtractHLT()
       Int_t nbE          = calibra->GetNumberEnt();
       // enough statistics
       if ((nbtg >                  0) && 
-         (nbfit        >= 0.95*nbE)) {
+         (nbfit        >= 0.5*nbE)) {
        // create the cal objects
+       calibra->PutMeanValueOtherVectorFit(1,kTRUE);
+       calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
        TObjArray object  = calibra->GetVectorFit();
        AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
        TObject *objdriftvelocitypad      = calibra->CreatePadObjectVdrift();
@@ -591,7 +867,6 @@ Bool_t AliTRDPreprocessor::ExtractHLT()
       calibra->ResetVectorFit();
     }// if TProfile2D
     
-    
     // prf
     TProfile2D *histoprf = (TProfile2D *) filehlt->Get("PRF2d");
     histoprf->SetDirectory(0);
@@ -629,3 +904,162 @@ Bool_t AliTRDPreprocessor::ExtractHLT()
   return error;
   
 }
+
+//_____________________________________________________________________________
+UInt_t AliTRDPreprocessor::ProcessDCSConfigData()
+{
+  // 
+  // process the configuration of FEE, PTR and GTU
+  // reteive XML filei(s) from the DCS FXS
+  // parse it/them and store TObjArrays in the CDB
+  //
+  // return 0 for success, otherwise:
+  //  5 : Could not get the SOR and EOR file from the FXS
+  //  8 : Something wrong with the SOR file
+  //  9 : Something wrong with the EOR file
+  // 10 : SOR XML is not well-formed
+  // 11 : EOR XML is not well-formed
+  // 12 : ERROR in XML SAX validation: something wrong with the content
+  // 14 : ERROR while creating calibration objects in the handler
+  // 15 : ERROR while storing data in the CDB
+  //
+
+  Log("Processing the DCS config summary files.");
+
+  // get the XML files
+  Log("Requesting the 2 summaryfiles from the FXS..");
+  const char *xmlFileS = GetFile(kDCS,"CONFIGSUMMARYSOR","");
+  const char *xmlFileE = GetFile(kDCS,"CONFIGSUMMARYEOR","");
+  // Request EOR and SOR files from the fxs, if both are not found exit
+
+  if (xmlFileS == NULL && xmlFileE == NULL) {
+    Log(Form("ERROR: SOR and EOR Files %s and %s not found!",xmlFileS,xmlFileE));
+    return 5;
+  } 
+
+  Bool_t fileExistE = true, fileExistS = true;
+
+  if (xmlFileS == NULL) {
+    Log(Form("Warning: SOR File %s not found!",xmlFileS));
+    fileExistE = false;
+  } else if (xmlFileE == NULL) {
+    Log(Form("Warning: EOR File %s not found!",xmlFileE));
+    fileExistS = false;
+  } else {
+    Log(Form("Both Files (%s and %s) found.",xmlFileS,xmlFileE));
+  }
+
+  if (fileExistS) {
+    // test the files
+    std::ifstream fileTestS;
+    fileTestS.open(xmlFileS, std::ios_base::binary | std::ios_base::in);
+    if (!fileTestS.good() || fileTestS.eof() || !fileTestS.is_open()) {
+      Log(Form("ERROR: File %s not valid!",xmlFileS));
+      return 8;
+    }
+    fileTestS.seekg(0, std::ios_base::end);
+    if (static_cast<int>(fileTestS.tellg()) < 2) {
+      Log(Form("ERROR: File %s is empty!",xmlFileS));
+      return 8;
+    }
+  }
+
+  if (fileExistE) {
+    std::ifstream fileTestE;
+    fileTestE.open(xmlFileE, std::ios_base::binary | std::ios_base::in);
+    if (!fileTestE.good() || fileTestE.eof() || !fileTestE.is_open()) {
+      Log(Form("ERROR: File %s not valid!",xmlFileE));
+      return 9;
+    }
+    fileTestE.seekg(0, std::ios_base::end);
+    if (static_cast<int>(fileTestE.tellg()) < 2) {
+      Log(Form("ERROR: File %s is empty!",xmlFileE));
+      return 9;
+    }
+  }
+
+  Log("Tested files are valid.");   
+
+  // make a robust XML validation
+  TSAXParser testParser;
+  if (fileExistS && testParser.ParseFile(xmlFileS) < 0 ) {
+    Log("ERROR: XML content (SOR) is not well-formed.");
+    return 10;
+  } else if (fileExistE && testParser.ParseFile(xmlFileE) < 0 ) {
+    Log("ERROR: XML content (EOR) is not well-formed.");
+    return 11;
+  }
+  Log("XML contents are well-formed.");
+
+  // create parser and parse
+  TSAXParser saxParserS, saxParserE;
+  AliTRDSaxHandler saxHandlerS, saxHandlerE;
+
+  if (fileExistS) {
+    saxParserS.ConnectToHandler("AliTRDSaxHandler", &saxHandlerS);
+    saxParserS.ParseFile(xmlFileS);
+  }
+  if (fileExistE) {
+    saxParserE.ConnectToHandler("AliTRDSaxHandler", &saxHandlerE);
+    saxParserE.ParseFile(xmlFileE);
+  }
+
+  // report errors if present 
+  if (((fileExistS && saxParserS.GetParseCode() == 0) || !fileExistS) && (!fileExistE || (fileExistE && saxParserE.GetParseCode() == 0))) {
+    Log("XML file validation OK.");
+  } else {
+    if (fileExistS) {
+      Log(Form("ERROR in XML file validation. SOR Parse Code: %s", saxParserS.GetParseCode()));
+    }
+    if (fileExistE) {
+      Log(Form("ERROR in XML file validation. EOR Parse Code: %s", saxParserE.GetParseCode()));
+    }
+    return 12;
+  }
+  if (((fileExistS && saxHandlerS.GetHandlerStatus() == 0) || !fileExistS) && (!fileExistE || (saxHandlerE.GetHandlerStatus() == 0))) {
+    Log("SAX handler reports no errors.");
+  } else  {
+    if (fileExistS) {
+      Log(Form("ERROR while creating calibration objects. SOR Error code: %s", saxHandlerS.GetHandlerStatus()));
+    }
+    if (fileExistE) {
+      Log(Form("ERROR while creating calibration objects. EOR Error code: %s", saxHandlerE.GetHandlerStatus()));
+    }
+    return 14;
+  }
+
+  // put both objects in one TObjArray to store them
+  TObjArray* fCalObjArray = new TObjArray(2);
+  fCalObjArray->SetOwner();
+
+  // get the calibration object storing the data from the handler
+  if (fileExistS) {
+    AliTRDCalDCS* fCalDCSObjSOR = saxHandlerS.GetCalDCSObj();
+    fCalDCSObjSOR->EvaluateGlobalParameters();
+    fCalObjArray->AddAt(fCalDCSObjSOR,0);
+  }
+
+  if (fileExistE) {
+    AliTRDCalDCS* fCalDCSObjEOR = saxHandlerE.GetCalDCSObj();
+    fCalDCSObjEOR->EvaluateGlobalParameters();
+    fCalObjArray->AddAt(fCalDCSObjEOR,1);
+  }
+
+  // store the DCS calib data in the CDB
+  AliCDBMetaData metaData1;
+  metaData1.SetBeamPeriod(0);
+  metaData1.SetResponsible("Frederick Kramer");
+  metaData1.SetComment("DCS configuration data in two AliTRDCalDCS objects in one TObjArray (0:SOR, 1:EOR).");
+  if (!Store("Calib", "DCS", fCalObjArray, &metaData1, 0, kTRUE)) {
+    Log("problems while storing DCS config data object");
+    return 15;
+  } else {
+    Log("DCS config data object stored.");
+  }
+
+  //delete fCalObjArray;
+
+  Log("Processing of the DCS config summary file DONE.");  
+  return 0;
+}
+