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