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"
27 #include "AliCDBManager.h"
28 #include "AliCDBStorage.h"
29 #include "AliCDBEntry.h"
30 #include "AliGRPManager.h"
31 #include "AliRawReader.h"
32 #include "AliRawEventHeaderBase.h"
33 #include "AliTracker.h"
34 #ifndef HAVE_NOT_ALIESDHLTDECISION
35 #include "AliESDHLTDecision.h"
36 #endif //HAVE_NOT_ALIESDHLTDECISION
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, int version, int subVersion) const
113 // see header file for function documentation
114 AliCDBManager* man = AliCDBManager::Instance();
115 if (!man) return NULL;
117 const char* uri=man->GetURI(path);
118 if (!uri) return NULL;
120 AliCDBStorage* store = AliCDBManager::Instance()->GetStorage(uri);
125 TString strUri=store->GetURI();
126 bool bIsGrid=strUri.BeginsWith("alien://");
128 if (version<0) version = store->GetLatestVersion(path, runNo);
130 // OCDB objects on GRID have no sub version
131 if (subVersion<0 && !bIsGrid) subVersion = store->GetLatestSubVersion(path, runNo, version);
132 AliCDBEntry* entry=man->Get(path, runNo, version, subVersion);
134 // there seems to be a problem with the caching of objects in the CDBManager
135 // regardless what version is specified it returns the object from the cache
136 AliCDBId id=entry->GetId();
137 if (id.GetVersion()==version &&
138 id.GetSubVersion()==subVersion) {
139 // entry in the cache has the correct version
143 return store->Get(path, runNo, version, subVersion);
146 TObject* AliHLTMiscImplementation::ExtractObject(AliCDBEntry* entry) const
148 // see header file for function documentation
149 if (!entry) return NULL;
150 return entry->GetObject();
153 int AliHLTMiscImplementation::CheckOCDBEntries(const TMap* const pMap) const
155 // check the availability of the OCDB entry descriptions in the TMap
156 // key : complete OCDB path of the entry
157 // value : auxiliary object - short description
159 if (!pMap) return -EINVAL;
161 const TMap* pStorages=AliCDBManager::Instance()->GetStorageMap();
162 Int_t runNo = GetCDBRunNo();
164 TIterator* next=pMap->MakeIterator();
165 if (!next) return -ENOENT;
167 TObject* pEntry=NULL;
168 while ((pEntry=next->Next())) {
169 // check if the entry has specific storage
170 AliCDBStorage* pStorage=NULL;
171 TObject* pStorageId=pStorages->GetValue(pEntry->GetName());
173 pStorage=AliCDBManager::Instance()->GetStorage(pStorageId->GetName());
175 pStorage=AliCDBManager::Instance()->GetDefaultStorage();
178 // FIXME: this will fail as soon as we have several specific storages
179 // access to the internal mapping information for specific storages is needed
180 if (pStorage->GetLatestVersion(pEntry->GetName(), runNo)<0) {
182 log.Logging(kHLTLogError, "CheckOCDBEntries", "CDB handling", "can not find required OCDB object %s for run number %d in storage %s", pEntry->GetName(), runNo, pStorage->GetURI().Data());
186 log.Logging(kHLTLogDebug, "CheckOCDBEntries", "CDB handling", "found required OCDB object %s for run number %d in storage %s", pEntry->GetName(), runNo, pStorage->GetURI().Data());
195 int AliHLTMiscImplementation::InitMagneticField() const
197 // see header file for function documentation
199 // BAD: unit test fails if I call TGeoGlobalMagField::Instance()
200 // at this point. Something goes wrong in the cleaning of the global
203 if (TGeoGlobalMagField::Instance()->GetField()) {
204 // everything set, but think about storing the currents for
210 // The magnetic field is initialized once at the start
211 // of run. The fields are supposed to be constant througout the
212 // data taking of one run. The run is aborted if the changes
213 // exceed a certain limit.
214 AliGRPManager grpman;
215 if (grpman.ReadGRPEntry() && grpman.SetMagField()) {
222 AliHLTUInt64_t AliHLTMiscImplementation::GetTriggerMask(AliRawReader* rawReader) const
224 // see header file for function documentation
225 if (!rawReader) return 0;
226 AliHLTUInt64_t trgMask=0;
228 const UInt_t* pattern=rawReader->GetTriggerPattern();
229 trgMask=pattern[1]&0xfffffff; // 28 upper bits of the 50 bit mask
231 trgMask|=pattern[0]; // 32 lower bits of the mask
236 AliHLTUInt32_t AliHLTMiscImplementation::GetTimeStamp(AliRawReader* rawReader) const
238 // extract time stamp of the event from the event header
239 if (!rawReader) return 0;
240 const AliRawEventHeaderBase* eventHeader = rawReader->GetEventHeader();
241 if (!eventHeader) return 0;
242 return eventHeader->Get("Timestamp");
245 AliHLTUInt32_t AliHLTMiscImplementation::GetEventType(AliRawReader* rawReader) const
247 // extract event type from the event header
248 if (!rawReader) return 0;
249 const AliRawEventHeaderBase* eventHeader = rawReader->GetEventHeader();
250 if (!eventHeader) return 0;
251 return eventHeader->Get("Type");
254 const char* AliHLTMiscImplementation::GetBeamTypeFromGRP() const
256 // get beam type from GRP
260 Double_t AliHLTMiscImplementation::GetBz()
263 return AliTracker::GetBz();
266 Double_t AliHLTMiscImplementation::GetBz(const Double_t *r)
268 // Returns Bz (kG) at the point "r" .
269 return AliTracker::GetBz(r);
272 void AliHLTMiscImplementation::GetBxByBz(const Double_t r[3], Double_t b[3])
274 // Returns Bx, By and Bz (kG) at the point "r" .
275 return AliTracker::GetBxByBz(r, b);
278 const TClass* AliHLTMiscImplementation::IsAliESDHLTDecision() const
280 // Return the IsA of the AliESDHLTDecision class
281 #ifndef HAVE_NOT_ALIESDHLTDECISION
282 return AliESDHLTDecision::Class();
283 #else // HAVE_NOT_ALIESDHLTDECISION
285 #endif // HAVE_NOT_ALIESDHLTDECISION
288 int AliHLTMiscImplementation::Copy(const AliHLTGlobalTriggerDecision* pDecision, TObject* object) const
290 // Copy HLT global trigger decision to AliESDHLTDecision container
291 if (!pDecision || !object) return -EINVAL;
292 #ifndef HAVE_NOT_ALIESDHLTDECISION
293 AliESDHLTDecision* pESDHLTDecision=NULL;
294 if (object->IsA()==NULL ||
295 object->IsA() != AliESDHLTDecision::Class() ||
296 (pESDHLTDecision=dynamic_cast<AliESDHLTDecision*>(object))==NULL) {
297 // HLTError("can not copy HLT global decision to object of class \"%s\"",
298 // object->IsA()?object->IsA()->GetName():"NULL");
302 pESDHLTDecision->~AliESDHLTDecision();
303 new (pESDHLTDecision) AliESDHLTDecision(pDecision->Result(), pDecision->GetTitle());
305 #endif // HAVE_NOT_ALIESDHLTDECISION
309 int AliHLTMiscImplementation::InitStreamerInfos(const char* ocdbEntry) const
311 // init streamer infos for HLT reconstruction
312 // Root schema evolution is not enabled for AliHLTMessage and all streamed objects.
313 // Objects in the raw data payload rely on the availability of the correct stream info.
314 // The relevant streamer info for a specific run is stored in the OCDB.
317 AliCDBEntry* pEntry=LoadOCDBEntry(ocdbEntry);
318 TObject* pObject=NULL;
319 if (pEntry && (pObject=ExtractObject(pEntry))!=NULL)
321 TObjArray* pSchemas=dynamic_cast<TObjArray*>(pObject);
323 iResult=InitStreamerInfos(pSchemas);
325 AliError(Form("internal mismatch in OCDB entry %s: wrong class type", ocdbEntry));
328 AliWarning(Form("missing HLT reco data (%s), skipping initialization of streamer info for TObjects in HLT raw data payload", ocdbEntry));
333 int AliHLTMiscImplementation::InitStreamerInfos(TObjArray* pSchemas) const
335 // init streamer infos for HLT reconstruction from an array of TStreamerInfo objects
337 for (int i=0; i<pSchemas->GetEntriesFast(); i++) {
338 if (pSchemas->At(i)) {
339 TStreamerInfo* pSchema=dynamic_cast<TStreamerInfo*>(pSchemas->At(i));
341 int version=pSchema->GetClassVersion();
342 TClass* pClass=TClass::GetClass(pSchema->GetName());
344 if (pClass->GetClassVersion()==version) {
345 AliDebug(0,Form("skipping schema definition %d version %d to class %s as this is the native version", i, version, pSchema->GetName()));
348 TObjArray* pInfos=pClass->GetStreamerInfos();
349 if (pInfos /*&& version<pInfos->GetEntriesFast()*/) {
350 if (pInfos->At(version)==NULL) {
351 TStreamerInfo* pClone=(TStreamerInfo*)pSchema->Clone();
353 pClone->SetClass(pClass);
355 pInfos->AddAtAndExpand(pClone, version);
356 AliDebug(0,Form("adding schema definition %d version %d to class %s", i, version, pSchema->GetName()));
358 AliError(Form("skipping schema definition %d (%s), unable to create clone object", i, pSchema->GetName()));
361 TStreamerInfo* pInfo=dynamic_cast<TStreamerInfo*>(pInfos->At(version));
362 if (pInfo && pInfo->GetClassVersion()==version) {
363 AliDebug(0,Form("schema definition %d version %d already available in class %s, skipping ...", i, version, pSchema->GetName()));
365 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));
369 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));
372 AliError(Form("skipping schema definition %d (%s), unable to find class", i, pSchema->GetName()));
375 AliError(Form("skipping schema definition %d, not of TStreamerInfo", i));