]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliGRPPreprocessor.cxx
Coverity fixes.
[u/mrichter/AliRoot.git] / STEER / AliGRPPreprocessor.cxx
index c93ec583af5bb1a7b525f122e468e48dd72872ca..8ff30685d0464f24cbb8bc80ae7695e4ea5a9966 100644 (file)
 
 #include "AliTriggerConfiguration.h"
 #include "AliTriggerRunScalers.h"
+#include "AliTriggerInput.h"
 
 #include "AliCDBMetaData.h"
 #include "AliESDVertex.h"
 #include "AliLHCReader.h"
 #include "AliLHCData.h"
 #include "AliDCSArray.h"
+#include "AliDAQ.h"
+#include "AliLTUConfig.h"
 
 class AliLog;
 class AliDCSValue;
@@ -197,7 +200,8 @@ ClassImp(AliGRPPreprocessor)
                   "(SPD Mean Vertex ERROR)",
                   "(DCS FXS Error for LHC Data)",
                   "(LHC Data Error)",
-                  "(LHC Clock Phase Error (from LHC Data))"
+                  "(LHC Clock Phase Error (from LHC Data))",
+                  "(LTU Configuration Error)"
   };
 
 //_______________________________________________________________
@@ -518,6 +522,90 @@ UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
                error |= 32;
        }
 
+        //===========================//
+       // LTU Configuration         //
+        //===========================//
+
+       Log("*************** Processing LTU Configuration");
+       
+       if (partition.IsNull() && !detector.IsNull()){ // standalone partition
+               Log("STANDALONE partition for current run, using LTU configuration dummy value");
+               AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyLTUConfig");
+               if (!cdbEntry) {
+                       Log(Form("No dummy LTU Config entry found, going into error..."));
+                       error |= 2048;
+               }
+               else{
+                       TObjArray *ltuConfig = (TObjArray*)cdbEntry->GetObject();
+                       if (!ltuConfig){
+                               Log(Form("dummy LTU Config not found in OCDB entry, going into error..."));
+                               error |= 2048;
+                       }
+                       else {
+                               AliCDBMetaData metadata;
+                               metadata.SetResponsible("Roman Lietava");
+                               metadata.SetComment("LTU Config from dummy entry in OCDB");
+                               if (!Store("CTP","LTUConfig", ltuConfig, &metadata, 0, 0)) {
+                                       Log("Unable to store the dummy LTU Config object to OCDB!");
+                                       error |= 2048;
+                               }
+                       }
+               }
+       }
+
+       else if (!partition.IsNull() && detector.IsNull()){ // global partition
+       
+               Log("GLOBAL partition for current run, getting LTU Config from DAQ Logbook (logbook_detectors table)");
+               UInt_t  detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
+               Printf ("detectormask = %d",detectorMask);
+               TObjArray * ltuarray = new TObjArray();
+               ltuarray->SetOwner(1);
+               Bool_t isLTUok = kTRUE;
+               for(Int_t i = 0; i<AliDAQ::kNDetectors-2; i++){
+                       if ((detectorMask >> i) & 0x1) {
+                               TString det = AliDAQ::OfflineModuleName(i);
+                               TString detCTPName = AliTriggerInput::fgkCTPDetectorName[i];
+                               if (detCTPName == "CTP") {
+                                       detCTPName="TRG"; // converting according to what is found in DAQ logbook_detectors                                     
+                                       Printf("Processing CTP (CTP Detector name %s) --> SKIPPING, CTP does not have any LTU!!!!!!",detCTPName.Data());
+                                       continue;
+                               }                               
+                               Printf("Processing detector %s (CTP Detector name %s)",det.Data(),detCTPName.Data());
+                               TString* ltu = GetLTUConfig(detCTPName.Data());
+                               if (!ltu){
+                                       Log(Form("No LTU Configuration from DAQ logbook for detector %s (BUT it was expected)! The corresponding CDB entry will not be filled!",detCTPName.Data()));
+                                       error |= 2048;
+                                       isLTUok = kFALSE;
+                                       break;
+                               }
+                               else{
+                                       Float_t ltuFineDelay1 = ltu[0].Atof();
+                                       Float_t ltuFineDelay2 = ltu[1].Atof();
+                                       Float_t ltuBCDelayAdd = ltu[2].Atof();
+                                       const char* name = AliDAQ::DetectorName(i);
+                                       AliLTUConfig* ltuConfig = new AliLTUConfig((UChar_t)AliDAQ::DetectorID(name),ltuFineDelay1,ltuFineDelay2,ltuBCDelayAdd);
+                                       ltuarray->AddAtAndExpand(ltuConfig,i);
+                               }                               
+                       }
+               }
+               if (isLTUok){
+                       AliCDBMetaData metadata;
+                       metadata.SetBeamPeriod(0);
+                       metadata.SetResponsible("Roman Lietava");
+                       metadata.SetComment("LTU Configuration for current run");
+                       if (!Store("CTP","LTUConfig", ltuarray, &metadata, 0, 0)) {
+                               Log("Unable to store the LTU Config object to OCDB!");
+                               error |= 2048;
+                       }               
+               }
+               if (ltuarray) delete ltuarray;
+       }
+
+       else {
+               Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
+               error |= 32;
+       }
+
 
        //=================//
        // LHC Data        //
