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