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