]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx
175bf7fc5ffefd13278193d973e7e49ea426875e
[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
26 using namespace std;
27
28
29 const AliHLTComponentDataType AliHLTPHOSClusterizerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
30
31 AliHLTPHOSClusterizerComponent gAliHLTPHOSClusterizerComponent;
32
33 AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): AliHLTPHOSBase(), AliHLTProcessor(), fClusterizerPtr(0), fOutPtr(0), 
34                                                                  fRecPointStructArrayPtr(0), fRecPointListPtr(0)
35 {
36   //Constructor
37 }
38
39 AliHLTPHOSClusterizerComponent::~AliHLTPHOSClusterizerComponent()
40 {
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     {
57       for(int i = 0; i < 1000; i++) 
58         {
59           fRecPointStructArrayPtr[i].Del();
60         }
61       delete fRecPointStructArrayPtr;
62       fRecPointStructArrayPtr = 0;
63     }
64   
65 }
66
67 // PTH AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(const AliHLTPHOSClusterizerComponent &):AliHLTProcessor(), 
68 //                                                                                                     fClusterizerPtr(0), 
69 //                                                                                                     fOutPtr(0),
70 //                                                                                                     fRecPointStructArrayPtr(0),
71 //                                                                                                     fRecPointListPtr(0)
72 //{
73   //Copy constructor, not implemented
74 //}
75
76 int
77 AliHLTPHOSClusterizerComponent::Deinit()
78 {
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     }
92   
93   for(int i = 0; i < 1000; i++) 
94     {
95       fRecPointStructArrayPtr[i].Del();
96     }
97   
98   if(fRecPointStructArrayPtr)
99     {
100       for(int i = 0; i < 1000; i++) 
101         {
102           fRecPointStructArrayPtr[i].Del();
103         }
104       delete fRecPointStructArrayPtr;
105       fRecPointStructArrayPtr = 0;
106     }
107
108
109
110
111
112   return 0;
113 }
114
115 int
116 AliHLTPHOSClusterizerComponent::DoDeinit()
117 {
118   //Do deinitialization
119   Logging(kHLTLogInfo, "HLT", "PHOS", ",AliHLTPHOSClusterizerComponent DoDeinit");
120
121   return 0;
122 }
123
124
125 const Char_t* 
126 AliHLTPHOSClusterizerComponent::GetComponentID()
127 {
128   return "AliHltPhosClusterizer";
129 }
130
131 void
132 AliHLTPHOSClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
133 {
134   //Get datatypes for input
135   const AliHLTComponentDataType* pType=fgkInputDataTypes;
136   while (pType->fID!=0) {
137     list.push_back(*pType);
138     pType++;
139   }
140 }
141
142 AliHLTComponentDataType 
143 AliHLTPHOSClusterizerComponent::GetOutputDataType()
144 {
145   //  return AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
146   return AliHLTPHOSDefinitions::fgkAliHLTClusterDataType;
147 }
148
149 void
150 AliHLTPHOSClusterizerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
151
152 {
153   constBase = 30;
154   inputMultiplier = 0.2;
155 }
156
157 int 
158 AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
159                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
160                                         std::vector<AliHLTComponentBlockData>& outputBlocks)
161 {
162   //Do event
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),
185                                                      fRecPointListPtr);
186       
187     }
188  
189   nRecPoints = fClusterizerPtr->CreateRecPointStructArray(fRecPointStructArrayPtr, fRecPointListPtr, index);
190   
191   cout << "Number of clusters found: " << nRecPoints << endl;
192   
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]);
200       //      fClusterizerPtr->CalculateMoments(&fRecPointStructArrayPtr[i], 0);
201       //     fClusterizerPtr->ClusterizeStruct(&fRecPointStructArrayPtr[i], fOutPtr);
202
203       mysize += sizeof(AliHLTPHOSClusterDataStruct);
204       
205       AliHLTComponentBlockData bd;
206       FillBlockData( bd );
207       bd.fOffset = offset;
208       bd.fSize = mysize;
209       // PTH      bd.fDataType = AliHLTPHOSPhysicsDefinitions::fgkAliHLTClusterDataType;
210       bd.fDataType = AliHLTPHOSDefinitions::fgkAliHLTClusterDataType;
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
226   size = tSize;
227   fClusterizerPtr->ResetCellEnergyArray();
228
229   return 0;
230
231 }
232
233 int
234 AliHLTPHOSClusterizerComponent::DoInit(int argc, const char** argv )
235 {
236   //Do initialization
237   fClusterizerPtr = new AliHLTPHOSClusterizer();
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     }
251   fClusterizerPtr->ResetCellEnergyArray();
252   fRecPointListPtr = new AliHLTPHOSRecPointListDataStruct[N_ZROWS_MOD*N_XCOLUMNS_MOD];
253   fRecPointStructArrayPtr = new AliHLTPHOSRecPointDataStruct[1000];
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());
265
266   return 0;
267 }
268
269 AliHLTComponent*
270 AliHLTPHOSClusterizerComponent::Spawn()
271 {
272   //Spawn a new AliHLTPHOSClusterizerComponent, for HLT framework
273   return new AliHLTPHOSClusterizerComponent();
274 }