]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/EMCAL/AliHLTEMCALClusterizerComponent.cxx
Extacting the OCDB in a separate module. The detectors have write permission in the...
[u/mrichter/AliRoot.git] / HLT / EMCAL / AliHLTEMCALClusterizerComponent.cxx
CommitLineData
4a8f32a0 1/**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
6 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
7 * for The ALICE HLT Project. *
8 * *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
18/** @file AliHLTEMCALClusterizerComponent.cxx
19 @author Mateusz Ploskon
20 @date
21 @brief EMCAL clusterizer component for HLT. */
22
23#if __GNUC__== 3
24using namespace std;
25#endif
26
27#include "AliHLTEMCALClusterizerComponent.h"
28#include "AliHLTEMCALDefinitions.h"
a558187d 29#include "AliHLTEMCALUtils.h"
4a8f32a0 30
31#include "TString.h"
32#include "TObjString.h"
33#include "TObjArray.h"
a558187d 34#include "TTree.h"
4a8f32a0 35#include "AliCDBEntry.h"
36#include "AliCDBManager.h"
a558187d 37#include "AliRawReaderMemory.h"
38
39// this is a global object used for automatic component registration, do not use this
40AliHLTEMCALClusterizerComponent gAliHLTEMCALClusterizerComponent;
4a8f32a0 41
42/** ROOT macro for the implementation of ROOT specific class methods */
43ClassImp(AliHLTEMCALClusterizerComponent)
44
45AliHLTEMCALClusterizerComponent::AliHLTEMCALClusterizerComponent()
46 : AliHLTProcessor()
47 , fOutputPercentage(100)
162637e4 48 , fStorageDBpath("local://$ALICE_ROOT/OCDB")
4a8f32a0 49 , fCDB(NULL)
4a8f32a0 50 , fGeometryFileName("")
4a8f32a0 51{
52 // see header file for class documentation
53 // or
54 // refer to README to build package
55 // or
56 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
57}
58
59AliHLTEMCALClusterizerComponent::AliHLTEMCALClusterizerComponent(const AliHLTEMCALClusterizerComponent &/*c*/)
60 : AliHLTProcessor()
61 , fOutputPercentage(100)
162637e4 62 , fStorageDBpath("local://$ALICE_ROOT/OCDB")
4a8f32a0 63 , fCDB(NULL)
4a8f32a0 64 , fGeometryFileName("")
4a8f32a0 65{
66 // may not use the copy contructor
67 HLTError("May not use.");
68}
69
70AliHLTEMCALClusterizerComponent& AliHLTEMCALClusterizerComponent::operator=(const AliHLTEMCALClusterizerComponent&)
71{
72 // may not use the copy contructor
73 HLTError("May not use.");
74 return *this;
75}
76
77AliHLTEMCALClusterizerComponent::~AliHLTEMCALClusterizerComponent()
78{
79 // see header file for class documentation
80}
81
82AliHLTComponentDataType AliHLTEMCALClusterizerComponent::GetOutputDataType()
83{
a558187d 84 //return AliHLTEMCALDefinitions::fgkClusterDataType | AliHLTEMCALDefinitions::fgkDigitDataType;
4a8f32a0 85 return AliHLTEMCALDefinitions::fgkClusterDataType;
86}
87
a558187d 88const char* AliHLTEMCALClusterizerComponent::GetComponentID()
89{
90 return "EMCALClusterizer";
91}
92
93void AliHLTEMCALClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
94{
95 list.push_back(kAliHLTAnyDataType);
96}
97
98void AliHLTEMCALClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
99{
100 constBase = 0;
101 inputMultiplier = ((double)fOutputPercentage)/100.0;
102}
103
4a8f32a0 104int AliHLTEMCALClusterizerComponent::DoInit( int argc, const char** argv )
105{
106 // see header file for class documentation
107 int iResult=0;
108 HLTInfo("parsing %d arguments", argc);
109
110 TString argument="";
111 TString configuration="";
112 int bMissingParam=0;
113 bool bHaveMandatory1=false;
114 bool bHaveMandatory2=false;
115
116 char *cpErr = 0;
117
a558187d 118 for (int i=0; i<argc && iResult>=0; i++)
119 {
120 argument=argv[i];
121 if (argument.IsNull()) continue;
4a8f32a0 122
123 // -mandatory1
a558187d 124 if (argument.CompareTo("-cdb")==0)
125 {
126 bHaveMandatory1|=1;
127 if ((bMissingParam=(++i>=argc))) break;
128 HLTInfo("got \'-cdb\' argument: %s", argv[i]);
129 fStorageDBpath = argv[i];
130 HLTInfo("CDB path is: %s", fStorageDBpath.c_str());
131 // -mandatory2
132 }
133 else if (argument.CompareTo("-geometry")==0)
134 {
135 bHaveMandatory2|=1;
136 if ((bMissingParam=(++i>=argc))) break;
137 HLTInfo("got \'-geometry\' argument");
138 fGeometryFileName = argv[i];
139 HLTInfo("Geometry file is: %s", fGeometryFileName.c_str());
140 // -optional1
141 }
142 else if (argument.CompareTo("-output_percentage")==0)
143 {
144 if ((bMissingParam=(++i>=argc))) break;
145 HLTInfo("got \'-output_percentage\' argument: %s", argv[i]);
146 fOutputPercentage = strtoul(argv[i], &cpErr, 0);
147 if ( *cpErr )
148 {
149 HLTError("Unable to convert ouput_percentage to a number %s", argv[i]);
150 return -EINVAL;
151 }
152 }
153 else
154 {
155 // the remaining arguments are treated as configuration
156 if (!configuration.IsNull()) configuration+=" ";
157 configuration+=argument;
158 }
159 }
4a8f32a0 160
a558187d 161 if (bMissingParam)
162 {
163 HLTError("missing parameter for argument %s", argument.Data());
164 iResult=-EINVAL;
165 }
4a8f32a0 166
a558187d 167 if (iResult>=0 && !bHaveMandatory1)
168 {
169 HLTError("mandatory argument \'-cdb\' missing");
170 iResult=-EPROTO;
4a8f32a0 171 }
4a8f32a0 172
a558187d 173 if (iResult>=0 && !bHaveMandatory2)
174 {
175 HLTError("mandatory argument \'-geometry\' missing");
176 iResult=-EPROTO;
177 }
178
179 if (iResult>=0 && !configuration.IsNull())
180 {
181 iResult=Configure(configuration.Data());
182 }
183 else
184 {
185 iResult=Reconfigure(NULL, NULL);
186 }
187
188 // Initialize here
189 // raw reader
190
191 // geometry
192 if (AliHLTEMCALUtils::GetGeometry() == NULL)
193 {
194 HLTError("unable to init geometry");
195 iResult=-EPROTO;
196 }
197
198 // OCDB
199
200 // clusterizer and raw utils
201 if (AliHLTEMCALUtils::GetRawUtils() == NULL)
202 {
203 HLTError("unable to init rawutils");
204 iResult=-EPROTO;
205 }
206
207 if (AliHLTEMCALUtils::GetRawUtils() == NULL)
208 {
209 HLTError("unable to init rawutils");
210 iResult=-EPROTO;
211 }
212
213 if (AliHLTEMCALUtils::GetRecParam() == NULL)
214 {
215 HLTError("unable to init reco params");
216 iResult=-EPROTO;
217 }
218
219 if (AliHLTEMCALUtils::GetClusterizer() == NULL)
220 {
221 HLTError("unable to init clusterizer");
222 iResult=-EPROTO;
223 }
4a8f32a0 224
225 return iResult;
226}
227
228int AliHLTEMCALClusterizerComponent::DoDeinit()
229{
230 // see header file for class documentation
a558187d 231 AliHLTEMCALUtils::Cleanup();
4a8f32a0 232 HLTInfo("processing cleanup");
233 return 0;
234}
235
236int AliHLTEMCALClusterizerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
237 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
238 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks ) {
239 // see header file for class documentation
a558187d 240 // check if the input data are there at all - empty events possible
241 HLTDebug("processing data");
4a8f32a0 242 if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0 &&
243 outputPtr==0 && size==0)
244 {
245 outputBlocks.clear();
246 // this is just to get rid of the warning "unused parameter"
a558187d 247 return 0;
4a8f32a0 248 }
a558187d 249
250 UChar_t *buffer = 0;
251 ULong_t buffSize = 0;
252 Int_t eqID = 4608; //fixed for the moment - get this one from the input data
253 TString recoOption = "";
254 AliHLTUInt32_t dBlockSpecification = 0;
255
256 // Loop over all input blocks in the event
257 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
258 {
259 //if (blocks[i].fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginEMCAL))
260 if (blocks[i].fDataType != (kAliHLTDataTypeDDLRaw)) // for the moment until we have the EMCAL in the publisher setup
261 {
262 HLTWarning("COMPARE FAILED received type=%d expected-or-type=%d",
263 blocks[i].fDataType, kAliHLTDataTypeDDLRaw | kAliHLTDataOriginEMCAL);
264 continue;
265 }
266
267 dBlockSpecification = blocks[i].fSpecification;
268 unsigned long blockSize = blocks[i].fSize;
269 buffSize += blockSize;
270 }
271
272 buffer = (UChar_t*)calloc(buffSize, 1);
273 AliHLTUInt8_t *pBuf = (AliHLTUInt8_t *)buffer;
274 if (buffer == NULL)
275 {
276 HLTError("Unable to allocate %lu bytes", buffSize);
277 return -1;
278 }
279
280 // Make the memory continous
281 unsigned long copied = 0;
282 for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
283 {
284 // we process only the raw data from TRD
285 if ( blocks[i].fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginEMCAL) )
286 continue;
287
288 void *pos = (void*)(pBuf + copied);
289 void *copyret = memcpy(pos, blocks[i].fPtr, blocks[i].fSize);
290 if (copyret < 0)
291 {
292 HLTError("MEMORY Unable to copy %lu bytes", blocks[i].fSize);
293 return -1;
294 }
295 copied += blocks[i].fSize;
296 }
297
298 // do it all function RAW->ClusterTree
299 // TTree* AliHLTEMCALUtils::RawBuffer2Clusters(UChar_t *buffer, ULong_t buffSize,
300 // Int_t eqID,
301 // Option_t* sDigitsOption)
302
303 AliHLTEMCALUtils::ResetReconstructionTrees();
304 TTree* outputTree = AliHLTEMCALUtils::RawBuffer2Clusters(buffer, buffSize, eqID, recoOption.Data());
305 PushBack(outputTree, AliHLTEMCALDefinitions::fgkClusterDataType);
306
307 TTree *digitsTree = AliHLTEMCALUtils::GetDigitsTree();
308 PushBack(digitsTree, AliHLTEMCALDefinitions::fgkDigitDataType);
309
310 free(buffer);
311
4a8f32a0 312 return 0;
313}
314
315int AliHLTEMCALClusterizerComponent::Configure(const char* arguments)
316{
317 // see header file for class documentation
318 int iResult=0;
319 if (!arguments) return iResult;
320 HLTInfo("parsing configuration string \'%s\'", arguments);
321
a558187d 322 TString allArgs = arguments;
4a8f32a0 323 TString argument;
324 int bMissingParam=0;
325
a558187d 326 TObjArray* pTokens = allArgs.Tokenize(" ");
327 if (pTokens)
328 {
329 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++)
330 {
331 argument=((TObjString*)pTokens->At(i))->GetString();
332 if (argument.IsNull()) continue;
333 HLTInfo("processing argument %\n", argument.Data());
334 // -config1
335 if (argument.CompareTo("-cdb")==0)
336 {
337 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
338 HLTInfo("got \'-cdb\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
339 // -config2
340 }
341 else if (argument.CompareTo("-geometry")==0)
342 {
343 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
344 HLTInfo("got \'-geometry\'");
345 }
346 else if (argument.CompareTo("-output_percentage")==0)
347 {
348 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
349 HLTInfo("got \'-output_percentage\'");
350 }
351 else
352 {
353 HLTError("unknown argument %s", argument.Data());
354 iResult=-EINVAL;
355 break;
356 }
357 }
358 delete pTokens;
359 }
4a8f32a0 360
a558187d 361 if (bMissingParam)
362 {
363 HLTError("missing parameter for argument %s", argument.Data());
364 iResult=-EINVAL;
4a8f32a0 365 }
a558187d 366
4a8f32a0 367 return iResult;
368}
369
370int AliHLTEMCALClusterizerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
371{
372 // see header file for class documentation
373 int iResult=0;
a558187d 374 const char* path="HLT/ConfigEMCAL/EMCALClusterizerComponent";
4a8f32a0 375 const char* defaultNotify="";
a558187d 376 if (cdbEntry)
377 {
378 path=cdbEntry;
379 defaultNotify=" (default)";
380 }
381 if (path)
382 {
383 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
384 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
385 if (pEntry)
386 {
387 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
388 if (pString)
389 {
390 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
391 iResult=Configure(pString->GetString().Data());
392 } else
393 {
394 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
395 }
396 }
397 else
398 {
399 HLTError("can not fetch object \"%s\" from CDB", path);
400 }
4a8f32a0 401 }
4a8f32a0 402 return iResult;
403}
404
405int AliHLTEMCALClusterizerComponent::ReadPreprocessorValues(const char* modules)
406{
407 // see header file for class documentation
408 int iResult=0;
409 TString detectors(modules!=NULL?modules:"");
410 HLTInfo("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data());
411 return iResult;
412}