]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx
- cosmetics
[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 AliHLTPHOSClusterizerComponent gAliHLTPHOSClusterizerComponent;
41
42 AliHLTPHOSClusterizerComponent::AliHLTPHOSClusterizerComponent(): 
43   AliHLTPHOSProcessor(), 
44   fAllDigitsPtr(0),
45   fClusterizerPtr(0),
46   fDigitCount(0),
47   fNoCrazyness(0)
48 {
49   //See headerfile for documentation
50 }
51
52 AliHLTPHOSClusterizerComponent::~AliHLTPHOSClusterizerComponent()
53 {
54   //See headerfile for documentation
55
56   if(fClusterizerPtr)
57     {
58       delete fClusterizerPtr;
59       fClusterizerPtr = 0;
60     }
61   if(fAllDigitsPtr)
62     {
63       delete fAllDigitsPtr;
64       fAllDigitsPtr = 0;
65     }
66 }
67
68
69 int
70 AliHLTPHOSClusterizerComponent::Deinit()
71 {
72   //See headerfile for documentation
73
74   if (fClusterizerPtr)
75     {
76       delete fClusterizerPtr;
77       fClusterizerPtr = 0;
78     }
79
80   return 0;
81 }
82
83 const Char_t*
84 AliHLTPHOSClusterizerComponent::GetComponentID()
85 {
86   //See headerfile for documentation
87   return "PhosClusterizer";
88 }
89
90 void
91 AliHLTPHOSClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
92 {
93   //See headerfile for documentation
94   list.clear();
95   list.push_back(AliHLTPHOSDefinitions::fgkDigitDataType);
96 }
97
98 AliHLTComponentDataType
99 AliHLTPHOSClusterizerComponent::GetOutputDataType()
100 {
101   //See headerfile for documentation
102   return AliHLTPHOSDefinitions::fgkRecPointDataType;
103 }
104
105 void
106 AliHLTPHOSClusterizerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
107
108 {
109   //See headerfile for documentation
110   constBase = sizeof(AliHLTPHOSRecPointHeaderStruct) + sizeof(AliHLTPHOSRecPointDataStruct) + (sizeof(AliHLTPHOSDigitDataStruct) << 7); //Reasonable estimate... ;
111   inputMultiplier = 1.5;
112 }
113
114 int
115 AliHLTPHOSClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
116                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
117                                         std::vector<AliHLTComponentBlockData>& outputBlocks)
118 {
119   //See headerfile for documentation
120   
121   UInt_t offset           = 0;
122   UInt_t mysize           = 0;
123   Int_t nRecPoints        = 0;
124   Int_t nDigits           = 0;
125   Int_t j                 = 0;
126   
127   AliHLTUInt8_t* outBPtr;
128   outBPtr = outputPtr;
129   const AliHLTComponentBlockData* iter = 0;
130   unsigned long ndx;
131   
132   UInt_t specification = 0;
133   
134   AliHLTPHOSDigitDataStruct *digitDataPtr = 0;
135   
136   AliHLTPHOSRecPointHeaderStruct* recPointHeaderPtr = reinterpret_cast<AliHLTPHOSRecPointHeaderStruct*>(outBPtr);
137
138   fClusterizerPtr->SetRecPointDataPtr(reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(outBPtr+sizeof(AliHLTPHOSRecPointHeaderStruct)));
139   
140   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
141     {
142       iter = blocks+ndx;
143       if (iter->fDataType == AliHLTPHOSDefinitions::fgkDigitDataType)
144         {
145           specification = specification|iter->fSpecification;
146           nDigits = iter->fSize/sizeof(AliHLTPHOSDigitDataStruct);
147           digitDataPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(iter->fPtr);
148           for (Int_t i = 0; i < nDigits; i++)
149             {
150               fAllDigitsPtr->fDigitDataStruct[j].fX = digitDataPtr->fX;
151               fAllDigitsPtr->fDigitDataStruct[j].fZ = digitDataPtr->fZ;
152               fAllDigitsPtr->fDigitDataStruct[j].fEnergy = digitDataPtr->fEnergy;
153               fAllDigitsPtr->fDigitDataStruct[j].fTime = digitDataPtr->fTime;
154               fAllDigitsPtr->fDigitDataStruct[j].fCrazyness = digitDataPtr->fCrazyness;
155               fAllDigitsPtr->fDigitDataStruct[j].fModule = digitDataPtr->fModule;
156               j++;
157               digitDataPtr++;
158             }
159         }
160     }
161
162   fAllDigitsPtr->fNDigits = j;
163   HLTDebug("Number of digits: %d", j);
164   nRecPoints = fClusterizerPtr->ClusterizeEvent(size, mysize);
165
166   if(nRecPoints == -1)
167     {
168       HLTError("Running out of buffer, exiting for safety.");
169       return -ENOBUFS;
170     }
171
172   recPointHeaderPtr->fNRecPoints = nRecPoints;
173   mysize += sizeof(AliHLTPHOSRecPointHeaderStruct);
174   
175   HLTDebug("Number of clusters: %d", nRecPoints);
176
177   AliHLTComponentBlockData clusterBd;
178   FillBlockData( clusterBd );
179   clusterBd.fOffset = offset;
180   clusterBd.fSize = mysize;
181   clusterBd.fDataType = AliHLTPHOSDefinitions::fgkRecPointDataType;
182   clusterBd.fSpecification = specification;
183   outputBlocks.push_back( clusterBd );
184
185   if(false)
186     {
187       AliHLTComponentBlockData digitBd;
188       FillBlockData(digitBd);
189     }
190        
191   size = mysize;
192   
193   return 0;
194 }
195
196 int 
197 AliHLTPHOSClusterizerComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
198 {  
199   // see header file for class documentation
200
201   const char* path="HLT/ConfigPHOS/ClusterizerComponent";
202
203   if (cdbEntry) path = cdbEntry;
204
205   return ConfigureFromCDBTObjString(cdbEntry);
206 }
207
208 int 
209 AliHLTPHOSClusterizerComponent::ScanConfigurationArgument(int argc, const char **argv)
210 {
211   //See header file for documentation
212
213   if(argc <= 0) return 0;
214
215   int i=0;
216
217   TString argument=argv[i];
218
219   if (argument.CompareTo("-digitthreshold") == 0)
220     {
221       if (++i >= argc) return -EPROTO;
222       argument = argv[i];
223       fClusterizerPtr->SetEmcMinEnergyThreshold(argument.Atof());
224       return 1;
225     }
226
227   if (argument.CompareTo("-recpointthreshold") == 0)
228     {
229       if (++i >= argc) return -EPROTO;
230       argument = argv[i];
231       fClusterizerPtr->SetEmcClusteringThreshold(argument.Atof());
232       return 1;
233     }
234
235 }
236
237 int
238 AliHLTPHOSClusterizerComponent::DoInit(int argc, const char** argv )
239 {
240   //See headerfile for documentation
241
242   fAllDigitsPtr = new AliHLTPHOSDigitContainerDataStruct();
243   fClusterizerPtr = new AliHLTPHOSClusterizer();
244   fClusterizerPtr->SetDigitContainer(fAllDigitsPtr);
245   fNoCrazyness = false;
246   //
247
248   const char *path = "HLT/ConfigPHOS/ClusterizerComponent";
249
250   ConfigureFromCDBTObjString(path);
251
252   for (int i = 0; i < argc; i++)
253     {
254       ScanConfigurationArgument(i, argv[i]);
255     }
256
257   return 0;
258 }
259
260 AliHLTComponent*
261 AliHLTPHOSClusterizerComponent::Spawn()
262 {
263   //See headerfile for documentation
264
265   return new AliHLTPHOSClusterizerComponent();
266 }