]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/CALO/AliHLTCaloClusterizerComponent.cxx
a1709ed4c490dc8c5212e994563a931597925593
[u/mrichter/AliRoot.git] / HLT / CALO / AliHLTCaloClusterizerComponent.cxx
1 // $Id: AliHLTCaloClusterizerComponent.cxx 36709 2009-11-12 16:57:55Z odjuvsla $
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 "AliHLTCaloClusterizerComponent.h"
18 #include "AliHLTCaloClusterizer.h"
19 #include "AliHLTCaloClusterAnalyser.h" 
20 #include "AliHLTCaloRecPointDataStruct.h"
21 #include "AliHLTCaloRecPointHeaderStruct.h"
22 #include "AliHLTCaloDigitDataStruct.h"
23 #include "AliHLTCaloDigitContainerDataStruct.h"
24 #include "AliHLTCaloDefinitions.h"
25 #include "AliHLTCaloClusterDataStruct.h"
26 #include "AliHLTCaloRecoParamHandler.h"
27 #include "TString.h"
28
29 /** @file   AliHLTCaloClusterizerComponent.cxx
30     @author Oystein Djuvsland
31     @date   
32     @brief  A clusterizer component for PHOS HLT
33 */
34
35 // see header file for class documentation
36 // or
37 // refer to README to build package
38 // or
39 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
40
41 AliHLTCaloClusterizerComponent::AliHLTCaloClusterizerComponent(TString det): 
42   AliHLTCaloProcessor(),
43   AliHLTCaloConstantsHandler(det),
44   fDataOrigin('\0'),
45   fAnalyserPtr(0),
46   fRecoParamsPtr(0),
47   fDigitsPointerArray(0), 
48   fOutputDigitsArray(0),
49   fClusterizerPtr(0),
50   fDigitCount(0)
51 {
52   //See headerfile for documentation
53
54   fDigitsPointerArray = new AliHLTCaloDigitDataStruct*[fCaloConstants->GetNXCOLUMNSMOD()*fCaloConstants->GetNZROWSMOD()];
55
56   fClusterizerPtr = new AliHLTCaloClusterizer(det);
57
58   fClusterizerPtr->SetDigitArray(fDigitsPointerArray);
59    
60   fAnalyserPtr = new AliHLTCaloClusterAnalyser();
61   
62   if(det == "PHOS")
63   {
64      fAnalyserPtr->SetClusterType(kPHOSCluster);
65   }
66   else if(det == "EMCAL")
67   {
68      fAnalyserPtr->SetClusterType(kEMCALClusterv1);
69   }
70   else
71   {
72      fAnalyserPtr->SetClusterType(kUndef);
73   }
74   
75   
76 }
77
78 AliHLTCaloClusterizerComponent::~AliHLTCaloClusterizerComponent()
79 {
80   //See headerfile for documentation
81 delete fAnalyserPtr;
82   if(fClusterizerPtr)
83     {
84       delete fClusterizerPtr;
85       fClusterizerPtr = 0;
86     }
87 }
88
89
90 int
91 AliHLTCaloClusterizerComponent::Deinit()
92 {
93   //See headerfile for documentation
94
95 if (fClusterizerPtr)
96     {
97       delete fClusterizerPtr;
98       fClusterizerPtr = 0;
99     }
100
101   return 0;
102 }
103
104 int
105 AliHLTCaloClusterizerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
106                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
107                                         std::vector<AliHLTComponentBlockData>& outputBlocks)
108 {
109   //See headerfile for documentation
110
111   if(blocks == 0) return 0;
112   
113   UInt_t offset           = 0;
114   UInt_t mysize           = 0;
115   Int_t nRecPoints        = 0;
116   Int_t nDigits           = 0;
117   Int_t digCount          = 0;
118
119   UInt_t availableSize = size;
120   AliHLTUInt8_t* outBPtr;
121   outBPtr = outputPtr;
122   const AliHLTComponentBlockData* iter = 0;
123   unsigned long ndx;
124   
125   UInt_t specification = 0;
126   
127   AliHLTCaloDigitDataStruct *digitDataPtr = 0;
128   
129   // Adding together all the digits, should be put in standalone method  
130   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
131     {
132       iter = blocks+ndx;
133       //            HLTError("Got block");
134       if (iter->fDataType == (AliHLTCaloDefinitions::fgkDigitDataType|fDataOrigin))
135         {
136
137            // Update the number of digits
138           nDigits = iter->fSize/sizeof(AliHLTCaloDigitDataStruct);
139           availableSize -= iter->fSize;
140           
141           specification = specification|iter->fSpecification;
142
143           digitDataPtr = reinterpret_cast<AliHLTCaloDigitDataStruct*>(iter->fPtr);
144           for (Int_t i = 0; i < nDigits; i++)
145             {
146               fDigitsPointerArray[digCount] = digitDataPtr;
147               digCount++;
148               digitDataPtr++;
149             }
150         }
151     }
152
153   if(digCount > 0)
154     {
155        
156       AliHLTCaloClusterHeaderStruct* caloClusterHeaderPtr = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(outBPtr);
157       caloClusterHeaderPtr->fNDigits = digCount;
158       
159       outBPtr += sizeof(AliHLTCaloClusterHeaderStruct);
160       mysize += sizeof(AliHLTCaloClusterHeaderStruct);
161       
162       // Sort the digit pointers
163       qsort(fDigitsPointerArray, digCount, sizeof(AliHLTCaloDigitDataStruct*), CompareDigits);
164
165       // Copy the digits to the output
166       fOutputDigitsArray = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
167       for(Int_t n = 0; n < digCount; n++)
168         {
169           memcpy(outBPtr, fDigitsPointerArray[n], sizeof(AliHLTCaloDigitDataStruct));
170           //fOutputDigitsArray[n] = reinterpret_cast<AliHLTCaloDigitDataStruct*>(outBPtr);
171           outBPtr = outBPtr + sizeof(AliHLTCaloDigitDataStruct);
172         }
173   
174       mysize += digCount*sizeof(AliHLTCaloDigitDataStruct);
175       
176       //HLTDebug("Total number of digits: %d", digCount );
177
178       nRecPoints = fClusterizerPtr->ClusterizeEvent(digCount);
179
180       //HLTDebug("Number of rec points found: %d", nRecPoints);
181       fAnalyserPtr->SetCaloClusterData(reinterpret_cast<AliHLTCaloClusterDataStruct*>(outBPtr));
182       
183       fAnalyserPtr->SetRecPointArray(fClusterizerPtr->GetRecPoints(), nRecPoints);
184
185       fAnalyserPtr->SetDigitDataArray(fOutputDigitsArray);
186       
187       Int_t nClusters = fAnalyserPtr->CreateClusters(nRecPoints, size, mysize);
188       
189       if (nClusters < 0) 
190         {
191           caloClusterHeaderPtr->fNClusters = 0;
192         } 
193       else 
194         {
195           caloClusterHeaderPtr->fNClusters = nClusters;
196         }
197      
198       //HLTDebug("Number of clusters: %d", nRecPoints);
199       
200       AliHLTComponentBlockData bd;
201       FillBlockData( bd );
202       bd.fOffset = offset;
203       bd.fSize = mysize;
204       bd.fDataType = kAliHLTDataTypeCaloCluster | fDataOrigin;
205       bd.fSpecification = specification;
206       outputBlocks.push_back( bd );
207     }
208
209   size = mysize;
210   
211   return 0;
212 }
213
214 int 
215 AliHLTCaloClusterizerComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
216 {  
217   // see header file for class documentation
218
219   const char* path="HLT/ConfigPHOS/ClusterizerComponent";
220
221   if (cdbEntry) path = cdbEntry;
222
223   return ConfigureFromCDBTObjString(cdbEntry);
224 }
225
226 int 
227 AliHLTCaloClusterizerComponent::ScanConfigurationArgument(int argc, const char **argv)
228 {
229   //See header file for documentation
230
231   if(argc <= 0) return 0;
232
233   int i=0;
234
235   TString argument=argv[i];
236
237   if (argument.CompareTo("-digitthreshold") == 0)
238     {
239       if (++i >= argc) return -EPROTO;
240       argument = argv[i];
241       fClusterizerPtr->SetEmcMinEnergyThreshold(argument.Atof());
242       return 1;
243     }
244
245   if (argument.CompareTo("-recpointthreshold") == 0)
246     {
247       if (++i >= argc) return -EPROTO;
248       argument = argv[i];
249       fClusterizerPtr->SetEmcClusteringThreshold(argument.Atof());
250       return 1;
251     }
252   return 0;
253 }
254
255 int
256 AliHLTCaloClusterizerComponent::DoInit(int argc, const char** argv )
257 {
258   //See headerfile for documentation
259
260   if(fRecoParamsPtr)
261   {
262      if(!fRecoParamsPtr->GetParametersFromCDB())
263      {
264          fAnalyserPtr->SetRecoParamHandler(fRecoParamsPtr);
265      }
266   }
267   //
268
269   //  const char *path = "HLT/ConfigPHOS/ClusterizerComponent";
270
271   //  ConfigureFromCDBTObjString(path);
272
273   for (int i = 0; i < argc; i++)
274     {
275       ScanConfigurationArgument(i, argv);
276     }
277
278   return 0;
279 }
280
281 Int_t 
282 AliHLTCaloClusterizerComponent::CompareDigits(const void *dig0, const void *dig1)
283 {
284   // See header file for documentation
285   return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
286
287   //return (*((AliHLTCaloDigitDataStruct**)(dig0)))->fID - (*((AliHLTCaloDigitDataStruct**)(dig1)))->fID;
288 }