]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCPreprocessor.cxx
New version of the TPC preprocessor. New preprocessor configuration directory (Haavard)
[u/mrichter/AliRoot.git] / TPC / AliTPCPreprocessor.cxx
index bff7e9fca33af666d888532c07603b8736244d04..01af52df5fa902d8422ab533f61fda35db7cfb9f 100644 (file)
 
 
 #include "AliTPCPreprocessor.h"
+#include "AliShuttleInterface.h"
 
 #include "AliCDBMetaData.h"
 #include "AliDCSValue.h"
 #include "AliLog.h"
 #include "AliTPCSensorTempArray.h"
-#include "AliTPCDBPressure.h"
+#include "AliTPCROC.h"
+#include "AliTPCCalROC.h"
+#include "AliTPCCalPad.h"
+#include "AliTPCCalibPedestal.h"
+#include "TFile.h"
+#include "TTree.h"
+#include "TEnv.h"
 
 #include <TTimeStamp.h>
 
-const Int_t kValCutTemp = 100;         // discard temperatures > 100 degrees
-const Int_t kDiffCutTemp = 5;     // discard temperature differences > 5 degrees
+const Int_t kValCutTemp = 100;               // discard temperatures > 100 degrees
+const Int_t kDiffCutTemp = 5;               // discard temperature differences > 5 degrees
+const TString kPedestalRunType = "PEDESTAL_RUN";  // pedestal run identifier
 
 //
 // This class is the SHUTTLE preprocessor for the TPC detector.
-// It contains several components, this far the part containing 
+// It contains several components, this far the part containing
 // temperatures is implemented
 //
 
@@ -38,28 +46,29 @@ ClassImp(AliTPCPreprocessor)
 //______________________________________________________________________________________________
 AliTPCPreprocessor::AliTPCPreprocessor(AliShuttleInterface* shuttle) :
   AliPreprocessor("TPC",shuttle),
-  fTemp(0), fPressure(0), fConfigOK(kTRUE)
+  fConfEnv(0), fTemp(0), fPressure(0), fConfigOK(kTRUE), fROC(0)
 {
   // constructor
+  fROC = AliTPCROC::Instance();
 }
 //______________________________________________________________________________________________
 // AliTPCPreprocessor::AliTPCPreprocessor(const AliTPCPreprocessor& org) :
 //   AliPreprocessor(org),
-//   fTemp(0), fPressure(0), fConfigOK(kTRUE)
+//   fConfEnv(0), fTemp(0), fPressure(0), fConfigOK(kTRUE)
 // {
 //   // copy constructor not implemented
-//   //   -- missing underlying copy constructor in AliPreprocessor 
-// 
+//   //   -- missing underlying copy constructor in AliPreprocessor
+//
 //   Fatal("AliTPCPreprocessor", "copy constructor not implemented");
-//   
-// //  fTemp = new AliTPCSensorTempArray(*(org.fTemp)); 
+//
+// //  fTemp = new AliTPCSensorTempArray(*(org.fTemp));
 // }
 
 //______________________________________________________________________________________________
 AliTPCPreprocessor::~AliTPCPreprocessor()
 {
   // destructor
-  
+
   delete fTemp;
   delete fPressure;
 }
@@ -83,33 +92,43 @@ void AliTPCPreprocessor::Initialize(Int_t run, UInt_t startTime,
                TTimeStamp(startTime).AsString(),
                TTimeStamp(endTime).AsString()));
 
+  // Preprocessor configuration
+
+       AliCDBEntry* entry = GetFromOCDB("Config", "Temperature");
+        if (entry) fConfEnv = (TEnv*) entry->GetObject();
+        if ( fConfEnv==0 ) {
+           AliWarning(Form("Preprocessor Config OCDB entry missing.\n"));
+           Log("AliTPCPreprocsessor: Preprocessor Config OCDB entry missing.\n");
+        }
+
   // Temperature sensors
 
