- moved digit struct to BASE/util to facilitate for ESD conversion in the global...
[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),
43 fDigitsPointerArray(0),
4d42193f 44 fClusterizerPtr(0),
7c80a370 45 fAnalyserPtr(0),
ad44d760 46 fDigitCount(0)
4d42193f 47{
48 //See headerfile for documentation
ad44d760 49
50 fDigitsPointerArray = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNXCOLUMNSRCU()*fCaloConstants->GetNZROWSRCU()];
51
52 fClusterizerPtr = new AliHLTCaloClusterizer(det);
53
54 fClusterizerPtr->SetDigitArray(fDigitsPointerArray);
7c80a370 55
56 fAnalyserPtr = new AliHLTCaloClusterAnalyser();
57
4d42193f 58}
59
60AliHLTCaloClusterizerComponent::~AliHLTCaloClusterizerComponent()
61{
62 //See headerfile for documentation
63
64 if(fClusterizerPtr)
65 {
66 delete fClusterizerPtr;
67 fClusterizerPtr = 0;
68 }
4d42193f 69}
70
71
72int
73AliHLTCaloClusterizerComponent::Deinit()
74{
75 //See headerfile for documentation
76
77 if (fClusterizerPtr)
78 {
79 delete fClusterizerPtr;
80 fClusterizerPtr = 0;
81 }
82
83 return 0;
84}
85
ad44d760 86// void
87// AliHLTCaloClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
88// {
89// //See headerfile for documentation
90// list.clear();
91// list.push_back(AliHLTCaloDefinitions::fgkDigitDataType|kAliHLTDataOriginPHOS);
92// }
93
94// AliHLTComponentDataType
95// AliHLTCaloClusterizerComponent::GetOutputDataType()
96// {
97// //See headerfile for documentation
98// return AliHLTCaloDefinitions::fgkRecPointDataType|kAliHLTDataOriginPHOS;
99// }
100
101// void
102// AliHLTCaloClusterizerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
103
104// {
105// //See headerfile for documentation
106// constBase = sizeof(AliHLTCaloRecPointHeaderStruct) + sizeof(AliHLTCaloRecPointDataStruct) + (sizeof(AliHLTCaloDigitDataStruct) << 7); //Reasonable estimate... ;
107// inputMultiplier = 1.5;
108// }
4d42193f 109
110int
111AliHLTCaloClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
112 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
113 std::vector<AliHLTComponentBlockData>& outputBlocks)
114{
115 //See headerfile for documentation
116
117 if(blocks == 0) return 0;
118
119 UInt_t offset = 0;
120 UInt_t mysize = 0;
121 Int_t nRecPoints = 0;
122 Int_t nDigits = 0;
ad44d760 123 Int_t digCount = 0;
4d42193f 124
7c80a370 125 UInt_t availableSize = size;
4d42193f 126 AliHLTUInt8_t* outBPtr;
127 outBPtr = outputPtr;
128 const AliHLTComponentBlockData* iter = 0;
129 unsigned long ndx;
130
131 UInt_t specification = 0;
132
133 AliHLTCaloDigitDataStruct *digitDataPtr = 0;
7c80a370 134
135// delete fAnalyserPtr;
136// fAnalyserPtr = new AliHLTCaloClusterAnalyser();
137//
4d42193f 138 // Adding together all the digits, should be put in standalone method
139 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
140 {
141 iter = blocks+ndx;
ad44d760 142 // HLTError("Got block");
7c80a370 143 if (iter->fDataType == (AliHLTCaloDefinitions::fgkDigitDataType|fDataOrigin))
4d42193f 144 {
4d42193f 145
7c80a370 146// fDigitsPointerArray[digCount] = reinterpret_cast<AliHLTCaloDigitDataStruct*>(iter->fPtr);
147
148 //cout << "Digits pointer array [" << digCount << "]: " << fDigitsPointerArray[digCount] << endl;
4d42193f 149 // Update the number of digits
ad44d760 150 nDigits = iter->fSize/sizeof(AliHLTCaloDigitDataStruct);;
7c80a370 151// digCount += nDigits;
ad44d760 152 // HLTError("Got %d digits", nDigits);
7c80a370 153
154 availableSize -= iter->fSize;
155
4d42193f 156 specification = specification|iter->fSpecification;
157
7c80a370 158 digitDataPtr = reinterpret_cast<AliHLTCaloDigitDataStruct*>(iter->fPtr);
159 for (Int_t i = 0; i < nDigits; i++)
160 {
161 fDigitsPointerArray[digCount] = digitDataPtr;
162 digCount++;
163 digitDataPtr++;
164 }
4d42193f 165 }
166 }
4d42193f 167
ad44d760 168 if(digCount > 0)
4d42193f 169 {
7c80a370 170
171 AliHLTCaloClusterHeaderStruct* caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(outBPtr);
172 caloClusterHeaderPtr->fNDigits = digCount;
173
b4479a87 174 outBPtr += sizeof(AliHLTCaloClusterHeaderStruct);
175 mysize += sizeof(AliHLTCaloClusterHeaderStruct);
176
ad44d760 177 // Sort the digit pointers
178 qsort(fDigitsPointerArray, digCount, sizeof(AliHLTCaloDigitDataStruct*), CompareDigits);
4d42193f 179
ad44d760 180 // Copy the digits to the output
7c80a370 181 fOutputDigitsArray = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
ad44d760 182 for(Int_t n = 0; n < digCount; n++)
183 {
184 memcpy(outBPtr, fDigitsPointerArray[n], sizeof(AliHLTCaloDigitDataStruct));
7c80a370 185 //fOutputDigitsArray[n] = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
ad44d760 186 outBPtr = outBPtr + sizeof(AliHLTCaloDigitDataStruct);
7c80a370 187 printf("CL: digit energy: %f, ID: %d\n", fOutputDigitsArray[n].fEnergy, fOutputDigitsArray[n].fID);
ad44d760 188 }
189
7c80a370 190 mysize += digCount*sizeof(AliHLTCaloDigitDataStruct);
ad44d760 191
7c80a370 192// AliHLTComponentBlockData bdDigits;
193// FillBlockData( bdDigits );
194// bdDigits.fOffset = offset;
195// bdDigits.fSize = mysize;
196// bdDigits.fDataType = iter->fDataType;
197// bdDigits.fSpecification = specification;
198// outputBlocks.push_back( bdDigits );
ad44d760 199
7c80a370 200 //HLTDebug("Total number of digits: %d", digCount );
ad44d760 201
7c80a370 202 nRecPoints = fClusterizerPtr->ClusterizeEvent(digCount);
203 //fClusterizerPtr->CheckDigits();
204 //HLTDebug("Number of rec points found: %d", nRecPoints);
ad44d760 205
b4479a87 206 fAnalyserPtr->SetCaloClusterData(reinterpret_cast<AliHLTCaloClusterDataStruct*>(outBPtr));
7c80a370 207
208 //fClusterizerPtr->CheckDigits(fClusterizerPtr->GetRecPoints(), fOutputDigitsArray, nRecPoints);
ad44d760 209
7c80a370 210 fAnalyserPtr->SetRecPointArray(fClusterizerPtr->GetRecPoints(), nRecPoints);
ad44d760 211
7c80a370 212 //fClusterizerPtr->CheckDigits(fClusterizerPtr->GetRecPoints(), fOutputDigitsArray, nRecPoints);
213
214 fAnalyserPtr->SetDigitDataArray(fOutputDigitsArray);
215
b4479a87 216// fClusterizerPtr->CheckDigits(fClusterizerPtr->GetRecPoints(), fOutputDigitsArray, nRecPoints);
7c80a370 217
b4479a87 218 Int_t nClusters = fAnalyserPtr->CreateClusters(nRecPoints, size, mysize);
ad44d760 219
b4479a87 220 caloClusterHeaderPtr->fNClusters = nClusters;
221
ad44d760 222 // HLTError("Number of clusters: %d", nRecPoints);
223
224 AliHLTComponentBlockData bd;
225 FillBlockData( bd );
226 bd.fOffset = offset;
227 bd.fSize = mysize;
b4479a87 228 bd.fDataType = kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS;
ad44d760 229 bd.fSpecification = specification;
230 outputBlocks.push_back( bd );
231 }
232
4d42193f 233 size = mysize;
234
235 return 0;
236}
237
238int
239AliHLTCaloClusterizerComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
240{
241 // see header file for class documentation
242
243 const char* path="HLT/ConfigPHOS/ClusterizerComponent";
244
245 if (cdbEntry) path = cdbEntry;
246
247 return ConfigureFromCDBTObjString(cdbEntry);
248}
249
250int
251AliHLTCaloClusterizerComponent::ScanConfigurationArgument(int argc, const char **argv)
252{
253 //See header file for documentation
254
255 if(argc <= 0) return 0;
256
257 int i=0;
258
259 TString argument=argv[i];
260
261 if (argument.CompareTo("-digitthreshold") == 0)
262 {
263 if (++i >= argc) return -EPROTO;
264 argument = argv[i];
265 fClusterizerPtr->SetEmcMinEnergyThreshold(argument.Atof());
266 return 1;
267 }
268
269 if (argument.CompareTo("-recpointthreshold") == 0)
270 {
271 if (++i >= argc) return -EPROTO;
272 argument = argv[i];
273 fClusterizerPtr->SetEmcClusteringThreshold(argument.Atof());
274 return 1;
275 }
276 return 0;
277}
278
279int
280AliHLTCaloClusterizerComponent::DoInit(int argc, const char** argv )
281{
282 //See headerfile for documentation
283
ad44d760 284
4d42193f 285 //
286
287 // const char *path = "HLT/ConfigPHOS/ClusterizerComponent";
288
289 // ConfigureFromCDBTObjString(path);
290
291 for (int i = 0; i < argc; i++)
292 {
293 ScanConfigurationArgument(i, argv);
294 }
295
296 return 0;
297}
298
ad44d760 299Int_t
300AliHLTCaloClusterizerComponent::CompareDigits(const void *dig0, const void *dig1)
4d42193f 301{
ad44d760 302 // See header file for documentation
303 return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
7c80a370 304
305 //return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
4d42193f 306}