]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliGRPPreprocessor.cxx
adding run type, removing unused constructor
[u/mrichter/AliRoot.git] / STEER / AliGRPPreprocessor.cxx
index 6e099501562c2393b9c05b1f8c03ead9bcfeb112..8291e7bf0a3e6c1c9663b9b02ef78ba01a54e77a 100644 (file)
@@ -33,6 +33,9 @@
 #include "AliGRPDCS.h"
 #include "AliDCSSensorArray.h"
 
+#include "AliTriggerConfiguration.h"
+#include "AliTriggerRunScalers.h"
+
 #include "AliCDBMetaData.h"
 #include "AliLog.h"
 
@@ -48,18 +51,12 @@ ClassImp(AliGRPPreprocessor)
 //_______________________________________________________________
   const char* AliGRPPreprocessor::fgkDCSDataPoints[12] = {"LHCState","LHCPeriod","LHCLuminosity","BeamIntensity","L3Current","L3Polarity","DipoleCurrent","DipolePolarity","CavernTemperature","CavernAtmosPressure","gva_cr5AtmosphericPressure","gva_meyrinAtmosphericPressure"};
 
-//_______________________________________________________________
-AliGRPPreprocessor::AliGRPPreprocessor():
-  AliPreprocessor("GRP",0), fPressure(0) {
-  // default constructor - Don't use this!
-  
-}
-
 //_______________________________________________________________
 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
   AliPreprocessor("GRP",shuttle), fPressure(0) {
   // constructor - shuttle must be instantiated!
-  
+
+  AddRunType("PHYSICS");
 }
 
 //_______________________________________________________________
@@ -71,12 +68,9 @@ AliGRPPreprocessor::~AliGRPPreprocessor() {
 //_______________________________________________________________
 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime) {
   // Initialize preprocessor
-  
-  AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, TTimeStamp(startTime).AsString(), TTimeStamp(endTime).AsString()));
-  
-  fRun = run;
-  fStartTime = startTime;
-  fEndTime = endTime;
+
+  AliPreprocessor::Initialize(run, startTime, endTime);
+    
   AliInfo("Initialization of the GRP preprocessor.");
 
   TClonesArray * array = new TClonesArray("AliDCSSensor",2);
