Event offset for merging added.
[u/mrichter/AliRoot.git] / HLT / ITS / AliHLTITSClusterFinderComponent.cxx
CommitLineData
6b7742a2 1// $Id$
2//**************************************************************************
3//* This file is property of and copyright by the ALICE HLT Project *
4//* ALICE Experiment at CERN, All rights reserved. *
5//* *
6//* Primary Authors: Gaute Øvrebekk <st05886@alf.uib.no> *
7//* for The ALICE HLT Project. *
8//* *
9//* Permission to use, copy, modify and distribute this software and its *
10//* documentation strictly for non-commercial purposes is hereby granted *
11//* without fee, provided that the above copyright notice appears in all *
12//* copies and that both the copyright notice and this permission notice *
13//* appear in the supporting documentation. The authors make no claims *
14//* about the suitability of this software for any purpose. It is *
15//* provided "as is" without express or implied warranty. *
16//**************************************************************************
17
18/** @file AliHLTITSClusterFinderComponent.cxx
19 @author Gaute Øvrebekk <st05886@alf.uib.no>
20 @date
21 @brief Component to run offline clusterfinders
22*/
23
24#if __GNUC__>= 3
25using namespace std;
26#endif
27
28#include "AliHLTITSClusterFinderComponent.h"
29
30#include "AliCDBEntry.h"
31#include "AliCDBManager.h"
32#include "AliHLTDataTypes.h"
33#include "AliITSgeomTGeo.h"
34#include "AliITSRecPoint.h"
35#include "AliHLTITSSpacePointData.h"
36#include "AliHLTITSClusterDataFormat.h"
37#include <AliHLTDAQ.h>
38#include "AliGeomManager.h"
39#include "TTree.h"
40#include "TBranch.h"
41#include "AliITSClusterFinderV2SPD.h"
42#include "AliITSClusterFinderV2SDD.h"
43#include "AliITSClusterFinderV2SSD.h"
060f29ad 44#include "AliITSRecoParam.h"
45#include "AliITSReconstructor.h"
6b7742a2 46
47#include <cstdlib>
48#include <cerrno>
49#include "TString.h"
50#include "TObjString.h"
51#include <sys/time.h>
52
53/** ROOT macro for the implementation of ROOT specific class methods */
54ClassImp(AliHLTITSClusterFinderComponent);
55
56AliHLTITSClusterFinderComponent::AliHLTITSClusterFinderComponent(int mode)
57 :
58 fModeSwitch(mode),
59 fNModules(0),
60 fId(0),
61 fNddl(0),
62 fClusterFinder(NULL),
63 fRawReader(NULL),
64 fDettype(NULL),
65 fgeom(NULL),
66 fgeomInit(NULL)
67{
68 // see header file for class documentation
69 // or
70 // refer to README to build package
71 // or
72 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
73 if (fModeSwitch!=kClusterFinderSPD &&
74 fModeSwitch!=kClusterFinderSDD &&
75 fModeSwitch!=kClusterFinderSSD) {
76 HLTFatal("unknown cluster finder");
77 }
78}
79
80AliHLTITSClusterFinderComponent::~AliHLTITSClusterFinderComponent() {
81 // see header file for class documentation
82}
83
84// Public functions to implement AliHLTComponent's interface.
85// These functions are required for the registration process
86
87const char* AliHLTITSClusterFinderComponent::GetComponentID()
88{
89 // see header file for class documentation
90 switch(fModeSwitch){
91 case kClusterFinderSPD:
92 return "ITSClusterFinderSPD";
93 break;
94 case kClusterFinderSDD:
95 return "ITSClusterFinderSDD";
96 break;
97 case kClusterFinderSSD:
98 return "ITSClusterFinderSSD";
99 break;
100 }
101 return "";
102}
103
104void AliHLTITSClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
105 // see header file for class documentation
106 list.clear();
107 switch(fModeSwitch){
108 case kClusterFinderSPD:
109 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSPD );
110 break;
111 case kClusterFinderSDD:
112 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSDD );
113 break;
114 case kClusterFinderSSD:
115 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSSD );
116 break;
117 }
118}
119
120AliHLTComponentDataType AliHLTITSClusterFinderComponent::GetOutputDataType() {
121 // see header file for class documentation
41625b12 122 switch(fModeSwitch){
123 case kClusterFinderSPD:
124 return kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD;
125 break;
126 case kClusterFinderSDD:
127 return kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD;
128 break;
129 case kClusterFinderSSD:
130 return kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD;
131 break;
132 }
133 return kAliHLTVoidDataType;
6b7742a2 134}
135
136void AliHLTITSClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
137 // see header file for class documentation
138 constBase = 0;
139 inputMultiplier = 100;
140}
141
142AliHLTComponent* AliHLTITSClusterFinderComponent::Spawn() {
143 // see header file for class documentation
144 return new AliHLTITSClusterFinderComponent(fModeSwitch);
145}
146
147Int_t AliHLTITSClusterFinderComponent::DoInit( int /*argc*/, const char** /*argv*/ ) {
148 // see header file for class documentation
149
150 if ( fClusterFinder )
151 return -EINPROGRESS;
152
153 if(fModeSwitch==kClusterFinderSPD) {
154 HLTDebug("using ClusterFinder for SPD");
155 fNModules=AliITSgeomTGeo::GetNDetectors(1)*AliITSgeomTGeo::GetNLadders(1) + AliITSgeomTGeo::GetNDetectors(2)*AliITSgeomTGeo::GetNLadders(2);
156 fId=AliHLTDAQ::DdlIDOffset("ITSSPD");
157 fNddl=AliHLTDAQ::NumberOfDdls("ITSSPD");
158 }
159 else if(fModeSwitch==kClusterFinderSDD) {
160 HLTDebug("using ClusterFinder for SDD");
161 fNModules=AliITSgeomTGeo::GetNDetectors(3)*AliITSgeomTGeo::GetNLadders(3) + AliITSgeomTGeo::GetNDetectors(4)*AliITSgeomTGeo::GetNLadders(4);
162 fId=AliHLTDAQ::DdlIDOffset("ITSSDD");
163 fNddl=AliHLTDAQ::NumberOfDdls("ITSSDD");
164 }
165 else if(fModeSwitch==kClusterFinderSSD) {
166 HLTDebug("using ClusterFinder for SSD");
167 fNModules=AliITSgeomTGeo::GetNDetectors(5)*AliITSgeomTGeo::GetNLadders(5) + AliITSgeomTGeo::GetNDetectors(6)*AliITSgeomTGeo::GetNLadders(6);
168 fId=AliHLTDAQ::DdlIDOffset("ITSSSD");
169 fNddl=AliHLTDAQ::NumberOfDdls("ITSSSD");
170 }
171 else{
172 HLTFatal("No mode set for clusterfindercomponent");
173 }
174
060f29ad 175 //Removed the warning for loading default RecoParam in HLT
176 AliITSRecoParam *par = AliITSRecoParam::GetLowFluxParam();
177 AliITSReconstructor *rec = new AliITSReconstructor();
178 rec->SetRecoParam(par);
179
180
6b7742a2 181 AliCDBManager* man = AliCDBManager::Instance();
182 if (!man->IsDefaultStorageSet()){
183 HLTError("Default CDB storage has not been set !");
184 return -ENOENT;
185 }
186
187 if(AliGeomManager::GetGeometry()==NULL){
188 AliGeomManager::LoadGeometry();
189 }
190 //fgeomInit = new AliITSInitGeometry(kvSPD02,2);
191 fgeomInit = new AliITSInitGeometry(kvPPRasymmFMD,2);
192 //fgeomInit->InitAliITSgeom(fgeom);
193 fgeom = fgeomInit->CreateAliITSgeom();
194
195 //set dettype
196 fDettype = new AliITSDetTypeRec();
197 fDettype->SetITSgeom(fgeom);
198 if(fModeSwitch==kClusterFinderSPD) {fDettype->SetReconstructionModel(0,fClusterFinder);}
199 else if(fModeSwitch==kClusterFinderSDD) {fDettype->SetReconstructionModel(1,fClusterFinder);}
200 else if(fModeSwitch==kClusterFinderSSD) {fDettype->SetReconstructionModel(2,fClusterFinder);}
201 fDettype->SetDefaultClusterFindersV2(kTRUE);
202 fDettype->SetDefaults();
203
204 if(fModeSwitch==kClusterFinderSPD) {fClusterFinder = new AliITSClusterFinderV2SPD(fDettype); }
205 else if(fModeSwitch==kClusterFinderSDD) {fClusterFinder = new AliITSClusterFinderV2SDD(fDettype); }
206 else if(fModeSwitch==kClusterFinderSSD) {fClusterFinder = new AliITSClusterFinderV2SSD(fDettype); }
207 fClusterFinder->InitGeometry();
208
209 if ( fRawReader )
210 return -EINPROGRESS;
211
212 fRawReader = new AliRawReaderMemory();
213
214 return 0;
215}
216
217Int_t AliHLTITSClusterFinderComponent::DoDeinit() {
218 // see header file for class documentation
219
220 if ( fRawReader )
221 delete fRawReader;
222 fRawReader = NULL;
223
224 if ( fClusterFinder )
225 delete fClusterFinder;
226 fClusterFinder = NULL;
227
228 if ( fDettype )
229 delete fDettype;
230 fDettype = NULL;
231
232 if ( fgeomInit )
233 delete fgeomInit;
234 fgeomInit = NULL;
235
236 return 0;
237}
238
239Int_t AliHLTITSClusterFinderComponent::DoEvent( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& /*trigData*/)
240{ // see header file for class documentation
241
242 // -- Iterator over Data Blocks --
243 const AliHLTComponentBlockData* iter = NULL;
244
245 if (!IsDataEvent()) return 0;
246
247 if ( evtData.fBlockCnt<=0 )
248 {
41625b12 249 HLTDebug("no blocks in event" );
6b7742a2 250 return 0;
251 }
252 AliHLTComponentDataType datatype;
253 if(fModeSwitch==kClusterFinderSPD) { datatype = kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSPD;}
254 else if(fModeSwitch==kClusterFinderSDD) {datatype = kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSDD;}
255 else if(fModeSwitch==kClusterFinderSSD) {datatype = kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSSD;}
256
257 // -- Loop over blocks
258 for ( iter = GetFirstInputBlock(datatype); iter != NULL; iter = GetNextInputBlock() ) {
259
260 // -- Debug output of datatype --
261 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
262 evtData.fEventID, evtData.fEventID,
263 DataType2Text(iter->fDataType).c_str(),
264 DataType2Text(datatype).c_str());
265
266 // -- Check for the correct data type
267 if ( iter->fDataType != (datatype) )
268 continue;
269
270 // -- Get equipment ID out of specification
271 AliHLTUInt32_t spec = iter->fSpecification;
272
273 Int_t id = fId;
274 for ( Int_t ii = 0; ii < fNddl ; ii++ ) { //number of ddl's
275 if ( spec & 0x00000001 ) {
276 id += ii;
277 break;
278 }
279 spec = spec >> 1 ;
280 }
281
282 // -- Set equipment ID to the raw reader
283
284 if(!fRawReader->AddBuffer((UChar_t*) iter->fPtr, iter->fSize, id)){
285 HLTWarning("Could not add buffer");
286 }
287
288 //fClusterFinder->RawdataToClusters(fRawReader,fClusters);
289 TTree *tree = new TTree();
290 if(fModeSwitch==kClusterFinderSPD) {fDettype->DigitsToRecPoints(fRawReader,tree,"SPD");}
291 else if(fModeSwitch==kClusterFinderSDD) {fDettype->DigitsToRecPoints(fRawReader,tree,"SDD");}
292 else if(fModeSwitch==kClusterFinderSSD) {fDettype->DigitsToRecPoints(fRawReader,tree,"SSD");}
293
294 UInt_t nClusters=0;
295 TClonesArray *array=new TClonesArray("AliITSRecPoint",1000);
296 TBranch *branch = tree->GetBranch("ITSRecPoints");
297 branch->SetAddress(&array);
298 for(int ev=0;ev<branch->GetEntries();ev++){
299 branch->GetEntry(ev);
300 nClusters += array->GetEntries();
301 }
302
303 UInt_t bufferSize = nClusters * sizeof(AliHLTITSSpacePointData) + sizeof(AliHLTITSClusterData);
304 AliHLTUInt8_t *buffer = new AliHLTUInt8_t[bufferSize];
305 AliHLTITSClusterData *outputClusters = reinterpret_cast<AliHLTITSClusterData*>(buffer);
306 outputClusters->fSpacePointCnt=nClusters;
307
308 int clustIdx=0;
309 for(int i=0;i<branch->GetEntries();i++){
310 branch->GetEntry(i);
311 for(int j=0;j<array->GetEntries();j++){
312 AliITSRecPoint *recpoint = (AliITSRecPoint*) array->At(j);
313 outputClusters->fSpacePoints[clustIdx].fY=recpoint->GetY();
314 outputClusters->fSpacePoints[clustIdx].fZ=recpoint->GetZ();
315 outputClusters->fSpacePoints[clustIdx].fSigmaY2=recpoint->GetSigmaY2();
316 outputClusters->fSpacePoints[clustIdx].fSigmaZ2=recpoint->GetSigmaZ2();
317 outputClusters->fSpacePoints[clustIdx].fSigmaYZ=recpoint->GetSigmaYZ();
318 outputClusters->fSpacePoints[clustIdx].fQ=recpoint->GetQ();
319 outputClusters->fSpacePoints[clustIdx].fNy=recpoint->GetNy();
320 outputClusters->fSpacePoints[clustIdx].fNz=recpoint->GetNz();
321 outputClusters->fSpacePoints[clustIdx].fLayer=recpoint->GetLayer();
322 if(fModeSwitch==kClusterFinderSDD){outputClusters->fSpacePoints[clustIdx].fIndex=recpoint->GetDetectorIndex() | recpoint->GetPindex() | recpoint->GetNindex();}
323 else{outputClusters->fSpacePoints[clustIdx].fIndex=recpoint->GetDetectorIndex();}
324 outputClusters->fSpacePoints[clustIdx].fTracks[0]=recpoint->GetLabel(0);
325 outputClusters->fSpacePoints[clustIdx].fTracks[1]=recpoint->GetLabel(1);
326 outputClusters->fSpacePoints[clustIdx].fTracks[2]=recpoint->GetLabel(2);
327
328 clustIdx++;
329 }
330 }
331
332 if(fModeSwitch==kClusterFinderSPD) {PushBack(buffer,bufferSize,kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD,iter->fSpecification);}
333 else if(fModeSwitch==kClusterFinderSDD) {PushBack(buffer,bufferSize,kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD,iter->fSpecification);}
334 else if(fModeSwitch==kClusterFinderSSD) {PushBack(buffer,bufferSize,kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD,iter->fSpecification);}
335
336 array->Delete();
337 delete array;
338 delete tree;
339 delete buffer;
340 fRawReader->ClearBuffers();
341
342 } // for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
343
344 return 0;
345}
346
347int AliHLTITSClusterFinderComponent::Configure(const char* arguments)
348{
349
350 int iResult=0;
351
352 if (!arguments) return iResult;
353
354 TString allArgs=arguments;
355 TString argument;
356
357 TObjArray* pTokens=allArgs.Tokenize(" ");
358
359 if (pTokens) {
360 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
361 argument=((TObjString*)pTokens->At(i))->GetString();
362 if (argument.IsNull()) continue;
363 /*
364 if (argument.CompareTo("")==0) {
365 HLTInfo("");
366 continue;
367 }
368
369 else if (argument.CompareTo("")==0) {
370 HLTInfo("");
371 continue;
372 }
373 */
374 else {
375 HLTError("unknown argument %s", argument.Data());
376 iResult=-EINVAL;
377 break;
378 }
379 }
380 delete pTokens;
381 }
382
383 return iResult;
384}
385
386int AliHLTITSClusterFinderComponent::Reconfigure(const char* cdbEntry, const char* chainId)
387{
388 // see header file for class documentation
389 int iResult=0;
390
391 const char* path="HLT/ConfigITS/ClusterFinderComponent";
392 const char* defaultNotify="";
393 if (cdbEntry) {
394 path=cdbEntry;
395 defaultNotify=" (default)";
396 }
397 if (path) {
398 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
399 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path);
400 if (pEntry) {
401 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
402 if (pString) {
403 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
404 iResult=Configure(pString->GetString().Data());
405 } else {
406 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
407 }
408 } else {
409 HLTError("can not fetch object \"%s\" from CDB", path);
410 }
411 }
412
413 return iResult;
414}
415