adding availability check for a list of OCDB objects, code cleanup and updated docume...
[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"
26#include "AliCDBManager.h"
22d17395 27#include "AliCDBStorage.h"
2b545cdd 28#include "AliCDBEntry.h"
cc484ed9 29#include "AliGRPManager.h"
73305a93 30#include "AliRawReader.h"
a5e775ec 31#include "AliTracker.h"
8cc935e5 32#ifndef HAVE_NOT_ALIESDHLTDECISION
95ea76b5 33#include "AliESDHLTDecision.h"
8cc935e5 34#endif //HAVE_NOT_ALIESDHLTDECISION
cc484ed9 35#include "TGeoGlobalMagField.h"
95ea76b5 36#include "AliHLTGlobalTriggerDecision.h"
2b545cdd 37
38/** ROOT macro for the implementation of ROOT specific class methods */
39ClassImp(AliHLTMiscImplementation);
40
41AliHLTMiscImplementation::AliHLTMiscImplementation()
42{
43}
44
45AliHLTMiscImplementation::~AliHLTMiscImplementation()
46{
47 // see header file for function documentation
48}
49
50int AliHLTMiscImplementation::InitCDB(const char* cdbpath)
51{
52 // see header file for function documentation
53 int iResult=0;
54 AliCDBManager* pCDB = AliCDBManager::Instance();
55 AliHLTLogging log;
56 if (!pCDB) {
57 log.Logging(kHLTLogError, "InitCDB", "CDB handling", "Could not get CDB instance");
58 } else {
59 if (cdbpath && cdbpath[0]!=0) {
cc484ed9 60 TString uri=cdbpath;
61 if (!uri.BeginsWith("local://") &&
62 !uri.Contains("://")) {
63 // assume a local path if no uri specifier is found
64 uri="local://";
65 uri+=cdbpath;
66 }
67 pCDB->SetDefaultStorage(uri);
2b545cdd 68 log.Logging(kHLTLogDebug, "InitCDB", "CDB handling", "CDB instance 0x%x", pCDB);
69 } else if (!pCDB->IsDefaultStorageSet()) {
70 const char* cdbUri="local://$ALICE_ROOT/OCDB";
71 pCDB->SetDefaultStorage(cdbUri);
72 pCDB->SetRun(0);
73 log.Logging(kHLTLogInfo, "InitCDB", "CDB handling", "set default URI: %s", cdbUri);
74 }
75 }
76 return iResult;
77}
78
79int AliHLTMiscImplementation::SetCDBRunNo(int runNo)
80{
81 // see header file for function documentation
82 int iResult=0;
83 AliCDBManager* pCDB = AliCDBManager::Instance();
84 AliHLTLogging log;
85 if (!pCDB) {
cc484ed9 86 log.Logging(kHLTLogError, "SetCDBRunNo", "CDB handling", "Could not get CDB instance");
2b545cdd 87 } else {
88 pCDB->SetRun(runNo);
89 }
90 return iResult;
91}
92
74c1905c 93int AliHLTMiscImplementation::GetCDBRunNo() const
df5d2b78 94{
95 // see header file for function documentation
96 AliCDBManager* pCDB = AliCDBManager::Instance();
97 AliHLTLogging log;
98 if (!pCDB) {
99 log.Logging(kHLTLogError, "SetCDBRunNo", "CDB handling", "Could not get CDB instance");
100 } else {
101 return pCDB->GetRun();
102 }
103 return -1;
104}
105
74c1905c 106AliCDBEntry* AliHLTMiscImplementation::LoadOCDBEntry(const char* path, int runNo, int version, int subVersion) const
2b545cdd 107{
108 // see header file for function documentation
22d17395 109 AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
110 if (!store) {
111 return NULL;
112 }
113 if (version<0) version = store->GetLatestVersion(path, runNo);
114 if (subVersion<0) subVersion = store->GetLatestSubVersion(path, runNo, version);
74c1905c 115 return store->Get(path, runNo, version, subVersion);
2b545cdd 116}
117
74c1905c 118TObject* AliHLTMiscImplementation::ExtractObject(AliCDBEntry* entry) const
2b545cdd 119{
120 // see header file for function documentation
121 if (!entry) return NULL;
122 return entry->GetObject();
123}
124
74c1905c 125int AliHLTMiscImplementation::CheckOCDBEntries(const TMap* const pMap) const
126{
127 // check the availability of the OCDB entry descriptions in the TMap
128 // key : complete OCDB path of the entry
129 // value : auxiliary object - short description
130 int iResult=0;
131 if (!pMap) return -EINVAL;
132
133 const TMap* pStorages=AliCDBManager::Instance()->GetStorageMap();
134 Int_t runNo = GetCDBRunNo();
135
136 TIterator* next=pMap->MakeIterator();
137 TObject* pEntry=NULL;
138 while ((pEntry=next->Next())) {
139 // check if the entry has specific storage
140 AliCDBStorage* pStorage=NULL;
141 TObject* pStorageId=pStorages->GetValue(pEntry->GetName());
142 if (pStorageId) {
143 pStorage=AliCDBManager::Instance()->GetStorage(pStorageId->GetName());
144 } else {
145 pStorage=AliCDBManager::Instance()->GetDefaultStorage();
146 }
147
148 if (pStorage->GetLatestVersion(pEntry->GetName(), runNo)<0) {
149 AliHLTLogging log;
150 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());
151 iResult=-ENOENT;
152 } else {
153 AliHLTLogging log;
154 log.Logging(kHLTLogDebug, "CheckOCDBEntries", "CDB handling", "found required OCDB object %s for run number %d in storage %s", pEntry->GetName(), runNo, pStorage->GetURI().Data());
155 }
156 }
157
158 return iResult;
159}
160
cc484ed9 161int AliHLTMiscImplementation::InitMagneticField() const
2b545cdd 162{
cc484ed9 163 // see header file for function documentation
164
165 // BAD: unit test fails if I call TGeoGlobalMagField::Instance()
166 // at this point. Something goes wrong in the cleaning of the global
167 // ROOT onject
168 /*
169 if (TGeoGlobalMagField::Instance()->GetField()) {
170 // everything set, but think about storing the currents for
171 // a cross-check
172 return 0;
2b545cdd 173 }
cc484ed9 174 */
2b545cdd 175
cc484ed9 176 // The magnetic field is initialized once at the start
177 // of run. The fields are supposed to be constant througout the
178 // data taking of one run. The run is aborted if the changes
179 // exceed a certain limit.
180 AliGRPManager grpman;
181 if (grpman.ReadGRPEntry() && grpman.SetMagField()) {
182 return 0;
2b545cdd 183 }
cc484ed9 184
185 return -ENOENT;
2b545cdd 186}
73305a93 187
188AliHLTUInt64_t AliHLTMiscImplementation::GetTriggerMask(AliRawReader* rawReader) const
189{
190 // see header file for function documentation
191 if (!rawReader) return 0;
192 AliHLTUInt64_t trgMask=0;
193 if (rawReader) {
194 const UInt_t* pattern=rawReader->GetTriggerPattern();
195 trgMask=pattern[1]&0xfffffff; // 28 upper bits of the 50 bit mask
196 trgMask<<=32;
197 trgMask|=pattern[0]; // 32 lower bits of the mask
198 }
199 return trgMask;
200}
a5e775ec 201
202Double_t AliHLTMiscImplementation::GetBz()
203{
204 // Returns Bz.
205 return AliTracker::GetBz();
206}
207
208Double_t AliHLTMiscImplementation::GetBz(const Double_t *r)
209{
210 // Returns Bz (kG) at the point "r" .
211 return AliTracker::GetBz(r);
212}
213
214void AliHLTMiscImplementation::GetBxByBz(const Double_t r[3], Double_t b[3])
215{
216 // Returns Bx, By and Bz (kG) at the point "r" .
217 return AliTracker::GetBxByBz(r, b);
218}
95ea76b5 219
220const TClass* AliHLTMiscImplementation::IsAliESDHLTDecision() const
221{
222 // Return the IsA of the AliESDHLTDecision class
8cc935e5 223#ifndef HAVE_NOT_ALIESDHLTDECISION
95ea76b5 224 return AliESDHLTDecision::Class();
8cc935e5 225#else // HAVE_NOT_ALIESDHLTDECISION
95ea76b5 226 return NULL;
8cc935e5 227#endif // HAVE_NOT_ALIESDHLTDECISION
95ea76b5 228}
229
230int AliHLTMiscImplementation::Copy(const AliHLTGlobalTriggerDecision* pDecision, TObject* object) const
231{
232 // Copy HLT global trigger decision to AliESDHLTDecision container
233 if (!pDecision || !object) return -EINVAL;
8cc935e5 234#ifndef HAVE_NOT_ALIESDHLTDECISION
95ea76b5 235 AliESDHLTDecision* pESDHLTDecision=NULL;
236 if (object->IsA()==NULL ||
237 object->IsA() != AliESDHLTDecision::Class() ||
238 (pESDHLTDecision=dynamic_cast<AliESDHLTDecision*>(object))==NULL) {
239// HLTError("can not copy HLT global decision to object of class \"%s\"",
240// object->IsA()?object->IsA()->GetName():"NULL");
241 return -EINVAL;
242 }
243
244 pESDHLTDecision->~AliESDHLTDecision();
84f84689 245 new (pESDHLTDecision) AliESDHLTDecision(pDecision->Result(), pDecision->GetTitle());
95ea76b5 246
8cc935e5 247#endif // HAVE_NOT_ALIESDHLTDECISION
95ea76b5 248 return 0;
249}