@@ -100,35 +94,42 @@ UInt_t AliGRPPreprocessor::Process(TMap* valueMap) {
   TList *daqlblist = ProcessDaqLB();
   if(!daqlblist) {
     Log(Form("Problem with the DAQ logbook parameters!!!"));
-    return 0;
+    return 1;
   }
-  TMap *m1 = (TMap *)daqlblist->At(0);
-  TObjString *s1 = (TObjString *)m1->GetValue("fAliceStartTime");
-  UInt_t iStartTime = atoi(s1->String().Data());
-  TMap *m2 = (TMap *)daqlblist->At(1);
-  TObjString *s2 = (TObjString *)m2->GetValue("fAliceStopTime");
-  UInt_t iStopTime = atoi(s2->String().Data());
-  TMap *m3 = (TMap *)daqlblist->At(6);
-  TObjString *s3 = (TObjString *)m3->GetValue("fLHCPeriod");
-  TString productionYear = "";
 
   //=================//
   // DAQ FXS         //
   //=================//
   UInt_t iDaqFxs = ProcessDaqFxs();
-  if(iDaqFxs == 1) Log(Form("Raw data merged tags copied succesfully in AliEn!!!"));
+  if(iDaqFxs == 0) {
+       Log(Form("ProcessDaqFxs successful!"));
+  } else {
+       Log(Form("Could not store run raw tag file!"));
+       return 1;
+  }
+  
+  //=================//
+  // DCS FXS         //
+  //=================//
+  UInt_t iDcsFxs = ProcessDcsFxs();
+  if(iDcsFxs == 0) {
+       Log(Form("ProcessDcsFxs successful!"));
+  } else {
+       Log(Form("Could not store CTP run configuration and scalers!"));
+       return 1;
+  }
+  
   //=================//
   // DCS data points //
   //=================//
-  TList *dcsdplist = ProcessDcsDPs(valueMap, iStartTime, iStopTime);
+  TList *dcsdplist = ProcessDcsDPs(valueMap);
   if(!dcsdplist) {
     Log(Form("Problem with the DCS data points!!!"));
-    return 0;
+    return 1; 
   }    
   if(dcsdplist->GetEntries() != 10) {
     Log(Form("Problem with the DCS data points!!!"));
-    return 0;
+    // return 1; // TODO:COMMENTED FOR TESTING PURPOSES!
   }
   //NEEDS TO BE REVISED - BREAKS!!!
 //   AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap,fPressure);
@@ -137,18 +138,17 @@ UInt_t AliGRPPreprocessor::Process(TMap* valueMap) {
 //     return 0;
 //   }
 
-  TList * list = new TList();
-  list = GetGlobalList(daqlblist,dcsdplist);
-  list->SetOwner(1);
-  AliInfo(Form("Final list entries: %d",list->GetEntries()));
+  daqlblist->AddAll(dcsdplist);
+  daqlblist->SetOwner(1);
+  AliInfo(Form("Final list entries: %d",daqlblist->GetEntries()));
   
   AliCDBMetaData md;
   md.SetResponsible("Panos Christakoglou");
   md.SetComment("Output parameters from the GRP preprocessor.");
   
-  Bool_t result = Store("GRP", "Data", list, &md);
+  Bool_t result = Store("GRP", "Data", daqlblist, &md);
   
-  delete list;
+  delete daqlblist;
   
   if (result)
     return 0;
@@ -156,19 +156,6 @@ UInt_t AliGRPPreprocessor::Process(TMap* valueMap) {
     return 1;
 }
 
-//_______________________________________________________________
-TList *AliGRPPreprocessor::GetGlobalList(TList *l1, TList *l2) {
-  //Getting the global output TList
-  TList *list = new TList();
-  TMap *map = new TMap();
-  for(Int_t i = 0; i < l1->GetEntries(); i++) 
-    list->AddLast(map = (TMap *)l1->At(i));
-  for(Int_t i = 0; i < l2->GetEntries(); i++) 
-    list->AddLast(map = (TMap *)l2->At(i));
-
-  return list;
-}
-
 //_______________________________________________________________
 TList *AliGRPPreprocessor::ProcessDaqLB() {
   //Getting the DAQ lb informnation
@@ -241,6 +228,10 @@ TList *AliGRPPreprocessor::ProcessDaqLB() {
   list->Add(mapDAQ3); list->Add(mapDAQ4);
   list->Add(mapDAQ5); list->Add(mapDAQ6);
   list->Add(mapDAQ7);
+  
+  TMap* mapDAQ8 = new TMap;
+  mapDAQ8->Add(new TObjString("fRunType"), new TObjString(GetRunType()));
+  list->Add(mapDAQ8);
 
   return list;
 }
@@ -248,13 +239,22 @@ TList *AliGRPPreprocessor::ProcessDaqLB() {
 //_______________________________________________________________
 UInt_t AliGRPPreprocessor::ProcessDaqFxs() {
   //======DAQ FXS======//
-  TChain *fRawTagChain = new TChain("T");
 
   TList* list = GetFileSources(kDAQ);  
   if (!list) {
-    Log("No raw data tag list found!!!");
+    Log("No raw data tag list: connection problems with DAQ FXS logbook!");
     return 1;
   }
+  
+  if (list->GetEntries() == 0)
+  {
+       Log("no raw data tags in this run: nothing to merge!");
+       delete  list; list=0;
+       return 0;
+  }
+
+  TChain *fRawTagChain = new TChain("T");
+  Int_t nFiles=0;
   TIterator* iter = list->MakeIterator();
   TObject* obj = 0;
   while ((obj = iter->Next())) {
@@ -263,44 +263,151 @@ UInt_t AliGRPPreprocessor::ProcessDaqFxs() {
       Log(Form("Found source %s", objStr->String().Data()));
       TList* list2 = GetFileIDs(kDAQ, objStr->String());
       if (!list2) {
-       Log("No list with ids from DAQ was found!!!");
-       return 2;
+       Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
+       delete fRawTagChain; fRawTagChain=0;
+       return 1;
       }
       Log(Form("Number of ids: %d",list2->GetEntries()));
       for(Int_t i = 0; i < list2->GetEntries(); i++) {
        TObjString *idStr = (TObjString *)list2->At(i);
-       //Log(Form("Filename1: %s",idStr->String().Data()));
-       TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());      
-       Log(Form("Adding file in the chain: %s",fileName.Data()));
-       fRawTagChain->Add(fileName.Data());
-       //fRawDataFileName = fileName(0,fileName.First("_"));
+       TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
+       if (fileName.Length() > 0) 
+       {      
+               Log(Form("Adding file in the chain: %s",fileName.Data()));
+               fRawTagChain->Add(fileName.Data());
+               nFiles++;
+       } else {
+               Log(Form("Could not retrieve file with id %s from source %s: "
+                       "connection problems with DAQ FXS!",
+                               idStr->String().Data(),objStr->String().Data()));
+               delete list; list=0;
+               delete list2; list2=0;
+               delete fRawTagChain; fRawTagChain=0;
+               return 2;
+       }
       }
       delete list2;
     }
   }
+  
+  TString fRawDataFileName = "GRP_Merged.tag.root";
+  Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
+  fRawTagChain->Merge(fRawDataFileName);
+  
+  TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
+  Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
+  
+  if (!result)
+  {
+       Log("Problem storing raw data tags in local file!!");
+  } else {
+       Log("Raw data tags merged successfully!!");  
+  }
+  
   delete iter;
   delete list;
-  TString fRawDataFileName = "GRP_Merged.tag.root";
-  Log(Form("Merging raw data tags into file: %s",fRawDataFileName.Data()));
+  delete fRawTagChain; fRawTagChain=0;
+  
+  if (result == kFALSE)
+  {
+       return 3;
+  }
+  
+  return 0;
+  
+}
 
-  TFile* f = new TFile(fRawDataFileName.Data(), "RECREATE");
-  f->cd();
-  fRawTagChain->Write();
-  f->Close();
-  delete f; f=0;  
+//_______________________________________________________________
+UInt_t AliGRPPreprocessor::ProcessDcsFxs() {
+  //======DCS FXS======//
+  // Get the CTP run configuration
+  // and scalers from DCS FXS
+
+  {
+    // Get the CTP run configuration
+    TList* list = GetFileSources(kDCS,"CTP_runconfig");  
+    if (!list) {
+      Log("No CTP runconfig file: connection problems with DCS FXS logbook!");
+      return 1;
+    }
   
-  //TString outputfile = "alien:///alice/data/"; 
-  //outputfile += productionYear.Data(); outputfile += "/";
-  //outputfile += lhcperiod.Data(); outputfile += "/";
-  //outputfile += fRun; outputfile += "/raw/"; 
-  TString outputfile = "runMetadata.root";
-  Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
+    if (list->GetEntries() == 0) {
+      Log("No CTP runconfig file to be processed!");
+    }
+    else {
+      TIter iter(list);
+      TObjString *source;
+      while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
+       TString runcfgfile = GetFile(kDCS, "CTP_runconfig", source->GetName());
+       if (runcfgfile.IsNull()) {
+         Log("No CTP runconfig files has been found: empty source!");
+       }
+       else {
+         Log(Form("File with Id CTP_runconfig found in source %s! Copied to %s",source->GetName(),runcfgfile.Data()));
+         AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfiguration(runcfgfile);
+         if (!runcfg) {
+           Log("Bad CTP run configuration file! The corresponding CDB entry will not be filled!");
+         }
+         else {
+           AliCDBMetaData metaData;
+           metaData.SetBeamPeriod(0);
+           metaData.SetResponsible("Roman Lietava");
+           metaData.SetComment("CTP run configuration");
+           if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
+             Log("Unable to store the CTP run configuration object to OCDB!");
+           }
+         }
+       }
+      }
+    }
+    delete list;
+  }
+
+  {
+    // Get the CTP counters information
+    TList* list = GetFileSources(kDCS,"CTP_xcounters");  
+    if (!list) {
+      Log("No CTP counters file: connection problems with DAQ FXS logbook!");
+      return 1;
+    }
+  
+    if (list->GetEntries() == 0) {
+      Log("No CTP counters file to be processed!");
+    }
+    else {
+      TIter iter(list);
+      TObjString *source;
+      while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
+       TString countersfile = GetFile(kDCS, "CTP_xcounters", source->GetName());
+       if (countersfile.IsNull()) {
+         Log("No CTP counters files has been found: empty source!");
+       }
+       else {
+         Log(Form("File with Id CTP_xcounters found in source %s! Copied to %s",source->GetName(),countersfile.Data()));
+         AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
+         if (!scalers) {
+           Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
+         }
+         else {
+           AliCDBMetaData metaData;
+           metaData.SetBeamPeriod(0);
+           metaData.SetResponsible("Roman Lietava");
+           metaData.SetComment("CTP scalers");
+           if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
+             Log("Unable to store the CTP scalers object to OCDB!");
+           }
+         }
+       }
+      }
+    }
+    delete list;
+  }
 
