]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCPreprocessor.cxx
Updated flags for low flux case (A. Dainese)
[u/mrichter/AliRoot.git] / TPC / AliTPCPreprocessor.cxx
index eb16bb53fb794d098dd779851cebc8c472939f1c..cd0aa9f77093d5bb934605937c8640ab1f4aa87d 100644 (file)
 #include "AliTPCCalibPedestal.h"
 #include "AliTPCCalibPulser.h"
 #include "AliTPCCalibCE.h"
+#include "AliTPCdataQA.h"
 #include "TFile.h"
 #include "TTree.h"
+#include "TGraph.h" 
 #include "TEnv.h"
+#include "TParameter.h"
 
 #include <TTimeStamp.h>
 
 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
-const TString kPulserRunType = "PULSER_RUN";   // pulser run identifier
+const TString kPedestalRunType = "PEDESTAL";  // pedestal run identifier
+const TString kPulserRunType = "CALIBRATION_PULSER";   // pulser run identifier
 const TString kPhysicsRunType = "PHYSICS";   // physics run identifier
 const TString kStandAloneRunType = "STANDALONE"; // standalone run identifier
+const TString kStandAlonePulserRunType = "STANDALONE_PULSER"; // standalone run identifier
+const TString kCosmicRunType = "COSMIC"; // cosmic run identifier
+const TString kLaserRunType = "LASER";   // laser run identifier
 const TString kDaqRunType = "DAQ"; // DAQ run identifier
-const TString kAmandaTemp = "tpc_PT_%d.Temperature"; // Amanda string for temperature entries
+const TString kAmandaTemp = "TPC_PT_%d_TEMPERATURE"; // Amanda string for temperature entries
 //const Double_t kFitFraction = 0.7;                 // Fraction of DCS sensor fits required              
 const Double_t kFitFraction = -1.0;          // Don't require minimum number of fits in commissioning run 
 
@@ -53,23 +59,33 @@ ClassImp(AliTPCPreprocessor)
 //______________________________________________________________________________________________
 AliTPCPreprocessor::AliTPCPreprocessor(AliShuttleInterface* shuttle) :
   AliPreprocessor("TPC",shuttle),
-  fConfEnv(0), fTemp(0), fHighVoltage(0), fConfigOK(kTRUE), fROC(0)
+  fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0), fConfigOK(kTRUE), fROC(0)
 {
   // constructor
   fROC = AliTPCROC::Instance();
+
+  // define run types to be processed
+  
+  AddRunType(kPedestalRunType);
+  AddRunType(kPulserRunType);
+  AddRunType(kPhysicsRunType);
+  AddRunType(kStandAloneRunType);
+  AddRunType(kStandAlonePulserRunType);
+  AddRunType(kCosmicRunType);
+  AddRunType(kLaserRunType);
+  AddRunType(kDaqRunType);
+  
 }
 //______________________________________________________________________________________________
-// AliTPCPreprocessor::AliTPCPreprocessor(const AliTPCPreprocessor& org) :
-//   AliPreprocessor(org),
-//   fConfEnv(0), fTemp(0), fHighVoltage(0), fConfigOK(kTRUE)
-// {
-//   // copy constructor not implemented
-//   //   -- missing underlying copy constructor in AliPreprocessor
-//
-//   Fatal("AliTPCPreprocessor", "copy constructor not implemented");
+ AliTPCPreprocessor::AliTPCPreprocessor(const AliTPCPreprocessor&  ) :
+   AliPreprocessor("TPC",0),
+   fConfEnv(0), fTemp(0), fHighVoltage(0), fHighVoltageStat(0), fGoofie(0), fConfigOK(kTRUE), fROC(0)
+ {
+
+   Fatal("AliTPCPreprocessor", "copy constructor not implemented");
 //
 // //  fTemp = new AliTPCSensorTempArray(*(org.fTemp));
-// }
+ }
 
 //______________________________________________________________________________________________
 AliTPCPreprocessor::~AliTPCPreprocessor()
