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