]>
Commit | Line | Data |
---|---|---|
154cba94 | 1 | /************************************************************************** |
2 | * This file is property of and copyright by the ALICE HLT Project * | |
3 | * All rights reserved. * | |
4 | * * | |
5 | * Primary Authors: * | |
6 | * Artur Szostak <artursz@iafrica.com> * | |
7 | * * | |
8 | * Permission to use, copy, modify and distribute this software and its * | |
9 | * documentation strictly for non-commercial purposes is hereby granted * | |
10 | * without fee, provided that the above copyright notice appears in all * | |
11 | * copies and that both the copyright notice and this permission notice * | |
12 | * appear in the supporting documentation. The authors make no claims * | |
13 | * about the suitability of this software for any purpose. It is * | |
14 | * provided "as is" without express or implied warranty. * | |
15 | **************************************************************************/ | |
16 | ||
17 | /* $Id: $ */ | |
18 | ||
19 | /// | |
20 | /// @file AliHLTMUONProcessor.cxx | |
21 | /// @author Artur Szostak <artursz@iafrica.com> | |
dba14d7d | 22 | /// @date 19 May 2008 |
154cba94 | 23 | /// @brief Implementation of the abstract base dHLT processor component. |
24 | /// | |
25 | /// This component is the abstract base class of dHLT specific components. | |
26 | /// It implements some common methods used by all the dHLT components. | |
27 | /// | |
28 | ||
29 | #include "AliHLTMUONProcessor.h" | |
dba14d7d | 30 | #include "AliCDBManager.h" |
31 | #include "AliCDBStorage.h" | |
ffc1a6f6 | 32 | #include "AliCDBEntry.h" |
dba14d7d | 33 | #include "AliMpCDB.h" |
34 | #include "AliMpDDLStore.h" | |
35 | #include "AliMpDEStore.h" | |
ffc1a6f6 | 36 | #include "TMap.h" |
37 | #include "TObjString.h" | |
38 | #include "TString.h" | |
154cba94 | 39 | |
40 | ClassImp(AliHLTMUONProcessor) | |
41 | ||
dba14d7d | 42 | |
ffc1a6f6 | 43 | int AliHLTMUONProcessor::SetCDBPathAndRunNo( |
dba14d7d | 44 | const char* cdbPath, Int_t run, bool useDefault |
45 | ) const | |
46 | { | |
ffc1a6f6 | 47 | /// Sets the CDB path and run number to read from. |
dba14d7d | 48 | /// \param cdbPath The CDB path to use. If set to NULL and the path has |
49 | /// not been set in the CDB manager then the default path | |
50 | /// "local://$ALICE_ROOT" is used if the 'useDefault' flag is also true. | |
51 | /// \param run The run number to use. If set to -1 and the run number has | |
52 | /// not been set in the CDB manager then a value of zero is used if | |
53 | /// the 'useDefault' flag is also true. | |
ffc1a6f6 | 54 | /// \param useDefault If set to true then a default CDB path and/or run number |
dba14d7d | 55 | /// is used if they have not been set and 'cdbPath' == NULL or |
ffc1a6f6 | 56 | /// 'run' == -1. |
57 | /// \return Zero if the object could be loaded. Otherwise an error code, | |
58 | /// compatible with the HLT framework, is returned. | |
dba14d7d | 59 | |
60 | const char* defaultPath = "local://$ALICE_ROOT"; | |
61 | Int_t defaultRun = 0; | |
62 | ||
63 | AliCDBManager* cdbManager = AliCDBManager::Instance(); | |
64 | if (cdbManager == NULL) | |
65 | { | |
66 | HLTError("CDB manager instance does not exist."); | |
67 | return -EIO; | |
68 | } | |
69 | ||
70 | // Setup the CDB path. | |
dba14d7d | 71 | if (cdbPath != NULL) |
72 | { | |
73 | cdbManager->SetDefaultStorage(cdbPath); | |
dba14d7d | 74 | } |
ffc1a6f6 | 75 | else if (not cdbManager->IsDefaultStorageSet() and useDefault) |
dba14d7d | 76 | { |
ffc1a6f6 | 77 | cdbManager->SetDefaultStorage(defaultPath); |
dba14d7d | 78 | } |
79 | ||
80 | // Now setup the run number. | |
81 | if (run != -1) | |
82 | { | |
83 | cdbManager->SetRun(run); | |
84 | } | |
85 | else | |
86 | { | |
87 | if (useDefault) cdbManager->SetRun(defaultRun); | |
88 | } | |
ffc1a6f6 | 89 | |
90 | return 0; | |
91 | } | |
92 | ||
93 | ||
94 | int AliHLTMUONProcessor::FetchMappingStores() const | |
95 | { | |
96 | /// Fetches the DDL and detector element store objects for MUON mapping. | |
97 | /// \return Zero if the objects could be loaded. Otherwise an error code, | |
98 | /// which is compatible with the HLT framework, is returned. | |
99 | /// \note AliMpDDLStore::Instance() and AliMpDEStore::Instance() must be used | |
100 | /// to fetch the objects after this method returns a code equal to zero. | |
101 | ||
102 | Bool_t warn = kFALSE; | |
103 | ||
104 | // Check if the objects are already loaded. If they are then exit early, | |
105 | // otherwise we need to try load the objects. | |
106 | if (AliMpDDLStore::Instance(warn) != NULL and AliMpDEStore::Instance(warn) != NULL) | |
107 | return 0; | |
108 | ||
109 | AliCDBManager* cdbManager = AliCDBManager::Instance(); | |
110 | if (cdbManager == NULL) | |
111 | { | |
112 | HLTError("CDB manager instance does not exist."); | |
113 | return -EIO; | |
114 | } | |
115 | ||
116 | const char* cdbPathUsed = "unknown (not set)"; | |
117 | AliCDBStorage* store = cdbManager->GetDefaultStorage(); | |
118 | if (store != NULL) cdbPathUsed = store->GetURI().Data(); | |
119 | ||
dba14d7d | 120 | Int_t runUsed = cdbManager->GetRun(); |
121 | ||
122 | // Now we can try load the DDL and DE store objects. | |
dba14d7d | 123 | if (not AliMpCDB::LoadDDLStore(warn)) |
124 | { | |
125 | HLTError("Failed to load DDL or detector element store specified" | |
126 | " for CDB path '%s' and run no. %d.", | |
127 | cdbPathUsed, runUsed | |
128 | ); | |
129 | return -ENOENT; | |
130 | } | |
131 | ||
550ea228 | 132 | if (AliMpDDLStore::Instance(warn) == NULL or AliMpDEStore::Instance(warn) == NULL) |
dba14d7d | 133 | { |
134 | HLTError("Could not find or load the DDL or detector element store instance."); | |
135 | return -EIO; | |
136 | } | |
137 | ||
138 | return 0; | |
139 | } | |
140 | ||
ffc1a6f6 | 141 | |
142 | int AliHLTMUONProcessor::FetchTMapFromCDB(const char* pathToEntry, TMap*& map) const | |
143 | { | |
144 | /// Fetches a TMap object from the CDB. | |
145 | /// [in] \param pathToEntry The relative path to the entry in the CDB to fetch. | |
146 | /// [out] \param map This will be filled with the TMap object found if | |
147 | /// a successful status code is returned. Otherwise it will be unchanged. | |
148 | /// \return Zero if the object could be found. Otherwise an error code, | |
149 | /// which is compatible with the HLT framework, is returned. | |
150 | ||
151 | assert(AliCDBManager::Instance() != NULL); | |
152 | ||
153 | AliCDBEntry* entry = AliCDBManager::Instance()->Get(pathToEntry); | |
154 | if (entry == NULL) | |
155 | { | |
156 | HLTError("Could not get the CDB entry for \"%s\".", pathToEntry); | |
157 | return -EIO; | |
158 | } | |
159 | ||
160 | TObject* obj = entry->GetObject(); | |
161 | if (obj == NULL) | |
162 | { | |
163 | HLTError("Configuration object for \"%s\" is missing.", pathToEntry); | |
164 | return -ENOENT; | |
165 | } | |
166 | ||
167 | if (obj->IsA() != TMap::Class()) | |
168 | { | |
169 | HLTError("Wrong type for configuration object in \"%s\". Found a %s but we need a TMap.", | |
170 | pathToEntry, obj->ClassName() | |
171 | ); | |
172 | return -EPROTO; | |
173 | } | |
174 | map = dynamic_cast<TMap*>(obj); | |
175 | ||
176 | return 0; | |
177 | } | |
178 | ||
179 | ||
180 | int AliHLTMUONProcessor::GetValueFromTMap( | |
181 | TMap* map, const char* paramName, TString& value, | |
182 | const char* pathToEntry, const char* prettyName | |
183 | ) const | |
184 | { | |
185 | /// Tries to find the string value associated with a certain parameter in a TMap. | |
186 | /// [in] \param map The TMap object to search in. | |
187 | /// [in] \param paramName The name of the parameter to search for. | |
188 | /// [out] \param value Will be filled with the object found. | |
189 | /// [in] \param pathToEntry The relative path to the entry in the CDB. | |
190 | /// Used when printing error messages. If set to NULL then a string of | |
191 | /// "(unknown)" is used. (default is NULL). | |
192 | /// [in] \param prettyName Should be the name of the parameter which will | |
193 | /// be used when printing error messages. If this is set to NULL then | |
194 | /// the paramName will be used instead (default is NULL). | |
195 | /// \return Zero if the object could be found. Otherwise an error code, | |
196 | /// which is compatible with the HLT framework, is returned. | |
197 | ||
198 | if (pathToEntry == NULL) pathToEntry = "(unknown)"; | |
199 | if (prettyName == NULL) prettyName = paramName; | |
200 | ||
201 | TPair* pair = static_cast<TPair*>(map->FindObject(paramName)); | |
202 | if (pair == NULL) | |
203 | { | |
204 | HLTError("Configuration object for \"%s\" does not contain the %s value.", | |
205 | pathToEntry, prettyName | |
206 | ); | |
207 | return -ENOENT; | |
208 | } | |
209 | TObject* valueObj = pair->Value(); | |
210 | if (valueObj->IsA() != TObjString::Class()) | |
211 | { | |
212 | HLTError("The %s parameter found in configuration object \"%s\"" | |
213 | " is not a TObjString. Found an object of type %s instead.", | |
214 | prettyName, pathToEntry, valueObj->ClassName() | |
215 | ); | |
216 | return -EPROTO; | |
217 | } | |
218 | value = dynamic_cast<TObjString*>(valueObj)->GetString(); | |
219 | ||
220 | return 0; | |
221 | } | |
222 | ||
223 | ||
224 | int AliHLTMUONProcessor::GetIntFromTMap( | |
225 | TMap* map, const char* paramName, Int_t& value, | |
226 | const char* pathToEntry, const char* prettyName | |
227 | ) const | |
228 | { | |
229 | /// Tries to find a certain parameter in the TMap object and convert it to | |
230 | /// an integer value. | |
231 | /// [in] \param map The TMap object to search in. | |
232 | /// [in] \param paramName The name of the parameter to search for. | |
233 | /// [out] \param value Will be filled with the integer value for the parameter, | |
234 | /// if it was found and it was an integer value. | |
235 | /// [in] \param pathToEntry The relative path to the entry in the CDB. | |
236 | /// Used when printing error messages. If set to NULL then a string of | |
237 | /// "(unknown)" is used. (default is NULL). | |
238 | /// [in] \param prettyName Should be the name of the parameter which will | |
239 | /// be used when printing error messages. If this is set to NULL then | |
240 | /// the paramName will be used instead (default is NULL). | |
241 | /// \return Zero if the object could be found and is valid. Otherwise an | |
242 | /// error code, which is compatible with the HLT framework, is returned. | |
243 | ||
244 | if (pathToEntry == NULL) pathToEntry = "(unknown)"; | |
245 | if (prettyName == NULL) prettyName = paramName; | |
246 | ||
247 | TString valueStr; | |
248 | int result = GetValueFromTMap(map, paramName, valueStr, prettyName); | |
249 | if (result != 0) return result; | |
250 | ||
251 | if (not valueStr.IsDigit()) | |
252 | { | |
253 | HLTError("The %s parameter found in configuration object \"%s\"" | |
254 | "is not a valid integer number string; found \"%s\".", | |
255 | prettyName, pathToEntry, valueStr.Data() | |
256 | ); | |
257 | return -EPROTO; | |
258 | } | |
259 | value = valueStr.Atoi(); | |
260 | ||
261 | return 0; | |
262 | } | |
263 | ||
264 | ||
265 | int AliHLTMUONProcessor::GetPositiveIntFromTMap( | |
266 | TMap* map, const char* paramName, Int_t& value, | |
267 | const char* pathToEntry, const char* prettyName | |
268 | ) const | |
269 | { | |
270 | /// Tries to find a certain parameter in the TMap object and convert it to | |
271 | /// a positive integer value. | |
272 | /// [in] \param map The TMap object to search in. | |
273 | /// [in] \param paramName The name of the parameter to search for. | |
274 | /// [out] \param value Will be filled with the integer value for the parameter, | |
275 | /// if it was found and it was a positive integer value. | |
276 | /// [in] \param pathToEntry The relative path to the entry in the CDB. | |
277 | /// Used when printing error messages. If set to NULL then a string of | |
278 | /// "(unknown)" is used. (default is NULL). | |
279 | /// [in] \param prettyName Should be the name of the parameter which will | |
280 | /// be used when printing error messages. If this is set to NULL then | |
281 | /// the paramName will be used instead (default is NULL). | |
282 | /// \return Zero if the object could be found and is valid. Otherwise an | |
283 | /// error code, which is compatible with the HLT framework, is returned. | |
284 | ||
285 | if (pathToEntry == NULL) pathToEntry = "(unknown)"; | |
286 | if (prettyName == NULL) prettyName = paramName; | |
287 | ||
288 | TString valueStr; | |
289 | int result = GetValueFromTMap(map, paramName, valueStr, prettyName); | |
290 | if (result != 0) return result; | |
291 | ||
292 | if (not valueStr.IsDigit()) | |
293 | { | |
294 | HLTError("The %s parameter found in configuration object \"%s\"" | |
295 | "is not a valid integer number string; found \"%s\".", | |
296 | prettyName, pathToEntry, valueStr.Data() | |
297 | ); | |
298 | return -EPROTO; | |
299 | } | |
300 | Int_t val = valueStr.Atoi(); | |
301 | if (val < 0) | |
302 | { | |
303 | HLTError("The %s parameter found in configuration object \"%s\"" | |
304 | "is not a positive integer number; found \"%d\".", | |
305 | prettyName, pathToEntry, val | |
306 | ); | |
307 | return -EPROTO; | |
308 | } | |
309 | value = val; | |
310 | ||
311 | return 0; | |
312 | } | |
313 | ||
314 | ||
315 | int AliHLTMUONProcessor::GetFloatFromTMap( | |
316 | TMap* map, const char* paramName, Double_t& value, | |
317 | const char* pathToEntry, const char* prettyName | |
318 | ) const | |
319 | { | |
320 | /// Tries to find a certain parameter in the TMap object and convert it to | |
321 | /// an floating point value. | |
322 | /// [in] \param map The TMap object to search in. | |
323 | /// [in] \param paramName The name of the parameter to search for. | |
324 | /// [out] \param value Will be filled with the floating point value for the | |
325 | /// parameter, if it was found and it was a floating point value. | |
326 | /// [in] \param pathToEntry The relative path to the entry in the CDB. | |
327 | /// Used when printing error messages. If set to NULL then a string of | |
328 | /// "(unknown)" is used. (default is NULL). | |
329 | /// [in] \param prettyName Should be the name of the parameter which will | |
330 | /// be used when printing error messages. If this is set to NULL then | |
331 | /// the paramName will be used instead (default is NULL). | |
332 | /// \return Zero if the object could be found and is valid. Otherwise an | |
333 | /// error code, which is compatible with the HLT framework, is returned. | |
334 | ||
335 | if (pathToEntry == NULL) pathToEntry = "(unknown)"; | |
336 | if (prettyName == NULL) prettyName = paramName; | |
337 | ||
338 | TString valueStr; | |
339 | int result = GetValueFromTMap(map, paramName, valueStr, prettyName); | |
340 | if (result != 0) return result; | |
341 | ||
342 | if (not valueStr.IsFloat()) | |
343 | { | |
344 | HLTError("The %s parameter found in configuration object \"%s\"" | |
345 | "is not a valid floating point number string; found \"%s\".", | |
346 | prettyName, pathToEntry, valueStr.Data() | |
347 | ); | |
348 | return -EPROTO; | |
349 | } | |
350 | value = valueStr.Atof(); | |
351 | ||
352 | return 0; | |
353 | } | |
354 | ||
355 | ||
356 | int AliHLTMUONProcessor::GetPositiveFloatFromTMap( | |
357 | TMap* map, const char* paramName, Double_t& value, | |
358 | const char* pathToEntry, const char* prettyName | |
359 | ) const | |
360 | { | |
361 | /// Tries to find a certain parameter in the TMap object and convert it to | |
362 | /// an positive floating point value. | |
363 | /// [in] \param map The TMap object to search in. | |
364 | /// [in] \param paramName The name of the parameter to search for. | |
365 | /// [out] \param value Will be filled with the floating point value for the | |
366 | /// parameter, if it was found and it was a positive floating point value. | |
367 | /// [in] \param pathToEntry The relative path to the entry in the CDB. | |
368 | /// Used when printing error messages. If set to NULL then a string of | |
369 | /// "(unknown)" is used. (default is NULL). | |
370 | /// [in] \param prettyName Should be the name of the parameter which will | |
371 | /// be used when printing error messages. If this is set to NULL then | |
372 | /// the paramName will be used instead (default is NULL). | |
373 | /// \return Zero if the object could be found and is valid. Otherwise an | |
374 | /// error code, which is compatible with the HLT framework, is returned. | |
375 | ||
376 | if (pathToEntry == NULL) pathToEntry = "(unknown)"; | |
377 | if (prettyName == NULL) prettyName = paramName; | |
378 | ||
379 | TString valueStr; | |
380 | int result = GetValueFromTMap(map, paramName, valueStr, prettyName); | |
381 | if (result != 0) return result; | |
382 | ||
383 | if (not valueStr.IsFloat()) | |
384 | { | |
385 | HLTError("The %s parameter found in configuration object \"%s\"" | |
386 | "is not a valid floating point number string; found \"%s\".", | |
387 | prettyName, pathToEntry, valueStr.Data() | |
388 | ); | |
389 | return -EPROTO; | |
390 | } | |
391 | Double_t val = valueStr.Atof(); | |
392 | if (val < 0) | |
393 | { | |
394 | HLTError("The %s parameter found in configuration object \"%s\"" | |
395 | "is not a positive floating point number; found \"%d\".", | |
396 | prettyName, pathToEntry, val | |
397 | ); | |
398 | return -EPROTO; | |
399 | } | |
400 | value = val; | |
401 | ||
402 | return 0; | |
403 | } |