-  return result;
+  return 0;
 }
 
 //_______________________________________________________________
-TList *AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, UInt_t iStartTime, UInt_t iStopTime) {
+TList *AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap) {
   //Getting the DCS dps
   //===========//
   
@@ -314,7 +421,7 @@ TList *AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, UInt_t iStartTime, UInt
     Log(Form("LHCState not found!!!"));
     return list;
   }
-  AliGRPDCS *dcs1 = new AliGRPDCS(aliasLHCState,iStartTime,iStopTime);
+  AliGRPDCS *dcs1 = new AliGRPDCS(aliasLHCState,fStartTime,fEndTime);
   TString sLHCState = dcs1->ProcessDCS(3);  
   if (sLHCState) {
     Log(Form("<LHCState> for run %d: %s",fRun, sLHCState.Data()));
@@ -331,7 +438,7 @@ TList *AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, UInt_t iStartTime, UInt
     Log(Form("LHCPeriod not found!!!"));
     return list;
   }
-  AliGRPDCS *dcs2 = new AliGRPDCS(aliasLHCPeriod,iStartTime,iStopTime);
+  AliGRPDCS *dcs2 = new AliGRPDCS(aliasLHCPeriod,fStartTime,fEndTime);
   TString sLHCPeriod = dcs2->ProcessDCS(3);  
   if (sLHCPeriod) {
     Log(Form("<LHCPeriod> for run %d: %s",fRun, sLHCPeriod.Data()));
@@ -348,7 +455,7 @@ TList *AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, UInt_t iStartTime, UInt
     Log(Form("LHCLuminosity not found!!!"));
     return list;
   }