@@ -582,7 +670,7 @@ UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
                Log("GRP Preprocessor Success");
                return 0;
        } else {
-               Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s%s",
+               Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s%s%s%s%s",
                          kppError[(error&1)?1:0],
                          kppError[(error&2)?2:0],
                          kppError[(error&4)?3:0],
@@ -593,7 +681,8 @@ UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
                          kppError[(error&128)?8:0],
                          kppError[(error&256)?9:0],
                          kppError[(error&512)?10:0],
-                         kppError[(error&1024)?11:0]
+                         kppError[(error&1024)?11:0],
+                         kppError[(error&2048)?12:0]
                          ));
                return error;
        }
@@ -803,7 +892,7 @@ UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
                                        }
                                }
                                if (!foundBeamStart){
-                                       AliInfo("No value for the Machine Mode found before start of run, the Machine Mode will remain empty");
+                                       AliInfo("No value for the Beam Type found before start of run, the Machine Mode will remain empty");
                                }
                                else {
                                        AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
@@ -814,13 +903,19 @@ UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
                                                AliInfo("Setting beam type to p-p");
                                                grpobj->SetBeamType("p-p");
                                        }
-                                       else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
+                                       else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
+                                               AliInfo("Setting beam type to A-A");
+                                               grpobj->SetBeamType("A-A");
+                                       }
+                                       /*
+                                         else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
                                                AliInfo("Setting beam type to Pb-Pb");
                                                grpobj->SetBeamType("Pb-Pb");
                                        }
                                        else{
                                                AliError("Beam Type not known, leaving it empty");
                                        }
+                                       */
                                        if (indexBeam < nBeam-1){
                                                AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
                                                if (beam1){
@@ -899,7 +994,7 @@ UInt_t AliGRPPreprocessor::ProcessLHCData(AliGRPObject *grpobj)
                        Log(Form("Problems in retrieving LHC Clock data from LHC file"));
                        return 4;
                }                       
-               AliLHCClockPhase *phaseObj = ProcessLHCClockPhase(beam1phase,beam2phase,timeStart,timeEnd);
+               AliLHCClockPhase *phaseObj = ProcessLHCClockPhase(beam1phase,beam2phase,timeEnd);
                if (phaseObj){
                        AliInfo(Form("LHC Phase found"));
                        AliCDBMetaData mdPhase;
@@ -2340,7 +2435,7 @@ Int_t AliGRPPreprocessor::ReceivePromptRecoParameters(UInt_t run, const char* db
        
        // main logbook
        TString sqlQuery;
-       sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
+       sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent,beamType FROM logbook WHERE run = %d", run);
        TSQLResult* result = server->Query(sqlQuery);
        if (!result)
                {
@@ -2368,12 +2463,16 @@ Int_t AliGRPPreprocessor::ReceivePromptRecoParameters(UInt_t run, const char* db
        TString detectorMaskString(row->GetField(2));
        TString l3CurrentString(row->GetField(3));
        TString dipoleCurrentString(row->GetField(4));
+       TString beamTypeString(row->GetField(5));
        time_t timeStart = (time_t)(timeStartString.Atoi());
        UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
        Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
        Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
        Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
        Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
+       if (beamTypeString.CompareTo("Pb-Pb",TString::kIgnoreCase) == 0){
+               beamTypeString="A-A";
+       }
        
        AliGRPObject * grpObj = new AliGRPObject();
        grpObj->SetTimeStart(timeStart); 
@@ -2384,6 +2483,7 @@ Int_t AliGRPPreprocessor::ReceivePromptRecoParameters(UInt_t run, const char* db
        grpObj->SetL3Polarity(l3Polarity);
        grpObj->SetDipolePolarity(dipolePolarity);
        grpObj->SetPolarityConventionLHC();  // after the dipole cables swap we comply with LHC convention
+       grpObj->SetBeamType(beamTypeString);
 
        delete row;
        row = 0;
@@ -2822,7 +2922,7 @@ Float_t AliGRPPreprocessor::ProcessEnergy(TObjArray* const array, Double_t timeS
        return energy;
 }
 //------------------------------------------------------------------------------------------------------
-AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase,TObjArray *beam2phase, Double_t timeStart, Double_t timeEnd)
+AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase,TObjArray *beam2phase, Double_t timeEnd)
 {
   //
   // Method to process LHC-Clock Phase data
@@ -2831,6 +2931,10 @@ AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase
   AliLHCClockPhase *phaseObj = new AliLHCClockPhase;
 
   Bool_t foundBeam1Phase = kFALSE, foundBeam2Phase = kFALSE;
+  const Float_t threshold = 0.050; // we store the measurement only in case they differ with more 50ps from the previous one 
+
+  TString timeCreatedStr = GetRunParameter("time_created");
+  Double_t timeCreated = timeCreatedStr.Atof();
 
   Int_t nCounts = beam1phase->GetEntries();
   AliDebug(2,Form("Beam1 phase measurements = %d\n",nCounts));
@@ -2840,14 +2944,21 @@ AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase
     return NULL;
   }
   else{
+    Double_t prevPhase = 0;
     for (Int_t i = 0; i < nCounts; i++){
       AliDCSArray *dcs = (AliDCSArray*)beam1phase->At(i);
       if (dcs){
-       if (dcs->GetTimeStamp()>=timeStart && dcs->GetTimeStamp()<=timeEnd) {
-         foundBeam1Phase = kTRUE;
-         AliInfo(Form("Beam1 Clock Phase = %f at timestamp = %f",
-                      (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));  
-         phaseObj->AddPhaseB1DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
+             //if (dcs->GetTimeStamp()>=timeStart && dcs->GetTimeStamp()<=timeEnd) {
+             if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
+         if ((i == 0) || (i == (nCounts-1)) ||
+             !foundBeam1Phase ||
+             (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
+           prevPhase = dcs->GetDouble(0);
+           foundBeam1Phase = kTRUE;
+           AliInfo(Form("B1 Clk Phase = %f at TS = %f",
+                        (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));  
+           phaseObj->AddPhaseB1DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
+         }
        }
       }
     }
@@ -2866,14 +2977,20 @@ AliLHCClockPhase* AliGRPPreprocessor::ProcessLHCClockPhase(TObjArray *beam1phase
     return NULL;
   }
   else{
+    Double_t prevPhase = 0;
     for (Int_t i = 0; i < nCounts; i++){
       AliDCSArray *dcs = (AliDCSArray*)beam2phase->At(i);
       if (dcs){
-       if (dcs->GetTimeStamp()>=timeStart && dcs->GetTimeStamp()<=timeEnd) {
-         foundBeam2Phase = kTRUE;
-         AliInfo(Form("Beam2 Clock Phase = %f at timestamp = %f",
-                      (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));  
-         phaseObj->AddPhaseB2DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
+       if (dcs->GetTimeStamp()>=timeCreated && dcs->GetTimeStamp()<=timeEnd) {
+         if ((i == 0) || (i == (nCounts-1)) ||
+             !foundBeam2Phase ||
+             (TMath::Abs(dcs->GetDouble(0)-prevPhase) > threshold)) {
+           prevPhase = dcs->GetDouble(0);
+           foundBeam2Phase = kTRUE;
+           AliInfo(Form("B2 Clk Phase = %f at TS = %f",
+                        (Float_t)dcs->GetDouble(0),dcs->GetTimeStamp()));  
+           phaseObj->AddPhaseB2DP((UInt_t)dcs->GetTimeStamp(),(Float_t)dcs->GetDouble(0));
+         }
        }
       }
     }