- adding cell info to ESDs
[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"
ad44d760 26#include "TString.h"
4d42193f 27
28/** @file AliHLTCaloClusterizerComponent.cxx
29 @author Oystein Djuvsland
30 @date
31 @brief A clusterizer component for PHOS HLT
32*/
33
34// see header file for class documentation
35// or
36// refer to README to build package
37// or
38// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
39
ad44d760 40AliHLTCaloClusterizerComponent::AliHLTCaloClusterizerComponent(TString det):
ad44d760 41 AliHLTCaloProcessor(),
f92dcf21 42 AliHLTCaloConstantsHandler(det),
98baf84d 43 fDataOrigin('\0'),
44 fAnalyserPtr(0),
f92dcf21 45 fDigitsPointerArray(0),
98baf84d 46 fOutputDigitsArray(0),
4d42193f 47 fClusterizerPtr(0),
ad44d760 48 fDigitCount(0)
4d42193f 49{
50 //See headerfile for documentation
ad44d760 51
52 fDigitsPointerArray = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNXCOLUMNSRCU()*fCaloConstants->GetNZROWSRCU()];
53
54 fClusterizerPtr = new AliHLTCaloClusterizer(det);
55
56 fClusterizerPtr->SetDigitArray(fDigitsPointerArray);
7c80a370 57
58 fAnalyserPtr = new AliHLTCaloClusterAnalyser();
59
a6db7bcd 60 if(det == "PHOS")
61 {
62 fAnalyserPtr->SetClusterType(kPHOSCluster);
63 }
64 else if(det == "EMCAL")
65 {
66 fAnalyserPtr->SetClusterType(kEMCALClusterv1);
67 }
68 else
69 {
70 fAnalyserPtr->SetClusterType(kUndef);
71 }
72
73
4d42193f 74}
75
76AliHLTCaloClusterizerComponent::~AliHLTCaloClusterizerComponent()
77{
78 //See headerfile for documentation
73d6f579 79delete fAnalyserPtr;
4d42193f 80 if(fClusterizerPtr)
81 {
82 delete fClusterizerPtr;
83 fClusterizerPtr = 0;
84 }
4d42193f 85}
86
87
88int
89AliHLTCaloClusterizerComponent::Deinit()
90{
91 //See headerfile for documentation
92
73d6f579 93if (fClusterizerPtr)
4d42193f 94 {
95 delete fClusterizerPtr;
96 fClusterizerPtr = 0;
97 }
98
99 return 0;
100}
101
4d42193f 102int
103AliHLTCaloClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
104 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
105 std::vector<AliHLTComponentBlockData>& outputBlocks)
106{
107 //See headerfile for documentation
108
109 if(blocks == 0) return 0;
110
111 UInt_t offset = 0;
112 UInt_t mysize = 0;
4f8d3cfb 113 UInt_t digitSize = 0;
4d42193f 114 Int_t nRecPoints = 0;
115 Int_t nDigits = 0;
ad44d760 116 Int_t digCount = 0;
4d42193f 117
7c80a370 118 UInt_t availableSize = size;
4d42193f 119 AliHLTUInt8_t* outBPtr;
120 outBPtr = outputPtr;
121 const AliHLTComponentBlockData* iter = 0;
122 unsigned long ndx;
123
124 UInt_t specification = 0;
125
126 AliHLTCaloDigitDataStruct *digitDataPtr = 0;
7c80a370 127
4d42193f 128 // Adding together all the digits, should be put in standalone method
129 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
130 {
131 iter = blocks+ndx;
ad44d760 132 // HLTError("Got block");
bb29f0e9 133// PrintComponentDataTypeInfo(iter->fDataType);
7c80a370 134 if (iter->fDataType == (AliHLTCaloDefinitions::fgkDigitDataType|fDataOrigin))
4d42193f 135 {
4d42193f 136 // Update the number of digits
ad44d760 137 nDigits = iter->fSize/sizeof(AliHLTCaloDigitDataStruct);;
7c80a370 138
139 availableSize -= iter->fSize;
140
4d42193f 141 specification = specification|iter->fSpecification;
142
7c80a370 143 digitDataPtr = reinterpret_cast<AliHLTCaloDigitDataStruct*>(iter->fPtr);
144 for (Int_t i = 0; i < nDigits; i++)
145 {
146 fDigitsPointerArray[digCount] = digitDataPtr;
147 digCount++;
148 digitDataPtr++;
149 }
4d42193f 150 }
151 }
4d42193f 152
ad44d760 153 if(digCount > 0)
4d42193f 154 {
7c80a370 155
156 AliHLTCaloClusterHeaderStruct* caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(outBPtr);
157 caloClusterHeaderPtr->fNDigits = digCount;
158
b4479a87 159 outBPtr += sizeof(AliHLTCaloClusterHeaderStruct);
160 mysize += sizeof(AliHLTCaloClusterHeaderStruct);
161
ad44d760 162 // Sort the digit pointers
163 qsort(fDigitsPointerArray, digCount, sizeof(AliHLTCaloDigitDataStruct*), CompareDigits);
4d42193f 164
ad44d760 165 // Copy the digits to the output
7c80a370 166 fOutputDigitsArray = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
ad44d760 167 for(Int_t n = 0; n < digCount; n++)
168 {
169 memcpy(outBPtr, fDigitsPointerArray[n], sizeof(AliHLTCaloDigitDataStruct));
7c80a370 170 //fOutputDigitsArray[n] = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
ad44d760 171 outBPtr = outBPtr + sizeof(AliHLTCaloDigitDataStruct);
172 }
173
7c80a370 174 mysize += digCount*sizeof(AliHLTCaloDigitDataStruct);
4f8d3cfb 175 digitSize = mysize;
176
177 AliHLTComponentBlockData dd;
178 FillBlockData( dd );
179 dd.fOffset = offset;
180 dd.fSize = digitSize;
181 dd.fDataType = AliHLTCaloDefinitions::fgkDigitDataType | fDataOrigin;
182 dd.fSpecification = specification;
183 outputBlocks.push_back( dd );
184
185
7c80a370 186 //HLTDebug("Total number of digits: %d", digCount );
ad44d760 187
7c80a370 188 nRecPoints = fClusterizerPtr->ClusterizeEvent(digCount);
98baf84d 189
7c80a370 190 //HLTDebug("Number of rec points found: %d", nRecPoints);
ad44d760 191
b4479a87 192 fAnalyserPtr->SetCaloClusterData(reinterpret_cast<AliHLTCaloClusterDataStruct*>(outBPtr));
7c80a370 193
7c80a370 194 fAnalyserPtr->SetRecPointArray(fClusterizerPtr->GetRecPoints(), nRecPoints);
ad44d760 195
7c80a370 196 fAnalyserPtr->SetDigitDataArray(fOutputDigitsArray);
a6db7bcd 197
b4479a87 198 Int_t nClusters = fAnalyserPtr->CreateClusters(nRecPoints, size, mysize);
713ace13 199 if (nClusters < 0)
200 {
201 caloClusterHeaderPtr->fNClusters = 0;
202 }
203 else
204 {
205 caloClusterHeaderPtr->fNClusters = nClusters;
206 }
207
98baf84d 208 //HLTDebug("Number of clusters: %d", nRecPoints);
73d6f579 209
ad44d760 210 AliHLTComponentBlockData bd;
211 FillBlockData( bd );
212 bd.fOffset = offset;
4f8d3cfb 213 bd.fSize = mysize - digitSize;
a6db7bcd 214 bd.fDataType = kAliHLTDataTypeCaloCluster | fDataOrigin;
ad44d760 215 bd.fSpecification = specification;
216 outputBlocks.push_back( bd );
217 }
218
4d42193f 219 size = mysize;
220
221 return 0;
222}
223
224int
225AliHLTCaloClusterizerComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
226{
227 // see header file for class documentation
228
229 const char* path="HLT/ConfigPHOS/ClusterizerComponent";
230
231 if (cdbEntry) path = cdbEntry;
232
233 return ConfigureFromCDBTObjString(cdbEntry);
234}
235
236int
237AliHLTCaloClusterizerComponent::ScanConfigurationArgument(int argc, const char **argv)
238{
239 //See header file for documentation
240
241 if(argc <= 0) return 0;
242
243 int i=0;
244
245 TString argument=argv[i];
246
247 if (argument.CompareTo("-digitthreshold") == 0)
248 {
249 if (++i >= argc) return -EPROTO;
250 argument = argv[i];
251 fClusterizerPtr->SetEmcMinEnergyThreshold(argument.Atof());
252 return 1;
253 }
254
255 if (argument.CompareTo("-recpointthreshold") == 0)
256 {
257 if (++i >= argc) return -EPROTO;
258 argument = argv[i];
259 fClusterizerPtr->SetEmcClusteringThreshold(argument.Atof());
260 return 1;
261 }
262 return 0;
263}
264
265int
266AliHLTCaloClusterizerComponent::DoInit(int argc, const char** argv )
267{
268 //See headerfile for documentation
269
ad44d760 270
4d42193f 271 //
272
273 // const char *path = "HLT/ConfigPHOS/ClusterizerComponent";
274
275 // ConfigureFromCDBTObjString(path);
276
277 for (int i = 0; i < argc; i++)
278 {
279 ScanConfigurationArgument(i, argv);
280 }
281
282 return 0;
283}
284
ad44d760 285Int_t
286AliHLTCaloClusterizerComponent::CompareDigits(const void *dig0, const void *dig1)
4d42193f 287{
ad44d760 288 // See header file for documentation
289 return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
7c80a370 290
291 //return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
4d42193f 292}