-        AliCDBEntry* entry = GetFromOCDB("Config", "Temperature"); 
-        TTree *confTree = (TTree*) entry->GetObject();
+        TTree *confTree = 0;
+       entry = GetFromOCDB("Config", "Temperature");
+        if (entry) confTree = (TTree*) entry->GetObject();
         if ( confTree==0 ) {
            AliError(Form("Temperature Config OCDB entry missing.\n"));
            Log("AliTPCPreprocsessor: Temperature Config OCDB entry missing.\n");
           fConfigOK = kFALSE;
+          return;
         }
         fTemp = new AliTPCSensorTempArray(fStartTime, fEndTime, confTree);
        fTemp->SetValCut(kValCutTemp);
        fTemp->SetDiffCut(kDiffCutTemp);
-       confTree->Delete(); delete confTree; confTree=0;
-       entry->Delete(); delete entry; entry=0;
-  
+
   // Pressure sensors
-        entry = GetFromOCDB("Config", "Pressure"); 
-        confTree = (TTree*) entry->GetObject();
+
+        confTree=0;
+       entry=0;
+       entry = GetFromOCDB("Config", "Pressure");
+        if (entry) confTree = (TTree*) entry->GetObject();
         if ( confTree==0 ) {
            AliError(Form("Pressure Config OCDB entry missing.\n"));
            Log("AliTPCPreprocsessor: Pressure Config OCDB entry missing.\n");
           fConfigOK = kFALSE;
+          return;
         }
        fPressure = new AliDCSSensorArray(fStartTime, fEndTime, confTree);
-       confTree->Delete(); delete confTree; confTree=0;
-       entry->Delete(); delete entry; entry=0;
 
 }
 
@@ -118,11 +137,14 @@ UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
 {
   // Fills data into TPC calibrations objects
 
-   if (!dcsAliasMap) return 9;
-   if (!fConfigOK) return 9;
-
   // Amanda servers provide information directly through dcsAliasMap
 
+  if (!dcsAliasMap) return 9;
+  if (dcsAliasMap->GetEntries() == 0 ) return 9;
+  if (!fConfigOK) return 9;
+
+  TString runType = GetRunType();
+
   // Temperature sensors are processed by AliTPCCalTemp
 
 
@@ -133,9 +155,9 @@ UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
 
   UInt_t pressureResult = MapPressure(dcsAliasMap);
   result += pressureResult;
-  
+
   // Other calibration information will be retrieved through FXS files
-  //  examples: 
+  //  examples:
   //    TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
   //    const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
   //
@@ -143,6 +165,17 @@ UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
   //    const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
 
 
+  if(runType == kPedestalRunType) {
+    Int_t pedestalSource = AliShuttleInterface::kDAQ;
+    TString source = fConfEnv->GetValue("Pedestal","DAQ");
+    source.ToUpper();
+    if ( source == "HLT" ) pedestalSource = AliShuttleInterface::kHLT;
+    UInt_t pedestalResult = ExtractPedestals(pedestalSource);
+    result += pedestalResult;
+
+  }
+
+
   return result;
 }
 //______________________________________________________________________________________________
@@ -163,24 +196,23 @@ UInt_t AliTPCPreprocessor::MapTemperature(TMap* dcsAliasMap)
   }
   delete map;
   // Now store the final CDB file
-  
-  if ( result == 0 ) { 
+
+  if ( result == 0 ) {
         AliCDBMetaData metaData;
        metaData.SetBeamPeriod(0);
        metaData.SetResponsible("Haavard Helstrup");
        metaData.SetComment("Preprocessor AliTPC data base entries.");
 
-       result = Store("Calib", "Temperature", fTemp, &metaData, 0, 0);
-        if ( result == 1 ) {                  
-          result = 0;
-       } else {
-         result = 1;
-       }                      // revert to new return code conventions
+       Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
+        if ( !storeOK )  result=1;
+
    }
 
    return result;
+
 }
 //______________________________________________________________________________________________
