2 //**************************************************************************
3 //* This file is property of and copyright by the ALICE HLT Project *
4 //* ALICE Experiment at CERN, All rights reserved. *
6 //* Primary Authors: Gaute Øvrebekk <st05886@alf.uib.no> *
7 //* for The ALICE HLT Project. *
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 //**************************************************************************
18 /** @file AliHLTITSClusterFinderComponent.cxx
19 @author Gaute Øvrebekk <st05886@alf.uib.no>
21 @brief Component to run offline clusterfinders
28 #include "AliHLTITSClusterFinderComponent.h"
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 "AliITSRecoParam.h"
40 #include "AliITSReconstructor.h"
41 #include "AliHLTITSClusterFinderSPD.h"
42 #include "AliHLTITSClusterFinderSSD.h"
47 #include "TObjString.h"
50 /** ROOT macro for the implementation of ROOT specific class methods */
51 ClassImp(AliHLTITSClusterFinderComponent);
53 AliHLTITSClusterFinderComponent::AliHLTITSClusterFinderComponent(int mode)
56 fInputDataType(kAliHLTVoidDataType),
57 fOutputDataType(kAliHLTVoidDataType),
70 // see header file for class documentation
72 // refer to README to build package
74 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
77 case kClusterFinderSPD:
78 fInputDataType = kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSPD;
79 fOutputDataType = kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD;
81 case kClusterFinderSDD:
82 fInputDataType = kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSDD;
83 fOutputDataType = kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD;
85 case kClusterFinderSSD:
86 fInputDataType = kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSSD;
87 fOutputDataType = kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD;
90 HLTFatal("unknown cluster finder");
94 AliHLTITSClusterFinderComponent::~AliHLTITSClusterFinderComponent()
96 // see header file for class documentation
104 // Public functions to implement AliHLTComponent's interface.
105 // These functions are required for the registration process
107 const char* AliHLTITSClusterFinderComponent::GetComponentID()
109 // see header file for class documentation
111 case kClusterFinderSPD:
112 return "ITSClusterFinderSPD";
114 case kClusterFinderSDD:
115 return "ITSClusterFinderSDD";
117 case kClusterFinderSSD:
118 return "ITSClusterFinderSSD";
124 void AliHLTITSClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
126 // see header file for class documentation
128 list.push_back( fInputDataType );
131 AliHLTComponentDataType AliHLTITSClusterFinderComponent::GetOutputDataType()
133 // see header file for class documentation
134 return fOutputDataType;
137 void AliHLTITSClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
138 // see header file for class documentation
140 inputMultiplier = 100;
143 AliHLTComponent* AliHLTITSClusterFinderComponent::Spawn() {
144 // see header file for class documentation
145 return new AliHLTITSClusterFinderComponent(fModeSwitch);
148 Int_t AliHLTITSClusterFinderComponent::DoInit( int argc, const char** argv ) {
149 // see header file for class documentation
157 if(fModeSwitch==kClusterFinderSPD) {
158 HLTDebug("using ClusterFinder for SPD");
159 //fNModules=AliITSgeomTGeo::GetNDetectors(1)*AliITSgeomTGeo::GetNLadders(1) + AliITSgeomTGeo::GetNDetectors(2)*AliITSgeomTGeo::GetNLadders(2);
160 fId=AliHLTDAQ::DdlIDOffset("ITSSPD");
161 fNddl=AliHLTDAQ::NumberOfDdls("ITSSPD");
163 else if(fModeSwitch==kClusterFinderSDD) {
164 HLTDebug("using ClusterFinder for SDD");
165 //fNModules=AliITSgeomTGeo::GetNDetectors(3)*AliITSgeomTGeo::GetNLadders(3) + AliITSgeomTGeo::GetNDetectors(4)*AliITSgeomTGeo::GetNLadders(4);
166 fId=AliHLTDAQ::DdlIDOffset("ITSSDD");
167 fNddl=AliHLTDAQ::NumberOfDdls("ITSSDD");
169 else if(fModeSwitch==kClusterFinderSSD) {
170 HLTDebug("using ClusterFinder for SSD");
171 //fNModules=AliITSgeomTGeo::GetNDetectors(5)*AliITSgeomTGeo::GetNLadders(5) + AliITSgeomTGeo::GetNDetectors(6)*AliITSgeomTGeo::GetNLadders(6);
172 fId=AliHLTDAQ::DdlIDOffset("ITSSSD");
173 fNddl=AliHLTDAQ::NumberOfDdls("ITSSSD");
176 HLTFatal("No mode set for clusterfindercomponent");
179 //Removed the warning for loading default RecoParam in HLT
180 AliITSRecoParam *par = AliITSRecoParam::GetLowFluxParam();
181 AliITSReconstructor *rec = new AliITSReconstructor();
182 rec->SetRecoParam(par);
184 AliCDBManager* man = AliCDBManager::Instance();
185 if (!man->IsDefaultStorageSet()){
186 HLTError("Default CDB storage has not been set !");
190 if(AliGeomManager::GetGeometry()==NULL){
191 AliGeomManager::LoadGeometry();
194 //fgeomInit = new AliITSInitGeometry(kvSPD02,2);
195 fgeomInit = new AliITSInitGeometry(kvPPRasymmFMD,2);
196 //fgeomInit->InitAliITSgeom(fgeom);
197 fgeom = fgeomInit->CreateAliITSgeom();
199 fNModules = fgeom->GetIndexMax();
201 fClusters = new TClonesArray*[fNModules];
202 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
203 fClusters[iModule] = NULL;
207 fDettype = new AliITSDetTypeRec();
208 fDettype->SetITSgeom(fgeom);
209 fDettype->SetDefaults();
210 fDettype->SetDefaultClusterFindersV2(kTRUE);
215 fRawReader = new AliRawReaderMemory();
216 fSPD = new AliHLTITSClusterFinderSPD( fDettype );
217 fSSD = new AliHLTITSClusterFinderSSD( fDettype, fRawReader );
219 TString arguments = "";
220 for ( int i = 0; i < argc; i++ ) {
221 if ( !arguments.IsNull() ) arguments += " ";
222 arguments += argv[i];
225 return Configure( arguments.Data() );
228 Int_t AliHLTITSClusterFinderComponent::DoDeinit() {
229 // see header file for class documentation
249 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
250 if(fClusters[iModule] != NULL){
251 fClusters[iModule]->Delete();
252 delete fClusters[iModule];
254 fClusters[iModule] = NULL;
257 fUseOfflineFinder = 0;
262 // #include "TStopwatch.h"
264 int AliHLTITSClusterFinderComponent::DoEvent
266 const AliHLTComponentEventData& evtData,
267 const AliHLTComponentBlockData* blocks,
268 AliHLTComponentTriggerData& /*trigData*/,
269 AliHLTUInt8_t* outputPtr,
270 AliHLTUInt32_t& size,
271 vector<AliHLTComponentBlockData>& outputBlocks )
273 // see header file for class documentation
275 AliHLTUInt32_t maxBufferSize = size;
276 size = 0; // output size
278 if (!IsDataEvent()) return 0;
280 if ( evtData.fBlockCnt<=0 )
282 HLTDebug("no blocks in event" );
290 // -- Loop over blocks
291 for( const AliHLTComponentBlockData* iter = GetFirstInputBlock(fInputDataType); iter != NULL; iter = GetNextInputBlock() ) {
293 // -- Debug output of datatype --
294 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
295 evtData.fEventID, evtData.fEventID,
296 DataType2Text(iter->fDataType).c_str(),
297 DataType2Text(fInputDataType).c_str());
299 // -- Check for the correct data type
300 if ( iter->fDataType != (fInputDataType) )
303 // -- Get equipment ID out of specification
304 AliHLTUInt32_t spec = iter->fSpecification;
307 for ( Int_t ii = 0; ii < fNddl ; ii++ ) { //number of ddl's
308 if ( spec & 0x00000001 ) {
315 // -- Set equipment ID to the raw reader
317 if(!fRawReader->AddBuffer((UChar_t*) iter->fPtr, iter->fSize, id)){
318 HLTWarning("Could not add buffer");
320 // TStopwatch timer1;
322 std::vector<AliITSRecPoint> vclusters;
324 if(fModeSwitch==kClusterFinderSPD && !fUseOfflineFinder){ fSPD->RawdataToClusters( fRawReader, vclusters ); }
325 else if(fModeSwitch==kClusterFinderSSD && !fUseOfflineFinder){ fSSD->RawdataToClusters( vclusters ); }
327 if(fModeSwitch==kClusterFinderSPD && fUseOfflineFinder) {fDettype->DigitsToRecPoints(fRawReader,fClusters,"SPD");}
328 if(fModeSwitch==kClusterFinderSSD && fUseOfflineFinder) {fDettype->DigitsToRecPoints(fRawReader,fClusters,"SSD");}
329 if(fModeSwitch==kClusterFinderSDD) {fDettype->DigitsToRecPoints(fRawReader,fClusters,"SDD");}
330 for(int i=0;i<fNModules;i++){
331 if(fClusters[i] != NULL){
332 for(int j=0;j<fClusters[i]->GetEntriesFast();j++){
333 AliITSRecPoint *recpoint = (AliITSRecPoint*) (fClusters[i]->At(j));
334 vclusters.push_back(*recpoint);
336 fClusters[i]->Delete();
344 // fStatTime+=timer1.RealTime();
345 // fStatTimeC+=timer1.CpuTime();
347 fRawReader->ClearBuffers();
349 UInt_t nClusters=vclusters.size();
351 UInt_t bufferSize = nClusters * sizeof(AliHLTITSSpacePointData) + sizeof(AliHLTITSClusterData);
352 if( size + bufferSize > maxBufferSize ){
353 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d)", maxBufferSize, size+bufferSize);
357 //cout<<"event "<<fStatNEv<<", nclu="<<nClusters<<":"<<endl;
359 AliHLTITSClusterData *outputClusters = reinterpret_cast<AliHLTITSClusterData*>(outputPtr + size);
360 outputClusters->fSpacePointCnt=nClusters;
362 for(int i=0;i<vclusters.size();i++){
363 AliITSRecPoint *recpoint = (AliITSRecPoint*) &(vclusters[i]);
364 //cout<<recpoint->GetDetectorIndex()<<" "<<recpoint->GetY()<<" "<<recpoint->GetZ()<<endl;
365 outputClusters->fSpacePoints[clustIdx].fY=recpoint->GetY();
366 outputClusters->fSpacePoints[clustIdx].fZ=recpoint->GetZ();
367 outputClusters->fSpacePoints[clustIdx].fSigmaY2=recpoint->GetSigmaY2();
368 outputClusters->fSpacePoints[clustIdx].fSigmaZ2=recpoint->GetSigmaZ2();
369 outputClusters->fSpacePoints[clustIdx].fSigmaYZ=recpoint->GetSigmaYZ();
370 outputClusters->fSpacePoints[clustIdx].fQ=recpoint->GetQ();
371 outputClusters->fSpacePoints[clustIdx].fNy=recpoint->GetNy();
372 outputClusters->fSpacePoints[clustIdx].fNz=recpoint->GetNz();
373 outputClusters->fSpacePoints[clustIdx].fLayer=recpoint->GetLayer();
374 outputClusters->fSpacePoints[clustIdx].fIndex=recpoint->GetDetectorIndex() | recpoint->GetPindex() | recpoint->GetNindex();
375 outputClusters->fSpacePoints[clustIdx].fTracks[0]=recpoint->GetLabel(0);
376 outputClusters->fSpacePoints[clustIdx].fTracks[1]=recpoint->GetLabel(1);
377 outputClusters->fSpacePoints[clustIdx].fTracks[2]=recpoint->GetLabel(2);
380 AliHLTComponentBlockData bd;
383 bd.fSize = bufferSize;
384 bd.fSpecification = iter->fSpecification;
385 bd.fDataType = GetOutputDataType();
386 outputBlocks.push_back( bd );
395 fStatTimeAll+=timer.RealTime();
396 fStatTimeAllC+=timer.CpuTime();
398 if( fStatNEv%1000==0 && fStatTimeAll>0.0 && fStatTime>0.0 && fStatTimeAllC>0.0 && fStatTimeC>0.0)
399 cout<<fStatTimeAll/fStatNEv*1.e3<<" "<<fStatTime/fStatNEv*1.e3<<" "
400 <<fStatTimeAllC/fStatNEv*1.e3<<" "<<fStatTimeC/fStatNEv*1.e3<<" ms"<<endl;
406 int AliHLTITSClusterFinderComponent::Configure(const char* arguments)
411 if (!arguments) return iResult;
413 TString allArgs=arguments;
416 TObjArray* pTokens=allArgs.Tokenize(" ");
419 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
420 argument=((TObjString*)pTokens->At(i))->GetString();
421 if (argument.IsNull()) continue;
422 if (argument.CompareTo("-use-offline-finder")==0) {
423 fUseOfflineFinder = 1;
424 HLTInfo("Off-line ClusterFinder will be used");
428 else if (argument.CompareTo("")==0) {
434 HLTError("unknown argument %s", argument.Data());
445 int AliHLTITSClusterFinderComponent::Reconfigure(const char* cdbEntry, const char* chainId)
447 // see header file for class documentation
450 const char* path="HLT/ConfigITS/ClusterFinderComponent";
451 const char* defaultNotify="";
454 defaultNotify=" (default)";
457 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
458 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path);
460 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
462 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
463 iResult=Configure(pString->GetString().Data());
465 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
468 HLTError("can not fetch object \"%s\" from CDB", path);