]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/rec/AliHLTMiscImplementation.cxx
adding support for the new AliESDHLTDecision class which will allow to store
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTMiscImplementation.cxx
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 // define will be set set from configure.ac, but for now it needs
25 // to be set until the changes in STEER have been committed
26 #define HAVE_NOT_ALIESDHLTDECISION
27
28 #include "AliHLTMiscImplementation.h"
29 #include "AliHLTLogging.h"
30 #include "AliCDBManager.h"
31 #include "AliCDBStorage.h"
32 #include "AliCDBEntry.h"
33 #include "AliGRPManager.h"
34 #include "AliRawReader.h"
35 #include "AliTracker.h"
36 #ifndef HAVE_NOT_ALIESDHLTDECISION
37 #include "AliESDHLTDecision.h"
38 #endif //HAVE_NOT_ALIESDHLTDECISION
39 #include "TGeoGlobalMagField.h"
40 #include "AliHLTGlobalTriggerDecision.h"
41
42 /** ROOT macro for the implementation of ROOT specific class methods */
43 ClassImp(AliHLTMiscImplementation);
44
45 AliHLTMiscImplementation::AliHLTMiscImplementation()
46 {
47 }
48
49 AliHLTMiscImplementation::~AliHLTMiscImplementation()
50 {
51   // see header file for function documentation
52 }
53
54 int AliHLTMiscImplementation::InitCDB(const char* cdbpath)
55 {
56   // see header file for function documentation
57   int iResult=0;
58   AliCDBManager* pCDB = AliCDBManager::Instance();
59   AliHLTLogging log;
60   if (!pCDB) {
61     log.Logging(kHLTLogError, "InitCDB", "CDB handling", "Could not get CDB instance");
62   } else {
63     if (cdbpath && cdbpath[0]!=0) {
64       TString uri=cdbpath;
65       if (!uri.BeginsWith("local://") &&
66           !uri.Contains("://")) {
67         // assume a local path if no uri specifier is found
68         uri="local://";
69         uri+=cdbpath;
70       }
71       pCDB->SetDefaultStorage(uri);
72       log.Logging(kHLTLogDebug, "InitCDB", "CDB handling", "CDB instance 0x%x", pCDB);
73     } else if (!pCDB->IsDefaultStorageSet()) {
74       const char* cdbUri="local://$ALICE_ROOT/OCDB";
75       pCDB->SetDefaultStorage(cdbUri);
76       pCDB->SetRun(0);
77       log.Logging(kHLTLogInfo, "InitCDB", "CDB handling", "set default URI: %s", cdbUri);
78     }
79   }
80   return iResult;
81 }
82
83 int AliHLTMiscImplementation::SetCDBRunNo(int runNo)
84 {
85   // see header file for function documentation
86   int iResult=0;
87   AliCDBManager* pCDB = AliCDBManager::Instance();
88   AliHLTLogging log;
89   if (!pCDB) {
90     log.Logging(kHLTLogError, "SetCDBRunNo", "CDB handling", "Could not get CDB instance");
91   } else {
92     pCDB->SetRun(runNo);
93   }
94   return iResult;
95 }
96
97 AliCDBEntry* AliHLTMiscImplementation::LoadOCDBEntry(const char* path, int runNo, int version, int subVersion)
98 {
99   // see header file for function documentation
100   AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
101   if (!store) {
102     return NULL;
103   }
104   if (version<0) version = store->GetLatestVersion(path, runNo);
105   if (subVersion<0) subVersion = store->GetLatestSubVersion(path, runNo, version);
106   return AliCDBManager::Instance()->Get(path, runNo, version, subVersion);
107 }
108
109 TObject* AliHLTMiscImplementation::ExtractObject(AliCDBEntry* entry)
110 {
111   // see header file for function documentation
112   if (!entry) return NULL;
113   return entry->GetObject();
114 }
115
116 int AliHLTMiscImplementation::InitMagneticField() const
117 {
118   // see header file for function documentation
119
120   // BAD: unit test fails if I call TGeoGlobalMagField::Instance()
121   // at this point. Something goes wrong in the cleaning of the global
122   // ROOT onject
123   /*
124   if (TGeoGlobalMagField::Instance()->GetField()) {
125     // everything set, but think about storing the currents for
126     // a cross-check
127     return 0;
128   }
129   */
130
131   // The magnetic field is initialized once at the start
132   // of run. The fields are supposed to be constant througout the
133   // data taking of one run. The run is aborted if the changes
134   // exceed a certain limit.
135   AliGRPManager grpman;
136   if (grpman.ReadGRPEntry() && grpman.SetMagField()) {
137     return 0;
138   }
139
140   return -ENOENT;
141 }
142
143 AliHLTUInt64_t AliHLTMiscImplementation::GetTriggerMask(AliRawReader* rawReader) const
144 {
145   // see header file for function documentation
146   if (!rawReader) return 0;
147   AliHLTUInt64_t trgMask=0;
148   if (rawReader) {
149     const UInt_t* pattern=rawReader->GetTriggerPattern();
150     trgMask=pattern[1]&0xfffffff; // 28 upper bits of the 50 bit mask
151     trgMask<<=32;
152     trgMask|=pattern[0]; // 32 lower bits of the mask
153   }
154   return trgMask;
155 }
156
157 Double_t AliHLTMiscImplementation::GetBz()
158 {
159   // Returns Bz.
160   return AliTracker::GetBz();
161 }
162
163 Double_t AliHLTMiscImplementation::GetBz(const Double_t *r)
164 {
165   // Returns Bz (kG) at the point "r" .
166   return AliTracker::GetBz(r);
167 }
168
169 void AliHLTMiscImplementation::GetBxByBz(const Double_t r[3], Double_t b[3])
170 {
171   // Returns Bx, By and Bz (kG) at the point "r" .
172   return AliTracker::GetBxByBz(r, b);
173 }
174
175 const TClass* AliHLTMiscImplementation::IsAliESDHLTDecision() const
176 {
177   // Return the IsA of the AliESDHLTDecision class
178 #ifndef HAVE_NOT_ALIESDHLTDECISION
179   return AliESDHLTDecision::Class();
180 #else // HAVE_NOT_ALIESDHLTDECISION
181   return NULL;
182 #endif // HAVE_NOT_ALIESDHLTDECISION
183 }
184
185 int AliHLTMiscImplementation::Copy(const AliHLTGlobalTriggerDecision* pDecision, TObject* object) const
186 {
187   // Copy HLT global trigger decision to AliESDHLTDecision container
188   if (!pDecision || !object) return -EINVAL;
189 #ifndef HAVE_NOT_ALIESDHLTDECISION
190   AliESDHLTDecision* pESDHLTDecision=NULL;
191   if (object->IsA()==NULL ||
192       object->IsA() != AliESDHLTDecision::Class() ||
193       (pESDHLTDecision=dynamic_cast<AliESDHLTDecision*>(object))==NULL) {
194 //     HLTError("can not copy HLT global decision to object of class \"%s\"", 
195 //           object->IsA()?object->IsA()->GetName():"NULL");
196     return -EINVAL;
197   }
198
199   pESDHLTDecision->~AliESDHLTDecision();
200   new (pESDHLTDecision) AliESDHLTDecision(pDecision->GetTitle());
201
202 #endif // HAVE_NOT_ALIESDHLTDECISION
203   return 0;
204 }