@@ -91,13 +107,16 @@ AliTPCPreprocessor& AliTPCPreprocessor::operator = (const AliTPCPreprocessor& )
 void AliTPCPreprocessor::Initialize(Int_t run, UInt_t startTime,
        UInt_t endTime)
 {
-  // Creates AliTestDataDCS object
+  // Creates AliTestDataDCS object -- start maps half an hour beforre actual run start
 
-  AliPreprocessor::Initialize(run, startTime, endTime);
+  UInt_t startTimeLocal = startTime-3600;
+  UInt_t endTimeLocal = endTime+1800;
+
+  AliPreprocessor::Initialize(run, startTimeLocal, endTimeLocal);
 
        AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
-               TTimeStamp(startTime).AsString(),
-               TTimeStamp(endTime).AsString()));
+               TTimeStamp((time_t)startTime,0).AsString(),
+               TTimeStamp((time_t)endTime,0).AsString()));
 
   // Preprocessor configuration
 
@@ -123,7 +142,7 @@ void AliTPCPreprocessor::Initialize(Int_t run, UInt_t startTime,
           fConfigOK = kFALSE;
           return;
         }
-        fTemp = new AliTPCSensorTempArray(fStartTime, fEndTime, confTree, kAmandaTemp);
+        fTemp = new AliTPCSensorTempArray(startTimeLocal, endTimeLocal, confTree, kAmandaTemp);
        fTemp->SetValCut(kValCutTemp);
        fTemp->SetDiffCut(kDiffCutTemp);
        }
@@ -142,8 +161,44 @@ void AliTPCPreprocessor::Initialize(Int_t run, UInt_t startTime,
            fConfigOK = kFALSE;
            return;
         }
-        fHighVoltage = new AliDCSSensorArray(fStartTime, fEndTime, confTree);
+        fHighVoltage = new AliDCSSensorArray(startTimeLocal, endTimeLocal, confTree);
+      }
+
+   // High voltage status values
+     
+      TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
+      hvStatConf.ToUpper();
+      if (hvStatConf != "OFF" ) { 
+        confTree=0;
+        entry=0;
+        entry = GetFromOCDB("Config", "HighVoltageStat");
+        if (entry) confTree = (TTree*) entry->GetObject();
+        if ( confTree==0 ) {
+           Log("AliTPCPreprocsessor: High Voltage Status Config OCDB entry missing.\n");
+           fConfigOK = kFALSE;
+           return;
+        }
+        fHighVoltageStat = new AliDCSSensorArray(startTimeLocal, endTimeLocal, confTree);
       }
+
+   // Goofie values
+     
+      TString goofieConf = fConfEnv->GetValue("Goofie","ON");
+      goofieConf.ToUpper();
+      if (goofieConf != "OFF" ) { 
+        confTree=0;
+        entry=0;
+        entry = GetFromOCDB("Config", "Goofie");
+        if (entry) confTree = (TTree*) entry->GetObject();
+        if ( confTree==0 ) {
+           Log("AliTPCPreprocsessor: Goofie Config OCDB entry missing.\n");
+           fConfigOK = kFALSE;
+           return;
+        }
+        fGoofie = new AliDCSSensorArray(startTimeLocal, endTimeLocal, confTree);
+      }
+
+
 }
 
 //______________________________________________________________________________________________
@@ -153,10 +208,27 @@ UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
 
   // Amanda servers provide information directly through dcsAliasMap
 
-  if (!dcsAliasMap) return 9;
-  if (dcsAliasMap->GetEntries() == 0 ) return 9;
+  
   if (!fConfigOK) return 9;
   UInt_t result = 0;
+  TObjArray *resultArray = new TObjArray();
+  TString errorHandling = fConfEnv->GetValue("ErrorHandling","ON");
+  errorHandling.ToUpper();
+  TObject * status;
+
+  UInt_t dcsResult=0;
+  if (errorHandling == "OFF" ) {
+    if (!dcsAliasMap) dcsResult=1;
+    if (dcsAliasMap->GetEntries() == 0 ) dcsResult=1;  
+    status = new TParameter<int>("dcsResult",dcsResult);
+    resultArray->Add(status);
+  } else {
+    if (!dcsAliasMap) return 9;
+    if (dcsAliasMap->GetEntries() == 0 ) return 9;
+  }
+
+
+  
 
   TString runType = GetRunType();
 