-  AliGRPDCS *dcs3 = new AliGRPDCS(aliasLHCLuminosity,iStartTime,iStopTime);
+  AliGRPDCS *dcs3 = new AliGRPDCS(aliasLHCLuminosity,fStartTime,fEndTime);
   TString sMeanLHCLuminosity = dcs3->ProcessDCS(2);  
   if (sMeanLHCLuminosity) {
     Log(Form("<LHCLuminosity> for run %d: %s",fRun, sMeanLHCLuminosity.Data()));
@@ -365,7 +472,7 @@ TList *AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, UInt_t iStartTime, UInt
     Log(Form("BeamIntensity not found!!!"));
     return list;
   }
-  AliGRPDCS *dcs4 = new AliGRPDCS(aliasBeamIntensity,iStartTime,iStopTime);
+  AliGRPDCS *dcs4 = new AliGRPDCS(aliasBeamIntensity,fStartTime,fEndTime);
   TString sMeanBeamIntensity = dcs4->ProcessDCS(2);  
   if (sMeanBeamIntensity) {
     Log(Form("<BeamIntensity> for run %d: %s",fRun, sMeanBeamIntensity.Data()));
@@ -382,7 +489,7 @@ TList *AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, UInt_t iStartTime, UInt
     Log(Form("L3Current not found!!!"));
     return list;
   }
