]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/pendolino/PredictionProcessor/HLT/AliHLTPredicProcTempMonitor.cxx
234a9b7f85ff2d127382541d26509da7a0641a01
[u/mrichter/AliRoot.git] / HLT / pendolino / PredictionProcessor / HLT / AliHLTPredicProcTempMonitor.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: Sebastian Bablok <Sebastian.Bablok@ift.uib.no>        *
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   AliHLTPredicProcTempMonitor.cxx
20     @author Sebastian Bablok
21     @date   
22     @brief  
23 */
24
25 #include "AliHLTPredicProcTempMonitor.h"
26
27 #include <AliCDBMetaData.h>
28 #include <AliCDBEntry.h>
29 #include <AliDCSValue.h>
30
31 #include <TMap.h>
32 #include <TObjString.h>
33 #include <TObjArray.h>
34
35 #include <TTimeStamp.h>
36
37
38 ClassImp(AliHLTPredicProcTempMonitor)
39
40
41 const TString AliHLTPredicProcTempMonitor::kPath2("CalibMonitor");
42
43 const TString AliHLTPredicProcTempMonitor::kPath3("DCSTempMon");
44
45 const TString AliHLTPredicProcTempMonitor::kCreator("S. Bablok (HLT)");
46
47 const TString AliHLTPredicProcTempMonitor::kComment("Calib Object for monitoring DCS temperature values in HLT.");
48
49 const TString AliHLTPredicProcTempMonitor::kAliRootVersion("");
50
51 const UInt_t AliHLTPredicProcTempMonitor::kUnableToStoreObject = 7;
52
53 //const TString AliHLTPredicProcTempMonitor::kAmandaTempSensor = "TPC_PT_%d_TEMPERATURE";
54
55                 
56 AliHLTPredicProcTempMonitor::AliHLTPredicProcTempMonitor(
57                         const char* detector, AliHLTPendolino* pendolino) :
58                                 AliHLTPredictionProcessorInterface(detector, pendolino),
59                                 fPredict(true), fRun(0), fStartTime(0), fEndTime(0), fBField("") {
60         // C-tor for AliHLTPredicProcTempMonitor
61 //      fPredict = true;
62 //      fRun = 0;
63 //      fStartTime = 0;
64 //      fEndTime = 0;
65 }
66
67
68 AliHLTPredicProcTempMonitor::~AliHLTPredicProcTempMonitor() {
69         // D-tor for AliHLTPredicProcTempMonitor
70
71 }
72
73
74 UInt_t AliHLTPredicProcTempMonitor::makePrediction(Bool_t doPrediction) {
75         // switch for prediction making in AliHLTPredicProcTempMonitor
76         Log("AliHLTPredicProcTempMonitor + B-Field extractor: prediction switched on");
77         fPredict = doPrediction;
78         return 0;
79 }
80
81
82 void AliHLTPredicProcTempMonitor::Initialize(Int_t run, UInt_t startTime, 
83                         UInt_t endTime) {
84         // initializes AliHLTPredicProcTempMonitor
85         fRun = run;
86         fStartTime = startTime;
87         fEndTime = endTime;
88
89         TString msg("Initialized HLT PredictionProcessor; Run: ");
90         msg += fRun;
91         msg += ", start time: ";
92         msg += fStartTime;
93         msg += ", end time: ";
94         msg += fEndTime;
95         msg += ".";     
96         Log(msg.Data());
97 }
98
99
100 UInt_t AliHLTPredicProcTempMonitor::Process(TMap* dcsAliasMap) {
101         // processes the DCS value map in AliHLTPredicProcTempMonitor
102         UInt_t beamPeriod = 0;
103         
104         UInt_t retVal = 0;
105         UInt_t tempRet = 0;
106         Int_t start = 0;
107         TMap* tempMap = 0;
108         Bool_t infiniteValid = kFALSE;
109         
110                 
111         //test GetFromOCDB() calls
112         AliCDBEntry* entry = GetFromOCDB(kPath2.Data(), kPath3.Data());
113         if (entry == 0) {
114                 // No object in HCDB -> discarding old values
115                 TString msg("No '" + kPath2 + "/" + kPath3 + 
116                                 "' in HCDB, most likely first round, filling object now...");
117                 Log(msg.Data());
118                 tempMap = dcsAliasMap;
119                 
120         } else {
121                 Log("Old data is already stored in HCDB, but now discarding that...");
122                 tempMap = dcsAliasMap; 
123         
124 // If old data shall be included use lines below and uncomment lines above
125 /*
126                 Log("Adding new DCS value to old Temperature map...");
127                 // Adding new DCS values to old Temperature map 
128                 tempMap = (TMap*) entry->GetObject();
129
130                 TMapIter iter(dcsAliasMap);        // iterator for values in TMap
131                 TObject* aKey;
132                            
133                 while ((aKey = iter.Next())) {
134                         tempMap->Add(aKey, dcsAliasMap->GetValue(aKey));
135                 }
136 */
137         }
138
139         AliCDBMetaData meta(kCreator.Data(), beamPeriod, kAliRootVersion.Data(), 
140                         kComment.Data());
141
142         if (Store(kPath2.Data(), kPath3.Data(), (TObject*) tempMap, &meta, start, 
143                         infiniteValid)) {
144                 TString msg(" +++ Successfully stored object '" + kPath2 + "/" + kPath3 + 
145                                 "' in HCDB.");
146                 Log(msg.Data());
147         } else {
148                 TString msg(" *** Storing of object '" + kPath2 + "/" + kPath3 + 
149                                 "' in HCDB failed.");
150                 Log(msg.Data());
151                 retVal = kUnableToStoreObject;
152         }
153
154         // extract B-Field
155         tempRet = ExtractBField(dcsAliasMap);
156         retVal = tempRet & retVal; // combine retvals
157         
158         return retVal;
159 }
160
161 UInt_t AliHLTPredicProcTempMonitor::ExtractBField(TMap* dcsAliasMap) {
162         // extracts the B-field value from DCS value map
163   
164         TString stringId = "L3Current"; // "dcs_magnet:Magnet/ALICESolenoid.Current";
165   
166         Float_t BField = 0; 
167         Bool_t bRet = GetSensorValue(dcsAliasMap,stringId.Data(),&BField);
168
169         if (bRet) {
170                 BField = BField / 60000; // If we get field, take this away and change SensorValue
171                 TString dummy("-solenoidBZ ");
172                 dummy += BField;
173                 TObjString dummy2(dummy.Data());
174                 fBField = dummy2; 
175                 Log(Form("BField set to %s", fBField.String().Data())); 
176         } else {
177                 return 1;
178         }
179
180         TString path2("Config");
181         TString path3("BField");
182         Int_t start = 0;
183
184         TString comment("BField");
185         AliCDBMetaData meta(this->GetName(), 0, "unknownAliRoot", comment.Data());
186   
187         if (Store(path2.Data(), path3.Data(), (TObject*) (&fBField), &meta, start, 
188                         kTRUE)) {
189                 Log(" +++ Successfully stored object ;-)");
190         } else {
191                 Log(" *** Storing of OBJECT failed!!");
192                 return 7;
193         }
194
195         return 0;
196 }
197
198 Bool_t AliHLTPredicProcTempMonitor::GetSensorValue(TMap* dcsAliasMap,
199                         const char* stringId, Float_t *value) {
200         // retreives the sensor value
201   // return last value read from sensor specified by stringId
202   
203         TObjArray* valueSet;
204         TPair* pair = (TPair*) (dcsAliasMap->FindObject(stringId));
205         if (pair) {
206                 valueSet = (TObjArray*) (pair->Value());
207                 if (valueSet) {
208                         Int_t nentriesDCS = (valueSet->GetEntriesFast()) - 1;
209                         if (nentriesDCS >= 0) {
210                                 AliDCSValue* val = (AliDCSValue*) (valueSet->At(nentriesDCS));
211                                 if (val) {
212                                         *value = val->GetFloat();
213                                         return kTRUE;
214                                 }
215                         }
216                 }
217         }
218         return kFALSE;
219 }
220
221 TMap* AliHLTPredicProcTempMonitor::produceTestData(TString /*aliasName*/) {
222         // produces test data for AliHLTPredicProcTempMonitor
223     TMap* resultMap = 0;
224
225     // here has to come real dummy data :-)
226     resultMap = new TMap();
227     TTimeStamp tt;
228         Float_t fval = 33.3;
229     TObjString* name = new TObjString("L3Current");
230     AliDCSValue* val = new AliDCSValue(fval, tt.GetTime());
231     TObjArray* arr = new TObjArray();
232     arr->Add(val);
233     resultMap->Add(name, arr);
234
235     return resultMap;
236 }
237
238