+
 UInt_t AliTPCPreprocessor::MapPressure(TMap* dcsAliasMap)
 {
 
@@ -198,20 +230,97 @@ UInt_t AliTPCPreprocessor::MapPressure(TMap* dcsAliasMap)
   }
   delete map;
   // Now store the final CDB file
-  
-  if ( result == 0 ) { 
+
+  if ( result == 0 ) {
         AliCDBMetaData metaData;
        metaData.SetBeamPeriod(0);
        metaData.SetResponsible("Haavard Helstrup");
        metaData.SetComment("Preprocessor AliTPC data base entries.");
 
-       result = Store("Calib", "Pressure", fPressure, &metaData, 0, 0);
-        if ( result == 1 ) {                  
-          result = 0;
-       } else {
-         result = 1;
-       }                      // revert to new return code conventions
+       Bool_t storeOK = Store("Calib", "Pressure", fPressure, &metaData, 0, 0);
+        if ( !storeOK ) result=1;
+
    }
 
    return result;
+
+}
+
+
+//______________________________________________________________________________________________
+
+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;
+ AliCDBEntry* entry = GetFromOCDB("Calib", "Pedestals");
+ if (entry) calPadPed = (AliTPCCalPad*)entry->GetObject();
+ if ( calPadPed==NULL ) {
+     AliWarning(Form("No previous TPC pedestal entry available.\n"));
+     Log("AliTPCPreprocsessor: No previous TPC pedestal entry available.\n");
+     calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
+ }
+
+ AliTPCCalPad *calPadRMS=0;
+ entry = GetFromOCDB("Calib", "Noise");
+ if (entry) calPadRMS = (AliTPCCalPad*)entry->GetObject();
+ if ( calPadRMS==NULL ) {
+     AliWarning(Form("No previous TPC noise entry available.\n"));
+     Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
+     calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
+ }
+
+
+ UInt_t result=0;
+
+ Int_t nSectors = fROC->GetNSectors();
+ TList* list = GetFileSources(sourceFXS,"pedestals");
+ if (list) {
+
+//  loop through all files from LDCs
+
+    UInt_t index = 0;
+    while (list->At(index)!=NULL) {
+     TObjString* fileNameEntry = (TObjString*) list->At(index);
+     if (fileNameEntry!=NULL) {
+        TString fileName = GetFile(sourceFXS, "pedestals",
+                                        fileNameEntry->GetString().Data());
+        TFile *f = TFile::Open(fileName);
+        AliTPCCalibPedestal *calPed;
+       f->GetObject("AliTPCCalibPedestal",calPed);
+
+        //  replace entries for the sectors available in the present file
+
+        for (Int_t sector=0; sector<nSectors; sector++) {
+           AliTPCCalROC *rocPed=calPed->GetCalRocPedestal(sector, kFALSE);
+           if ( rocPed )  calPadPed->SetCalROC(rocPed,sector);
+           AliTPCCalROC *rocRMS=calPed->GetCalRocRMS(sector, kFALSE);
+           if ( rocRMS )  calPadRMS->SetCalROC(rocRMS,sector);
+        }
+      }
+     ++index;
+    }  // while(list)
+//
+//  Store updated pedestal entry to OCDB
+//
+    AliCDBMetaData metaData;
+    metaData.SetBeamPeriod(0);
+    metaData.SetResponsible("Haavard Helstrup");
+    metaData.SetComment("Preprocessor AliTPC data base entries.");
+
+    Bool_t storeOK = Store("Calib", "Pedestals", calPadPed, &metaData, 0, kTRUE);
+    if ( !storeOK ) ++result;
+    storeOK = Store("Calib", "PadNoise", calPadRMS, &metaData, 0, kTRUE);
+    if ( !storeOK ) ++result;
+
+  }
+
+  return result;
 }
+
+//______________________________________________________________________________________________
+
+