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