@@ -167,6 +239,8 @@ UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
   if (tempConf != "OFF" ) {
     UInt_t tempResult = MapTemperature(dcsAliasMap);
     result=tempResult;
+    status = new TParameter<int>("tempResult",tempResult);
+    resultArray->Add(status);
   }
 
   // High Voltage recordings
@@ -177,6 +251,20 @@ UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
   if (hvConf != "OFF" ) { 
    UInt_t hvResult = MapHighVoltage(dcsAliasMap);
    result+=hvResult;
+   status = new TParameter<int>("hvResult",hvResult);
+   resultArray->Add(status);
+ }
+
+  // Goofie values
+
+
+  TString goofieConf = fConfEnv->GetValue("Goofie","ON");
+  goofieConf.ToUpper();
+  if (goofieConf != "OFF" ) { 
+   UInt_t goofieResult = MapGoofie(dcsAliasMap);
+   result+=goofieResult;
+   status = new TParameter<int>("goofieResult",goofieResult);
+   resultArray->Add(status);
  }
 
   // Other calibration information will be retrieved through FXS files
@@ -205,10 +293,12 @@ UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
      if (source == "DAQHLT" ) numSources=2;
      UInt_t pedestalResult=0;
      for (Int_t i=0; i<numSources; i++ ) {     
-       UInt_t pedestalResult = ExtractPedestals(pedestalSource[i]);
+       pedestalResult = ExtractPedestals(pedestalSource[i]);
        if ( pedestalResult == 0 ) break;
      }
      result += pedestalResult;
+     status = new TParameter<int>("pedestalResult",pedestalResult);
+     resultArray->Add(status);
     }
   }
 
@@ -234,6 +324,8 @@ UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
        if ( pulserResult == 0 ) break;
      }
      result += pulserResult;
+     status = new TParameter<int>("pulserResult",pulserResult);
+     resultArray->Add(status);
     }
   }
 
@@ -244,6 +336,7 @@ UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
   if( runType == kPhysicsRunType || runType == kStandAloneRunType || 
       runType == kDaqRunType ) {    
 
+//   if (true) {                 // do CE processing for all run types
     Int_t numSources = 1;
     Int_t ceSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
     TString source = fConfEnv->GetValue("CE","DAQ");
@@ -263,15 +356,45 @@ UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
        if ( ceResult == 0 ) break;
      }
      result += ceResult;
+     status = new TParameter<int>("ceResult",ceResult);
+     resultArray->Add(status);
+
+    numSources = 1;
+    Int_t qaSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
+    source = fConfEnv->GetValue("QA","DAQ");
+    source.ToUpper();
+    if ( source != "OFF" ) { 
+     if ( source == "HLT") qaSource[0] = AliShuttleInterface::kHLT;
+     if (!GetHLTStatus()) qaSource[0] = AliShuttleInterface::kDAQ;
+     if (source == "HLTDAQ" ) {
+        numSources=2;
+       qaSource[0] = AliShuttleInterface::kHLT;
+       qaSource[1] = AliShuttleInterface::kDAQ;
+     }
+     if (source == "DAQHLT" ) numSources=2;
+     UInt_t qaResult=0;
+     for (Int_t i=0; i<numSources; i++ ) {     
+       qaResult = ExtractQA(qaSource[i]);
+       if ( qaResult == 0 ) break;
+     }
+//     result += qaResult;
+     if ( qaResult !=0 ) Log ("ExtractQA failed, no QA entry available.");
+     status = new TParameter<int>("qaResult",qaResult);
+     resultArray->Add(status);
     }
+   }
   }
   
-  TString errorHandling = fConfEnv->GetValue("ErrorHandling","ON");
-  errorHandling.ToUpper();
   if (errorHandling == "OFF" ) {
-   return 0;
+    AliCDBMetaData metaData;
+    metaData.SetBeamPeriod(0);
+    metaData.SetResponsible("Haavard Helstrup");
+    metaData.SetComment("Preprocessor AliTPC status.");
+    Store("Calib", "PreprocStatus", resultArray, &metaData, 0, kFALSE);
+    resultArray->Delete();
+    return 0;
   } else { 
-   return result;
+    return result;
   }
 }
 //______________________________________________________________________________________________
