]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx
coding conventions (Oystein/Per Thomas)
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSClusterizerComponent.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Authors: Ã\98ystein Djuvsland <oysteind@ift.uib.no>                       *
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  **************************************************************************/
14
15
16
17
18 #include "AliHLTPHOSClusterizerComponent.h"
19 #include "AliHLTPHOSClusterizer.h"
20 //#include "AliHLTPHOSPhysicsDefinitions.h"
21 //#include "AliHLTPHOSDefinitions.h"
22 #include "AliHLTPHOSRecPointDataStruct.h"
23 #include "AliHLTPHOSClusterDataStruct.h"
24 #include "AliHLTPHOSRecPointListDataStruct.h"
25 #include "AliHLTPHOSDigitContainerDataStruct.h"
26
27 using namespace std;
28
29
30 const AliHLTComponentDataType AliHLTPHOSClusterizerComponent::fgkInputDataTypes[]=
31   {
32     kAliHLTVoidDataType,{0,"",""}
33   };
34
35 AliHLTPHOSClusterizerComponent gAliHLTPHOSClusterizerComponent;
36
37 //AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSBase(), AliHLTProcessor(), fClusterizerPtr(0), fOutPtr(0),
38 //                                                               fRecPointStructArrayPtr(0), fRecPointListPtr(0)
39 AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSProcessor(), fClusterizerPtr(0), fOutPtr(0),
40     fRecPointStructArrayPtr(0), fRecPointListPtr(0)
41 {
42   //Constructor
43 }
44
45 AliHLTPHOSClusterizerComponent::~AliHLTPHOSClusterizerComponent()
46 {
47   //Destructor
48
49   if (fClusterizerPtr)
50     {
51       delete fClusterizerPtr;
52       fClusterizerPtr = 0;
53     }
54
55   if (fRecPointListPtr)
56     {
57       delete fRecPointListPtr;
58       fRecPointListPtr = 0;
59     }
60
61   if (fRecPointStructArrayPtr)
62     {
63       for (int i = 0; i < 1000; i++)
64         {
65           //      fRecPointStructArrayPtr[i].Del();
66         }
67       delete fRecPointStructArrayPtr;
68       fRecPointStructArrayPtr = 0;
69     }
70
71 }
72
73 /*
74 int
75 AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent::Deinit()
76 {
77   ////////// PTH WARNING you should Define a class AliHLTPHOSModuleProcessor
78 }
79 */
80
81 // PTH AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(const AliHLTPHOSClusterizerComponent &):AliHLTProcessor(),
82 //                                                                                                     fClusterizerPtr(0),
83 //                                                                                                     fOutPtr(0),
84 //                                                                                                     fRecPointStructArrayPtr(0),
85 //                                                                                                     fRecPointListPtr(0)
86 //{
87 //Copy constructor, not implemented
88 //}
89
90 int
91 AliHLTPHOSClusterizerComponent::Deinit()
92 {
93   //Deinitialization
94
95   if (fClusterizerPtr)
96     {
97       delete fClusterizerPtr;
98       fClusterizerPtr = 0;
99     }
100
101   if (fRecPointListPtr)
102     {
103       delete fRecPointListPtr;
104       fRecPointListPtr = 0;
105     }
106
107   for (int i = 0; i < 1000; i++)
108     {
109       //    fRecPointStructArrayPtr[i].Del();
110     }
111
112   if (fRecPointStructArrayPtr)
113     {
114       for (int i = 0; i < 1000; i++)
115         {
116           //      fRecPointStructArrayPtr[i].Del();
117         }
118       delete fRecPointStructArrayPtr;
119       fRecPointStructArrayPtr = 0;
120     }
121
122   return 0;
123 }
124
125 int
126 AliHLTPHOSClusterizerComponent::DoDeinit()
127 {
128   //Do deinitialization
129   Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSClusterizerComponent DoDeinit");
130
131   return 0;
132 }
133
134
135 const Char_t*
136 AliHLTPHOSClusterizerComponent::GetComponentID()
137 {
138   //comment
139   return "AliHltPhosClusterizer";
140 }
141
142 void
143 AliHLTPHOSClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
144 {
145   //Get datatypes for input
146   const AliHLTComponentDataType* pType=fgkInputDataTypes;
147   while (pType->fID!=0)
148     {
149       list.push_back(*pType);
150       pType++;
151     }
152 }
153
154 AliHLTComponentDataType
155 AliHLTPHOSClusterizerComponent::GetOutputDataType()
156 {
157   //  return AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
158   return AliHLTPHOSDefinitions::fgkAliHLTClusterDataType;
159 }
160
161 void
162 AliHLTPHOSClusterizerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
163
164 {
165   constBase = 30;
166   inputMultiplier = 0.2;
167 }
168
169 int
170 AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
171                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
172                                         std::vector<AliHLTComponentBlockData>& outputBlocks)
173 {
174   //Do event
175
176   UInt_t tSize            = 0;
177   UInt_t offset           = 0;
178   UInt_t mysize           = 0;
179   Int_t nRecPoints        = 0;
180   Int_t nDigits           = 0;
181   Int_t index             = 0;
182   Int_t j =0;
183
184   AliHLTUInt8_t* outBPtr;
185   outBPtr = outputPtr;
186   const AliHLTComponentBlockData* iter = 0;
187   unsigned long ndx;
188
189   AliHLTPHOSDigitContainerDataStruct *digitContainerPtr = 0;
190   
191   //AliHLTPHOSRecPointContainerStruct *recPointContainerPtr = (AliHLTPHOSRecPointContainerStruct*)outBPtr;
192   fClusterizerPtr->SetRecPointContainer((AliHLTPHOSRecPointContainerStruct*)outBPtr);
193   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
194     {
195       iter = blocks+ndx;
196       digitContainerPtr = reinterpret_cast<AliHLTPHOSDigitContainerDataStruct*>(iter->fPtr);
197       if (iter->fDataType != AliHLTPHOSDefinitions::fgkAliHLTDigitDataType)
198         {
199           //      cout << "Warning: data type is not fgkAliHLTDigitDataType " << endl;
200           continue;
201         }
202       for (Int_t i = 0; i < digitContainerPtr->fNDigits; i++)
203         {
204           if(fNoCrazyness && digitContainerPtr->fDigitDataStruct[i].fCrazyness)
205             continue;
206             
207           fAllDigitsPtr->fDigitDataStruct[j+nDigits].fX = digitContainerPtr->fDigitDataStruct[i].fX;
208           fAllDigitsPtr->fDigitDataStruct[j+nDigits].fZ = digitContainerPtr->fDigitDataStruct[i].fZ;
209           fAllDigitsPtr->fDigitDataStruct[j+nDigits].fAmplitude = digitContainerPtr->fDigitDataStruct[i].fAmplitude;
210           fAllDigitsPtr->fDigitDataStruct[j+nDigits].fTime = digitContainerPtr->fDigitDataStruct[i].fTime;
211          // fAllDigitsPtr->fDigitDataStruct[i+nDigits].fCrazyness = digitContainerPtr->fDigitDataStruct[i].fCrazyness;
212           j++;
213         }
214       nDigits++;
215     }
216
217 // nRecPoints = fClusterizerPtr->CreateRecPointStructArray(fRecPointStructArrayPtr, fRecPointListPtr, index);
218
219   fOutPtr =  (AliHLTPHOSRecPointContainerStruct*)outBPtr;
220   nRecPoints = fClusterizerPtr->ClusterizeEvent();
221   //nRecPoints = fClusterizerPtr->CalculateCenterOfGravity(&fRecPointStructArrayPtr[i]);
222   cout << "Number of clusters found: " << nRecPoints << " extracted from " << nDigits << " digits" << endl;
223
224   mysize = 0;
225   offset = tSize;
226
227   //      fClusterizerPtr->CalculateMoments(&fRecPointStructArrayPtr[i], 0);
228   //     fClusterizerPtr->ClusterizeStruct(&fRecPointStructArrayPtr[i], fOutPtr);
229
230   mysize += sizeof(AliHLTPHOSClusterDataStruct);
231
232   AliHLTComponentBlockData bd;
233   FillBlockData( bd );
234   bd.fOffset = offset;
235   bd.fSize = mysize;
236   // PTH      bd.fDataType = AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
237   bd.fDataType = AliHLTPHOSDefinitions::fgkAliHLTClusterDataType;
238   bd.fSpecification = 0xFFFFFFFF;
239   outputBlocks.push_back( bd );
240
241   tSize += mysize;
242   outBPtr += mysize;
243
244   if ( tSize > size )
245     {
246       Logging( kHLTLogFatal, "HLT::AliHLTPHOSClusterizerComponent::DoEvent", "Too much data",
247                "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
248                , tSize, size );
249       return EMSGSIZE;
250     }
251
252
253   size = tSize;
254 // fClusterizerPtr->ResetCellEnergyArray();
255
256   return 0;
257
258 }
259
260 int
261 AliHLTPHOSClusterizerComponent::DoInit(int argc, const char** argv )
262 {
263   //Do initialization
264   fAllDigitsPtr = new AliHLTPHOSDigitContainerDataStruct();
265   fClusterizerPtr = new AliHLTPHOSClusterizer();
266   //fClusterizerPtr->SetNoCrazyness(true);
267   //
268   for (int i = 0; i < argc; i++)
269     {
270       /*
271       if(!strcmp("-threshold", argv[i]))
272       fClusterizerPtr->SetThreshold(atof(argv[i+1]));
273       if(!strcmp("-clusterthreshold", argv[i]))
274       fClusterizerPtr->SetClusterThreshold(atof(argv[i+1]));
275       if(!strcmp("-highgain", argv[i]))
276       fClusterizerPtr->SetHighGainFactor(atof(argv[i+1]));
277       if(!strcmp("-lowgain", argv[i]))
278       fClusterizerPtr->SetLowGainFactor(atof(argv[i+1]));
279       if(!strcmp("-arraysize", argv[i]))
280       fClusterizerPtr->SetArraySize(atoi(argv[i+1]));*/
281     }
282   //  fClusterizerPtr->ResetCellEnergyArray();
283   fRecPointListPtr = new AliHLTPHOSRecPointListDataStruct[N_ZROWS_MOD*N_XCOLUMNS_MOD];
284   fRecPointStructArrayPtr = new AliHLTPHOSRecPointDataStruct[1000];
285   for (int i = 0; i < 1000; i++)
286     {
287       fRecPointStructArrayPtr[i].fMultiplicity = atoi(argv[4])* atoi(argv[4]);
288       // fRecPointStructArrayPtr[i].New();
289     }
290   /*
291   printf("Clusterizer component started with:\n");
292   printf(" Cell threshold:     %f\n", fClusterizerPtr->GetThreshold());
293   printf(" Cluster threshold:  %f\n", fClusterizerPtr->GetClusterThreshold());
294   printf(" High gain factor:   %f\n", fClusterizerPtr->GetHighGainFactor());
295   printf(" Low gain factor:    %f\n", fClusterizerPtr->GetLowGainFactor());
296   printf(" Cluster array size: %d\n\n", fClusterizerPtr->GetArraySize());
297   */
298   return 0;
299 }
300
301 AliHLTComponent*
302 AliHLTPHOSClusterizerComponent::Spawn()
303 {
304   //Spawn a new AliHLTPHOSClusterizerComponent, for HLT framework
305   return new AliHLTPHOSClusterizerComponent();
306 }