3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Gaute Ovrebekk *
8 //* for The ALICE HLT Project. *
10 //* Permission to use, copy, modify and distribute this software and its *
11 //* documentation strictly for non-commercial purposes is hereby granted *
12 //* without fee, provided that the above copyright notice appears in all *
13 //* copies and that both the copyright notice and this permission notice *
14 //* appear in the supporting documentation. The authors make no claims *
15 //* about the suitability of this software for any purpose. It is *
16 //* provided "as is" without express or implied warranty. *
17 //**************************************************************************
19 // @file AliHLTPredictionProcessorGRP.cxx
20 // @author Matthias Richter
22 // @brief Prediction processor for the GRP entry
25 #include "AliHLTPredictionProcessorGRP.h"
26 #include "AliCDBManager.h"
27 #include "AliCDBEntry.h"
28 #include "AliGRPObject.h"
29 #include "AliCDBMetaData.h"
33 //#include <TObjArray.h>
34 //#include <AliDCSValue.h>
35 //#include <TTimeStamp.h>
38 ClassImp(AliHLTPredictionProcessorGRP)
40 AliHLTPredictionProcessorGRP::AliHLTPredictionProcessorGRP(AliHLTPendolino* pendolino)
41 : AliHLTPredictionProcessorInterface("GRP", pendolino)
44 // see header file for class documentation
46 // refer to README to build package
48 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
52 AliHLTPredictionProcessorGRP::~AliHLTPredictionProcessorGRP()
58 UInt_t AliHLTPredictionProcessorGRP::makePrediction(Bool_t /*doPrediction*/)
60 // switch for prediction making
62 // not exactly clear what to do here, have to check the interface
67 void AliHLTPredictionProcessorGRP::Initialize(Int_t run, UInt_t startTime,
70 // initializes AliHLTPredictionProcessorGRP
71 AliHLTPredictionProcessorInterface::Initialize(run, startTime, endTime);
73 TString msg("Initialized GRP PredictProc. Run: ");
74 msg += GetRunNumber();
75 msg += ", start time: ";
77 msg += ", end time: ";
84 UInt_t AliHLTPredictionProcessorGRP::Process(TMap* dcsAliasMap)
86 // processes the DCS value map
88 if (!dcsAliasMap) return 9;
89 if (dcsAliasMap->GetEntries() == 0 ) return 9;
91 Float_t l3Current=0.0;
92 Float_t l3Polarity=0.0;
93 Float_t dipoleCurrent=0.0;
94 Float_t dipolePolarity=0.0;
95 Float_t cavernAtmosPressure=0.0;
96 Float_t cavernAtmosPressure2=0.0;
97 Float_t surfaceAtmosPressure=0.0;
103 if (!GetSensorValue(dcsAliasMap, key, &l3Current)) {
104 Log(Form("failed to extract %s from alias map", key));
109 if (!GetSensorValue(dcsAliasMap, key, &l3Polarity)) {
110 Log(Form("failed to extract %s from alias map", key));
115 if (!GetSensorValue(dcsAliasMap, key, &dipoleCurrent)) {
116 Log(Form("failed to extract %s from alias map", key));
120 key="DipolePolarity";
121 if (!GetSensorValue(dcsAliasMap, key, &dipolePolarity)) {
122 Log(Form("failed to extract %s from alias map", key));
126 key="CavernAtmosPressure";
127 if (!GetSensorValue(dcsAliasMap, key, &cavernAtmosPressure)) {
128 Log(Form("failed to extract %s from alias map", key));
132 key="CavernAtmosPressure2";
133 if (!GetSensorValue(dcsAliasMap, key, &cavernAtmosPressure2)) {
134 Log(Form("failed to extract %s from alias map", key));
138 key="SurfaceAtmosPressure2";
139 if (!GetSensorValue(dcsAliasMap, key, &surfaceAtmosPressure)) {
140 Log(Form("failed to extract %s from alias map", key));
144 AliGRPObject* grpObj=NULL;
145 AliGRPObject* grpExist=NULL;
146 AliCDBMetaData* cdbMetaData=NULL;
149 // read existing GRP object
150 AliCDBEntry* pEntry=GetFromOCDB("GRP","Data");
152 grpExist=dynamic_cast<AliGRPObject*>(pEntry->GetObject());
154 // possible values for polarities: 0 and 1
155 // nominal value of currents is thousands of ampere
156 bUpdate=bUpdate || (TMath::Abs(grpExist->GetL3Polarity()- l3Polarity)>0.5);
157 bUpdate=bUpdate || (TMath::Abs(grpExist->GetL3Current(AliGRPObject::kMean) - l3Current)>10.0);
158 bUpdate=bUpdate || (TMath::Abs(grpExist->GetDipolePolarity()- dipolePolarity)>0.5);
159 bUpdate=bUpdate || (TMath::Abs(grpExist->GetDipoleCurrent(AliGRPObject::kMean) - dipoleCurrent)>10.0);
161 cdbMetaData=pEntry->GetMetaData();
164 // don't write if object is there and up-to-date
165 if (grpExist && !bUpdate) return 0;
168 // update existing object
171 // generate GRP object
172 grpObj=new AliGRPObject;
173 float cmsEnergy=14000;
174 grpObj->SetBeamEnergy(cmsEnergy/0.120); // LHC convention
175 grpObj->SetBeamType("p-p");
177 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
178 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
179 grpObj->SetL3Polarity(l3Polarity);
180 grpObj->SetDipolePolarity(dipolePolarity);
181 grpObj->SetPolarityConventionLHC(); // LHC convention +/+ current -> -/- field main components
184 cdbMetaData=new AliCDBMetaData;
185 cdbMetaData->SetResponsible("Matthias.Richter@cern.ch");
186 cdbMetaData->SetComment(Form("GRP entry for the magnetic field initialization of HLT components, produced by %s", ClassName()));
189 // note: 'validityStart' specifies run no w.r.t. current run no -> thus 0
190 // create with run specific validity -> kFALSE
191 if (Store("GRP", "Data", grpObj, cdbMetaData, 0, kFALSE)) {
193 Log(" *** Failed to store GRP object");
197 if (grpObj) delete grpObj;
199 if (cdbMetaData) delete cdbMetaData;
206 TMap* AliHLTPredictionProcessorGRP::produceTestData(TString /*aliasName*/)
208 // produces test data for AliHLTPredictionProcessorGRP
214 bool AliHLTPredictionProcessorGRP::CreateInitialGRPEntry(int runno, const char* beamtype, const char* runtype, const char* detectorList)
216 // Create the initial GRP entry.
217 // The beam type and run type parameters are propagated form the ECS to
218 // the run manager, and provided as arguments to the pendolino.
219 // The initial GRP entry is created ignoring the magnetic field, this
220 // is updated by the pendolino afterwords.
222 AliGRPObject* grpObj=new AliGRPObject;
223 float cmsEnergy=14000; // check if this can be obtained from somewhere
224 grpObj->SetBeamEnergy(cmsEnergy/0.120); // LHC convention
225 grpObj->SetBeamType(beamtype);
226 grpObj->SetRunType(runtype);
227 grpObj->SetL3Current(0.0,(AliGRPObject::Stats)0);
228 grpObj->SetDipoleCurrent(0.0,(AliGRPObject::Stats)0);
229 grpObj->SetL3Polarity(0);
230 grpObj->SetDipolePolarity(0);
231 grpObj->SetPolarityConventionLHC();
232 grpObj->SetTimeStart(time(NULL)); // check if time can be fetched from ECS
234 /* the following needs to be checked
235 grpObj->SetLHCPeriod(getenv("LHC_PERIOD"));
236 grpObj->SetNumberOfDetectors(numOfDetectors);
237 grpObj->SetDetectorMask(detectMask);
240 AliCDBManager* man = AliCDBManager::Instance();
241 if (!man || !man->IsDefaultStorageSet()) {
245 AliCDBPath cdbPath("GRP/GRP/Data");
246 AliCDBId cdbId(cdbPath, runno, runno);
247 AliCDBMetaData cdbMetaData;
248 cdbMetaData.SetResponsible("matthias.richter@cern.ch");
249 cdbMetaData.SetComment(Form("Online GRP entry, produced by AliHLTPredictionProcessorGRP"));
250 return man->Put(grpObj, cdbId, &cdbMetaData);