]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/pendolino/PredictionProcessor/GRP/AliHLTPredictionProcessorGRP.cxx
commenting unused function argument
[u/mrichter/AliRoot.git] / HLT / pendolino / PredictionProcessor / GRP / AliHLTPredictionProcessorGRP.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Gaute Ovrebekk                                        *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
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 //**************************************************************************
18
19 //  @file   AliHLTPredictionProcessorGRP.cxx
20 //  @author Matthias Richter
21 //  @date   2010-04-12
22 //  @brief  Prediction processor for the GRP entry
23 // 
24
25 #include "AliHLTPredictionProcessorGRP.h"
26 #include "AliCDBManager.h"
27 #include "AliCDBEntry.h"
28 #include "AliGRPObject.h"
29 #include "AliCDBMetaData.h"
30 #include "AliCDBId.h"
31 #include <cassert>
32
33 //#include <TObjArray.h>
34 //#include <AliDCSValue.h>
35 //#include <TTimeStamp.h>
36
37
38 ClassImp(AliHLTPredictionProcessorGRP)
39
40 AliHLTPredictionProcessorGRP::AliHLTPredictionProcessorGRP(AliHLTPendolino* pendolino)
41   : AliHLTPredictionProcessorInterface("GRP", pendolino)
42 {
43   // constructor
44   // see header file for class documentation
45   // or
46   // refer to README to build package
47   // or
48   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
49 }
50
51
52 AliHLTPredictionProcessorGRP::~AliHLTPredictionProcessorGRP()
53 {
54   // destructor
55 }
56
57
58 UInt_t AliHLTPredictionProcessorGRP::makePrediction(Bool_t /*doPrediction*/)
59 {
60   // switch for prediction making
61
62   // not exactly clear what to do here, have to check the interface
63   return 0;
64 }
65
66
67 void AliHLTPredictionProcessorGRP::Initialize(Int_t run, UInt_t startTime, 
68                                               UInt_t endTime)
69 {
70   // initializes AliHLTPredictionProcessorGRP
71   AliHLTPredictionProcessorInterface::Initialize(run, startTime, endTime);
72
73   TString msg("Initialized GRP PredictProc. Run: ");
74   msg += GetRunNumber();
75   msg += ", start time: ";
76   msg += StartTime();
77   msg += ", end time: ";
78   msg += EndTime();
79   msg += ".";   
80   Log(msg.Data());
81 }
82
83
84 UInt_t AliHLTPredictionProcessorGRP::Process(TMap* dcsAliasMap)
85 {
86   // processes the DCS value map
87   
88   if (!dcsAliasMap) return 9;
89   if (dcsAliasMap->GetEntries() == 0 ) return 9;
90
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;
98   
99   Bool_t bRet = kTRUE;
100   const char* key="";
101
102   key="L3Current";
103   if (!GetSensorValue(dcsAliasMap, key, &l3Current)) {
104     Log(Form("failed to extract %s from alias map", key));
105     bRet=kFALSE;
106   }
107
108   key="L3Polarity";
109   if (!GetSensorValue(dcsAliasMap, key, &l3Polarity)) {
110     Log(Form("failed to extract %s from alias map", key));
111     bRet=kFALSE;
112   }
113
114   key="DipoleCurrent";
115   if (!GetSensorValue(dcsAliasMap, key, &dipoleCurrent)) {
116     Log(Form("failed to extract %s from alias map", key));
117     bRet=kFALSE;
118   }
119
120   key="DipolePolarity";
121   if (!GetSensorValue(dcsAliasMap, key, &dipolePolarity)) {
122     Log(Form("failed to extract %s from alias map", key));
123     bRet=kFALSE;
124   }
125
126   key="CavernAtmosPressure";
127   if (!GetSensorValue(dcsAliasMap, key, &cavernAtmosPressure)) {
128     Log(Form("failed to extract %s from alias map", key));
129     bRet=kFALSE;
130   }
131
132   key="CavernAtmosPressure2";
133   if (!GetSensorValue(dcsAliasMap, key, &cavernAtmosPressure2)) {
134     Log(Form("failed to extract %s from alias map", key));
135     bRet=kFALSE;
136   }
137
138   key="SurfaceAtmosPressure2";
139   if (!GetSensorValue(dcsAliasMap, key, &surfaceAtmosPressure)) {
140     Log(Form("failed to extract %s from alias map", key));
141     bRet=kFALSE;
142   }
143
144   AliGRPObject* grpObj=NULL;
145   AliGRPObject* grpExist=NULL;
146   AliCDBMetaData* cdbMetaData=NULL;
147   bool bUpdate=false;
148
149   // read existing GRP object
150   AliCDBEntry* pEntry=GetFromOCDB("GRP","Data");
151   if (pEntry) {
152     grpExist=dynamic_cast<AliGRPObject*>(pEntry->GetObject());
153     if (grpExist) {
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);
160
161       cdbMetaData=pEntry->GetMetaData();
162     }
163   }
164   // don't write if object is there and up-to-date
165   if (grpExist && !bUpdate) return 0;
166
167   if (grpExist) {
168     // update existing object
169     grpObj=grpExist;
170   } else {
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");
176   }
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
182
183   if (!cdbMetaData) {
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()));
187   }
188
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)) {
192   } else {
193     Log(" *** Failed to store GRP object");
194     return 7;
195   }
196   if (!grpExist) {
197     if (grpObj) delete grpObj;
198     grpObj=NULL;
199     if (cdbMetaData) delete cdbMetaData;
200     cdbMetaData=NULL;
201   }
202   
203   return 0;
204 }
205
206 TMap* AliHLTPredictionProcessorGRP::produceTestData(TString /*aliasName*/)
207 {
208   // produces test data for AliHLTPredictionProcessorGRP
209   TMap* resultMap = 0;
210
211   return resultMap;
212 }
213
214 bool AliHLTPredictionProcessorGRP::CreateInitialGRPEntry(int runno, const char* beamtype, const char* runtype, const char* /*detectorList*/)
215 {
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.
221
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
233
234   /* the following needs to be checked
235   grpObj->SetLHCPeriod(getenv("LHC_PERIOD"));
236   grpObj->SetNumberOfDetectors(numOfDetectors);
237   grpObj->SetDetectorMask(detectMask);  
238   */
239   
240   AliCDBManager* man = AliCDBManager::Instance();
241   if (!man || !man->IsDefaultStorageSet()) {
242     return false;
243   }
244
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);
251 }