Removal of memory leaks (Laurent)
[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"
cc484ed9 32#include "TGeoGlobalMagField.h"
2b545cdd 33
34/** ROOT macro for the implementation of ROOT specific class methods */
35ClassImp(AliHLTMiscImplementation);
36
37AliHLTMiscImplementation::AliHLTMiscImplementation()
38{
39}
40
41AliHLTMiscImplementation::~AliHLTMiscImplementation()
42{
43 // see header file for function documentation
44}
45
46int AliHLTMiscImplementation::InitCDB(const char* cdbpath)
47{
48 // see header file for function documentation
49 int iResult=0;
50 AliCDBManager* pCDB = AliCDBManager::Instance();
51 AliHLTLogging log;
52 if (!pCDB) {
53 log.Logging(kHLTLogError, "InitCDB", "CDB handling", "Could not get CDB instance");
54 } else {
55 if (cdbpath && cdbpath[0]!=0) {
cc484ed9 56 TString uri=cdbpath;
57 if (!uri.BeginsWith("local://") &&
58 !uri.Contains("://")) {
59 // assume a local path if no uri specifier is found
60 uri="local://";
61 uri+=cdbpath;
62 }
63 pCDB->SetDefaultStorage(uri);
2b545cdd 64 log.Logging(kHLTLogDebug, "InitCDB", "CDB handling", "CDB instance 0x%x", pCDB);
65 } else if (!pCDB->IsDefaultStorageSet()) {
66 const char* cdbUri="local://$ALICE_ROOT/OCDB";
67 pCDB->SetDefaultStorage(cdbUri);
68 pCDB->SetRun(0);
69 log.Logging(kHLTLogInfo, "InitCDB", "CDB handling", "set default URI: %s", cdbUri);
70 }
71 }
72 return iResult;
73}
74
75int AliHLTMiscImplementation::SetCDBRunNo(int runNo)
76{
77 // see header file for function documentation
78 int iResult=0;
79 AliCDBManager* pCDB = AliCDBManager::Instance();
80 AliHLTLogging log;
81 if (!pCDB) {
cc484ed9 82 log.Logging(kHLTLogError, "SetCDBRunNo", "CDB handling", "Could not get CDB instance");
2b545cdd 83 } else {
84 pCDB->SetRun(runNo);
85 }
86 return iResult;
87}
88
89AliCDBEntry* AliHLTMiscImplementation::LoadOCDBEntry(const char* path, int runNo, int version, int subVersion)
90{
91 // see header file for function documentation
22d17395 92 AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
93 if (!store) {
94 return NULL;
95 }
96 if (version<0) version = store->GetLatestVersion(path, runNo);
97 if (subVersion<0) subVersion = store->GetLatestSubVersion(path, runNo, version);
2b545cdd 98 return AliCDBManager::Instance()->Get(path, runNo, version, subVersion);
99}
100
101TObject* AliHLTMiscImplementation::ExtractObject(AliCDBEntry* entry)
102{
103 // see header file for function documentation
104 if (!entry) return NULL;
105 return entry->GetObject();
106}
107
cc484ed9 108int AliHLTMiscImplementation::InitMagneticField() const
2b545cdd 109{
cc484ed9 110 // see header file for function documentation
111
112 // BAD: unit test fails if I call TGeoGlobalMagField::Instance()
113 // at this point. Something goes wrong in the cleaning of the global
114 // ROOT onject
115 /*
116 if (TGeoGlobalMagField::Instance()->GetField()) {
117 // everything set, but think about storing the currents for
118 // a cross-check
119 return 0;
2b545cdd 120 }
cc484ed9 121 */
2b545cdd 122
cc484ed9 123 // The magnetic field is initialized once at the start
124 // of run. The fields are supposed to be constant througout the
125 // data taking of one run. The run is aborted if the changes
126 // exceed a certain limit.
127 AliGRPManager grpman;
128 if (grpman.ReadGRPEntry() && grpman.SetMagField()) {
129 return 0;
2b545cdd 130 }
cc484ed9 131
132 return -ENOENT;
2b545cdd 133}
73305a93 134
135AliHLTUInt64_t AliHLTMiscImplementation::GetTriggerMask(AliRawReader* rawReader) const
136{
137 // see header file for function documentation
138 if (!rawReader) return 0;
139 AliHLTUInt64_t trgMask=0;
140 if (rawReader) {
141 const UInt_t* pattern=rawReader->GetTriggerPattern();
142 trgMask=pattern[1]&0xfffffff; // 28 upper bits of the 50 bit mask
143 trgMask<<=32;
144 trgMask|=pattern[0]; // 32 lower bits of the mask
145 }
146 return trgMask;
147}
a5e775ec 148
149Double_t AliHLTMiscImplementation::GetBz()
150{
151 // Returns Bz.
152 return AliTracker::GetBz();
153}
154
155Double_t AliHLTMiscImplementation::GetBz(const Double_t *r)
156{
157 // Returns Bz (kG) at the point "r" .
158 return AliTracker::GetBz(r);
159}
160
161void AliHLTMiscImplementation::GetBxByBz(const Double_t r[3], Double_t b[3])
162{
163 // Returns Bx, By and Bz (kG) at the point "r" .
164 return AliTracker::GetBxByBz(r, b);
165}