]>
Commit | Line | Data |
---|---|---|
2b545cdd | 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: Matthias Richter <Matthias.Richter@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 AliHLTMisc.cxx | |
20 | /// @author Matthias Richter | |
21 | /// @date | |
22 | /// @brief Miscellaneous methods for the HLT AliRoot integration | |
23 | ||
24 | #include "AliHLTMiscImplementation.h" | |
25 | #include "AliHLTLogging.h" | |
88bb1fd0 | 26 | #include "AliHLTErrorGuard.h" |
79c426cf | 27 | #include "AliLog.h" |
2b545cdd | 28 | #include "AliCDBManager.h" |
22d17395 | 29 | #include "AliCDBStorage.h" |
2b545cdd | 30 | #include "AliCDBEntry.h" |
cc484ed9 | 31 | #include "AliGRPManager.h" |
73305a93 | 32 | #include "AliRawReader.h" |
2572a09f | 33 | #include "AliRawEventHeaderBase.h" |
a5e775ec | 34 | #include "AliTracker.h" |
ee15809c | 35 | #include "AliESDtrack.h" |
95ea76b5 | 36 | #include "AliESDHLTDecision.h" |
cc484ed9 | 37 | #include "TGeoGlobalMagField.h" |
95ea76b5 | 38 | #include "AliHLTGlobalTriggerDecision.h" |
79c426cf | 39 | #include "TClass.h" |
40 | #include "TStreamerInfo.h" | |
41 | #include "TObjArray.h" | |
2b545cdd | 42 | |
43 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
44 | ClassImp(AliHLTMiscImplementation); | |
45 | ||
46 | AliHLTMiscImplementation::AliHLTMiscImplementation() | |
47 | { | |
48 | } | |
49 | ||
50 | AliHLTMiscImplementation::~AliHLTMiscImplementation() | |
51 | { | |
52 | // see header file for function documentation | |
53 | } | |
54 | ||
55 | int AliHLTMiscImplementation::InitCDB(const char* cdbpath) | |
56 | { | |
57 | // see header file for function documentation | |
58 | int iResult=0; | |
59 | AliCDBManager* pCDB = AliCDBManager::Instance(); | |
60 | AliHLTLogging log; | |
61 | if (!pCDB) { | |
62 | log.Logging(kHLTLogError, "InitCDB", "CDB handling", "Could not get CDB instance"); | |
63 | } else { | |
64 | if (cdbpath && cdbpath[0]!=0) { | |
cc484ed9 | 65 | TString uri=cdbpath; |
66 | if (!uri.BeginsWith("local://") && | |
67 | !uri.Contains("://")) { | |
68 | // assume a local path if no uri specifier is found | |
69 | uri="local://"; | |
70 | uri+=cdbpath; | |
71 | } | |
72 | pCDB->SetDefaultStorage(uri); | |
2b545cdd | 73 | log.Logging(kHLTLogDebug, "InitCDB", "CDB handling", "CDB instance 0x%x", pCDB); |
74 | } else if (!pCDB->IsDefaultStorageSet()) { | |
75 | const char* cdbUri="local://$ALICE_ROOT/OCDB"; | |
76 | pCDB->SetDefaultStorage(cdbUri); | |
77 | pCDB->SetRun(0); | |
78 | log.Logging(kHLTLogInfo, "InitCDB", "CDB handling", "set default URI: %s", cdbUri); | |
79 | } | |
80 | } | |
81 | return iResult; | |
82 | } | |
83 | ||
84 | int AliHLTMiscImplementation::SetCDBRunNo(int runNo) | |
85 | { | |
86 | // see header file for function documentation | |
87 | int iResult=0; | |
88 | AliCDBManager* pCDB = AliCDBManager::Instance(); | |
89 | AliHLTLogging log; | |
90 | if (!pCDB) { | |
cc484ed9 | 91 | log.Logging(kHLTLogError, "SetCDBRunNo", "CDB handling", "Could not get CDB instance"); |
2b545cdd | 92 | } else { |
93 | pCDB->SetRun(runNo); | |
94 | } | |
95 | return iResult; | |
96 | } | |
97 | ||
74c1905c | 98 | int AliHLTMiscImplementation::GetCDBRunNo() const |
df5d2b78 | 99 | { |
100 | // see header file for function documentation | |
101 | AliCDBManager* pCDB = AliCDBManager::Instance(); | |
102 | AliHLTLogging log; | |
103 | if (!pCDB) { | |
104 | log.Logging(kHLTLogError, "SetCDBRunNo", "CDB handling", "Could not get CDB instance"); | |
105 | } else { | |
106 | return pCDB->GetRun(); | |
107 | } | |
108 | return -1; | |
109 | } | |
110 | ||
5df320bf | 111 | AliCDBEntry* AliHLTMiscImplementation::LoadOCDBEntry(const char* path, int runNo) const |
2b545cdd | 112 | { |
113 | // see header file for function documentation | |
88bb1fd0 | 114 | if (!path) return NULL; |
115 | AliHLTLogging log; | |
116 | ||
de254f89 | 117 | AliCDBManager* man = AliCDBManager::Instance(); |
88bb1fd0 | 118 | if (!man) { |
119 | ALIHLTERRORGUARD(1, "failed to access CDB manager"); | |
120 | return NULL; | |
121 | } | |
3ed9cacd | 122 | if (runNo<0) runNo=man->GetRun(); |
de254f89 | 123 | |
88bb1fd0 | 124 | // check the cache first if no specific version required |
5df320bf | 125 | { //condition was deprecated, but keep for formatting |
88bb1fd0 | 126 | const TMap* pCache=man->GetEntryCache(); |
127 | TObject* pEntryObj=NULL; | |
128 | if (pCache && (pEntryObj=pCache->GetValue(path))!=NULL) { | |
129 | AliCDBEntry* pEntry=dynamic_cast<AliCDBEntry*>(pEntryObj); | |
130 | if (pEntry) { | |
131 | log.Logging(kHLTLogDebug, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "using OCDB object %s from cache", path); | |
132 | return pEntry; | |
133 | } else { | |
134 | log.Logging(kHLTLogError, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "invalid OCDB object %s found in cache, not of type AliCDBEntry", path); | |
135 | } | |
136 | } | |
137 | } | |
138 | ||
de254f89 | 139 | const char* uri=man->GetURI(path); |
88bb1fd0 | 140 | if (!uri) { |
141 | log.Logging(kHLTLogError, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "can not find URI for CDB object \"%s\"", path); | |
142 | return NULL; | |
143 | } | |
de254f89 | 144 | |
145 | AliCDBStorage* store = AliCDBManager::Instance()->GetStorage(uri); | |
22d17395 | 146 | if (!store) { |
88bb1fd0 | 147 | log.Logging(kHLTLogError, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "can not find storage for URI \"%s\"", uri); |
22d17395 | 148 | return NULL; |
149 | } | |
de254f89 | 150 | |
88bb1fd0 | 151 | int latest = store->GetLatestVersion(path, runNo); |
152 | if (latest<0) { | |
3e2b39d1 | 153 | log.Logging(kHLTLogError, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "Could not find an entry for \"%s\" in storage \"%s\", run %d.", path, uri, runNo>=0?runNo:man->GetRun()); |
88bb1fd0 | 154 | return NULL; |
155 | } | |
5df320bf | 156 | |
157 | AliCDBEntry* entry=man->Get(path, runNo); | |
158 | return entry; | |
2b545cdd | 159 | } |
160 | ||
74c1905c | 161 | TObject* AliHLTMiscImplementation::ExtractObject(AliCDBEntry* entry) const |
2b545cdd | 162 | { |
163 | // see header file for function documentation | |
164 | if (!entry) return NULL; | |
165 | return entry->GetObject(); | |
166 | } | |
167 | ||
74c1905c | 168 | int AliHLTMiscImplementation::CheckOCDBEntries(const TMap* const pMap) const |
169 | { | |
170 | // check the availability of the OCDB entry descriptions in the TMap | |
171 | // key : complete OCDB path of the entry | |
172 | // value : auxiliary object - short description | |
88bb1fd0 | 173 | // check uses AliCDBStorage::GetLatestVersion, which is the only method |
174 | // to check the existence without risking AliFatal | |
175 | ||
74c1905c | 176 | int iResult=0; |
177 | if (!pMap) return -EINVAL; | |
88bb1fd0 | 178 | AliHLTLogging log; |
179 | ||
180 | AliCDBManager* man = AliCDBManager::Instance(); | |
181 | if (!man) { | |
182 | ALIHLTERRORGUARD(1, "failed to access CDB manager"); | |
726d36e7 | 183 | return -ENOSYS; |
88bb1fd0 | 184 | } |
185 | const TMap* pCache=man->GetEntryCache(); | |
74c1905c | 186 | |
74c1905c | 187 | Int_t runNo = GetCDBRunNo(); |
188 | ||
189 | TIterator* next=pMap->MakeIterator(); | |
726d36e7 | 190 | if (!next) return -EFAULT; |
5d99ef2a | 191 | |
74c1905c | 192 | TObject* pEntry=NULL; |
193 | while ((pEntry=next->Next())) { | |
88bb1fd0 | 194 | // check if already on cache |
195 | if (pCache && pCache->GetValue(pEntry->GetName())!=NULL) { | |
196 | log.Logging(kHLTLogDebug, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "found OCDB object %s on cache", pEntry->GetName()); | |
197 | continue; | |
198 | } | |
199 | ||
74c1905c | 200 | // check if the entry has specific storage |
88bb1fd0 | 201 | const char* uri=man->GetURI(pEntry->GetName()); |
202 | if (!uri) { | |
203 | log.Logging(kHLTLogError, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "can not find URI for CDB object \"%s\"", pEntry->GetName()); | |
726d36e7 | 204 | return -ENODEV; |
88bb1fd0 | 205 | } |
206 | ||
207 | AliCDBStorage* pStorage = AliCDBManager::Instance()->GetStorage(uri); | |
208 | if (!pStorage) { | |
209 | log.Logging(kHLTLogError, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "can not find storage for URI \"%s\"", uri); | |
726d36e7 | 210 | return -EBADF; |
74c1905c | 211 | } |
212 | ||
88bb1fd0 | 213 | // GetLatestVersion is the only method to check the existence without potential AliFatal |
74c1905c | 214 | if (pStorage->GetLatestVersion(pEntry->GetName(), runNo)<0) { |
88bb1fd0 | 215 | log.Logging(kHLTLogError, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "can not find required OCDB object %s for run number %d in storage %s", pEntry->GetName(), runNo, pStorage->GetURI().Data()); |
74c1905c | 216 | iResult=-ENOENT; |
217 | } else { | |
88bb1fd0 | 218 | log.Logging(kHLTLogDebug, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "found required OCDB object %s for run number %d in storage %s", pEntry->GetName(), runNo, pStorage->GetURI().Data()); |
74c1905c | 219 | } |
220 | } | |
5d99ef2a | 221 | delete next; |
222 | next=NULL; | |
74c1905c | 223 | |
224 | return iResult; | |
225 | } | |
226 | ||
cc484ed9 | 227 | int AliHLTMiscImplementation::InitMagneticField() const |
2b545cdd | 228 | { |
cc484ed9 | 229 | // see header file for function documentation |
230 | ||
231 | // BAD: unit test fails if I call TGeoGlobalMagField::Instance() | |
232 | // at this point. Something goes wrong in the cleaning of the global | |
233 | // ROOT onject | |
234 | /* | |
235 | if (TGeoGlobalMagField::Instance()->GetField()) { | |
236 | // everything set, but think about storing the currents for | |
237 | // a cross-check | |
238 | return 0; | |
2b545cdd | 239 | } |
cc484ed9 | 240 | */ |
2b545cdd | 241 | |
cc484ed9 | 242 | // The magnetic field is initialized once at the start |
243 | // of run. The fields are supposed to be constant througout the | |
244 | // data taking of one run. The run is aborted if the changes | |
245 | // exceed a certain limit. | |
246 | AliGRPManager grpman; | |
247 | if (grpman.ReadGRPEntry() && grpman.SetMagField()) { | |
248 | return 0; | |
2b545cdd | 249 | } |
cc484ed9 | 250 | |
251 | return -ENOENT; | |
2b545cdd | 252 | } |
73305a93 | 253 | |
254 | AliHLTUInt64_t AliHLTMiscImplementation::GetTriggerMask(AliRawReader* rawReader) const | |
255 | { | |
256 | // see header file for function documentation | |
257 | if (!rawReader) return 0; | |
258 | AliHLTUInt64_t trgMask=0; | |
259 | if (rawReader) { | |
260 | const UInt_t* pattern=rawReader->GetTriggerPattern(); | |
261 | trgMask=pattern[1]&0xfffffff; // 28 upper bits of the 50 bit mask | |
262 | trgMask<<=32; | |
263 | trgMask|=pattern[0]; // 32 lower bits of the mask | |
264 | } | |
265 | return trgMask; | |
266 | } | |
a5e775ec | 267 | |
2572a09f | 268 | AliHLTUInt32_t AliHLTMiscImplementation::GetTimeStamp(AliRawReader* rawReader) const |
269 | { | |
270 | // extract time stamp of the event from the event header | |
271 | if (!rawReader) return 0; | |
272 | const AliRawEventHeaderBase* eventHeader = rawReader->GetEventHeader(); | |
273 | if (!eventHeader) return 0; | |
274 | return eventHeader->Get("Timestamp"); | |
275 | } | |
276 | ||
277 | AliHLTUInt32_t AliHLTMiscImplementation::GetEventType(AliRawReader* rawReader) const | |
278 | { | |
279 | // extract event type from the event header | |
280 | if (!rawReader) return 0; | |
281 | const AliRawEventHeaderBase* eventHeader = rawReader->GetEventHeader(); | |
282 | if (!eventHeader) return 0; | |
283 | return eventHeader->Get("Type"); | |
284 | } | |
285 | ||
de254f89 | 286 | const char* AliHLTMiscImplementation::GetBeamTypeFromGRP() const |
287 | { | |
288 | // get beam type from GRP | |
289 | return NULL; | |
290 | } | |
291 | ||
a5e775ec | 292 | Double_t AliHLTMiscImplementation::GetBz() |
293 | { | |
294 | // Returns Bz. | |
295 | return AliTracker::GetBz(); | |
296 | } | |
297 | ||
298 | Double_t AliHLTMiscImplementation::GetBz(const Double_t *r) | |
299 | { | |
300 | // Returns Bz (kG) at the point "r" . | |
301 | return AliTracker::GetBz(r); | |
302 | } | |
303 | ||
304 | void AliHLTMiscImplementation::GetBxByBz(const Double_t r[3], Double_t b[3]) | |
305 | { | |
306 | // Returns Bx, By and Bz (kG) at the point "r" . | |
307 | return AliTracker::GetBxByBz(r, b); | |
308 | } | |
95ea76b5 | 309 | |
310 | const TClass* AliHLTMiscImplementation::IsAliESDHLTDecision() const | |
311 | { | |
312 | // Return the IsA of the AliESDHLTDecision class | |
95ea76b5 | 313 | return AliESDHLTDecision::Class(); |
95ea76b5 | 314 | } |
315 | ||
316 | int AliHLTMiscImplementation::Copy(const AliHLTGlobalTriggerDecision* pDecision, TObject* object) const | |
317 | { | |
318 | // Copy HLT global trigger decision to AliESDHLTDecision container | |
319 | if (!pDecision || !object) return -EINVAL; | |
95ea76b5 | 320 | AliESDHLTDecision* pESDHLTDecision=NULL; |
321 | if (object->IsA()==NULL || | |
322 | object->IsA() != AliESDHLTDecision::Class() || | |
323 | (pESDHLTDecision=dynamic_cast<AliESDHLTDecision*>(object))==NULL) { | |
324 | // HLTError("can not copy HLT global decision to object of class \"%s\"", | |
325 | // object->IsA()?object->IsA()->GetName():"NULL"); | |
326 | return -EINVAL; | |
327 | } | |
328 | ||
329 | pESDHLTDecision->~AliESDHLTDecision(); | |
84f84689 | 330 | new (pESDHLTDecision) AliESDHLTDecision(pDecision->Result(), pDecision->GetTitle()); |
95ea76b5 | 331 | |
95ea76b5 | 332 | return 0; |
333 | } | |
79c426cf | 334 | |
335 | int AliHLTMiscImplementation::InitStreamerInfos(const char* ocdbEntry) const | |
336 | { | |
337 | // init streamer infos for HLT reconstruction | |
338 | // Root schema evolution is not enabled for AliHLTMessage and all streamed objects. | |
339 | // Objects in the raw data payload rely on the availability of the correct stream info. | |
340 | // The relevant streamer info for a specific run is stored in the OCDB. | |
341 | int iResult=0; | |
342 | ||
343 | AliCDBEntry* pEntry=LoadOCDBEntry(ocdbEntry); | |
344 | TObject* pObject=NULL; | |
345 | if (pEntry && (pObject=ExtractObject(pEntry))!=NULL) | |
346 | { | |
347 | TObjArray* pSchemas=dynamic_cast<TObjArray*>(pObject); | |
348 | if (pSchemas) { | |
349 | iResult=InitStreamerInfos(pSchemas); | |
350 | } else { | |
351 | AliError(Form("internal mismatch in OCDB entry %s: wrong class type", ocdbEntry)); | |
352 | } | |
353 | } else { | |
354 | AliWarning(Form("missing HLT reco data (%s), skipping initialization of streamer info for TObjects in HLT raw data payload", ocdbEntry)); | |
355 | } | |
356 | return iResult; | |
357 | } | |
358 | ||
359 | int AliHLTMiscImplementation::InitStreamerInfos(TObjArray* pSchemas) const | |
360 | { | |
361 | // init streamer infos for HLT reconstruction from an array of TStreamerInfo objects | |
362 | ||
363 | for (int i=0; i<pSchemas->GetEntriesFast(); i++) { | |
364 | if (pSchemas->At(i)) { | |
365 | TStreamerInfo* pSchema=dynamic_cast<TStreamerInfo*>(pSchemas->At(i)); | |
366 | if (pSchema) { | |
367 | int version=pSchema->GetClassVersion(); | |
368 | TClass* pClass=TClass::GetClass(pSchema->GetName()); | |
369 | if (pClass) { | |
370 | if (pClass->GetClassVersion()==version) { | |
371 | AliDebug(0,Form("skipping schema definition %d version %d to class %s as this is the native version", i, version, pSchema->GetName())); | |
372 | continue; | |
373 | } | |
374 | TObjArray* pInfos=pClass->GetStreamerInfos(); | |
375 | if (pInfos /*&& version<pInfos->GetEntriesFast()*/) { | |
376 | if (pInfos->At(version)==NULL) { | |
377 | TStreamerInfo* pClone=(TStreamerInfo*)pSchema->Clone(); | |
378 | if (pClone) { | |
379 | pClone->SetClass(pClass); | |
380 | pClone->BuildOld(); | |
381 | pInfos->AddAtAndExpand(pClone, version); | |
382 | AliDebug(0,Form("adding schema definition %d version %d to class %s", i, version, pSchema->GetName())); | |
383 | } else { | |
384 | AliError(Form("skipping schema definition %d (%s), unable to create clone object", i, pSchema->GetName())); | |
385 | } | |
386 | } else { | |
387 | TStreamerInfo* pInfo=dynamic_cast<TStreamerInfo*>(pInfos->At(version)); | |
388 | if (pInfo && pInfo->GetClassVersion()==version) { | |
389 | AliDebug(0,Form("schema definition %d version %d already available in class %s, skipping ...", i, version, pSchema->GetName())); | |
390 | } else { | |
391 | AliError(Form("can not verify version for already existing schema definition %d (%s) version %d: version of existing definition is %d", i, pSchema->GetName(), version, pInfo?pInfo->GetClassVersion():-1)); | |
392 | } | |
393 | } | |
394 | } else { | |
395 | AliError(Form("skipping schema definition %d (%s), unable to set version %d in info array of size %d", i, pSchema->GetName(), version, pInfos?pInfos->GetEntriesFast():-1)); | |
396 | } | |
397 | } else { | |
398 | AliError(Form("skipping schema definition %d (%s), unable to find class", i, pSchema->GetName())); | |
399 | } | |
400 | } else { | |
401 | AliError(Form("skipping schema definition %d, not of TStreamerInfo", i)); | |
402 | } | |
403 | } | |
404 | } | |
405 | ||
406 | return 0; | |
407 | } | |
ee15809c | 408 | |
409 | void AliHLTMiscImplementation::SetAliESDtrackOnlineModeFlag(bool mode) const | |
410 | { | |
411 | /// set the online mode flag of AliESDtrack | |
412 | AliESDtrack::OnlineMode(mode); | |
413 | } | |
414 | ||
415 | bool AliHLTMiscImplementation::GetAliESDtrackOnlineModeFlag() const | |
416 | { | |
417 | /// get status of the online mode flag of AliESDtrack | |
418 | return AliESDtrack::OnlineMode(); | |
419 | } |