]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/rec/AliHLTMiscImplementation.cxx
removing unused variable
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTMiscImplementation.cxx
CommitLineData
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 */
44ClassImp(AliHLTMiscImplementation);
45
46AliHLTMiscImplementation::AliHLTMiscImplementation()
47{
48}
49
50AliHLTMiscImplementation::~AliHLTMiscImplementation()
51{
52 // see header file for function documentation
53}
54
55int 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
84int 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 98int 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 111AliCDBEntry* 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
151 TString strUri=store->GetURI();
de254f89 152
88bb1fd0 153 int latest = store->GetLatestVersion(path, runNo);
154 if (latest<0) {
155 log.Logging(kHLTLogError, "AliHLTMiscImplementation::LoadOCDBEntry", "CDB handling", "Could not find an entry in the CDB for \"%s\".", path);
156 return NULL;
157 }
5df320bf 158
159 AliCDBEntry* entry=man->Get(path, runNo);
160 return entry;
2b545cdd 161}
162
74c1905c 163TObject* AliHLTMiscImplementation::ExtractObject(AliCDBEntry* entry) const
2b545cdd 164{
165 // see header file for function documentation
166 if (!entry) return NULL;
167 return entry->GetObject();
168}
169
74c1905c 170int AliHLTMiscImplementation::CheckOCDBEntries(const TMap* const pMap) const
171{
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
88bb1fd0 175 // check uses AliCDBStorage::GetLatestVersion, which is the only method
176 // to check the existence without risking AliFatal
177
74c1905c 178 int iResult=0;
179 if (!pMap) return -EINVAL;
88bb1fd0 180 AliHLTLogging log;
181
182 AliCDBManager* man = AliCDBManager::Instance();
183 if (!man) {
184 ALIHLTERRORGUARD(1, "failed to access CDB manager");
726d36e7 185 return -ENOSYS;
88bb1fd0 186 }
187 const TMap* pCache=man->GetEntryCache();
74c1905c 188
74c1905c 189 Int_t runNo = GetCDBRunNo();
190
191 TIterator* next=pMap->MakeIterator();
726d36e7 192 if (!next) return -EFAULT;
5d99ef2a 193
74c1905c 194 TObject* pEntry=NULL;
195 while ((pEntry=next->Next())) {
88bb1fd0 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());
199 continue;
200 }
201
74c1905c 202 // check if the entry has specific storage
88bb1fd0 203 const char* uri=man->GetURI(pEntry->GetName());
204 if (!uri) {
205 log.Logging(kHLTLogError, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "can not find URI for CDB object \"%s\"", pEntry->GetName());
726d36e7 206 return -ENODEV;
88bb1fd0 207 }
208
209 AliCDBStorage* pStorage = AliCDBManager::Instance()->GetStorage(uri);
210 if (!pStorage) {
211 log.Logging(kHLTLogError, "AliHLTMiscImplementation::CheckOCDBEntries", "CDB handling", "can not find storage for URI \"%s\"", uri);
726d36e7 212 return -EBADF;
74c1905c 213 }
214
88bb1fd0 215 // GetLatestVersion is the only method to check the existence without potential AliFatal
74c1905c 216 if (pStorage->GetLatestVersion(pEntry->GetName(), runNo)<0) {
88bb1fd0 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());
74c1905c 218 iResult=-ENOENT;
219 } else {
88bb1fd0 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());
74c1905c 221 }
222 }
5d99ef2a 223 delete next;
224 next=NULL;
74c1905c 225
226 return iResult;
227}
228
cc484ed9 229int AliHLTMiscImplementation::InitMagneticField() const
2b545cdd 230{
cc484ed9 231 // see header file for function documentation
232
233 // BAD: unit test fails if I call TGeoGlobalMagField::Instance()
234 // at this point. Something goes wrong in the cleaning of the global
235 // ROOT onject
236 /*
237 if (TGeoGlobalMagField::Instance()->GetField()) {
238 // everything set, but think about storing the currents for
239 // a cross-check
240 return 0;
2b545cdd 241 }
cc484ed9 242 */
2b545cdd 243
cc484ed9 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()) {
250 return 0;
2b545cdd 251 }
cc484ed9 252
253 return -ENOENT;
2b545cdd 254}
73305a93 255
256AliHLTUInt64_t AliHLTMiscImplementation::GetTriggerMask(AliRawReader* rawReader) const
257{
258 // see header file for function documentation
259 if (!rawReader) return 0;
260 AliHLTUInt64_t trgMask=0;
261 if (rawReader) {
262 const UInt_t* pattern=rawReader->GetTriggerPattern();
263 trgMask=pattern[1]&0xfffffff; // 28 upper bits of the 50 bit mask
264 trgMask<<=32;
265 trgMask|=pattern[0]; // 32 lower bits of the mask
266 }
267 return trgMask;
268}
a5e775ec 269
2572a09f 270AliHLTUInt32_t AliHLTMiscImplementation::GetTimeStamp(AliRawReader* rawReader) const
271{
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");
277}
278
279AliHLTUInt32_t AliHLTMiscImplementation::GetEventType(AliRawReader* rawReader) const
280{
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");
286}
287
de254f89 288const char* AliHLTMiscImplementation::GetBeamTypeFromGRP() const
289{
290 // get beam type from GRP
291 return NULL;
292}
293
a5e775ec 294Double_t AliHLTMiscImplementation::GetBz()
295{
296 // Returns Bz.
297 return AliTracker::GetBz();
298}
299
300Double_t AliHLTMiscImplementation::GetBz(const Double_t *r)
301{
302 // Returns Bz (kG) at the point "r" .
303 return AliTracker::GetBz(r);
304}
305
306void AliHLTMiscImplementation::GetBxByBz(const Double_t r[3], Double_t b[3])
307{
308 // Returns Bx, By and Bz (kG) at the point "r" .
309 return AliTracker::GetBxByBz(r, b);
310}
95ea76b5 311
312const TClass* AliHLTMiscImplementation::IsAliESDHLTDecision() const
313{
314 // Return the IsA of the AliESDHLTDecision class
95ea76b5 315 return AliESDHLTDecision::Class();
95ea76b5 316}
317
318int AliHLTMiscImplementation::Copy(const AliHLTGlobalTriggerDecision* pDecision, TObject* object) const
319{
320 // Copy HLT global trigger decision to AliESDHLTDecision container
321 if (!pDecision || !object) return -EINVAL;
95ea76b5 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");
328 return -EINVAL;
329 }
330
331 pESDHLTDecision->~AliESDHLTDecision();
84f84689 332 new (pESDHLTDecision) AliESDHLTDecision(pDecision->Result(), pDecision->GetTitle());
95ea76b5 333
95ea76b5 334 return 0;
335}
79c426cf 336
337int AliHLTMiscImplementation::InitStreamerInfos(const char* ocdbEntry) const
338{
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.
343 int iResult=0;
344
345 AliCDBEntry* pEntry=LoadOCDBEntry(ocdbEntry);
346 TObject* pObject=NULL;
347 if (pEntry && (pObject=ExtractObject(pEntry))!=NULL)
348 {
349 TObjArray* pSchemas=dynamic_cast<TObjArray*>(pObject);
350 if (pSchemas) {
351 iResult=InitStreamerInfos(pSchemas);
352 } else {
353 AliError(Form("internal mismatch in OCDB entry %s: wrong class type", ocdbEntry));
354 }
355 } else {
356 AliWarning(Form("missing HLT reco data (%s), skipping initialization of streamer info for TObjects in HLT raw data payload", ocdbEntry));
357 }
358 return iResult;
359}
360
361int AliHLTMiscImplementation::InitStreamerInfos(TObjArray* pSchemas) const
362{
363 // init streamer infos for HLT reconstruction from an array of TStreamerInfo objects
364
365 for (int i=0; i<pSchemas->GetEntriesFast(); i++) {
366 if (pSchemas->At(i)) {
367 TStreamerInfo* pSchema=dynamic_cast<TStreamerInfo*>(pSchemas->At(i));
368 if (pSchema) {
369 int version=pSchema->GetClassVersion();
370 TClass* pClass=TClass::GetClass(pSchema->GetName());
371 if (pClass) {
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()));
374 continue;
375 }
376 TObjArray* pInfos=pClass->GetStreamerInfos();
377 if (pInfos /*&& version<pInfos->GetEntriesFast()*/) {
378 if (pInfos->At(version)==NULL) {
379 TStreamerInfo* pClone=(TStreamerInfo*)pSchema->Clone();
380 if (pClone) {
381 pClone->SetClass(pClass);
382 pClone->BuildOld();
383 pInfos->AddAtAndExpand(pClone, version);
384 AliDebug(0,Form("adding schema definition %d version %d to class %s", i, version, pSchema->GetName()));
385 } else {
386 AliError(Form("skipping schema definition %d (%s), unable to create clone object", i, pSchema->GetName()));
387 }
388 } else {
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()));
392 } else {
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));
394 }
395 }
396 } else {
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));
398 }
399 } else {
400 AliError(Form("skipping schema definition %d (%s), unable to find class", i, pSchema->GetName()));
401 }
402 } else {
403 AliError(Form("skipping schema definition %d, not of TStreamerInfo", i));
404 }
405 }
406 }
407
408 return 0;
409}
ee15809c 410
411void AliHLTMiscImplementation::SetAliESDtrackOnlineModeFlag(bool mode) const
412{
413 /// set the online mode flag of AliESDtrack
414 AliESDtrack::OnlineMode(mode);
415}
416
417bool AliHLTMiscImplementation::GetAliESDtrackOnlineModeFlag() const
418{
419 /// get status of the online mode flag of AliESDtrack
420 return AliESDtrack::OnlineMode();
421}