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 "AliCDBStorage.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),
72 fBenchmark(GetComponentID())
74 // see header file for class documentation
76 // refer to README to build package
78 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
81 case kClusterFinderSPD:
82 fInputDataType = kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSPD;
83 fOutputDataType = kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD;
85 case kClusterFinderSDD:
86 fInputDataType = kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSDD;
87 fOutputDataType = kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD;
89 case kClusterFinderSSD:
90 fInputDataType = kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSSD;
91 fOutputDataType = kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD;
93 case kClusterFinderDigits:
94 fInputDataType = kAliHLTDataTypeAliTreeD|kAliHLTDataOriginITS;
95 fOutputDataType = kAliHLTDataTypeClusters|kAliHLTDataOriginITS;
98 HLTFatal("unknown cluster finder");
102 AliHLTITSClusterFinderComponent::~AliHLTITSClusterFinderComponent()
104 // see header file for class documentation
112 // Public functions to implement AliHLTComponent's interface.
113 // These functions are required for the registration process
115 const char* AliHLTITSClusterFinderComponent::GetComponentID()
117 // see header file for class documentation
119 case kClusterFinderSPD:
120 return "ITSClusterFinderSPD";
122 case kClusterFinderSDD:
123 return "ITSClusterFinderSDD";
125 case kClusterFinderSSD:
126 return "ITSClusterFinderSSD";
128 case kClusterFinderDigits:
129 return "ITSClusterFinderDigits";
135 void AliHLTITSClusterFinderComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
137 // see header file for class documentation
139 list.push_back( fInputDataType );
142 AliHLTComponentDataType AliHLTITSClusterFinderComponent::GetOutputDataType()
144 // see header file for class documentation
145 return fOutputDataType;
148 void AliHLTITSClusterFinderComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
149 // see header file for class documentation
151 inputMultiplier = 100;
154 AliHLTComponent* AliHLTITSClusterFinderComponent::Spawn() {
155 // see header file for class documentation
156 return new AliHLTITSClusterFinderComponent(fModeSwitch);
159 Int_t AliHLTITSClusterFinderComponent::DoInit( int argc, const char** argv ) {
160 // see header file for class documentation
162 fBenchmark.SetTimer(0,"total");
163 fBenchmark.SetTimer(1,"reco");
173 Int_t runNo = GetRunNo();
174 AliCDBStorage* store = AliCDBManager::Instance()->GetDefaultStorage();
181 if(store->GetLatestVersion("ITS/Calib/SPDNoisy", runNo)<0){
182 HLTError("SPDNoisy is not found in SPD/Calib");
185 if(store->GetLatestVersion("ITS/Calib/SPDDead", runNo)<0){
186 HLTError("SPDDead is not found in SPD/Calib");
189 if(store->GetLatestVersion("TRIGGER/SPD/PITConditions", runNo)<0){
190 HLTError("PITConditions is not found in TRIGGER/SPD");
195 if(store->GetLatestVersion("ITS/Calib/CalibSDD", runNo)<0){
196 HLTError("CalibSDD is not found in ITS/Calib");
199 if(store->GetLatestVersion("ITS/Calib/RespSDD", runNo)<0){
200 HLTError("RespSDD is not found in ITS/Calib");
203 if(store->GetLatestVersion("ITS/Calib/DriftSpeedSDD", runNo)<0){
204 HLTError("DriftSpeedSDD is not found in ITS/Calib");
207 if(store->GetLatestVersion("ITS/Calib/DDLMapSDD", runNo)<0){
208 HLTError("DDLMapSDD is not found in ITS/Calib");
211 if(store->GetLatestVersion("ITS/Calib/MapsTimeSDD", runNo)<0){
212 HLTError("MapsTimeSDD is not found in ITS/Calib");
217 if(store->GetLatestVersion("ITS/Calib/NoiseSSD", runNo)<0){
218 HLTError("NoiseSSD is not found in ITS/Calib");
221 if(store->GetLatestVersion("ITS/Calib/GainSSD", runNo)<0){
222 HLTError("GainSSD is not found in ITS/Calib");
225 if(store->GetLatestVersion("ITS/Calib/BadChannelsSSD", runNo)<0){
226 HLTError("BadChannelsSSD is not found in ITS/Calib");
230 //General reconstruction
231 if(store->GetLatestVersion("GRP/CTP/Scalers", runNo)<0){
232 HLTError("Scalers is not found in GRP/CTP/");
235 if(!cdbOK){return NULL;}
237 if(fModeSwitch==kClusterFinderSPD) {
238 HLTDebug("using ClusterFinder for SPD");
239 //fNModules=AliITSgeomTGeo::GetNDetectors(1)*AliITSgeomTGeo::GetNLadders(1) + AliITSgeomTGeo::GetNDetectors(2)*AliITSgeomTGeo::GetNLadders(2);
240 fId=AliHLTDAQ::DdlIDOffset("ITSSPD");
241 fNddl=AliHLTDAQ::NumberOfDdls("ITSSPD");
243 else if(fModeSwitch==kClusterFinderSDD) {
244 HLTDebug("using ClusterFinder for SDD");
245 //fNModules=AliITSgeomTGeo::GetNDetectors(3)*AliITSgeomTGeo::GetNLadders(3) + AliITSgeomTGeo::GetNDetectors(4)*AliITSgeomTGeo::GetNLadders(4);
246 fId=AliHLTDAQ::DdlIDOffset("ITSSDD");
247 fNddl=AliHLTDAQ::NumberOfDdls("ITSSDD");
249 else if(fModeSwitch==kClusterFinderSSD) {
250 HLTDebug("using ClusterFinder for SSD");
251 //fNModules=AliITSgeomTGeo::GetNDetectors(5)*AliITSgeomTGeo::GetNLadders(5) + AliITSgeomTGeo::GetNDetectors(6)*AliITSgeomTGeo::GetNLadders(6);
252 fId=AliHLTDAQ::DdlIDOffset("ITSSSD");
253 fNddl=AliHLTDAQ::NumberOfDdls("ITSSSD");
255 else if(fModeSwitch==kClusterFinderDigits) {
259 HLTFatal("No mode set for clusterfindercomponent");
262 //Removed the warning for loading default RecoParam in HLT
263 AliITSRecoParam *par = AliITSRecoParam::GetLowFluxParam();
264 AliITSReconstructor *rec = new AliITSReconstructor();
265 rec->SetRecoParam(par);
267 AliCDBManager* man = AliCDBManager::Instance();
268 if (!man->IsDefaultStorageSet()){
269 HLTError("Default CDB storage has not been set !");
273 if(AliGeomManager::GetGeometry()==NULL){
274 AliGeomManager::LoadGeometry();
277 //fgeomInit = new AliITSInitGeometry(kvSPD02,2);
278 fgeomInit = new AliITSInitGeometry(kvPPRasymmFMD,2);
279 //fgeomInit->InitAliITSgeom(fgeom);
280 fgeom = fgeomInit->CreateAliITSgeom();
282 fNModules = fgeom->GetIndexMax();
284 fClusters = new TClonesArray*[fNModules];
285 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
286 fClusters[iModule] = NULL;
290 fDettype = new AliITSDetTypeRec();
291 fDettype->SetITSgeom(fgeom);
292 fDettype->SetDefaults();
293 fDettype->SetDefaultClusterFindersV2(kTRUE);
298 fRawReader = new AliRawReaderMemory();
299 fSPD = new AliHLTITSClusterFinderSPD( fDettype );
300 fSSD = new AliHLTITSClusterFinderSSD( fDettype, fRawReader );
302 TString arguments = "";
303 for ( int i = 0; i < argc; i++ ) {
304 if ( !arguments.IsNull() ) arguments += " ";
305 arguments += argv[i];
311 return Configure( arguments.Data() );
314 Int_t AliHLTITSClusterFinderComponent::DoDeinit() {
315 // see header file for class documentation
335 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
336 if(fClusters[iModule] != NULL){
337 fClusters[iModule]->Delete();
338 delete fClusters[iModule];
340 fClusters[iModule] = NULL;
343 fUseOfflineFinder = 0;
348 int AliHLTITSClusterFinderComponent::DoEvent
350 const AliHLTComponentEventData& evtData,
351 const AliHLTComponentBlockData* /*blocks*/,
352 AliHLTComponentTriggerData& /*trigData*/,
353 AliHLTUInt8_t* outputPtr,
354 AliHLTUInt32_t& size,
355 vector<AliHLTComponentBlockData>& outputBlocks )
357 // see header file for class documentation
359 AliHLTUInt32_t maxBufferSize = size;
360 size = 0; // output size
362 if (!IsDataEvent()) return 0;
364 if ( evtData.fBlockCnt<=0 )
366 HLTDebug("no blocks in event" );
370 fBenchmark.StartNewEvent();
372 for( const AliHLTComponentBlockData *i= GetFirstInputBlock(fInputDataType); i!=NULL; i=GetNextInputBlock() ){
373 fBenchmark.AddInput(i->fSize);
378 if(fModeSwitch==kClusterFinderDigits) {
380 for ( const TObject *iter = GetFirstInputObject(fInputDataType); iter != NULL; iter = GetNextInputObject() ) {
381 tD = dynamic_cast<TTree*>(const_cast<TObject*>( iter ) );
383 HLTFatal("No Digit Tree found");
387 fDettype->SetTreeAddressD(tD);
388 fDettype->MakeBranch(tR,"R");
389 fDettype->SetTreeAddressR(tR);
392 fDettype->DigitsToRecPoints(tD,tR,0,opt,kTRUE);
394 TClonesArray * fRecPoints;
395 tR->SetBranchAddress("ITSRecPoints",&fRecPoints);
396 for(Int_t treeEntry=0;treeEntry<tR->GetEntries();treeEntry++){
397 tR->GetEntry(treeEntry);
398 for(Int_t tCloneEntry=0;tCloneEntry<fRecPoints->GetEntries();tCloneEntry++){
399 AliITSRecPoint *recpoint=(AliITSRecPoint*)fRecPoints->At(tCloneEntry);
400 fclusters.push_back(*recpoint);
407 UInt_t nClusters=fclusters.size();
409 UInt_t bufferSize = nClusters * sizeof(AliHLTITSSpacePointData) + sizeof(AliHLTITSClusterData);
410 if( size + bufferSize > maxBufferSize ){
411 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d)", maxBufferSize, size+bufferSize);
417 RecPointToSpacePoint(outputPtr,size);
419 AliHLTComponentBlockData bd;
422 bd.fSize = bufferSize;
423 bd.fSpecification = 0x00000000;
424 bd.fDataType = GetOutputDataType();
425 outputBlocks.push_back( bd );
427 fBenchmark.AddOutput(bd.fSize);
434 // -- Loop over blocks
435 for( const AliHLTComponentBlockData* iter = GetFirstInputBlock(fInputDataType); iter != NULL; iter = GetNextInputBlock() ) {
437 // -- Debug output of datatype --
438 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
439 evtData.fEventID, evtData.fEventID,
440 DataType2Text(iter->fDataType).c_str(),
441 DataType2Text(fInputDataType).c_str());
443 // -- Check for the correct data type
444 if ( iter->fDataType != (fInputDataType) )
447 // -- Get equipment ID out of specification
448 AliHLTUInt32_t spec = iter->fSpecification;
451 for ( Int_t ii = 0; ii < fNddl ; ii++ ) { //number of ddl's
452 if ( spec & 0x00000001 ) {
459 // -- Set equipment ID to the raw reader
461 if(!fRawReader->AddBuffer((UChar_t*) iter->fPtr, iter->fSize, id)){
462 HLTWarning("Could not add buffer");
467 if(fModeSwitch==kClusterFinderSPD && !fUseOfflineFinder){ fSPD->RawdataToClusters( fRawReader, fclusters ); }
468 else if(fModeSwitch==kClusterFinderSSD && !fUseOfflineFinder){ fSSD->RawdataToClusters( fclusters ); }
470 if(fModeSwitch==kClusterFinderSPD && fUseOfflineFinder) {fDettype->DigitsToRecPoints(fRawReader,fClusters,"SPD");}
471 if(fModeSwitch==kClusterFinderSSD && fUseOfflineFinder) {fDettype->DigitsToRecPoints(fRawReader,fClusters,"SSD");}
472 if(fModeSwitch==kClusterFinderSDD) {fDettype->DigitsToRecPoints(fRawReader,fClusters,"SDD");}
473 for(int i=0;i<fNModules;i++){
474 if(fClusters[i] != NULL){
475 for(int j=0;j<fClusters[i]->GetEntriesFast();j++){
476 AliITSRecPoint *recpoint = (AliITSRecPoint*) (fClusters[i]->At(j));
477 fclusters.push_back(*recpoint);
479 fClusters[i]->Delete();
487 fRawReader->ClearBuffers();
489 UInt_t nClusters=fclusters.size();
491 UInt_t bufferSize = nClusters * sizeof(AliHLTITSSpacePointData) + sizeof(AliHLTITSClusterData);
492 if( size + bufferSize > maxBufferSize ){
493 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d)", maxBufferSize, size+bufferSize);
499 RecPointToSpacePoint(outputPtr,size);
501 AliHLTComponentBlockData bd;
504 bd.fSize = bufferSize;
505 bd.fSpecification = iter->fSpecification;
506 bd.fDataType = GetOutputDataType();
507 outputBlocks.push_back( bd );
509 fBenchmark.AddOutput(bd.fSize);
517 HLTInfo(fBenchmark.GetStatistics());
521 int AliHLTITSClusterFinderComponent::Configure(const char* arguments)
526 if (!arguments) return iResult;
528 TString allArgs=arguments;
531 TObjArray* pTokens=allArgs.Tokenize(" ");
534 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
535 argument=((TObjString*)pTokens->At(i))->GetString();
536 if (argument.IsNull()) continue;
537 if (argument.CompareTo("-use-offline-finder")==0) {
538 fUseOfflineFinder = 1;
539 HLTInfo("Off-line ClusterFinder will be used");
543 else if (argument.CompareTo("")==0) {
549 HLTError("unknown argument %s", argument.Data());
560 int AliHLTITSClusterFinderComponent::Reconfigure(const char* cdbEntry, const char* chainId)
562 // see header file for class documentation
565 const char* path="HLT/ConfigITS/ClusterFinderComponent";
566 const char* defaultNotify="";
569 defaultNotify=" (default)";
572 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
573 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path);
575 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
577 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
578 iResult=Configure(pString->GetString().Data());
580 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
583 HLTError("can not fetch object \"%s\" from CDB", path);
589 void AliHLTITSClusterFinderComponent::RecPointToSpacePoint(AliHLTUInt8_t* outputPtr,AliHLTUInt32_t& size){
590 AliHLTITSClusterData *outputClusters = reinterpret_cast<AliHLTITSClusterData*>(outputPtr + size);
591 outputClusters->fSpacePointCnt=fclusters.size();
593 for(UInt_t i=0;i<fclusters.size();i++){
594 AliITSRecPoint *recpoint = (AliITSRecPoint*) &(fclusters[i]);
595 outputClusters->fSpacePoints[clustIdx].fY=recpoint->GetY();
596 outputClusters->fSpacePoints[clustIdx].fZ=recpoint->GetZ();
597 outputClusters->fSpacePoints[clustIdx].fSigmaY2=recpoint->GetSigmaY2();
598 outputClusters->fSpacePoints[clustIdx].fSigmaZ2=recpoint->GetSigmaZ2();
599 outputClusters->fSpacePoints[clustIdx].fSigmaYZ=recpoint->GetSigmaYZ();
600 outputClusters->fSpacePoints[clustIdx].fQ=recpoint->GetQ();
601 outputClusters->fSpacePoints[clustIdx].fNy=recpoint->GetNy();
602 outputClusters->fSpacePoints[clustIdx].fNz=recpoint->GetNz();
603 outputClusters->fSpacePoints[clustIdx].fLayer=recpoint->GetLayer();
604 outputClusters->fSpacePoints[clustIdx].fIndex=recpoint->GetDetectorIndex() | recpoint->GetPindex() | recpoint->GetNindex();
605 outputClusters->fSpacePoints[clustIdx].fTracks[0]=recpoint->GetLabel(0);
606 outputClusters->fSpacePoints[clustIdx].fTracks[1]=recpoint->GetLabel(1);
607 outputClusters->fSpacePoints[clustIdx].fTracks[2]=recpoint->GetLabel(2);