@@ -335,6 +458,24 @@ UInt_t AliTPCPreprocessor::MapHighVoltage(TMap* dcsAliasMap)
     result=9;
   }
   delete map;
+
+  TString hvStatConf = fConfEnv->GetValue("HighVoltageStat","ON");
+  hvStatConf.ToUpper();
+  if (hvStatConf != "OFF" ) { 
+    TMap *map2 = fHighVoltageStat->ExtractDCS(dcsAliasMap);
+    if (map2) {
+      fHighVoltageStat->ClearFit();
+      fHighVoltageStat->SetGraph(map2);
+    } else {
+       Log("No high voltage status recordings extracted. \n");
+      result=9;
+    }
+    delete map2;
+
+    // add status maps to high voltage sensor array
+
+    fHighVoltage->AddSensors(fHighVoltageStat);
+   }
   // Now store the final CDB file
 
   if ( result == 0 ) {
@@ -352,6 +493,41 @@ UInt_t AliTPCPreprocessor::MapHighVoltage(TMap* dcsAliasMap)
 
 }
 
+//______________________________________________________________________________________________
+UInt_t AliTPCPreprocessor::MapGoofie(TMap* dcsAliasMap)
+{
+
+   // extract DCS Goofie maps. Do not perform fits (low update rate)
+
+  UInt_t result=0;
+
+  TMap *map = fGoofie->ExtractDCS(dcsAliasMap);
+  if (map) {
+    fGoofie->ClearFit();
+    fGoofie->SetGraph(map);
+  } else {
+    Log("No Goofie recordings extracted. \n");
+    result=9;
+  }
+  delete map;
+
+  // Now store the final CDB file
+
+  if ( result == 0 ) {
+        AliCDBMetaData metaData;
+       metaData.SetBeamPeriod(0);
+       metaData.SetResponsible("Haavard Helstrup");
+       metaData.SetComment("Preprocessor AliTPC data base entries.");
+
+       Bool_t storeOK = Store("Calib", "Goofie", fGoofie, &metaData, 0, kFALSE);
+        if ( !storeOK )  result=1;
+
+   }
+
+   return result;
+
+}
+
 
 //______________________________________________________________________________________________
 
@@ -370,7 +546,7 @@ UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
  }
 
  AliTPCCalPad *calPadRMS=0;
- entry = GetFromOCDB("Calib", "Noise");
+ entry = GetFromOCDB("Calib", "PadNoise");
  if (entry) calPadRMS = (AliTPCCalPad*)entry->GetObject();
  if ( calPadRMS==NULL ) {
      Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
@@ -401,7 +577,7 @@ UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
          break;
        }
         AliTPCCalibPedestal *calPed;
-       f->GetObject("AliTPCCalibPedestal",calPed);
+       f->GetObject("tpcCalibPedestal",calPed);
         if ( !calPed ) {
          Log ("No pedestal calibration object in file.");
          result = 2;
@@ -417,6 +593,8 @@ UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
            AliTPCCalROC *rocRMS=calPed->GetCalRocRMS(sector, kFALSE);
            if ( rocRMS )  calPadRMS->SetCalROC(rocRMS,sector);
         }
+        delete calPed; 
+        f->Close();
       }
      ++index;
     }  // while(list)
@@ -502,7 +680,7 @@ UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
          break;
        }
         AliTPCCalibPulser *calPulser;
-       f->GetObject("AliTPCCalibPulser",calPulser);
+       f->GetObject("tpcCalibPulser",calPulser);
         if ( !calPulser ) {
          Log ("No pulser calibration object in file.");
          result = 2;
@@ -520,6 +698,8 @@ UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
            AliTPCCalROC *rocQmean=calPulser->GetCalRocQ(sector);
            if ( rocQmean )  pulserQmean->SetCalROC(rocQmean,sector);
         }
