- fixing compilation warning
[u/mrichter/AliRoot.git] / HLT / CALO / AliHLTCaloClusterizerComponent.cxx
CommitLineData
4d42193f 1// $Id: AliHLTCaloClusterizerComponent.cxx 36709 2009-11-12 16:57:55Z odjuvsla $
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Oystein Djuvsland <oysteind@ift.uib.no> *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
4d42193f 17#include "AliHLTCaloClusterizerComponent.h"
18#include "AliHLTCaloClusterizer.h"
7c80a370 19#include "AliHLTCaloClusterAnalyser.h"
4d42193f 20#include "AliHLTCaloRecPointDataStruct.h"
21#include "AliHLTCaloRecPointHeaderStruct.h"
22#include "AliHLTCaloDigitDataStruct.h"
23#include "AliHLTCaloDigitContainerDataStruct.h"
24#include "AliHLTCaloDefinitions.h"
7c80a370 25#include "AliHLTCaloClusterDataStruct.h"
c1e4a18c 26#include "AliHLTCaloRecoParamHandler.h"
ad44d760 27#include "TString.h"
4d42193f 28
29/** @file AliHLTCaloClusterizerComponent.cxx
30 @author Oystein Djuvsland
31 @date
32 @brief A clusterizer component for PHOS HLT
33*/
34
35// see header file for class documentation
36// or
37// refer to README to build package
38// or
39// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
40
ad44d760 41AliHLTCaloClusterizerComponent::AliHLTCaloClusterizerComponent(TString det):
ad44d760 42 AliHLTCaloProcessor(),
f92dcf21 43 AliHLTCaloConstantsHandler(det),
98baf84d 44 fDataOrigin('\0'),
45 fAnalyserPtr(0),
c1e4a18c 46 fRecoParamsPtr(0),
f92dcf21 47 fDigitsPointerArray(0),
98baf84d 48 fOutputDigitsArray(0),
4d42193f 49 fClusterizerPtr(0),
427c373f 50 fDigitCount(0)
4d42193f 51{
52 //See headerfile for documentation
a6db7bcd 53
427c373f 54
a6db7bcd 55
4d42193f 56}
57
58AliHLTCaloClusterizerComponent::~AliHLTCaloClusterizerComponent()
59{
60 //See headerfile for documentation
73d6f579 61delete fAnalyserPtr;
4d42193f 62 if(fClusterizerPtr)
63 {
64 delete fClusterizerPtr;
65 fClusterizerPtr = 0;
66 }
4d42193f 67}
68
4d42193f 69int
70AliHLTCaloClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
71 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
72 std::vector<AliHLTComponentBlockData>& outputBlocks)
73{
74 //See headerfile for documentation
75
76 if(blocks == 0) return 0;
77
78 UInt_t offset = 0;
79 UInt_t mysize = 0;
80 Int_t nRecPoints = 0;
81 Int_t nDigits = 0;
ad44d760 82 Int_t digCount = 0;
4d42193f 83
7c80a370 84 UInt_t availableSize = size;
4d42193f 85 AliHLTUInt8_t* outBPtr;
86 outBPtr = outputPtr;
87 const AliHLTComponentBlockData* iter = 0;
88 unsigned long ndx;
89
90 UInt_t specification = 0;
91
92 AliHLTCaloDigitDataStruct *digitDataPtr = 0;
427c373f 93
4d42193f 94 // Adding together all the digits, should be put in standalone method
95 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
96 {
97 iter = blocks+ndx;
ad44d760 98 // HLTError("Got block");
7c80a370 99 if (iter->fDataType == (AliHLTCaloDefinitions::fgkDigitDataType|fDataOrigin))
4d42193f 100 {
70c86cde 101
102 // Update the number of digits
103 nDigits = iter->fSize/sizeof(AliHLTCaloDigitDataStruct);
7c80a370 104 availableSize -= iter->fSize;
105
4d42193f 106 specification = specification|iter->fSpecification;
107
7c80a370 108 digitDataPtr = reinterpret_cast<AliHLTCaloDigitDataStruct*>(iter->fPtr);
109 for (Int_t i = 0; i < nDigits; i++)
110 {
111 fDigitsPointerArray[digCount] = digitDataPtr;
112 digCount++;
113 digitDataPtr++;
114 }
4d42193f 115 }
116 }
4d42193f 117
ad44d760 118 if(digCount > 0)
4d42193f 119 {
7c80a370 120
121 AliHLTCaloClusterHeaderStruct* caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(outBPtr);
122 caloClusterHeaderPtr->fNDigits = digCount;
123
b4479a87 124 outBPtr += sizeof(AliHLTCaloClusterHeaderStruct);
125 mysize += sizeof(AliHLTCaloClusterHeaderStruct);
126
ad44d760 127 // Sort the digit pointers
128 qsort(fDigitsPointerArray, digCount, sizeof(AliHLTCaloDigitDataStruct*), CompareDigits);
4d42193f 129
ad44d760 130 // Copy the digits to the output
7c80a370 131 fOutputDigitsArray = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
ad44d760 132 for(Int_t n = 0; n < digCount; n++)
133 {
134 memcpy(outBPtr, fDigitsPointerArray[n], sizeof(AliHLTCaloDigitDataStruct));
7c80a370 135 //fOutputDigitsArray[n] = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
ad44d760 136 outBPtr = outBPtr + sizeof(AliHLTCaloDigitDataStruct);
137 }
138
70c86cde 139 mysize += digCount*sizeof(AliHLTCaloDigitDataStruct);
4f8d3cfb 140
7c80a370 141 //HLTDebug("Total number of digits: %d", digCount );
ad44d760 142
7c80a370 143 nRecPoints = fClusterizerPtr->ClusterizeEvent(digCount);
98baf84d 144
7c80a370 145 //HLTDebug("Number of rec points found: %d", nRecPoints);
b4479a87 146 fAnalyserPtr->SetCaloClusterData(reinterpret_cast<AliHLTCaloClusterDataStruct*>(outBPtr));
7c80a370 147
7c80a370 148 fAnalyserPtr->SetRecPointArray(fClusterizerPtr->GetRecPoints(), nRecPoints);
ad44d760 149
7c80a370 150 fAnalyserPtr->SetDigitDataArray(fOutputDigitsArray);
a6db7bcd 151
b4479a87 152 Int_t nClusters = fAnalyserPtr->CreateClusters(nRecPoints, size, mysize);
70c86cde 153
713ace13 154 if (nClusters < 0)
155 {
156 caloClusterHeaderPtr->fNClusters = 0;
157 }
158 else
159 {
160 caloClusterHeaderPtr->fNClusters = nClusters;
161 }
162
98baf84d 163 //HLTDebug("Number of clusters: %d", nRecPoints);
73d6f579 164
ad44d760 165 AliHLTComponentBlockData bd;
166 FillBlockData( bd );
167 bd.fOffset = offset;
70c86cde 168 bd.fSize = mysize;
a6db7bcd 169 bd.fDataType = kAliHLTDataTypeCaloCluster | fDataOrigin;
ad44d760 170 bd.fSpecification = specification;
171 outputBlocks.push_back( bd );
172 }
173
4d42193f 174 size = mysize;
175
176 return 0;
177}
178
179int
180AliHLTCaloClusterizerComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
181{
182 // see header file for class documentation
183
184 const char* path="HLT/ConfigPHOS/ClusterizerComponent";
185
186 if (cdbEntry) path = cdbEntry;
187
188 return ConfigureFromCDBTObjString(cdbEntry);
189}
190
191int
192AliHLTCaloClusterizerComponent::ScanConfigurationArgument(int argc, const char **argv)
193{
194 //See header file for documentation
195
196 if(argc <= 0) return 0;
197
198 int i=0;
199
200 TString argument=argv[i];
201
202 if (argument.CompareTo("-digitthreshold") == 0)
203 {
204 if (++i >= argc) return -EPROTO;
205 argument = argv[i];
206 fClusterizerPtr->SetEmcMinEnergyThreshold(argument.Atof());
207 return 1;
208 }
209
210 if (argument.CompareTo("-recpointthreshold") == 0)
211 {
212 if (++i >= argc) return -EPROTO;
213 argument = argv[i];
214 fClusterizerPtr->SetEmcClusteringThreshold(argument.Atof());
215 return 1;
216 }
38a3b2ad 217
218 if (argument.CompareTo("-cutonsinglecell") == 0)
219 {
220 if (++i >= argc) return -EPROTO;
221 argument = argv[i];
222 fAnalyserPtr->SetCutOnSingleCellClusters(true, argument.Atof());
223 return 1;
224 }
225
4d42193f 226 return 0;
227}
228
229int
230AliHLTCaloClusterizerComponent::DoInit(int argc, const char** argv )
231{
232 //See headerfile for documentation
233
427c373f 234 fDigitsPointerArray = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNXCOLUMNSMOD()*fCaloConstants->GetNZROWSMOD()];
235
236 fClusterizerPtr = new AliHLTCaloClusterizer(fCaloConstants->GetDETNAME());
237
238 fClusterizerPtr->SetDigitArray(fDigitsPointerArray);
239
240 fAnalyserPtr = new AliHLTCaloClusterAnalyser();
241
242 if(fCaloConstants->GetDETNAME() == "PHOS")
243 {
244 fAnalyserPtr->SetClusterType(kPHOSCluster);
245 }
246 else if(fCaloConstants->GetDETNAME() == "EMCAL")
247 {
248 fAnalyserPtr->SetClusterType(kEMCALClusterv1);
249 }
250 else
251 {
252 fAnalyserPtr->SetClusterType(kUndef);
253 }
254 InitialiseGeometry();
c1e4a18c 255 if(fRecoParamsPtr)
256 {
257 if(!fRecoParamsPtr->GetParametersFromCDB())
258 {
259 fAnalyserPtr->SetRecoParamHandler(fRecoParamsPtr);
3a624ba3 260 fClusterizerPtr->SetEmcClusteringThreshold(fRecoParamsPtr->GetRecPointThreshold());
261 fClusterizerPtr->SetEmcMinEnergyThreshold(fRecoParamsPtr->GetRecPointMemberThreshold());
c1e4a18c 262 }
263 }
4d42193f 264 //
265
266 // const char *path = "HLT/ConfigPHOS/ClusterizerComponent";
267
268 // ConfigureFromCDBTObjString(path);
269
270 for (int i = 0; i < argc; i++)
271 {
272 ScanConfigurationArgument(i, argv);
273 }
274
275 return 0;
276}
427c373f 277int AliHLTCaloClusterizerComponent::DoDeinit()
278{
279 // See header file for documentation
280 if(fDigitsPointerArray)
281 {
282 delete [] fDigitsPointerArray;
283 fDigitsPointerArray = 0;
284 }
285 if(fClusterizerPtr)
286 {
287 delete fClusterizerPtr;
288 fClusterizerPtr = 0;
289 }
290 if(fAnalyserPtr)
291 {
292 delete fAnalyserPtr;
293 fAnalyserPtr = 0;
294 }
295 return 0;
296}
4d42193f 297
ad44d760 298Int_t
299AliHLTCaloClusterizerComponent::CompareDigits(const void *dig0, const void *dig1)
4d42193f 300{
ad44d760 301 // See header file for documentation
302 return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
7c80a370 303
304 //return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
4d42193f 305}