- adding clusterizer component to the CALO library
[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
17#include <iostream>
18
19#include "AliHLTCaloClusterizerComponent.h"
20#include "AliHLTCaloClusterizer.h"
21#include "AliHLTCaloRecPointDataStruct.h"
22#include "AliHLTCaloRecPointHeaderStruct.h"
23#include "AliHLTCaloDigitDataStruct.h"
24#include "AliHLTCaloDigitContainerDataStruct.h"
25#include "AliHLTCaloDefinitions.h"
26
27/** @file AliHLTCaloClusterizerComponent.cxx
28 @author Oystein Djuvsland
29 @date
30 @brief A clusterizer component for PHOS HLT
31*/
32
33// see header file for class documentation
34// or
35// refer to README to build package
36// or
37// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
38
39AliHLTCaloClusterizerComponent gAliHLTCaloClusterizerComponent;
40
41AliHLTCaloClusterizerComponent::AliHLTCaloClusterizerComponent():
42 AliHLTPHOSProcessor(),
43 fAllDigitsPtr(0),
44 fClusterizerPtr(0),
45 fDigitCount(0),
46 fNoCrazyness(0)
47{
48 //See headerfile for documentation
49}
50
51AliHLTCaloClusterizerComponent::~AliHLTCaloClusterizerComponent()
52{
53 //See headerfile for documentation
54
55 if(fClusterizerPtr)
56 {
57 delete fClusterizerPtr;
58 fClusterizerPtr = 0;
59 }
60 if(fAllDigitsPtr)
61 {
62 delete fAllDigitsPtr;
63 fAllDigitsPtr = 0;
64 }
65}
66
67
68int
69AliHLTCaloClusterizerComponent::Deinit()
70{
71 //See headerfile for documentation
72
73 if (fClusterizerPtr)
74 {
75 delete fClusterizerPtr;
76 fClusterizerPtr = 0;
77 }
78
79 return 0;
80}
81
82void
83AliHLTCaloClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
84{
85 //See headerfile for documentation
86 list.clear();
87 list.push_back(AliHLTPHOSDefinitions::fgkDigitDataType);
88}
89
90AliHLTComponentDataType
91AliHLTCaloClusterizerComponent::GetOutputDataType()
92{
93 //See headerfile for documentation
94 return AliHLTPHOSDefinitions::fgkRecPointDataType;
95}
96
97void
98AliHLTCaloClusterizerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
99
100{
101 //See headerfile for documentation
102 constBase = sizeof(AliHLTCaloRecPointHeaderStruct) + sizeof(AliHLTPHOSRecPointDataStruct) + (sizeof(AliHLTCaloDigitDataStruct) << 7); //Reasonable estimate... ;
103 inputMultiplier = 1.5;
104}
105
106int
107AliHLTCaloClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
108 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
109 std::vector<AliHLTComponentBlockData>& outputBlocks)
110{
111 //See headerfile for documentation
112
113 if(blocks == 0) return 0;
114
115 UInt_t offset = 0;
116 UInt_t mysize = 0;
117 Int_t nRecPoints = 0;
118 Int_t nDigits = 0;
119
120 UInt_t availableSize = size;
121 AliHLTUInt8_t* outBPtr;
122 outBPtr = outputPtr;
123 const AliHLTComponentBlockData* iter = 0;
124 unsigned long ndx;
125
126 UInt_t specification = 0;
127
128 AliHLTCaloDigitDataStruct *digitDataPtr = 0;
129
130 AliHLTCaloRecPointHeaderStruct* recPointHeaderPtr = reinterpret_cast<AliHLTCaloRecPointHeaderStruct*>(outBPtr);
131
132 fClusterizerPtr->SetRecPointDataPtr(reinterpret_cast<AliHLTCaloRecPointDataStruct*>(outBPtr+sizeof(AliHLTCaloRecPointHeaderStruct)));
133
134 // Adding together all the digits, should be put in standalone method
135 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
136 {
137 iter = blocks+ndx;
138 if (iter->fDataType == AliHLTCaloDefinitions::fgkDigitDataType)
139 {
140 // Get the digit header
141
142 // Update the number of digits
143 nDigits += iter->fSize/sizeof(AliHLTCaloDigitDataStruct);;
144 // Get the specification
145 specification = specification|iter->fSpecification;
146
147 digitDataPtr = reinterpret_cast<AliHLTCaloDigitDataStruct*>(iter->fPtr);
148 for (Int_t i = 0; i < nDigits; i++)
149 {
150 fAllDigitsPtr->fDigitDataStruct[j].fX = digitDataPtr->fX;
151 fAllDigitsPtr->fDigitDataStruct[j].fZ = digitDataPtr->fZ;
152 fAllDigitsPtr->fDigitDataStruct[j].fEnergy = digitDataPtr->fEnergy;
153 // HLTDebug("Digit energy: %f", digitDataPtr->fEnergy);
154 fAllDigitsPtr->fDigitDataStruct[j].fTime = digitDataPtr->fTime;
155 fAllDigitsPtr->fDigitDataStruct[j].fCrazyness = digitDataPtr->fCrazyness;
156 j++;
157 digitDataPtr++;
158 }
159
160 }
161 }
162
163 fAllDigitsPtr->fNDigits = j;
164 nRecPoints = fClusterizerPtr->ClusterizeEvent(size, mysize);
165
166 if(nRecPoints == -1)
167 {
168 HLTError("Running out of buffer, exiting for safety.");
169 return -ENOBUFS;
170 }
171
172 recPointHeaderPtr->fNRecPoints = nRecPoints;
173 mysize += sizeof(AliHLTCaloRecPointHeaderStruct);
174
175 HLTDebug("Number of clusters: %d", nRecPoints);
176
177 AliHLTComponentBlockData bd;
178 FillBlockData( bd );
179 bd.fOffset = offset;
180 bd.fSize = mysize;
181 bd.fDataType = AliHLTPHOSDefinitions::fgkClusterDataType;
182 bd.fSpecification = specification;
183 outputBlocks.push_back( bd );
184
185 size = mysize;
186
187 return 0;
188}
189
190int
191AliHLTCaloClusterizerComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
192{
193 // see header file for class documentation
194
195 const char* path="HLT/ConfigPHOS/ClusterizerComponent";
196
197 if (cdbEntry) path = cdbEntry;
198
199 return ConfigureFromCDBTObjString(cdbEntry);
200}
201
202int
203AliHLTCaloClusterizerComponent::ScanConfigurationArgument(int argc, const char **argv)
204{
205 //See header file for documentation
206
207 if(argc <= 0) return 0;
208
209 int i=0;
210
211 TString argument=argv[i];
212
213 if (argument.CompareTo("-digitthreshold") == 0)
214 {
215 if (++i >= argc) return -EPROTO;
216 argument = argv[i];
217 fClusterizerPtr->SetEmcMinEnergyThreshold(argument.Atof());
218 return 1;
219 }
220
221 if (argument.CompareTo("-recpointthreshold") == 0)
222 {
223 if (++i >= argc) return -EPROTO;
224 argument = argv[i];
225 fClusterizerPtr->SetEmcClusteringThreshold(argument.Atof());
226 return 1;
227 }
228 return 0;
229}
230
231int
232AliHLTCaloClusterizerComponent::DoInit(int argc, const char** argv )
233{
234 //See headerfile for documentation
235
236 fAllDigitsPtr = new AliHLTCaloDigitContainerDataStruct();
237 fClusterizerPtr = new AliHLTCaloClusterizer();
238 fClusterizerPtr->SetDigitContainer(fAllDigitsPtr);
239 fNoCrazyness = false;
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
254AliHLTComponent*
255AliHLTCaloClusterizerComponent::Spawn()
256{
257 //See headerfile for documentation
258
259 return new AliHLTCaloClusterizerComponent();
260}