3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /// @file AliHLTMisc.cxx
20 /// @author Matthias Richter
22 /// @brief Miscellaneous methods for the HLT AliRoot integration
24 #include "AliHLTMiscImplementation.h"
25 #include "AliHLTLogging.h"
26 #include "AliHLTErrorGuard.h"
28 #include "AliCDBManager.h"
29 #include "AliCDBStorage.h"
30 #include "AliCDBEntry.h"
31 #include "AliGRPManager.h"
32 #include "AliRawReader.h"
33 #include "AliRawEventHeaderBase.h"
34 #include "AliTracker.h"
35 #include "AliESDtrack.h"
36 #include "AliESDHLTDecision.h"
37 #include "TGeoGlobalMagField.h"
38 #include "AliHLTGlobalTriggerDecision.h"
40 #include "TStreamerInfo.h"
41 #include "TObjArray.h"
43 /** ROOT macro for the implementation of ROOT specific class methods */
44 ClassImp(AliHLTMiscImplementation);
46 AliHLTMiscImplementation::AliHLTMiscImplementation()
50 AliHLTMiscImplementation::~AliHLTMiscImplementation()
52 // see header file for function documentation
55 int AliHLTMiscImplementation::InitCDB(const char* cdbpath)
57 // see header file for function documentation
59 AliCDBManager* pCDB = AliCDBManager::Instance();
62 log.Logging(kHLTLogError, "InitCDB", "CDB handling", "Could not get CDB instance");
64 if (cdbpath && cdbpath[0]!=0) {
66 if (!uri.BeginsWith("local://") &&
67 !uri.Contains("://")) {
68 // assume a local path if no uri specifier is found
72 pCDB->SetDefaultStorage(uri);
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);
78 log.Logging(kHLTLogInfo, "InitCDB", "CDB handling", "set default URI: %s", cdbUri);
84 int AliHLTMiscImplementation::SetCDBRunNo(int runNo)
86 // see header file for function documentation
88 AliCDBManager* pCDB = AliCDBManager::Instance();
91 log.Logging(kHLTLogError, "SetCDBRunNo", "CDB handling", "Could not get CDB instance");
98 int AliHLTMiscImplementation::GetCDBRunNo() const
100 // see header file for function documentation
101 AliCDBManager* pCDB = AliCDBManager::Instance();
104 log.Logging(kHLTLogError, "SetCDBRunNo", "CDB handling", "Could not get CDB instance");
106 return pCDB->GetRun();
111 AliCDBEntry* AliHLTMiscImplementation::LoadOCDBEntry(const char* path, int runNo) const
113 // see header file for function documentation
114 if (!path) return NULL;
117 AliCDBManager* man = AliCDBManager::Instance();
119 ALIHLTERRORGUARD(1, "failed to access CDB manager");
122 if (runNo<0) runNo=man->GetRun();
124 // check the cache first if no specific version required
125 { //condition was deprecated, but keep for formatting
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);
131 log.Logging(kHLTLogDebug, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "using OCDB object %s from cache", path);
134 log.Logging(kHLTLogError, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "invalid OCDB object %s found in cache, not of type AliCDBEntry", path);
139 const char* uri=man->GetURI(path);
141 log.Logging(kHLTLogError, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "can not find URI for CDB object \"%s\"", path);
145 AliCDBStorage* store = AliCDBManager::Instance()->GetStorage(uri);
147 log.Logging(kHLTLogError, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "can not find storage for URI \"%s\"", uri);
151 int latest = store->GetLatestVersion(path, runNo);
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());
157 AliCDBEntry* entry=man->Get(path, runNo);
161 TObject* AliHLTMiscImplementation::ExtractObject(AliCDBEntry* entry) const
163 // see header file for function documentation
164 if (!entry) return NULL;
165 return entry->GetObject();
168 int AliHLTMiscImplementation::CheckOCDBEntries(const TMap* const pMap) const
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
173 // check uses AliCDBStorage::GetLatestVersion, which is the only method
174 // to check the existence without risking AliFatal
177 if (!pMap) return -EINVAL;
180 AliCDBManager* man = AliCDBManager::Instance();
182 ALIHLTERRORGUARD(1, "failed to access CDB manager");
185 const TMap* pCache=man->GetEntryCache();
187 Int_t runNo = GetCDBRunNo();
189 TIterator* next=pMap->MakeIterator();
190 if (!next) return -EFAULT;
192 TObject* pEntry=NULL;
193 while ((pEntry=next->Next())) {
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());
200 // check if the entry has specific storage
201 const char* uri=man->GetURI(pEntry->GetName());
203 log.Logging(kHLTLogError, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "can not find URI for CDB object \"%s\"", pEntry->GetName());
207 AliCDBStorage* pStorage = AliCDBManager::Instance()->GetStorage(uri);
209 log.Logging(kHLTLogError, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "can not find storage for URI \"%s\"", uri);
213 // GetLatestVersion is the only method to check the existence without potential AliFatal
214 if (pStorage->GetLatestVersion(pEntry->GetName(), runNo)<0) {
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());
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());
227 int AliHLTMiscImplementation::InitMagneticField() const
229 // see header file for function documentation
231 // BAD: unit test fails if I call TGeoGlobalMagField::Instance()
232 // at this point. Something goes wrong in the cleaning of the global
235 if (TGeoGlobalMagField::Instance()->GetField()) {
236 // everything set, but think about storing the currents for
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()) {
254 AliHLTUInt64_t AliHLTMiscImplementation::GetTriggerMask(AliRawReader* rawReader) const
256 // see header file for function documentation
257 if (!rawReader) return 0;
258 AliHLTUInt64_t trgMask=0;
260 const UInt_t* pattern=rawReader->GetTriggerPattern();
261 trgMask=pattern[1]&0xfffffff; // 28 upper bits of the 50 bit mask
263 trgMask|=pattern[0]; // 32 lower bits of the mask
268 AliHLTUInt32_t AliHLTMiscImplementation::GetTimeStamp(AliRawReader* rawReader) const
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");
277 AliHLTUInt32_t AliHLTMiscImplementation::GetEventType(AliRawReader* rawReader) const
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");
286 const char* AliHLTMiscImplementation::GetBeamTypeFromGRP() const
288 // get beam type from GRP
292 Double_t AliHLTMiscImplementation::GetBz()
295 return AliTracker::GetBz();
298 Double_t AliHLTMiscImplementation::GetBz(const Double_t *r)
300 // Returns Bz (kG) at the point "r" .
301 return AliTracker::GetBz(r);
304 void AliHLTMiscImplementation::GetBxByBz(const Double_t r[3], Double_t b[3])
306 // Returns Bx, By and Bz (kG) at the point "r" .
307 return AliTracker::GetBxByBz(r, b);
310 const TClass* AliHLTMiscImplementation::IsAliESDHLTDecision() const
312 // Return the IsA of the AliESDHLTDecision class
313 return AliESDHLTDecision::Class();
316 int AliHLTMiscImplementation::Copy(const AliHLTGlobalTriggerDecision* pDecision, TObject* object) const
318 // Copy HLT global trigger decision to AliESDHLTDecision container
319 if (!pDecision || !object) return -EINVAL;
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");
329 pESDHLTDecision->~AliESDHLTDecision();
330 new (pESDHLTDecision) AliESDHLTDecision(pDecision->Result(), pDecision->GetTitle());
335 int AliHLTMiscImplementation::InitStreamerInfos(const char* ocdbEntry) const
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.
343 AliCDBEntry* pEntry=LoadOCDBEntry(ocdbEntry);
344 TObject* pObject=NULL;
345 if (pEntry && (pObject=ExtractObject(pEntry))!=NULL)
347 TObjArray* pSchemas=dynamic_cast<TObjArray*>(pObject);
349 iResult=InitStreamerInfos(pSchemas);
351 AliError(Form("internal mismatch in OCDB entry %s: wrong class type", ocdbEntry));
354 AliWarning(Form("missing HLT reco data (%s), skipping initialization of streamer info for TObjects in HLT raw data payload", ocdbEntry));
359 int AliHLTMiscImplementation::InitStreamerInfos(TObjArray* pSchemas) const
361 // init streamer infos for HLT reconstruction from an array of TStreamerInfo objects
363 for (int i=0; i<pSchemas->GetEntriesFast(); i++) {
364 if (pSchemas->At(i)) {
365 TStreamerInfo* pSchema=dynamic_cast<TStreamerInfo*>(pSchemas->At(i));
367 int version=pSchema->GetClassVersion();
368 TClass* pClass=TClass::GetClass(pSchema->GetName());
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()));
374 TObjArray* pInfos=pClass->GetStreamerInfos();
375 if (pInfos /*&& version<pInfos->GetEntriesFast()*/) {
376 if (pInfos->At(version)==NULL) {
377 TStreamerInfo* pClone=(TStreamerInfo*)pSchema->Clone();
379 pClone->SetClass(pClass);
381 pInfos->AddAtAndExpand(pClone, version);
382 AliDebug(0,Form("adding schema definition %d version %d to class %s", i, version, pSchema->GetName()));
384 AliError(Form("skipping schema definition %d (%s), unable to create clone object", i, pSchema->GetName()));
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()));
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));
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));
398 AliError(Form("skipping schema definition %d (%s), unable to find class", i, pSchema->GetName()));
401 AliError(Form("skipping schema definition %d, not of TStreamerInfo", i));
409 void AliHLTMiscImplementation::SetAliESDtrackOnlineModeFlag(bool mode) const
411 /// set the online mode flag of AliESDtrack
412 AliESDtrack::OnlineMode(mode);
415 bool AliHLTMiscImplementation::GetAliESDtrackOnlineModeFlag() const
417 /// get status of the online mode flag of AliESDtrack
418 return AliESDtrack::OnlineMode();