]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/pendolino/TPC/AliHLTPredictionProcessorTPC.cxx
Including "-y" option in find for OCDB queries. Including new tag values
[u/mrichter/AliRoot.git] / HLT / pendolino / TPC / AliHLTPredictionProcessorTPC.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: Haavard Helstrup                                      *
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   AliHLTPredictionProcessorTPC.cxx
20     @author Haavard Helstrup
21     @date   
22     @brief  
23 */
24
25 #include "AliHLTPredictionProcessorTPC.h"
26
27 #include "TROOT.h"
28 #include "TArrayF.h"
29 #include "TObjArray.h"
30 #include "TTree.h"
31 #include "TString.h"
32 #include "TMap.h"
33 #include "TRandom2.h"
34 #include "AliCDBEntry.h"
35 #include "AliCDBMetaData.h"
36 #include "AliDCSValue.h"
37 #include "AliTPCSensorTempArray.h"
38
39 ClassImp(AliHLTPredictionProcessorTPC)
40
41 const TString kAmandaTemp = "TPC_PT_%d_TEMPERATURE";
42 const Int_t kValCutTemp = 100;               // discard temperatures > 100 degrees
43 const Int_t kDiffCutTemp = 5;                // discard temperature differences > 5 degrees
44
45 //______________________________________________________________________________________________
46
47 AliHLTPredictionProcessorTPC::AliHLTPredictionProcessorTPC(
48            const char* detector, AliHLTPendolino* pendolino) :
49                AliHLTPredictionProcessorInterface(detector, pendolino),
50                fConfigOK(kTRUE),
51                fConfTreeTemp(0),
52                fTemp(0),
53                fPredict(kFALSE),
54                fRun(0),
55                fStartTime(0),
56                fEndTime(0)
57 {
58  // constructor
59 }
60
61 //______________________________________________________________________________________________
62
63 AliHLTPredictionProcessorTPC::~AliHLTPredictionProcessorTPC()
64 {
65   // destructor
66   if (fConfTreeTemp) delete fConfTreeTemp;
67   if (fTemp) delete fTemp; 
68 }
69
70 //______________________________________________________________________________________________
71
72 UInt_t AliHLTPredictionProcessorTPC::makePrediction(Bool_t doPrediction) {
73 //
74 // Signal whether prediction making is required
75 //
76    fPredict = doPrediction; // own member indicating that prediction making is required
77    return 0;
78 }
79
80 //______________________________________________________________________________________________
81
82 void AliHLTPredictionProcessorTPC::Initialize(Int_t run, UInt_t startTime,
83            UInt_t endTime) {
84 //
85 //  Initialise TPC prediction processor. Read config entry from HCDB
86 //
87    fRun = run;               // storing locally the run number
88    fStartTime = startTime;   // storing locally the start time
89    fEndTime = endTime;       // storing locally the end time
90
91
92    AliCDBEntry* entry = GetFromOCDB("Config", "HLTTemperature");
93    if (entry) fConfTreeTemp = (TTree*) entry->GetObject();
94    if ( fConfTreeTemp==0 ) {
95      Log("AliHLTPredictionProcessorTPC: Temperature Config HCDB entry missing.\n");
96      fConfigOK = kFALSE;
97      return;
98    }
99 }
100
101 //______________________________________________________________________________________________
102
103 UInt_t AliHLTPredictionProcessorTPC::Process(TMap* dcsAliasMap) {
104 //
105 // Event-by-event processing of the PredictionProcessorTPC
106 //
107
108 // test if configuration available and DCS map valid
109
110   if (!dcsAliasMap) return 9;
111   if (dcsAliasMap->GetEntries() == 0 ) return 9;
112   if (!fConfigOK) return 9;
113
114 //
115 // Extract values from DCS maps. Store updated entry to HCDB
116 //
117    UInt_t retVal = 0;
118    Int_t start = 0;
119    TString path2("Calib");        // for the storage path in HCDB
120    TString path3("Temperature");    // for the storage path in HCDB
121
122    //get data from the HCDB
123    AliCDBEntry* entry = GetFromOCDB(path2.Data(), path3.Data());
124    if (entry != 0) {
125        entry->PrintMetaData();  // use the AliCDBEntry
126        fTemp = (AliTPCSensorTempArray*)entry->GetObject();
127    } else {
128        Log("Cannot retrieve HCDB entry. New AliTPCSensorTempArray generated");
129        UInt_t startTimeLocal = fStartTime-3600;
130        UInt_t endTimeLocal = fEndTime+1800;
131        fTemp = new AliTPCSensorTempArray(startTimeLocal, endTimeLocal, fConfTreeTemp, kAmandaTemp);
132        fTemp->SetValCut(kValCutTemp);
133        fTemp->SetDiffCut(kDiffCutTemp);     
134        fTemp->ExtractDCS(dcsAliasMap);
135    }
136
137    // process temperatures
138    
139    UInt_t tempResult = ExtractTemperature(dcsAliasMap); 
140
141    //process dcsAliasMap to ROOT object
142    // and create AliCDBEntry 
143
144    if (tempResult==0) {
145      // create meta data entry for HCDB
146      TString comment("HLT temperatures");
147      AliCDBMetaData meta(this->GetName(), 666, "unknownAliRoot", comment.Data());
148
149      // store AliCDBEntry in HCDB
150      if (Store(path2.Data(), path3.Data(), fTemp, &meta, start, kTRUE)) {
151          Log(" +++ Successfully stored object ;-)");
152      } else {
153          Log(" *** Storing of OBJECT failed!!");
154          retVal = 7;
155      }
156     } else {
157       retVal = 9;
158     }
159    
160    return retVal;
161 }
162
163 //______________________________________________________________________________________________
164
165 UInt_t AliHLTPredictionProcessorTPC::ExtractTemperature(TMap* dcsAliasMap)
166 {
167 // Extract temperature values from DCS maps, according to infoamtion from configuration tree
168
169   const Int_t error = 9; 
170   Int_t nentries = fConfTreeTemp->GetEntries();
171   if (nentries<1) return error;
172
173   TMap *map = fTemp->ExtractDCS(dcsAliasMap,kTRUE);
174   if (map) {
175     fTemp->MakeSplineFitAddPoints(map);
176   } else {
177     Log("No temperature map extracted.\n");
178     return error;
179   }
180   return 0;
181 }
182
183 //______________________________________________________________________________________________
184   
185 TMap* AliHLTPredictionProcessorTPC::produceTestData(TString aliasName) 
186 {
187    // produce dummy values for TPC temperature sensors
188
189    const Float_t defTemp = 22.0;
190    const Float_t tempVar = 2.0;
191    TMap* resultMap = 0;
192    TRandom2 random;
193    Float_t temp=0;
194    Float_t tempDelta=0;
195    TObjArray* arr = new TObjArray();
196
197    resultMap = new TMap();
198    TTimeStamp tt;
199
200    // loop through all sensors (extracted from OCDB config entry) if no input parameter is given
201    
202    if (aliasName.Length() == 0 ) {
203     if (!fConfTreeTemp) return 0;
204     Int_t nentries = fConfTreeTemp->GetEntries();
205     if (nentries<1) return 0;
206
207     TString stringId;
208     Int_t echa=0;
209     fConfTreeTemp->SetBranchAddress("ECha",&echa);
210
211     for (Int_t isensor=0; isensor<nentries; isensor++ ){
212       fConfTreeTemp->GetEntry(isensor);
213       stringId = Form(kAmandaString.Data(),echa);
214       tempDelta = (random.Rndm()-0.5)*tempVar;
215       temp = defTemp + tempDelta;
216       AliDCSValue* val = new AliDCSValue(temp, tt.GetTime());
217       TObjString* name = new TObjString(stringId);   
218       arr->Add(val);
219       resultMap->Add(name, arr);
220     }
221    } else {
222
223       // simulate value for given sensor if specified as parameter
224  
225       tempDelta = (random.Rndm()-0.5)*tempVar;
226       temp = defTemp + tempDelta;
227       AliDCSValue* val = new AliDCSValue(temp, tt.GetTime());
228       TObjString* name = new TObjString(aliasName.Data());   
229       arr->Add(val);
230       resultMap->Add(name, arr);
231    }
232    return resultMap;
233 }