]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTModulePreprocessor.cxx
correcting a typo in initialization
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTModulePreprocessor.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   AliHLTModulePreprocessor.cxx
20 // @author Matthias Richter
21 // @date   2008-01-22
22 // @brief  Base class for HLT module preprocessors
23 // 
24
25 #include <cstdlib>
26 #include <cassert>
27 #include "AliHLTModulePreprocessor.h"
28 #include "AliHLTShuttleInterface.h"
29 #include "TObjString.h"
30 #include "TString.h"
31 #include "TMap.h"
32 #include "TObject.h"
33 #include "TObjArray.h"
34
35
36 ClassImp(AliHLTModulePreprocessor)
37
38 AliHLTModulePreprocessor::AliHLTModulePreprocessor() 
39   :
40   fpInterface(NULL),
41   fActiveDetectors(0)
42 {
43   // see header file for class documentation
44   // or
45   // refer to README to build package
46   // or
47   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
48 }
49
50 AliHLTModulePreprocessor::~AliHLTModulePreprocessor() 
51 {
52   // see header file for function documentation
53 }
54
55 // TODO: map this constants to AliHLTDAQ class
56 const Int_t AliHLTModulePreprocessor::kNDetectors = 21;
57
58 const char* AliHLTModulePreprocessor::fgkDetectorName[kNDetectors] = 
59 {
60   "ITSSPD",
61   "ITSSDD",
62   "ITSSSD",
63   "TPC",
64   "TRD",
65   "TOF",
66   "HMPID",
67   "PHOS",
68   "CPV",
69   "PMD",
70   "MUONTRK",
71   "MUONTRG",
72   "FMD",
73   "T0",
74   "VZERO", // Name to be changed to V0 ?
75   "ZDC",
76   "ACORDE",
77   "TRG",
78   "EMCAL",
79   "DAQ_TEST",
80   "HLT"
81 };
82
83 void AliHLTModulePreprocessor::SetShuttleInterface(AliHLTShuttleInterface* pInterface)
84 {
85   assert(fpInterface==NULL || fpInterface==pInterface || pInterface==NULL);
86   fpInterface=pInterface;
87 }
88
89 Int_t AliHLTModulePreprocessor::GetRun() const
90 {
91   // see header file for function documentation
92
93   assert(fpInterface);
94   if (!fpInterface) return 0;
95   return fpInterface->PreprocessorGetRun();
96 }
97
98 UInt_t AliHLTModulePreprocessor::GetStartTime() const
99 {
100   // see header file for function documentation
101
102   assert(fpInterface);
103   if (!fpInterface) return 0;
104   return fpInterface->PreprocessorGetStartTime();
105 }
106
107 UInt_t AliHLTModulePreprocessor::GetEndTime() const
108 {
109   // see header file for function documentation
110
111   assert(fpInterface);
112   if (!fpInterface) return 0;
113   return fpInterface->PreprocessorGetEndTime();
114 }
115
116 Bool_t AliHLTModulePreprocessor::Store(const char* pathLevel2, const char* pathLevel3, TObject* object,
117                                  AliCDBMetaData* metaData, Int_t validityStart, Bool_t validityInfinite)
118 {
119   // see header file for function documentation
120
121   assert(fpInterface);
122   if (!fpInterface) return 0;
123   return fpInterface->PreprocessorStore(pathLevel2, pathLevel3, object, metaData, validityStart, validityInfinite);
124 }
125
126 Bool_t AliHLTModulePreprocessor::StoreReferenceData(const char* pathLevel2, const char* pathLevel3, TObject* object,
127                                               AliCDBMetaData* metaData)
128 {
129   // see header file for function documentation
130
131   assert(fpInterface);
132   if (!fpInterface) return 0;
133   return fpInterface->PreprocessorStoreReferenceData(pathLevel2, pathLevel3, object, metaData);
134 }
135
136 Bool_t AliHLTModulePreprocessor::StoreReferenceFile(const char* localFile, const char* gridFileName)
137 {
138   // see header file for function documentation
139
140   assert(fpInterface);
141   if (!fpInterface) return 0;
142   return fpInterface->PreprocessorStoreReferenceFile(localFile, gridFileName);
143 }
144
145 Bool_t AliHLTModulePreprocessor::StoreRunMetadataFile(const char* localFile, const char* gridFileName)
146 {
147   // see header file for function documentation
148
149   assert(fpInterface);
150   if (!fpInterface) return 0;
151   return fpInterface->PreprocessorStoreRunMetadataFile(localFile, gridFileName);
152 }
153     
154 const char* AliHLTModulePreprocessor::GetFile(Int_t system, const char* id, const char* source)
155 {
156   // see header file for function documentation
157
158   assert(fpInterface);
159   if (!fpInterface) return 0;
160   return fpInterface->PreprocessorGetFile(system, id, source);
161 }
162
163 TList* AliHLTModulePreprocessor::GetFileSources(Int_t system, const char* id)
164 {
165   // see header file for function documentation
166
167   assert(fpInterface);
168   if (!fpInterface) return 0;
169   return fpInterface->PreprocessorGetFileSources(system, id);
170 }
171
172 TList* AliHLTModulePreprocessor::GetFileIDs(Int_t system, const char* source)
173 {
174   // see header file for function documentation
175
176   assert(fpInterface);
177   if (!fpInterface) return 0;
178   return fpInterface->PreprocessorGetFileIDs(system, source);
179 }
180
181 const char* AliHLTModulePreprocessor::GetRunParameter(const char* param)
182 {
183   // see header file for function documentation
184
185   assert(fpInterface);
186   if (!fpInterface) return 0;
187   return fpInterface->PreprocessorGetRunParameter(param);
188 }
189
190 AliCDBEntry* AliHLTModulePreprocessor::GetFromOCDB(const char* pathLevel2, const char* pathLevel3)
191 {
192   // see header file for function documentation
193
194   assert(fpInterface);
195   if (!fpInterface) return 0;
196   return fpInterface->PreprocessorGetFromOCDB(pathLevel2, pathLevel3);
197 }
198
199 const char* AliHLTModulePreprocessor::GetRunType()
200 {
201   // see header file for function documentation
202
203   assert(fpInterface);
204   if (!fpInterface) return 0;
205   return fpInterface->PreprocessorGetRunType();
206 }
207
208 void AliHLTModulePreprocessor::Log(const char* message)
209 {
210   // see header file for function documentation
211
212   assert(fpInterface);
213   if (!fpInterface) return;
214   fpInterface->PreprocessorLog(message);
215 }
216
217 Int_t AliHLTModulePreprocessor::DetectorBitMask(const char *detectorName)
218 {
219   // Return the detector index
220   // corresponding to a given
221   // detector name
222   TString detStr = detectorName;
223
224   Int_t iDet;
225   for(iDet = 0; iDet < kNDetectors; iDet++) {
226     if (detStr.CompareTo(fgkDetectorName[iDet],TString::kIgnoreCase) == 0)
227       break;
228   }
229   if (iDet == kNDetectors) 
230     {
231       TString errormessage;
232       errormessage.Form("Invalid detector name: %s !",detectorName);
233       Log(errormessage.Data());
234       return -1;
235     }
236
237   Int_t detectorbitmask = 0;
238   if(iDet > 32)
239     {
240       TString errormessage2;
241       errormessage2.Form("Invalid detector bit position in detectorMask: %d !", iDet);
242       Log(errormessage2.Data());
243       return -1;
244     }
245   
246   detectorbitmask = (1 << iDet);
247   return detectorbitmask;
248 }
249
250 Bool_t AliHLTModulePreprocessor::GetDetectorStatus(Int_t detectorbitmask)
251 {
252   // see header file for function documentation
253   // retrieve list of active detectors from previous run.
254   fActiveDetectors = atoi(AliHLTModulePreprocessor::GetRunParameter("detectorMask"));
255  
256   if((fActiveDetectors & detectorbitmask) != 0)
257     {
258       return 1;
259     }
260   else
261     {
262       return 0;
263     }
264 }
265
266 // function copied from AliDAQ.cxx
267 const char *AliHLTModulePreprocessor::DetectorName(Int_t detectorID)
268 {
269   // Returns the name of particular
270   // detector identified by its index
271   if (detectorID < 0 || detectorID >= kNDetectors) 
272     {
273       TString errormessage;
274       errormessage.Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1);
275       Log(errormessage.Data());
276       return "";
277     }
278   return fgkDetectorName[detectorID];
279 }
280
281 TObject* AliHLTModulePreprocessor::GetFromMap(TMap* dcsAliasMap, const char* stringId) const
282 {
283   /// extract object from the alias map
284   /// return the last object from the value set
285   TObject* object=dcsAliasMap->FindObject(stringId);
286   if (!object) return NULL;
287   TPair* pair = dynamic_cast<TPair*>(object);
288   if (pair && pair->Value()) {
289     TObjArray* valueSet = dynamic_cast<TObjArray*>(pair->Value());
290     if (!valueSet) return NULL;
291     Int_t nentriesDCS = valueSet->GetEntriesFast() - 1;
292     if(nentriesDCS>=0 && valueSet->At(nentriesDCS)){
293       return valueSet->At(nentriesDCS);
294     }
295   }
296   return NULL;
297 }