]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx
7f40a906ceff0271bfd5a5496c005fd50ec4870d
[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 #include <iostream>
16
17 #include "AliHLTPHOSClusterizerComponent.h"
18 #include "AliHLTPHOSClusterizer.h"
19 #include "AliHLTPHOSRecPointDataStruct.h"
20 #include "AliHLTPHOSDigitContainerDataStruct.h"
21
22
23
24 /** @file   AliHLTPHOSClusterizerComponent.cxx
25     @author Oystein Djuvsland
26     @date   
27     @brief  A clusterizer component for PHOS HLT
28 */
29
30 // see header file for class documentation
31 // or
32 // refer to README to build package
33 // or
34 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
35
36 #if __GNUC__>= 3
37 using namespace std;
38 #endif
39
40 const AliHLTComponentDataType AliHLTPHOSClusterizerComponent::fgkInputDataTypes[]=
41   {
42     kAliHLTVoidDataType,{0,"",""}
43   };
44
45 AliHLTPHOSClusterizerComponent gAliHLTPHOSClusterizerComponent;
46
47
48 AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): 
49   AliHLTPHOSProcessor(), 
50   fAllDigitsPtr(0),
51   fClusterizerPtr(0),
52   fRecPointStructArrayPtr(0),
53   fDigitCount(0),
54   fModuleClusterizationMode(false),
55   fNoCrazyness(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   if(fRecPointStructArrayPtr)
70     {
71       for (int i = 0; i < 1000; i++)
72         {
73           //      fRecPointStructArrayPtr[i].Del();
74         }
75       delete fRecPointStructArrayPtr;
76       fRecPointStructArrayPtr = 0;
77     }
78   if(fAllDigitsPtr)
79     {
80       delete fAllDigitsPtr;
81       fAllDigitsPtr = 0;
82     }
83 }
84
85
86 int
87 AliHLTPHOSClusterizerComponent::Deinit()
88 {
89   //See headerfile for documentation
90
91   if (fClusterizerPtr)
92     {
93       delete fClusterizerPtr;
94       fClusterizerPtr = 0;
95     }
96   for (int i = 0; i < 1000; i++)
97     {
98       //    fRecPointStructArrayPtr[i].Del();
99     }
100
101   if (fRecPointStructArrayPtr)
102     {
103       for (int i = 0; i < 1000; i++)
104         {
105           //      fRecPointStructArrayPtr[i].Del();
106         }
107       delete fRecPointStructArrayPtr;
108       fRecPointStructArrayPtr = 0;
109     }
110
111   return 0;
112 }
113
114 const Char_t*
115 AliHLTPHOSClusterizerComponent::GetComponentID()
116 {
117   //See headerfile for documentation
118
119   return "PhosClusterizer";
120 }
121
122 void
123 AliHLTPHOSClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
124 {
125   list.clear();
126   list.push_back(AliHLTPHOSDefinitions::fgkDigitDataType);
127 }
128
129 AliHLTComponentDataType
130 AliHLTPHOSClusterizerComponent::GetOutputDataType()
131 {
132   //See headerfile for documentation
133   return AliHLTPHOSDefinitions::fgkClusterDataType;
134 }
135
136 void
137 AliHLTPHOSClusterizerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
138
139 {
140   //See headerfile for documentation
141   constBase = sizeof(AliHLTPHOSRecPointContainerStruct);
142   inputMultiplier = 1;
143 }
144
145 int
146 AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
147                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
148                                         std::vector<AliHLTComponentBlockData>& outputBlocks)
149 {
150   //See headerfile for documentation
151   
152   UInt_t tSize            = 0;
153   UInt_t offset           = 0;
154   UInt_t mysize           = 0;
155   Int_t nRecPoints        = 0;
156   Int_t j = 0;
157
158   AliHLTUInt8_t* outBPtr;
159   outBPtr = outputPtr;
160   const AliHLTComponentBlockData* iter = 0;
161   unsigned long ndx;
162
163   UInt_t specification = 0;
164
165   AliHLTPHOSDigitContainerDataStruct *digitContainerPtr = 0;
166   fClusterizerPtr->SetRecPointContainer((AliHLTPHOSRecPointContainerStruct*)outBPtr);
167   
168   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
169     {
170       iter = blocks+ndx;
171       if (iter->fDataType == AliHLTPHOSDefinitions::fgkDigitDataType)
172         {
173           specification = specification|iter->fSpecification;
174           digitContainerPtr = reinterpret_cast<AliHLTPHOSDigitContainerDataStruct*>(iter->fPtr);
175           if(fModuleClusterizationMode)
176             {
177               for (UInt_t i = 0; i < digitContainerPtr->fNDigits; i++)
178                 {
179                   fAllDigitsPtr->fDigitDataStruct[j].fX = digitContainerPtr->fDigitDataStruct[i].fX;
180                   fAllDigitsPtr->fDigitDataStruct[j].fZ = digitContainerPtr->fDigitDataStruct[i].fZ;
181                   fAllDigitsPtr->fDigitDataStruct[j].fAmplitude = digitContainerPtr->fDigitDataStruct[i].fAmplitude;
182                   fAllDigitsPtr->fDigitDataStruct[j].fEnergy = digitContainerPtr->fDigitDataStruct[i].fEnergy;
183                   fAllDigitsPtr->fDigitDataStruct[j].fTime = digitContainerPtr->fDigitDataStruct[i].fTime;
184                   fAllDigitsPtr->fDigitDataStruct[j].fCrazyness = digitContainerPtr->fDigitDataStruct[i].fCrazyness;
185                   j++;
186                 }
187           
188             }
189         }
190     }
191   fAllDigitsPtr->fNDigits = j;
192   if(fModuleClusterizationMode && fAllDigitsPtr != 0)
193     {
194       fClusterizerPtr->SetDigitContainer(fAllDigitsPtr);
195     }
196   else if(digitContainerPtr != 0)
197     {
198       fClusterizerPtr->SetDigitContainer(digitContainerPtr);
199     }      
200   if(digitContainerPtr != 0)
201     {
202       nRecPoints = fClusterizerPtr->ClusterizeEvent();
203       mysize = 0;
204       offset = tSize;
205
206       mysize += sizeof(AliHLTPHOSRecPointContainerStruct);
207       
208       AliHLTComponentBlockData bd;
209       FillBlockData( bd );
210       bd.fOffset = offset;
211       bd.fSize = mysize;
212       bd.fDataType = AliHLTPHOSDefinitions::fgkClusterDataType;
213       bd.fSpecification = specification;
214       outputBlocks.push_back( bd );
215       tSize += mysize;
216       outBPtr += mysize;
217   
218     }
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("-modulemode", argv[i]))
256         {
257           fModuleClusterizationMode = true;
258         }
259     }
260
261   return 0;
262 }
263
264 AliHLTComponent*
265 AliHLTPHOSClusterizerComponent::Spawn()
266 {
267   //See headerfile for documentation
268
269   return new AliHLTPHOSClusterizerComponent();
270 }