Header files added to compile the macro
[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),
ad44d760 50 fDigitCount(0)
4d42193f 51{
52 //See headerfile for documentation
ad44d760 53
70c86cde 54 fDigitsPointerArray = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNXCOLUMNSMOD()*fCaloConstants->GetNZROWSMOD()];
ad44d760 55
56 fClusterizerPtr = new AliHLTCaloClusterizer(det);
57
58 fClusterizerPtr->SetDigitArray(fDigitsPointerArray);
7c80a370 59
60 fAnalyserPtr = new AliHLTCaloClusterAnalyser();
61
a6db7bcd 62 if(det == "PHOS")
63 {
64 fAnalyserPtr->SetClusterType(kPHOSCluster);
65 }
66 else if(det == "EMCAL")
67 {
68 fAnalyserPtr->SetClusterType(kEMCALClusterv1);
69 }
70 else
71 {
72 fAnalyserPtr->SetClusterType(kUndef);
73 }
74
75
4d42193f 76}
77
78AliHLTCaloClusterizerComponent::~AliHLTCaloClusterizerComponent()
79{
80 //See headerfile for documentation
73d6f579 81delete fAnalyserPtr;
4d42193f 82 if(fClusterizerPtr)
83 {
84 delete fClusterizerPtr;
85 fClusterizerPtr = 0;
86 }
4d42193f 87}
88
89
90int
91AliHLTCaloClusterizerComponent::Deinit()
92{
93 //See headerfile for documentation
94
73d6f579 95if (fClusterizerPtr)
4d42193f 96 {
97 delete fClusterizerPtr;
98 fClusterizerPtr = 0;
99 }
100
101 return 0;
102}
103
4d42193f 104int
105AliHLTCaloClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
106 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
107 std::vector<AliHLTComponentBlockData>& outputBlocks)
108{
109 //See headerfile for documentation
110
111 if(blocks == 0) return 0;
112
113 UInt_t offset = 0;
114 UInt_t mysize = 0;
115 Int_t nRecPoints = 0;
116 Int_t nDigits = 0;
ad44d760 117 Int_t digCount = 0;
4d42193f 118
7c80a370 119 UInt_t availableSize = size;
4d42193f 120 AliHLTUInt8_t* outBPtr;
121 outBPtr = outputPtr;
122 const AliHLTComponentBlockData* iter = 0;
123 unsigned long ndx;
124
125 UInt_t specification = 0;
126
127 AliHLTCaloDigitDataStruct *digitDataPtr = 0;
7c80a370 128
4d42193f 129 // Adding together all the digits, should be put in standalone method
130 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
131 {
132 iter = blocks+ndx;
ad44d760 133 // HLTError("Got block");
7c80a370 134 if (iter->fDataType == (AliHLTCaloDefinitions::fgkDigitDataType|fDataOrigin))
4d42193f 135 {
70c86cde 136
137 // Update the number of digits
138 nDigits = iter->fSize/sizeof(AliHLTCaloDigitDataStruct);
7c80a370 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
70c86cde 174 mysize += digCount*sizeof(AliHLTCaloDigitDataStruct);
4f8d3cfb 175
7c80a370 176 //HLTDebug("Total number of digits: %d", digCount );
ad44d760 177
7c80a370 178 nRecPoints = fClusterizerPtr->ClusterizeEvent(digCount);
98baf84d 179
7c80a370 180 //HLTDebug("Number of rec points found: %d", nRecPoints);
b4479a87 181 fAnalyserPtr->SetCaloClusterData(reinterpret_cast<AliHLTCaloClusterDataStruct*>(outBPtr));
7c80a370 182
7c80a370 183 fAnalyserPtr->SetRecPointArray(fClusterizerPtr->GetRecPoints(), nRecPoints);
ad44d760 184
7c80a370 185 fAnalyserPtr->SetDigitDataArray(fOutputDigitsArray);
a6db7bcd 186
b4479a87 187 Int_t nClusters = fAnalyserPtr->CreateClusters(nRecPoints, size, mysize);
70c86cde 188
713ace13 189 if (nClusters < 0)
190 {
191 caloClusterHeaderPtr->fNClusters = 0;
192 }
193 else
194 {
195 caloClusterHeaderPtr->fNClusters = nClusters;
196 }
197
98baf84d 198 //HLTDebug("Number of clusters: %d", nRecPoints);
73d6f579 199
ad44d760 200 AliHLTComponentBlockData bd;
201 FillBlockData( bd );
202 bd.fOffset = offset;
70c86cde 203 bd.fSize = mysize;
a6db7bcd 204 bd.fDataType = kAliHLTDataTypeCaloCluster | fDataOrigin;
ad44d760 205 bd.fSpecification = specification;
206 outputBlocks.push_back( bd );
207 }
208
4d42193f 209 size = mysize;
210
211 return 0;
212}
213
214int
215AliHLTCaloClusterizerComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
216{
217 // see header file for class documentation
218
219 const char* path="HLT/ConfigPHOS/ClusterizerComponent";
220
221 if (cdbEntry) path = cdbEntry;
222
223 return ConfigureFromCDBTObjString(cdbEntry);
224}
225
226int
227AliHLTCaloClusterizerComponent::ScanConfigurationArgument(int argc, const char **argv)
228{
229 //See header file for documentation
230
231 if(argc <= 0) return 0;
232
233 int i=0;
234
235 TString argument=argv[i];
236
237 if (argument.CompareTo("-digitthreshold") == 0)
238 {
239 if (++i >= argc) return -EPROTO;
240 argument = argv[i];
241 fClusterizerPtr->SetEmcMinEnergyThreshold(argument.Atof());
242 return 1;
243 }
244
245 if (argument.CompareTo("-recpointthreshold") == 0)
246 {
247 if (++i >= argc) return -EPROTO;
248 argument = argv[i];
249 fClusterizerPtr->SetEmcClusteringThreshold(argument.Atof());
250 return 1;
251 }
252 return 0;
253}
254
255int
256AliHLTCaloClusterizerComponent::DoInit(int argc, const char** argv )
257{
258 //See headerfile for documentation
259
c1e4a18c 260 if(fRecoParamsPtr)
261 {
262 if(!fRecoParamsPtr->GetParametersFromCDB())
263 {
264 fAnalyserPtr->SetRecoParamHandler(fRecoParamsPtr);
265 }
266 }
4d42193f 267 //
268
269 // const char *path = "HLT/ConfigPHOS/ClusterizerComponent";
270
271 // ConfigureFromCDBTObjString(path);
272
273 for (int i = 0; i < argc; i++)
274 {
275 ScanConfigurationArgument(i, argv);
276 }
277
278 return 0;
279}
280
ad44d760 281Int_t
282AliHLTCaloClusterizerComponent::CompareDigits(const void *dig0, const void *dig1)
4d42193f 283{
ad44d760 284 // See header file for documentation
285 return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
7c80a370 286
287 //return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
4d42193f 288}