- bugfix in the AliHLTTrackMCData struct: use 0-length array now
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalEsdConverterComponent.cxx
CommitLineData
a1408c4b 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 AliHLTGlobalEsdConverterComponent.cxx
20 @author Matthias Richter
21 @date
22 @brief Global ESD converter component.
23*/
24
25// see header file for class documentation
26// or
27// refer to README to build package
28// or
29// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31#include <cassert>
32#include "AliHLTGlobalEsdConverterComponent.h"
33#include "AliHLTGlobalBarrelTrack.h"
34#include "AliHLTExternalTrackParam.h"
35#include "AliESDEvent.h"
36#include "AliESDtrack.h"
37#include "AliCDBEntry.h"
38#include "AliCDBManager.h"
39#include "TTree.h"
40#include "TList.h"
41
42/** ROOT macro for the implementation of ROOT specific class methods */
43ClassImp(AliHLTGlobalEsdConverterComponent)
44
45AliHLTGlobalEsdConverterComponent::AliHLTGlobalEsdConverterComponent()
46 : AliHLTProcessor()
47 , fESD(NULL)
48 , fSolenoidBz(5)
49 , fWriteTree(0)
50
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
59AliHLTGlobalEsdConverterComponent::~AliHLTGlobalEsdConverterComponent()
60{
61 // see header file for class documentation
62 if (fESD) delete fESD;
63 fESD=NULL;
64}
65
66int AliHLTGlobalEsdConverterComponent::Configure(const char* arguments)
67{
68 // see header file for class documentation
69 int iResult=0;
70 if (!arguments) return iResult;
71
72 TString allArgs=arguments;
73 TString argument;
74 int bMissingParam=0;
75
76 TObjArray* pTokens=allArgs.Tokenize(" ");
77 if (pTokens) {
78 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
79 argument=((TObjString*)pTokens->At(i))->GetString();
80 if (argument.IsNull()) continue;
81
82 if (argument.CompareTo("-solenoidBz")==0) {
83 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
84 HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
85 fSolenoidBz=((TObjString*)pTokens->At(i))->GetString().Atof();
86 continue;
87 } else {
88 HLTError("unknown argument %s", argument.Data());
89 iResult=-EINVAL;
90 break;
91 }
92 }
93 delete pTokens;
94 }
95 if (bMissingParam) {
96 HLTError("missing parameter for argument %s", argument.Data());
97 iResult=-EINVAL;
98 }
99
100 return iResult;
101}
102
103int AliHLTGlobalEsdConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
104{
105 // see header file for class documentation
106 int iResult=0;
107 const char* path=kAliHLTCDBSolenoidBz;
108 const char* defaultNotify="";
109 if (cdbEntry) {
110 path=cdbEntry;
111 defaultNotify=" (default)";
112 }
113 if (path) {
114 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
115 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
116 if (pEntry) {
117 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
118 if (pString) {
119 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
120 iResult=Configure(pString->GetString().Data());
121 } else {
122 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
123 }
124 } else {
125 HLTError("can not fetch object \"%s\" from CDB", path);
126 }
127 }
128
129 return iResult;
130}
131
132void AliHLTGlobalEsdConverterComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
133{
134 // see header file for class documentation
135 list.push_back(kAliHLTDataTypeTrack);
136 list.push_back(kAliHLTDataTypeTrackMC);
137}
138
139AliHLTComponentDataType AliHLTGlobalEsdConverterComponent::GetOutputDataType()
140{
141 // see header file for class documentation
142 return kAliHLTDataTypeESDObject|kAliHLTDataOriginHLT;
143}
144
145void AliHLTGlobalEsdConverterComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
146{
147 // see header file for class documentation
148 constBase=2000000;
149 inputMultiplier=10.0;
150}
151
152int AliHLTGlobalEsdConverterComponent::DoInit(int argc, const char** argv)
153{
154 // see header file for class documentation
155 int iResult=0;
156 TString argument="";
157 int bMissingParam=0;
158 for (int i=0; i<argc && iResult>=0; i++) {
159 argument=argv[i];
160 if (argument.IsNull()) continue;
161
162 // -notree
163 if (argument.CompareTo("-notree")==0) {
164 fWriteTree=0;
165
166 // -tree
167 } else if (argument.CompareTo("-tree")==0) {
168 fWriteTree=1;
169
170 } else {
171 HLTError("unknown argument %s", argument.Data());
172 break;
173 }
174 }
175 if (bMissingParam) {
176 HLTError("missing parameter for argument %s", argument.Data());
177 iResult=-EINVAL;
178 }
179
180 if (iResult>=0) {
181 iResult=Reconfigure(NULL, NULL);
182 }
183
184 if (iResult>=0) {
185 fESD = new AliESDEvent;
186 if (fESD) {
187 fESD->CreateStdContent();
188 } else {
189 iResult=-ENOMEM;
190 }
191 }
192
193 return iResult;
194}
195
196int AliHLTGlobalEsdConverterComponent::DoDeinit()
197{
198 // see header file for class documentation
199 if (fESD) delete fESD;
200 fESD=NULL;
201
202 return 0;
203}
204
205int AliHLTGlobalEsdConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
206 AliHLTComponentTriggerData& /*trigData*/)
207{
208 // see header file for class documentation
209 int iResult=0;
210 if (!fESD) return -ENODEV;
211
212 AliESDEvent* pESD = fESD;
213
214 pESD->Reset();
215 pESD->SetMagneticField(fSolenoidBz);
216
217 TTree* pTree = NULL;
218 if (fWriteTree)
219 pTree = new TTree("esdTree", "Tree with HLT ESD objects");
220
221 if (pTree) {
222 pTree->SetDirectory(0);
223 }
224
225 if ((iResult=ProcessBlocks(pTree, pESD))>0) {
226 // TODO: set the specification correctly
227 if (pTree) {
228 // the esd structure is written to the user info and is
229 // needed in te ReadFromTree method to read all objects correctly
230 pTree->GetUserInfo()->Add(pESD);
231 pESD->WriteToTree(pTree);
232 iResult=PushBack(pTree, kAliHLTDataTypeESDTree|kAliHLTDataOriginHLT, 0);
233 } else {
234 iResult=PushBack(pESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginHLT, 0);
235 }
236 }
237 if (pTree) {
238 // clear user info list to prevent objects from being deleted
239 pTree->GetUserInfo()->Clear();
240 delete pTree;
241 }
242 return iResult;
243}
244
245int AliHLTGlobalEsdConverterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD)
246{
247 // see header file for class documentation
248
249 int iResult=0;
250 int iAddedDataBlocks=0;
251
252 // Barrel tracking
253
254 // in the first attempt this component reads the TPC tracks and updates in the
255 // second step from the ITS tracks
256 std::vector<int> trackIdESD2TPCmap; // map esd index -> tpc index
257
258 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC);
259 pBlock!=NULL; pBlock=GetNextInputBlock()) {
260 vector<AliHLTGlobalBarrelTrack> tracks;
261 if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
262 for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
263 element!=tracks.end(); element++) {
264 Float_t points[4] = {
265 element->GetX(),
266 element->GetY(),
267 element->GetLastPointX(),
268 element->GetLastPointY()
269 };
270 AliESDtrack iotrack;
271 iotrack.UpdateTrackParams(&(*element),AliESDtrack::kTPCin);
272 iotrack.SetTPCPoints(points);
273
274 pESD->AddTrack(&iotrack);
275 }
276 iAddedDataBlocks++;
277 } else if (iResult<0) {
278 HLTError("can not extract tracks from data block of type %s (specification %08x) of size $d",
279 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize);
280 }
281 }
282
283 // ITS updated tracks
284 /*
285 int nESDTracks = pESD->GetNumberOfTracks();
286
287 // create map of tpc->esd track indices
288
289 int *trackIdTPC2ESDmap = new int[ nTPCTracks ];
290 {
291 for( int i=0; i<nTPCTracks; i++ ) trackIdTPC2ESDmap[i] = -1;
292 for( unsigned int i=0; i<trackIdESD2TPCmap.size(); i++ ){
293 int tpcId = trackIdESD2TPCmap[i];
294 if( tpcId>=0 && tpcId<nTPCTracks ) trackIdTPC2ESDmap[tpcId] = i;
295 }
296 }
297
298 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
299 iter = blocks+ndx;
300 if(iter->fDataType == fgkITSTracksDataType ) {
301 AliHLTITSTrackDataHeader *inPtr = reinterpret_cast<AliHLTITSTrackDataHeader*>( iter->fPtr );
302 int nTracks = inPtr->fTrackletCnt;
303 for( int itr=0; itr<nTracks; itr++ ){
304 AliHLTITSTrackData &tr = inPtr->fTracks[itr];
305 AliHLTITSTrack tITS( tr.fTrackParam );
306 int ncl=0;
307 for( int il=0; il<6; il++ ){
308 if( tr.fClusterIds[il]>=0 ) tITS.SetClusterIndex(ncl++, tr.fClusterIds[il]);
309 }
310 tITS.SetNumberOfClusters( ncl );
311 int tpcId = tr.fTPCId;
312 if( tpcId<0 || tpcId>=nTPCTracks ) continue;
313 int esdID = trackIdTPC2ESDmap[tpcId];
314 if( esdID<0 || esdID>=nESDTracks ) continue;
315 AliESDtrack *tESD = pESD->GetTrack( esdID );
316 if( tESD ) tESD->UpdateTrackParams( &tITS, AliESDtrack::kITSin );
317 }
318 }
319 }
320 delete[] trackIdTPC2ESDmap;
321
322 // primary vertex & V0's
323
324 //AliHLTVertexer vertexer;
325 //vertexer.SetESD( pESD );
326 //vertexer.FindPrimaryVertex();
327 //vertexer.FindV0s();
328 */
329 if (iAddedDataBlocks>0 && pTree) {
330 pTree->Fill();
331 }
332
333 if (iResult>=0) iResult=iAddedDataBlocks;
334 return iResult;
335}