]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSClusterizerComponent.cxx
- Bug fix: in the creation/reading of the trigger DCS values, the HV and currents...
[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   return "PhosClusterizer";
123 }
124
125 void
126 AliHLTPHOSClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
127 {
128   //See headerfile for documentation
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 offset           = 0;
157   UInt_t mysize           = 0;
158   Int_t nRecPoints        = 0;
159   Int_t nDigits           = 0;
160   Int_t j                 = 0;
161   
162   AliHLTUInt8_t* outBPtr;
163   outBPtr = outputPtr;
164   const AliHLTComponentBlockData* iter = 0;
165   unsigned long ndx;
166   
167   UInt_t specification = 0;
168   
169   AliHLTPHOSDigitDataStruct *digitDataPtr = 0;
170   
171   AliHLTPHOSRecPointHeaderStruct* recPointHeaderPtr = reinterpret_cast<AliHLTPHOSRecPointHeaderStruct*>(outBPtr);
172
173   fClusterizerPtr->SetRecPointDataPtr(reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(outBPtr+sizeof(AliHLTPHOSRecPointHeaderStruct)));
174   
175   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
176     {
177       iter = blocks+ndx;
178       if (iter->fDataType == AliHLTPHOSDefinitions::fgkDigitDataType)
179         {
180           specification = specification|iter->fSpecification;
181           nDigits = iter->fSize/sizeof(AliHLTPHOSDigitDataStruct);
182           //HLTDebug("Number of digits in block: %d", nDigits);
183           digitDataPtr = reinterpret_cast<AliHLTPHOSDigitDataStruct*>(iter->fPtr);
184           for (Int_t i = 0; i < nDigits; i++)
185             {
186               fAllDigitsPtr->fDigitDataStruct[j].fX = digitDataPtr->fX;
187               fAllDigitsPtr->fDigitDataStruct[j].fZ = digitDataPtr->fZ;
188               fAllDigitsPtr->fDigitDataStruct[j].fEnergy = digitDataPtr->fEnergy;
189               //HLTDebug("Digit energy: %f", digitDataPtr->fEnergy);
190               fAllDigitsPtr->fDigitDataStruct[j].fTime = digitDataPtr->fTime;
191               fAllDigitsPtr->fDigitDataStruct[j].fCrazyness = digitDataPtr->fCrazyness;
192               fAllDigitsPtr->fDigitDataStruct[j].fModule = digitDataPtr->fModule;
193               j++;
194               digitDataPtr++;
195             }
196         }
197     }
198
199   fAllDigitsPtr->fNDigits = j;
200   HLTDebug("Number of digits: %d", j);
201   nRecPoints = fClusterizerPtr->ClusterizeEvent(size, mysize);
202
203   if(nRecPoints == -1)
204     {
205       HLTError("Running out of buffer, exiting for safety.");
206       return -ENOBUFS;
207     }
208
209   recPointHeaderPtr->fNRecPoints = nRecPoints;
210   mysize += sizeof(AliHLTPHOSRecPointHeaderStruct);
211   
212   HLTDebug("Number of clusters: %d", nRecPoints);
213
214 //   if(nRecPoints > 0)
215 //     {
216
217       AliHLTComponentBlockData clusterBd;
218       FillBlockData( clusterBd );
219       clusterBd.fOffset = offset;
220       clusterBd.fSize = mysize;
221       clusterBd.fDataType = AliHLTPHOSDefinitions::fgkRecPointDataType;
222       clusterBd.fSpecification = specification;
223       outputBlocks.push_back( clusterBd );
224 //     }
225
226   // if(fAllDigitsPtr->fNDigits)
227   if(false)
228     {
229       AliHLTComponentBlockData digitBd;
230       FillBlockData(digitBd);
231     }
232   
233        
234   size = mysize;
235   
236   return 0;
237 }
238
239 int
240 AliHLTPHOSClusterizerComponent::DoInit(int argc, const char** argv )
241 {
242   //See headerfile for documentation
243
244   fAllDigitsPtr = new AliHLTPHOSDigitContainerDataStruct();
245   fClusterizerPtr = new AliHLTPHOSClusterizer();
246   fClusterizerPtr->SetDigitContainer(fAllDigitsPtr);
247   fNoCrazyness = false;
248   //
249
250   ScanArgumentsModule(argc, argv);
251   for (int i = 0; i < argc; i++)
252     {
253       if(!strcmp("-digitthreshold", argv[i]))
254         {
255           fClusterizerPtr->SetEmcMinEnergyThreshold(atof(argv[i+1]));
256         }
257       if(!strcmp("-recpointthreshold", argv[i]))
258         {
259           fClusterizerPtr->SetEmcClusteringThreshold(atof(argv[i+1]));
260         }
261       if(!strcmp("-partitionmode", argv[i]))
262         {
263           fModuleClusterizationMode = false;
264         }
265     }
266   return 0;
267 }
268
269 AliHLTComponent*
270 AliHLTPHOSClusterizerComponent::Spawn()
271 {
272   //See headerfile for documentation
273
274   return new AliHLTPHOSClusterizerComponent();
275 }