]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx
3094ff6d6c7825d93a0ed79765c353d8da040340
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSClusterizerComponent.cxx
1 // $Id$
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 "AliHLTPHOSClusterizerComponent.h"
20 #include "AliHLTPHOSClusterizer.h"
21 #include "AliHLTPHOSRecPointDataStruct.h"
22 #include "AliHLTPHOSRecPointHeaderStruct.h"
23 #include "AliHLTPHOSDigitDataStruct.h"
24 #include "AliHLTPHOSDigitContainerDataStruct.h"
25
26
27
28 /** @file   AliHLTPHOSClusterizerComponent.cxx
29     @author Oystein Djuvsland
30     @date   
31     @brief  A clusterizer component for PHOS HLT
32 */
33
34 // see header file for class documentation
35 // or
36 // refer to README to build package
37 // or
38 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
39
40 #if __GNUC__>= 3
41 using namespace std;
42 #endif
43
44 const AliHLTComponentDataType AliHLTPHOSClusterizerComponent::fgkInputDataTypes[]=
45   {
46     kAliHLTVoidDataType,{0,"",""}
47   };
48
49 AliHLTPHOSClusterizerComponent gAliHLTPHOSClusterizerComponent;
50
51
52 AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): 
53   AliHLTPHOSProcessor(), 
54   fAllDigitsPtr(0),
55   fClusterizerPtr(0),
56   fRecPointStructArrayPtr(0),
57   fDigitCount(0),
58   fModuleClusterizationMode(true),
59   fNoCrazyness(0)
60 {
61   //See headerfile for documentation
62 }
63
64 AliHLTPHOSClusterizerComponent::~AliHLTPHOSClusterizerComponent()
65 {
66   //See headerfile for documentation
67
68   if(fClusterizerPtr)
69     {
70       delete fClusterizerPtr;
71       fClusterizerPtr = 0;
72     }
73   if(fRecPointStructArrayPtr)
74     {
75       for (int i = 0; i < 1000; i++)
76         {
77           //      fRecPointStructArrayPtr[i].Del();
78         }
79       delete fRecPointStructArrayPtr;
80       fRecPointStructArrayPtr = 0;
81     }
82   if(fAllDigitsPtr)
83     {
84       delete fAllDigitsPtr;
85       fAllDigitsPtr = 0;
86     }
87 }
88
89
90 int
91 AliHLTPHOSClusterizerComponent::Deinit()
92 {
93   //See headerfile for documentation
94
95   if (fClusterizerPtr)
96     {
97       delete fClusterizerPtr;
98       fClusterizerPtr = 0;
99     }
100   for (int i = 0; i < 1000; i++)
101     {
102       //    fRecPointStructArrayPtr[i].Del();
103     }
104
105   if (fRecPointStructArrayPtr)
106     {
107       for (int i = 0; i < 1000; i++)
108         {
109           //      fRecPointStructArrayPtr[i].Del();
110         }
111       delete fRecPointStructArrayPtr;
112       fRecPointStructArrayPtr = 0;
113     }
114
115   return 0;
116 }
117
118 const Char_t*
119 AliHLTPHOSClusterizerComponent::GetComponentID()
120 {
121   //See headerfile for documentation
122
123   return "PhosClusterizer";
124 }
125
126 void
127 AliHLTPHOSClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
128 {
129   list.clear();
130   list.push_back(AliHLTPHOSDefinitions::fgkDigitDataType);
131 }
132
133 AliHLTComponentDataType
134 AliHLTPHOSClusterizerComponent::GetOutputDataType()
135 {
136   //See headerfile for documentation
137   return AliHLTPHOSDefinitions::fgkRecPointDataType;
138 }
139
140 void
141 AliHLTPHOSClusterizerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
142
143 {
144   //See headerfile for documentation
145   constBase = sizeof(AliHLTPHOSRecPointHeaderStruct) + sizeof(AliHLTPHOSRecPointDataStruct) + (sizeof(AliHLTPHOSDigitDataStruct) << 7); //Reasonable estimate... ;
146   inputMultiplier = 1.5;
147 }
148
149 int
150 AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
151                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
152                                         std::vector<AliHLTComponentBlockData>& outputBlocks)
153 {
154   //See headerfile for documentation
155   
156   UInt_t tSize            = 0;
157   UInt_t offset           = 0;
158   UInt_t mysize           = 0;
159   Int_t nRecPoints        = 0;
160   Int_t nDigits           = 0;
161   Int_t j                 = 0;
162   
163   AliHLTUInt8_t* outBPtr;
164   outBPtr = outputPtr;
165   const AliHLTComponentBlockData* iter = 0;
166   unsigned long ndx;
167   
168   UInt_t specification = 0;
169   
170   AliHLTPHOSDigitDataStruct *digitDataPtr = 0;
171   
172   AliHLTPHOSRecPointHeaderStruct* recPointHeaderPtr = reinterpret_cast<AliHLTPHOSRecPointHeaderStruct*>(outBPtr);
173
174   fClusterizerPtr->SetRecPointDataPtr(reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(outBPtr+sizeof(AliHLTPHOSRecPointHeaderStruct)));
175   
176   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
177     {
178       iter = blocks+ndx;
179       if (iter->fDataType == AliHLTPHOSDefinitions::fgkDigitDataType)
180         {
181           specification = specification|iter->fSpecification;
182           nDigits = iter->fSize/sizeof(AliHLTPHOSDigitDataStruct);
183           //HLTDebug("Number of digits in block: %d", nDigits);
184           digitDataPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(iter->fPtr);
185           for (Int_t i = 0; i < nDigits; i++)
186             {
187               fAllDigitsPtr->fDigitDataStruct[j].fX = digitDataPtr->fX;
188               fAllDigitsPtr->fDigitDataStruct[j].fZ = digitDataPtr->fZ;
189               fAllDigitsPtr->fDigitDataStruct[j].fEnergy = digitDataPtr->fEnergy;
190               //  HLTDebug("Digit energy: %f", digitDataPtr->fEnergy);
191               fAllDigitsPtr->fDigitDataStruct[j].fTime = digitDataPtr->fTime;
192               fAllDigitsPtr->fDigitDataStruct[j].fCrazyness = digitDataPtr->fCrazyness;
193               j++;
194               digitDataPtr++;
195             }
196         }
197     }
198   fAllDigitsPtr->fNDigits = j;
199   nRecPoints = fClusterizerPtr->ClusterizeEvent(size, mysize);
200
201   if(nRecPoints == -1)
202     {
203       HLTError("Running out of buffer, exiting for safety.");
204       return -ENOBUFS;
205     }
206
207   recPointHeaderPtr->fNRecPoints = nRecPoints;
208   mysize += sizeof(AliHLTPHOSRecPointHeaderStruct);
209   
210   HLTDebug("Number of clusters: %d", nRecPoints);
211
212   AliHLTComponentBlockData bd;
213   FillBlockData( bd );
214   bd.fOffset = offset;
215   bd.fSize = mysize;
216   bd.fDataType = AliHLTPHOSDefinitions::fgkClusterDataType;
217   bd.fSpecification = specification;
218   outputBlocks.push_back( bd );
219      
220   if ( tSize > size )
221     {
222       Logging( kHLTLogFatal, "HLT::AliHLTPHOSClusterizerComponent::DoEvent", "Too much data",
223                "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
224                , tSize, size );
225       return EMSGSIZE;
226     }
227
228   size = mysize;
229   
230   return 0;
231 }
232
233 int
234 AliHLTPHOSClusterizerComponent::DoInit(int argc, const char** argv )
235 {
236   //See headerfile for documentation
237
238   fAllDigitsPtr = new AliHLTPHOSDigitContainerDataStruct();
239   fClusterizerPtr = new AliHLTPHOSClusterizer();
240   fClusterizerPtr->SetDigitContainer(fAllDigitsPtr);
241   fNoCrazyness = false;
242   //
243
244   ScanArgumentsModule(argc, argv);
245   for (int i = 0; i < argc; i++)
246     {
247       if(!strcmp("-digitthreshold", argv[i]))
248         {
249           fClusterizerPtr->SetEmcMinEnergyThreshold(atof(argv[i+1]));
250         }
251       if(!strcmp("-recpointthreshold", argv[i]))
252         {
253           fClusterizerPtr->SetEmcClusteringThreshold(atof(argv[i+1]));
254         }
255       if(!strcmp("-partitionmode", argv[i]))
256         {
257           fModuleClusterizationMode = false;
258         }
259     }
260   return 0;
261 }
262
263 AliHLTComponent*
264 AliHLTPHOSClusterizerComponent::Spawn()
265 {
266   //See headerfile for documentation
267
268   return new AliHLTPHOSClusterizerComponent();
269 }