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 TString strUri=store->GetURI();
153 int latest = store->GetLatestVersion(path, runNo);
155 log.Logging(kHLTLogError, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "Could not find an entry in the CDB for \"%s\".", path);
159 AliCDBEntry* entry=man->Get(path, runNo);
163 TObject* AliHLTMiscImplementation::ExtractObject(AliCDBEntry* entry) const
165 // see header file for function documentation
166 if (!entry) return NULL;
167 return entry->GetObject();
170 int AliHLTMiscImplementation::CheckOCDBEntries(const TMap* const pMap) const
172 // check the availability of the OCDB entry descriptions in the TMap
173 // key : complete OCDB path of the entry
174 // value : auxiliary object - short description
175 // check uses AliCDBStorage::GetLatestVersion, which is the only method
176 // to check the existence without risking AliFatal
179 if (!pMap) return -EINVAL;
182 AliCDBManager* man = AliCDBManager::Instance();
184 ALIHLTERRORGUARD(1, "failed to access CDB manager");
187 const TMap* pCache=man->GetEntryCache();
189 Int_t runNo = GetCDBRunNo();
191 TIterator* next=pMap->MakeIterator();
192 if (!next) return -EFAULT;
194 TObject* pEntry=NULL;
195 while ((pEntry=next->Next())) {
196 // check if already on cache
197 if (pCache && pCache->GetValue(pEntry->GetName())!=NULL) {
198 log.Logging(kHLTLogDebug, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "found OCDB object %s on cache", pEntry->GetName());
202 // check if the entry has specific storage
203 const char* uri=man->GetURI(pEntry->GetName());
205 log.Logging(kHLTLogError, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "can not find URI for CDB object \"%s\"", pEntry->GetName());
209 AliCDBStorage* pStorage = AliCDBManager::Instance()->GetStorage(uri);
211 log.Logging(kHLTLogError, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "can not find storage for URI \"%s\"", uri);
215 // GetLatestVersion is the only method to check the existence without potential AliFatal
216 if (pStorage->GetLatestVersion(pEntry->GetName(), runNo)<0) {
217 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());
220 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());
229 int AliHLTMiscImplementation::InitMagneticField() const
231 // see header file for function documentation
233 // BAD: unit test fails if I call TGeoGlobalMagField::Instance()
234 // at this point. Something goes wrong in the cleaning of the global
237 if (TGeoGlobalMagField::Instance()->GetField()) {
238 // everything set, but think about storing the currents for
244 // The magnetic field is initialized once at the start
245 // of run. The fields are supposed to be constant througout the
246 // data taking of one run. The run is aborted if the changes
247 // exceed a certain limit.
248 AliGRPManager grpman;
249 if (grpman.ReadGRPEntry() && grpman.SetMagField()) {
256 AliHLTUInt64_t AliHLTMiscImplementation::GetTriggerMask(AliRawReader* rawReader) const
258 // see header file for function documentation
259 if (!rawReader) return 0;
260 AliHLTUInt64_t trgMask=0;
262 const UInt_t* pattern=rawReader->GetTriggerPattern();
263 trgMask=pattern[1]&0xfffffff; // 28 upper bits of the 50 bit mask
265 trgMask|=pattern[0]; // 32 lower bits of the mask
270 AliHLTUInt32_t AliHLTMiscImplementation::GetTimeStamp(AliRawReader* rawReader) const
272 // extract time stamp of the event from the event header
273 if (!rawReader) return 0;
274 const AliRawEventHeaderBase* eventHeader = rawReader->GetEventHeader();
275 if (!eventHeader) return 0;
276 return eventHeader->Get("Timestamp");
279 AliHLTUInt32_t AliHLTMiscImplementation::GetEventType(AliRawReader* rawReader) const
281 // extract event type from the event header
282 if (!rawReader) return 0;
283 const AliRawEventHeaderBase* eventHeader = rawReader->GetEventHeader();
284 if (!eventHeader) return 0;
285 return eventHeader->Get("Type");
288 const char* AliHLTMiscImplementation::GetBeamTypeFromGRP() const
290 // get beam type from GRP
294 Double_t AliHLTMiscImplementation::GetBz()
297 return AliTracker::GetBz();
300 Double_t AliHLTMiscImplementation::GetBz(const Double_t *r)
302 // Returns Bz (kG) at the point "r" .
303 return AliTracker::GetBz(r);
306 void AliHLTMiscImplementation::GetBxByBz(const Double_t r[3], Double_t b[3])
308 // Returns Bx, By and Bz (kG) at the point "r" .
309 return AliTracker::GetBxByBz(r, b);
312 const TClass* AliHLTMiscImplementation::IsAliESDHLTDecision() const
314 // Return the IsA of the AliESDHLTDecision class
315 return AliESDHLTDecision::Class();
318 int AliHLTMiscImplementation::Copy(const AliHLTGlobalTriggerDecision* pDecision, TObject* object) const
320 // Copy HLT global trigger decision to AliESDHLTDecision container
321 if (!pDecision || !object) return -EINVAL;
322 AliESDHLTDecision* pESDHLTDecision=NULL;
323 if (object->IsA()==NULL ||
324 object->IsA() != AliESDHLTDecision::Class() ||
325 (pESDHLTDecision=dynamic_cast<AliESDHLTDecision*>(object))==NULL) {
326 // HLTError("can not copy HLT global decision to object of class \"%s\"",
327 // object->IsA()?object->IsA()->GetName():"NULL");
331 pESDHLTDecision->~AliESDHLTDecision();
332 new (pESDHLTDecision) AliESDHLTDecision(pDecision->Result(), pDecision->GetTitle());
337 int AliHLTMiscImplementation::InitStreamerInfos(const char* ocdbEntry) const
339 // init streamer infos for HLT reconstruction
340 // Root schema evolution is not enabled for AliHLTMessage and all streamed objects.
341 // Objects in the raw data payload rely on the availability of the correct stream info.
342 // The relevant streamer info for a specific run is stored in the OCDB.
345 AliCDBEntry* pEntry=LoadOCDBEntry(ocdbEntry);
346 TObject* pObject=NULL;
347 if (pEntry && (pObject=ExtractObject(pEntry))!=NULL)
349 TObjArray* pSchemas=dynamic_cast<TObjArray*>(pObject);
351 iResult=InitStreamerInfos(pSchemas);
353 AliError(Form("internal mismatch in OCDB entry %s: wrong class type", ocdbEntry));
356 AliWarning(Form("missing HLT reco data (%s), skipping initialization of streamer info for TObjects in HLT raw data payload", ocdbEntry));
361 int AliHLTMiscImplementation::InitStreamerInfos(TObjArray* pSchemas) const
363 // init streamer infos for HLT reconstruction from an array of TStreamerInfo objects
365 for (int i=0; i<pSchemas->GetEntriesFast(); i++) {
366 if (pSchemas->At(i)) {
367 TStreamerInfo* pSchema=dynamic_cast<TStreamerInfo*>(pSchemas->At(i));
369 int version=pSchema->GetClassVersion();
370 TClass* pClass=TClass::GetClass(pSchema->GetName());
372 if (pClass->GetClassVersion()==version) {
373 AliDebug(0,Form("skipping schema definition %d version %d to class %s as this is the native version", i, version, pSchema->GetName()));
376 TObjArray* pInfos=pClass->GetStreamerInfos();
377 if (pInfos /*&& version<pInfos->GetEntriesFast()*/) {
378 if (pInfos->At(version)==NULL) {
379 TStreamerInfo* pClone=(TStreamerInfo*)pSchema->Clone();
381 pClone->SetClass(pClass);
383 pInfos->AddAtAndExpand(pClone, version);
384 AliDebug(0,Form("adding schema definition %d version %d to class %s", i, version, pSchema->GetName()));
386 AliError(Form("skipping schema definition %d (%s), unable to create clone object", i, pSchema->GetName()));
389 TStreamerInfo* pInfo=dynamic_cast<TStreamerInfo*>(pInfos->At(version));
390 if (pInfo && pInfo->GetClassVersion()==version) {
391 AliDebug(0,Form("schema definition %d version %d already available in class %s, skipping ...", i, version, pSchema->GetName()));
393 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));
397 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));
400 AliError(Form("skipping schema definition %d (%s), unable to find class", i, pSchema->GetName()));
403 AliError(Form("skipping schema definition %d, not of TStreamerInfo", i));
411 void AliHLTMiscImplementation::SetAliESDtrackOnlineModeFlag(bool mode) const
413 /// set the online mode flag of AliESDtrack
414 AliESDtrack::OnlineMode(mode);
417 bool AliHLTMiscImplementation::GetAliESDtrackOnlineModeFlag() const
419 /// get status of the online mode flag of AliESDtrack
420 return AliESDtrack::OnlineMode();