- a fast HLT version of the SSD clusterfinder created. The speed on pp mc is ~20kHz...
[u/mrichter/AliRoot.git] / HLT / ITS / AliHLTITSAgent.cxx
CommitLineData
dafa46c6 1// $Id$
2
3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8//* for The ALICE HLT Project. *
9//* *
10//* Permission to use, copy, modify and distribute this software and its *
11//* documentation strictly for non-commercial purposes is hereby granted *
12//* without fee, provided that the above copyright notice appears in all *
13//* copies and that both the copyright notice and this permission notice *
14//* appear in the supporting documentation. The authors make no claims *
15//* about the suitability of this software for any purpose. It is *
16//* provided "as is" without express or implied warranty. *
17//**************************************************************************
18
19/** @file AliHLTITSAgent.cxx
20 @author Matthias Richter
21 @date 25.08.2008
22 @brief Agent of the libAliHLTITS library
23*/
24
25#include <cassert>
26#include "AliHLTITSAgent.h"
27#include "AliHLTConfiguration.h"
6b87e199 28#include "AliHLTOUT.h"
68315dc4 29#include "AliHLTDAQ.h"
dafa46c6 30
31// header files of library components
32
33// header file of the module preprocessor
0c7d42ab 34#include "AliHLTITSCompressRawDataSDDComponent.h"
fd091d74 35#include "AliHLTITSSSDQARecPointsComponent.h"
36#include "AliHLTITSQAComponent.h"
6b7742a2 37#include "AliHLTITSClusterFinderComponent.h"
c0b68f8e 38#include "AliHLTITSClusterHistoComponent.h"
f2d22774 39#include "AliHLTITSTrackerComponent.h"
7f167a74 40#include "AliHLTITSVertexerSPDComponent.h"
dafa46c6 41
dafa46c6 42/** global instance for agent registration */
43AliHLTITSAgent gAliHLTITSAgent;
44
45/** ROOT macro for the implementation of ROOT specific class methods */
46ClassImp(AliHLTITSAgent)
47
48AliHLTITSAgent::AliHLTITSAgent()
49 :
50 AliHLTModuleAgent("ITS"),
51 fRawDataHandler(NULL)
52{
53 // see header file for class documentation
54 // or
55 // refer to README to build package
56 // or
57 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58}
59
60AliHLTITSAgent::~AliHLTITSAgent()
61{
62 // see header file for class documentation
63}
64
68315dc4 65int AliHLTITSAgent::CreateConfigurations(AliHLTConfigurationHandler* handler,
7c6a3cd3 66 AliRawReader* rawReader,
67 AliRunLoader* runloader) const
dafa46c6 68{
69 // see header file for class documentation
68315dc4 70 int iResult=0;
71 if (!handler) return -EINVAL;
72
73 ///////////////////////////////////////////////////////////////////////////////////////////////////
74 ///////////////////////////////////////////////////////////////////////////////////////////////////
75 //
76 // ITS tracking is currently only working on raw data
77 // to run on digits, a digit publisher needs to be implemented
7c6a3cd3 78
79 if (rawReader || !runloader) {
80 // AliSimulation: use the AliRawReaderPublisher if the raw reader is available
81 // Alireconstruction: indicated by runloader==NULL, run always on raw data
68315dc4 82
83 ///////////////////////////////////////////////////////////////////////////////////////////////////
84 //
7c6a3cd3 85 // define the ITS cluster finder configurations
68315dc4 86 //
87
be2c9ca9 88 TString spdCF;
89 TString ssdCF;
90 TString sddCF;
91
92 iResult=CreateCFConfigurations(handler, AliHLTDAQ::DetectorID("ITSSPD"), spdCF);
93 handler->CreateConfiguration("ITS-SPD-CF","BlockFilter",spdCF.Data(),"");
94
95 iResult=CreateCFConfigurations(handler, AliHLTDAQ::DetectorID("ITSSDD"), sddCF);
96 handler->CreateConfiguration("ITS-SDD-CF","BlockFilter",sddCF.Data(),"");
97
98 iResult=CreateCFConfigurations(handler, AliHLTDAQ::DetectorID("ITSSSD"), ssdCF);
99 handler->CreateConfiguration("ITS-SSD-CF","BlockFilter",ssdCF.Data(),"");
100
101
102 ///////////////////////////////////////////////////////////////////////////////////////////////////
103 //
104 // define the SPD vertexer Z configuration
105 //
106 handler->CreateConfiguration("ITS-SPD-vertexer","ITSVertexerSPD", "ITS-SPD-CF","");
107
7c6a3cd3 108
109 ///////////////////////////////////////////////////////////////////////////////////////////////////
110 //
111 // define the ITS tracker configuration
112 //
be2c9ca9 113 TString trackerInput="ITS-SPD-CF ITS-SDD-CF ITS-SSD-CF";
114
68315dc4 115 if (handler->FindConfiguration("TPC-globalmerger")) {
116 trackerInput+=" TPC-globalmerger";
117 }
118 handler->CreateConfiguration("ITS-tracker","ITSTracker",trackerInput.Data(),"");
119 }
dafa46c6 120 return 0;
121}
122
123const char* AliHLTITSAgent::GetReconstructionChains(AliRawReader* /*rawReader*/,
68315dc4 124 AliRunLoader* runloader) const
dafa46c6 125{
126 // see header file for class documentation
68315dc4 127 if (runloader) {
128 // reconstruction chains for AliRoot simulation
129 // Note: run loader is only available while running embedded into
130 // AliRoot simulation
131
132 // the chain is just defined and can be used as input for subsequent
133 // components
134 //return "ITS-tracker";
135 }
dafa46c6 136
137 return "";
138}
139
140const char* AliHLTITSAgent::GetRequiredComponentLibraries() const
141{
142 // see header file for class documentation
68315dc4 143 return "libAliHLTUtil.so libAliHLTRCU.so libAliHLTTPC.so";
dafa46c6 144}
145
146int AliHLTITSAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
147{
148 // see header file for class documentation
149 assert(pHandler);
150 if (!pHandler) return -EINVAL;
0c7d42ab 151 pHandler->AddComponent(new AliHLTITSCompressRawDataSDDComponent);
fd091d74 152 pHandler->AddComponent(new AliHLTITSSSDQARecPointsComponent);
153 pHandler->AddComponent(new AliHLTITSQAComponent);
6b7742a2 154 pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderSPD));
155 pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderSDD));
156 pHandler->AddComponent(new AliHLTITSClusterFinderComponent(AliHLTITSClusterFinderComponent::kClusterFinderSSD));
c0b68f8e 157 pHandler->AddComponent(new AliHLTITSClusterHistoComponent);
f2d22774 158 pHandler->AddComponent(new AliHLTITSTrackerComponent);
7f167a74 159 pHandler->AddComponent(new AliHLTITSVertexerSPDComponent);
dafa46c6 160
161 return 0;
162}
163
164AliHLTModulePreprocessor* AliHLTITSAgent::GetPreprocessor()
165{
166 // see header file for class documentation
167 return NULL;
168}
169
170int AliHLTITSAgent::GetHandlerDescription(AliHLTComponentDataType dt,
171 AliHLTUInt32_t spec,
172 AliHLTOUTHandlerDesc& desc) const
173{
174 // see header file for class documentation
175
176 // Handlers for ITS raw data. Even though there are 3 detectors
177 // everything is handled in one module library and one HLTOUT handler.
178 // This assumes that the data blocks are sent with data type
6b87e199 179 // {DDL_RAW :ISDD} and the bit set in the specification corresponding.
180 // to detector DDL id.
181 // An HLTOUT handler is implemented to extract the equipment id from
182 // the specification.
183 // Note: Future versions of the framework will provide a default handler
184 // class with that functionality.
185 if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD)) {
dafa46c6 186 desc=AliHLTOUTHandlerDesc(kRawReader, dt, GetModuleId());
187 HLTInfo("module %s handles data block type %s specification %d (0x%x)",
188 GetModuleId(), AliHLTComponent::DataType2Text(dt).c_str(), spec, spec);
189 return 1;
190 }
191 return 0;
192}
193
194AliHLTOUTHandler* AliHLTITSAgent::GetOutputHandler(AliHLTComponentDataType dt,
195 AliHLTUInt32_t /*spec*/)
196{
197 // see header file for class documentation
6b87e199 198 if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD)) {
dafa46c6 199 // use the default handler
200 if (!fRawDataHandler) {
6b87e199 201 fRawDataHandler=new AliHLTOUTSDDRawDataHandler;
dafa46c6 202 }
203 return fRawDataHandler;
204 }
205 return NULL;
206}
207
208int AliHLTITSAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
209{
210 // see header file for class documentation
211 if (pInstance==NULL) return -EINVAL;
212
213 if (pInstance==fRawDataHandler) {
214 delete fRawDataHandler;
215 fRawDataHandler=NULL;
216 return 0;
217 }
218
219 delete pInstance;
220 return 0;
221}
6b87e199 222
223int AliHLTITSAgent::AliHLTOUTSDDRawDataHandler::ProcessData(AliHLTOUT* pData)
224{
225 // see header file for class documentation
226 if (!pData) return -EINVAL;
227 static int errorCount=0;
228 const int maxErrorCount=10;
229 AliHLTComponentDataType dt=kAliHLTVoidDataType;
230 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
231 int iResult=pData->GetDataBlockDescription(dt, spec);
232 if (iResult>=0) {
233 if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD)) {
234 int ddlOffset=256;//AliDAQ::DdlIDOffset("ITSSDD");
235 int numberOfDDLs=24;//AliDAQ::NumberOfDdls("ITSSDD");
236 int ddlNo=0;
237 for (;ddlNo<32 && ddlNo<numberOfDDLs; ddlNo++) {
238 if (spec&(0x1<<ddlNo)) break;
239 }
240 if (ddlNo>=32 || ddlNo>=numberOfDDLs) {
241 HLTError("invalid specification 0x%08x: can not extract DDL id for data block %s", spec, AliHLTComponent::DataType2Text(dt).c_str());
242 iResult=-ENODEV;
243 } else if (spec^(0x1<<ddlNo)) {
244 iResult=-EEXIST;
245 HLTError("multiple links set in specification 0x%08x: can not extract DDL id for data block %s", spec, AliHLTComponent::DataType2Text(dt).c_str());
246 } else {
247 iResult=ddlOffset+ddlNo;
248 }
249 } else {
250 if (errorCount++<10) {
251 HLTError("wrong data type: expecting %s, got %s; %s",
252 AliHLTComponent::DataType2Text(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginITSSDD).c_str(),
253 AliHLTComponent::DataType2Text(dt).c_str(),
254 errorCount==maxErrorCount?"suppressing further error messages":"");
255 }
256 iResult=-EFAULT;
257 }
258 }
259 return iResult;
260}
68315dc4 261
262int AliHLTITSAgent::CreateCFConfigurations(AliHLTConfigurationHandler* pHandler, int detectorId, TString& output) const
263{
264 // see header file for class documentation
265 if (!pHandler) return -EINVAL;
266
267 ///////////////////////////////////////////////////////////////////////////////////////////////////
268 //
269 // define the ITS cluster finder components
270 //
271
272 //The spec starts from 0x1 in SPD, SDD and SSD. So 0x1 is ddl 0 for SPD, 0x10 is ddl 1, and so on
273 //in SDD 0x1 is ddl 256, 0x10 is ddl 257, and so on. This means that the spec has to be set to 0x1
274 //before the loops over the clusterfinder
275
276 TString idString=AliHLTDAQ::DetectorName(detectorId);
277 if (idString.CompareTo("ITSSPD") &&
278 idString.CompareTo("ITSSDD") &&
279 idString.CompareTo("ITSSSD")) {
280 HLTError("invalid detector id %d does not describe any ITS detector", detectorId);
281 return -ENOENT;
282 }
283
284 int minddl=AliHLTDAQ::DdlIDOffset(detectorId);
be2c9ca9 285 int maxddl=minddl+AliHLTDAQ::NumberOfDdls(detectorId)-1;
68315dc4 286 int spec=0x1;
287 int ddlno=0;
288
289 TString origin=idString; origin.ReplaceAll("ITS", "I");
290 TString cfBase=idString; cfBase+="_CF";
291 TString componentId=idString; componentId.ReplaceAll("ITS", "ITSClusterFinder");
292 for(ddlno=minddl;ddlno<=maxddl;ddlno++){
293 TString arg, publisher, cf;
294
295 // the HLT origin defines are 4 chars: ISPD, ISSD, ISDD respectively
296 arg.Form("-minid %d -datatype 'DDL_RAW ' '%s' -dataspec 0x%08x -verbose",ddlno, origin.Data(), spec);
297 publisher.Form("ITS-DP_%d", ddlno);
298 pHandler->CreateConfiguration(publisher.Data(), "AliRawReaderPublisher", NULL , arg.Data());
299
300 cf.Form("%s_%d",cfBase.Data(), ddlno);
301 pHandler->CreateConfiguration(cf.Data(), componentId.Data(), publisher.Data(), "");
302
303 if (output.Length()>0) output+=" ";
304 output+=cf;
305
306 spec=spec<<1;
307 }
308
309 return 0;
310}