-  AliGRPDCS *dcs5 = new AliGRPDCS(aliasL3Current,iStartTime,iStopTime);
+  AliGRPDCS *dcs5 = new AliGRPDCS(aliasL3Current,fStartTime,fEndTime);
   TString sMeanL3Current = dcs5->ProcessDCS(2);  
   if (sMeanL3Current) {
     Log(Form("<L3Current> for run %d: %s",fRun, sMeanL3Current.Data()));
@@ -399,7 +506,7 @@ TList *AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, UInt_t iStartTime, UInt
     Log(Form("L3Polarity not found!!!"));
     return list;
   }
-  AliGRPDCS *dcs6 = new AliGRPDCS(aliasL3Polarity,iStartTime,iStopTime);
+  AliGRPDCS *dcs6 = new AliGRPDCS(aliasL3Polarity,fStartTime,fEndTime);
   TString sL3Polarity = dcs6->ProcessDCS(4);  
   if (sL3Polarity) {
     Log(Form("<L3Polarity> for run %d: %s",fRun, sL3Polarity.Data()));
@@ -416,7 +523,7 @@ TList *AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, UInt_t iStartTime, UInt
     Log(Form("DipoleCurrent not found!!!"));
     return list;
   }
-  AliGRPDCS *dcs7 = new AliGRPDCS(aliasDipoleCurrent,iStartTime,iStopTime);
+  AliGRPDCS *dcs7 = new AliGRPDCS(aliasDipoleCurrent,fStartTime,fEndTime);
   TString sMeanDipoleCurrent = dcs7->ProcessDCS(2);  
   if (sMeanDipoleCurrent) {
     Log(Form("<DipoleCurrent> for run %d: %s",fRun, sMeanDipoleCurrent.Data()));
@@ -433,7 +540,7 @@ TList *AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, UInt_t iStartTime, UInt
     Log(Form("DipolePolarity not found!!!"));
     return list;
   }
-  AliGRPDCS *dcs8 = new AliGRPDCS(aliasDipolePolarity,iStartTime,iStopTime);
+  AliGRPDCS *dcs8 = new AliGRPDCS(aliasDipolePolarity,fStartTime,fEndTime);
   TString sDipolePolarity = dcs8->ProcessDCS(4);  
   if (sDipolePolarity) {
     Log(Form("<DipolePolarity> for run %d: %s",fRun, sDipolePolarity.Data()));
@@ -450,7 +557,7 @@ TList *AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, UInt_t iStartTime, UInt
     Log(Form("CavernTemperature not found!!!"));
     return list;
   }
-  AliGRPDCS *dcs9 = new AliGRPDCS(aliasCavernTemperature,iStartTime,iStopTime);
+  AliGRPDCS *dcs9 = new AliGRPDCS(aliasCavernTemperature,fStartTime,fEndTime);
   TString sMeanCavernTemperature = dcs9->ProcessDCS(2);  
   if (sMeanCavernTemperature) {
     Log(Form("<CavernTemperature> for run %d: %s",fRun, sMeanCavernTemperature.Data()));
@@ -467,7 +574,7 @@ TList *AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, UInt_t iStartTime, UInt
     Log(Form("CavernPressure not found!!!"));
     return list;
   }
-  AliGRPDCS *dcs10 = new AliGRPDCS(aliasCavernPressure,iStartTime,iStopTime);
+  AliGRPDCS *dcs10 = new AliGRPDCS(aliasCavernPressure,fStartTime,fEndTime);
   TString sMeanCavernPressure = dcs10->ProcessDCS(2);  
   if (sMeanCavernPressure) {
     Log(Form("<CavernPressure> for run %d: %s",fRun, sMeanCavernPressure.Data()));