+       delete calPulser;
+       f->Close();
       }
      ++index;
     }  // while(list)
@@ -553,6 +733,9 @@ UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
  AliTPCCalPad *ceTmean=0;
  AliTPCCalPad *ceTrms=0;
  AliTPCCalPad *ceQmean=0;
+ TObjArray    *rocTtime=0;  
+ TObjArray    *rocQtime=0;  
+
  AliCDBEntry* entry = GetFromOCDB("Calib", "CE");
  if (entry) ceObjects = (TObjArray*)entry->GetObject();
  if ( ceObjects==NULL ) {
@@ -560,6 +743,8 @@ UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
      ceObjects = new TObjArray;    
  }
 
+ Int_t nSectors = fROC->GetNSectors();
+
  ceTmean = (AliTPCCalPad*)ceObjects->FindObject("CETmean");
  if ( !ceTmean ) {
     ceTmean = new AliTPCCalPad("CETmean","CETmean");
@@ -575,11 +760,24 @@ UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
     ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
     ceObjects->Add(ceQmean);
  }
+ //!new from here please have a look!!!
+ rocTtime = (TObjArray*)ceObjects->FindObject("rocTtime");
+ if ( !rocTtime ) {
+     rocTtime = new TObjArray(nSectors);
+     rocTtime->SetName("rocTtime");
+     ceObjects->Add(rocTtime);
+ }
+ rocQtime = (TObjArray*)ceObjects->FindObject("rocQtime");
+ if ( !rocQtime ) {
+     rocQtime = new TObjArray(nSectors);
+     rocQtime->SetName("rocQtime");
+     ceObjects->Add(rocQtime);
+ }
 
 
  UInt_t result=0;
 
- Int_t nSectors = fROC->GetNSectors();
  TList* list = GetFileSources(sourceFXS,"CE");
  
  if (list && list->GetEntries()>0) {
@@ -599,8 +797,13 @@ UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
          break;
        }
         AliTPCCalibCE *calCE;
-       f->GetObject("AliTPCCalibCE",calCE);
+       f->GetObject("tpcCalibCE",calCE);
 
+        if (!calCE) {
+         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++) {
@@ -609,8 +812,14 @@ UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
            AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
            if ( rocTrms )  ceTrms->SetCalROC(rocTrms,sector);
            AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
-           if ( rocQmean )  ceQmean->SetCalROC(rocQmean,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 ) rocTtime->AddAt(grQ,sector);         
         }
+       delete calCE;
+       f->Close();
       }
      ++index;
     }  // while(list)
@@ -632,3 +841,58 @@ UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
 
   return result;
 }
+//______________________________________________________________________________________________
+
+UInt_t AliTPCPreprocessor::ExtractQA(Int_t sourceFXS)
+{
+ //
+ //  Read Quality Assurance file from file exchage server
+ //
+ UInt_t result=0;
+
+ TList* list = GetFileSources(sourceFXS,"QA");
+ if (list && list->GetEntries()>0) {
+
+//  only one QA objetc should be available!
+
+    AliTPCdataQA *calQA;
+
+    UInt_t nentries = list->GetEntries();  
+    UInt_t index=0;
+    if ( nentries > 1) Log ( "More than one QA entry. First one processed");      
+    TObjString* fileNameEntry = (TObjString*) list->At(index);
+    if (fileNameEntry!=NULL) {
+        TString fileName = GetFile(sourceFXS, "QA",
+                                        fileNameEntry->GetString().Data());
+        TFile *f = TFile::Open(fileName);
+        if (!f) {
+         Log ("Error opening QA file.");
+         result =2;          
+       } else {
+         f->GetObject("tpcCalibQA",calQA);
+          if ( calQA ) {      
+//
+//  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", "QA", calQA, &metaData, 0, kTRUE);
+           if ( !storeOK ) ++result;
+         }
+        }
+    } else {
+    Log ("Error: no QA files on FXS!");
+    result = 2;
+    }
+  } else {
+    Log ("Error: no QA entries in FXS list!");
+    result = 1;
+  }
+  return result;
+}
+