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