- adding AliHLTEMCALDigitMakerComponent
[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
4d42193f 60}
61
62AliHLTCaloClusterizerComponent::~AliHLTCaloClusterizerComponent()
63{
64 //See headerfile for documentation
73d6f579 65delete fAnalyserPtr;
4d42193f 66 if(fClusterizerPtr)
67 {
68 delete fClusterizerPtr;
69 fClusterizerPtr = 0;
70 }
4d42193f 71}
72
73
74int
75AliHLTCaloClusterizerComponent::Deinit()
76{
77 //See headerfile for documentation
78
73d6f579 79if (fClusterizerPtr)
4d42193f 80 {
81 delete fClusterizerPtr;
82 fClusterizerPtr = 0;
83 }
84
85 return 0;
86}
87
4d42193f 88int
89AliHLTCaloClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
90 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
91 std::vector<AliHLTComponentBlockData>& outputBlocks)
92{
93 //See headerfile for documentation
94
95 if(blocks == 0) return 0;
96
97 UInt_t offset = 0;
98 UInt_t mysize = 0;
99 Int_t nRecPoints = 0;
100 Int_t nDigits = 0;
ad44d760 101 Int_t digCount = 0;
4d42193f 102
7c80a370 103 UInt_t availableSize = size;
4d42193f 104 AliHLTUInt8_t* outBPtr;
105 outBPtr = outputPtr;
106 const AliHLTComponentBlockData* iter = 0;
107 unsigned long ndx;
108
109 UInt_t specification = 0;
110
111 AliHLTCaloDigitDataStruct *digitDataPtr = 0;
7c80a370 112
4d42193f 113 // Adding together all the digits, should be put in standalone method
114 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
115 {
116 iter = blocks+ndx;
ad44d760 117 // HLTError("Got block");
7c80a370 118 if (iter->fDataType == (AliHLTCaloDefinitions::fgkDigitDataType|fDataOrigin))
4d42193f 119 {
4d42193f 120
121 // Update the number of digits
ad44d760 122 nDigits = iter->fSize/sizeof(AliHLTCaloDigitDataStruct);;
7c80a370 123
124 availableSize -= iter->fSize;
125
4d42193f 126 specification = specification|iter->fSpecification;
127
7c80a370 128 digitDataPtr = reinterpret_cast<AliHLTCaloDigitDataStruct*>(iter->fPtr);
129 for (Int_t i = 0; i < nDigits; i++)
130 {
131 fDigitsPointerArray[digCount] = digitDataPtr;
132 digCount++;
133 digitDataPtr++;
134 }
4d42193f 135 }
136 }
4d42193f 137
ad44d760 138 if(digCount > 0)
4d42193f 139 {
7c80a370 140
141 AliHLTCaloClusterHeaderStruct* caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(outBPtr);
142 caloClusterHeaderPtr->fNDigits = digCount;
143
b4479a87 144 outBPtr += sizeof(AliHLTCaloClusterHeaderStruct);
145 mysize += sizeof(AliHLTCaloClusterHeaderStruct);
146
ad44d760 147 // Sort the digit pointers
148 qsort(fDigitsPointerArray, digCount, sizeof(AliHLTCaloDigitDataStruct*), CompareDigits);
4d42193f 149
ad44d760 150 // Copy the digits to the output
7c80a370 151 fOutputDigitsArray = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
ad44d760 152 for(Int_t n = 0; n < digCount; n++)
153 {
154 memcpy(outBPtr, fDigitsPointerArray[n], sizeof(AliHLTCaloDigitDataStruct));
7c80a370 155 //fOutputDigitsArray[n] = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
ad44d760 156 outBPtr = outBPtr + sizeof(AliHLTCaloDigitDataStruct);
157 }
158
7c80a370 159 mysize += digCount*sizeof(AliHLTCaloDigitDataStruct);
ad44d760 160
7c80a370 161 //HLTDebug("Total number of digits: %d", digCount );
ad44d760 162
7c80a370 163 nRecPoints = fClusterizerPtr->ClusterizeEvent(digCount);
98baf84d 164
7c80a370 165 //HLTDebug("Number of rec points found: %d", nRecPoints);
ad44d760 166
b4479a87 167 fAnalyserPtr->SetCaloClusterData(reinterpret_cast<AliHLTCaloClusterDataStruct*>(outBPtr));
7c80a370 168
7c80a370 169 fAnalyserPtr->SetRecPointArray(fClusterizerPtr->GetRecPoints(), nRecPoints);
ad44d760 170
7c80a370 171 fAnalyserPtr->SetDigitDataArray(fOutputDigitsArray);
172
b4479a87 173 Int_t nClusters = fAnalyserPtr->CreateClusters(nRecPoints, size, mysize);
ad44d760 174
b4479a87 175 caloClusterHeaderPtr->fNClusters = nClusters;
176
98baf84d 177 //HLTDebug("Number of clusters: %d", nRecPoints);
73d6f579 178
ad44d760 179 AliHLTComponentBlockData bd;
180 FillBlockData( bd );
181 bd.fOffset = offset;
182 bd.fSize = mysize;
b4479a87 183 bd.fDataType = kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS;
ad44d760 184 bd.fSpecification = specification;
185 outputBlocks.push_back( bd );
186 }
187
4d42193f 188 size = mysize;
189
190 return 0;
191}
192
193int
194AliHLTCaloClusterizerComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
195{
196 // see header file for class documentation
197
198 const char* path="HLT/ConfigPHOS/ClusterizerComponent";
199
200 if (cdbEntry) path = cdbEntry;
201
202 return ConfigureFromCDBTObjString(cdbEntry);
203}
204
205int
206AliHLTCaloClusterizerComponent::ScanConfigurationArgument(int argc, const char **argv)
207{
208 //See header file for documentation
209
210 if(argc <= 0) return 0;
211
212 int i=0;
213
214 TString argument=argv[i];
215
216 if (argument.CompareTo("-digitthreshold") == 0)
217 {
218 if (++i >= argc) return -EPROTO;
219 argument = argv[i];
220 fClusterizerPtr->SetEmcMinEnergyThreshold(argument.Atof());
221 return 1;
222 }
223
224 if (argument.CompareTo("-recpointthreshold") == 0)
225 {
226 if (++i >= argc) return -EPROTO;
227 argument = argv[i];
228 fClusterizerPtr->SetEmcClusteringThreshold(argument.Atof());
229 return 1;
230 }
231 return 0;
232}
233
234int
235AliHLTCaloClusterizerComponent::DoInit(int argc, const char** argv )
236{
237 //See headerfile for documentation
238
ad44d760 239
4d42193f 240 //
241
242 // const char *path = "HLT/ConfigPHOS/ClusterizerComponent";
243
244 // ConfigureFromCDBTObjString(path);
245
246 for (int i = 0; i < argc; i++)
247 {
248 ScanConfigurationArgument(i, argv);
249 }
250
251 return 0;
252}
253
ad44d760 254Int_t
255AliHLTCaloClusterizerComponent::CompareDigits(const void *dig0, const void *dig1)
4d42193f 256{
ad44d760 257 // See header file for documentation
258 return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
7c80a370 259
260 //return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
4d42193f 261}