]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx
eff C++
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSClusterizerComponent.cxx
CommitLineData
91b95d47 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
442af5b7 4 * Authors: Ã\98ystein Djuvsland <oysteind@ift.uib.no> *
91b95d47 5 * *
6 * Permission to use, copy, modify and distribute this software and its *
7 * documentation strictly for non-commercial purposes is hereby granted *
8 * without fee, provided that the above copyright notice appears in all *
9 * copies and that both the copyright notice and this permission notice *
10 * appear in the supporting documentation. The authors make no claims *
11 * about the suitability of this software for any purpose. It is *
12 * provided "as is" without express or implied warranty. *
13 **************************************************************************/
aac22523 14
aac22523 15
d2b84453 16
17
91b95d47 18#include "AliHLTPHOSClusterizerComponent.h"
aac22523 19#include "AliHLTPHOSClusterizer.h"
d2b84453 20//#include "AliHLTPHOSPhysicsDefinitions.h"
21//#include "AliHLTPHOSDefinitions.h"
91b95d47 22#include "AliHLTPHOSRecPointDataStruct.h"
23#include "AliHLTPHOSClusterDataStruct.h"
24#include "AliHLTPHOSRecPointListDataStruct.h"
25
26using namespace std;
aac22523 27
28
91b95d47 29const AliHLTComponentDataType AliHLTPHOSClusterizerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
aac22523 30
31AliHLTPHOSClusterizerComponent gAliHLTPHOSClusterizerComponent;
32
d2b84453 33AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSBase(), AliHLTProcessor(), fClusterizerPtr(0), fOutPtr(0),
aac22523 34 fRecPointStructArrayPtr(0), fRecPointListPtr(0)
35{
91b95d47 36 //Constructor
aac22523 37}
38
39AliHLTPHOSClusterizerComponent::~AliHLTPHOSClusterizerComponent()
40{
91b95d47 41 //Destructor
42
43 if(fClusterizerPtr)
44 {
45 delete fClusterizerPtr;
46 fClusterizerPtr = 0;
47 }
48
49 if(fRecPointListPtr)
50 {
51 delete fRecPointListPtr;
52 fRecPointListPtr = 0;
53 }
54
55 if(fRecPointStructArrayPtr)
56 {
6e709a0d 57 for(int i = 0; i < 1000; i++)
58 {
59 fRecPointStructArrayPtr[i].Del();
60 }
91b95d47 61 delete fRecPointStructArrayPtr;
62 fRecPointStructArrayPtr = 0;
63 }
6e709a0d 64
aac22523 65}
66
d2b84453 67// PTH AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(const AliHLTPHOSClusterizerComponent &):AliHLTProcessor(),
68// fClusterizerPtr(0),
69// fOutPtr(0),
70// fRecPointStructArrayPtr(0),
71// fRecPointListPtr(0)
72//{
91b95d47 73 //Copy constructor, not implemented
d2b84453 74//}
aac22523 75
6e709a0d 76int
aac22523 77AliHLTPHOSClusterizerComponent::Deinit()
78{
91b95d47 79 //Deinitialization
80
81 if(fClusterizerPtr)
82 {
83 delete fClusterizerPtr;
84 fClusterizerPtr = 0;
85 }
86
87 if(fRecPointListPtr)
88 {
89 delete fRecPointListPtr;
90 fRecPointListPtr = 0;
91 }
6e709a0d 92
93 for(int i = 0; i < 1000; i++)
94 {
95 fRecPointStructArrayPtr[i].Del();
96 }
97
91b95d47 98 if(fRecPointStructArrayPtr)
99 {
6e709a0d 100 for(int i = 0; i < 1000; i++)
101 {
102 fRecPointStructArrayPtr[i].Del();
103 }
91b95d47 104 delete fRecPointStructArrayPtr;
105 fRecPointStructArrayPtr = 0;
106 }
107
6e709a0d 108
109
110
111
aac22523 112 return 0;
113}
114
6e709a0d 115int
aac22523 116AliHLTPHOSClusterizerComponent::DoDeinit()
117{
91b95d47 118 //Do deinitialization
aac22523 119 Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSClusterizerComponent DoDeinit");
120
121 return 0;
122}
123
124
125const Char_t*
126AliHLTPHOSClusterizerComponent::GetComponentID()
127{
128 return "AliHltPhosClusterizer";
129}
130
131void
132AliHLTPHOSClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
133{
91b95d47 134 //Get datatypes for input
135 const AliHLTComponentDataType* pType=fgkInputDataTypes;
aac22523 136 while (pType->fID!=0) {
137 list.push_back(*pType);
138 pType++;
139 }
140}
141
142AliHLTComponentDataType
143AliHLTPHOSClusterizerComponent::GetOutputDataType()
144{
d2b84453 145 // return AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
146 return AliHLTPHOSDefinitions::fgkAliHLTClusterDataType;
aac22523 147}
148
149void
150AliHLTPHOSClusterizerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
151
152{
153 constBase = 30;
6e709a0d 154 inputMultiplier = 0.2;
aac22523 155}
156
6e709a0d 157int
aac22523 158AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
91b95d47 159 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
aac22523 160 std::vector<AliHLTComponentBlockData>& outputBlocks)
161{
91b95d47 162 //Do event
aac22523 163
164 UInt_t tSize = 0;
165 UInt_t offset = 0;
166 UInt_t mysize = 0;
167 Int_t nRecPoints = 0;
168 Int_t index = 0;
169
170 AliHLTUInt8_t* outBPtr;
171 outBPtr = outputPtr;
172 const AliHLTComponentBlockData* iter = 0;
173 unsigned long ndx;
174
175 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
176 {
177 iter = blocks+ndx;
178
179 if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType)
180 {
181 cout << "Warning: data type is not fgkCellEnergyDataType " << endl;
182 continue;
183 }
184 index = fClusterizerPtr->BuildCellEnergyArray( reinterpret_cast<AliHLTPHOSRcuCellEnergyDataStruct*>(iter->fPtr),
6e709a0d 185 fRecPointListPtr);
aac22523 186
187 }
6e709a0d 188
aac22523 189 nRecPoints = fClusterizerPtr->CreateRecPointStructArray(fRecPointStructArrayPtr, fRecPointListPtr, index);
190
6e709a0d 191 cout << "Number of clusters found: " << nRecPoints << endl;
192
aac22523 193 for(Int_t i = 0; i < nRecPoints; i++)
194 {
195 mysize = 0;
196 offset = tSize;
197
198 fOutPtr = (AliHLTPHOSClusterDataStruct*)outBPtr;
199 fClusterizerPtr->CalculateCenterOfGravity(&fRecPointStructArrayPtr[i]);
6e709a0d 200 // fClusterizerPtr->CalculateMoments(&fRecPointStructArrayPtr[i], 0);
201 // fClusterizerPtr->ClusterizeStruct(&fRecPointStructArrayPtr[i], fOutPtr);
aac22523 202
203 mysize += sizeof(AliHLTPHOSClusterDataStruct);
204
205 AliHLTComponentBlockData bd;
206 FillBlockData( bd );
207 bd.fOffset = offset;
208 bd.fSize = mysize;
d2b84453 209 // PTH bd.fDataType = AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
210 bd.fDataType = AliHLTPHOSDefinitions::fgkAliHLTClusterDataType;
aac22523 211 bd.fSpecification = 0xFFFFFFFF;
212 outputBlocks.push_back( bd );
213
214 tSize += mysize;
215 outBPtr += mysize;
216
217 if( tSize > size )
218 {
219 Logging( kHLTLogFatal, "HLT::AliHLTPHOSClusterizerComponent::DoEvent", "Too much data",
220 "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
221 , tSize, size );
222 return EMSGSIZE;
223 }
224 }
225
aac22523 226 size = tSize;
227 fClusterizerPtr->ResetCellEnergyArray();
228
229 return 0;
230
231}
232
6e709a0d 233int
9be2600f 234AliHLTPHOSClusterizerComponent::DoInit(int argc, const char** argv )
aac22523 235{
91b95d47 236 //Do initialization
aac22523 237 fClusterizerPtr = new AliHLTPHOSClusterizer();
6e709a0d 238 for(int i = 0; i < argc; i++)
239 {
240 if(!strcmp("-threshold", argv[i]))
241 fClusterizerPtr->SetThreshold(atof(argv[i+1]));
242 if(!strcmp("-clusterthreshold", argv[i]))
243 fClusterizerPtr->SetClusterThreshold(atof(argv[i+1]));
244 if(!strcmp("-highgain", argv[i]))
245 fClusterizerPtr->SetHighGainFactor(atof(argv[i+1]));
246 if(!strcmp("-lowgain", argv[i]))
247 fClusterizerPtr->SetLowGainFactor(atof(argv[i+1]));
248 if(!strcmp("-arraysize", argv[i]))
249 fClusterizerPtr->SetArraySize(atoi(argv[i+1]));
250 }
aac22523 251 fClusterizerPtr->ResetCellEnergyArray();
442af5b7 252 fRecPointListPtr = new AliHLTPHOSRecPointListDataStruct[N_ZROWS_MOD*N_XCOLUMNS_MOD];
aac22523 253 fRecPointStructArrayPtr = new AliHLTPHOSRecPointDataStruct[1000];
6e709a0d 254 for(int i = 0; i < 1000; i++)
255 {
256 fRecPointStructArrayPtr[i].fMultiplicity = atoi(argv[4])* atoi(argv[4]);
257 fRecPointStructArrayPtr[i].New();
258 }
259 printf("Clusterizer component started with:\n");
260 printf(" Cell threshold: %f\n", fClusterizerPtr->GetThreshold());
261 printf(" Cluster threshold: %f\n", fClusterizerPtr->GetClusterThreshold());
262 printf(" High gain factor: %f\n", fClusterizerPtr->GetHighGainFactor());
263 printf(" Low gain factor: %f\n", fClusterizerPtr->GetLowGainFactor());
264 printf(" Cluster array size: %d\n\n", fClusterizerPtr->GetArraySize());
aac22523 265
aac22523 266 return 0;
267}
268
269AliHLTComponent*
270AliHLTPHOSClusterizerComponent::Spawn()
271{
91b95d47 272 //Spawn a new AliHLTPHOSClusterizerComponent, for HLT framework
aac22523 273 return new AliHLTPHOSClusterizerComponent();
274}