]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/offline/AliHLTTPCOfflineTrackerComponent.cxx
Trigger bit mask and multiplicity per PMT in the VZERO ESD. Related changes and class...
[u/mrichter/AliRoot.git] / HLT / TPCLib / offline / AliHLTTPCOfflineTrackerComponent.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 //*                                                                        *
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 //**************************************************************************
17
18 /** @file   AliHLTTPCOfflineTrackerComponent.cxx
19     @author Matthias Richter
20     @date   
21     @brief  Wrapper component to the TPC offline tracker
22 */
23
24 #include "AliHLTTPCOfflineTrackerComponent.h"
25 #include "TString.h"
26 #include "TObjArray.h"
27 #include "TObjString.h"
28 #include "AliTPCParam.h"
29 #include "AliTPCParamSR.h"
30 #include "AliTPCtrackerMI.h"
31 #include "AliTPCClustersRow.h"
32 #include "AliESDEvent.h"
33 #include "AliHLTTPCDefinitions.h"
34 #include "AliTracker.h"
35 #include "AliMagFMaps.h"
36
37 /** ROOT macro for the implementation of ROOT specific class methods */
38 ClassImp(AliHLTTPCOfflineTrackerComponent)
39
40 AliHLTTPCOfflineTrackerComponent::AliHLTTPCOfflineTrackerComponent() : AliHLTProcessor(),
41 fOutputPercentage(100),
42 fTPCGeomParam(0),
43 fTracker(0),
44 fESD(0)
45 {
46   // see header file for class documentation
47   // or
48   // refer to README to build package
49   // or
50   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
51 }
52
53 AliHLTTPCOfflineTrackerComponent::~AliHLTTPCOfflineTrackerComponent()
54 {
55   // see header file for class documentation
56 }
57
58 const char* AliHLTTPCOfflineTrackerComponent::GetComponentID()
59 {
60   // see header file for class documentation
61   return "TPCOfflineTracker";
62 }
63
64 void AliHLTTPCOfflineTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
65 {
66   // get input data type
67   list.push_back(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/);
68 }
69
70 AliHLTComponentDataType AliHLTTPCOfflineTrackerComponent::GetOutputDataType()
71 {
72   // create output data type
73   return kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineTrackSegmentsDataType*/;
74 }
75
76 void AliHLTTPCOfflineTrackerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
77 {
78   // get output data size
79   constBase = 2000000;
80   inputMultiplier = ((double)fOutputPercentage)/100.0;
81 }
82
83 AliHLTComponent* AliHLTTPCOfflineTrackerComponent::Spawn()
84 {
85   // create instance of the component
86   return new AliHLTTPCOfflineTrackerComponent;
87 }
88
89 int AliHLTTPCOfflineTrackerComponent::DoInit( int argc, const char** argv )
90 {
91   // init configuration 
92   //
93   int iResult=0;
94 #ifdef HAVE_NOT_TPCOFFLINE_REC
95   HLTFatal("AliRoot version > v4-13-Release required");
96   return -ENOSYS;
97 #endif
98
99   TString argument="";
100   TString configuration=""; 
101   int bMissingParam=0;
102   for (int i=0; i<argc && iResult>=0; i++) {
103     argument=argv[i];
104     if (argument.IsNull()) continue;
105
106   }
107   if (bMissingParam) {
108     HLTError("missing parameter for argument %s", argument.Data());
109     iResult=-EINVAL;
110   }
111
112   if (iResult>=0 && !configuration.IsNull()) {
113     iResult=Configure(configuration.Data());
114   } else {
115     iResult=Reconfigure(NULL, NULL);
116   }
117
118   // TPC geometry parameters
119   fTPCGeomParam = new AliTPCParamSR;
120   if (fTPCGeomParam) {
121     fTPCGeomParam->ReadGeoMatrices();
122   }
123
124   // Init clusterer
125   fTracker = new AliTPCtrackerMI(fTPCGeomParam);
126
127   // AliESDEvent event needed by AliTPCtrackerMI
128   // output of the component
129   fESD = new AliESDEvent();
130   if (fESD) {
131     fESD->CreateStdContent();
132   }
133
134   // TODO: set the magnetic field correctly
135   // the tracker needs the field map correctly initialized in AliTracker.
136   // init from HLT/ConfigHLT/SolenoidBz or other appropriate CDB entry.
137   // temporarily set to 5kG
138   if (!AliTracker::GetFieldMap()) {
139     // this instance must never be deleted, the AliRoot framework and the design
140     // of AliTracker just does not support this. That's why we do not keep the
141     // pointer. The memory leak is relativly small.
142     AliMagFMaps* field = new AliMagFMaps("Maps","Maps", 2, 1., 10., AliMagFMaps::k5kG);
143     AliTracker::SetFieldMap(field,kTRUE);
144   }
145
146   if (!fTracker || !fESD || !fTPCGeomParam) {
147     HLTError("failed creating internal objects");
148     iResult=-ENOMEM;
149   }
150
151   return iResult;
152 }
153
154 int AliHLTTPCOfflineTrackerComponent::DoDeinit()
155 {
156   // deinit configuration
157
158   if(fTPCGeomParam) delete fTPCGeomParam; fTPCGeomParam = 0; 
159   if(fTracker) delete fTracker; fTracker = 0; 
160   if(fESD) delete fESD; fESD = 0;
161
162   return 0;
163 }
164
165 int AliHLTTPCOfflineTrackerComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
166 {
167   // tracker function
168   HLTInfo("DoEvent processing data");
169
170 //   Logging(kHLTLogDebug, "AliHLTTPCOfflineTrackerComponent::DoEvent", "Trigger data received",
171 //          "Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
172
173   TObjArray *clusterArray = 0;
174
175   int iResult=0;
176
177   if (fTracker && fESD) {
178     // loop over input data blocks: TObjArrays of clusters
179     for (TObject *pObj = (TObject *)GetFirstInputObject(kAliHLTDataTypeTObjArray|kAliHLTDataOriginTPC/*AliHLTTPCDefinitions::fgkOfflineClustersDataType*/,"TObjArray",0);
180          pObj !=0 && iResult>=0;
181          pObj = (TObject *)GetNextInputObject(0)) {
182       clusterArray = dynamic_cast<TObjArray*>(pObj);
183       if (!clusterArray) continue;
184 //       int lower=clusterArray->LowerBound();
185 //       int entries=clusterArray->GetEntries();
186 //       if (entries<=lower) continue;
187 //       if (clusterArray->At(lower)==NULL) continue; 
188 //       if (dynamic_cast<AliTPCClustersRow*>(clusterArray->At(lower))==NULL) continue;
189
190       HLTInfo("load %d cluster rows from block %s 0x%08x", clusterArray->GetEntries(), DataType2Text(GetDataType(pObj)).c_str(), GetSpecification(pObj));
191 #ifndef HAVE_NOT_TPCOFFLINE_REC
192       fTracker->LoadClusters(clusterArray);
193 #endif //HAVE_NOT_TPCOFFLINE_REC
194     }// end loop over input objects
195
196     // set magnetic field for the ESD, assumes correct initialization of
197     // the field map
198     fESD->SetMagneticField(AliTracker::GetBz());
199
200     // run tracker
201     fTracker->Clusters2Tracks(fESD);
202     fTracker->UnloadClusters();
203
204     Int_t nTracks = fESD->GetNumberOfTracks();
205     HLTInfo("Number of tracks %d", nTracks);
206
207     // TODO: calculate specification from the specification of input data blocks
208     PushBack(fESD, kAliHLTDataTypeESDObject|kAliHLTDataOriginTPC, 0);
209
210     // Alternatively: Push back tracks
211 //     for (Int_t it = 0; it < nTracks; it++) {
212 //       AliESDtrack* track = fESD->GetTrack(it);
213 //       PushBack(track, AliHLTTPCDefinitions::fgkOfflineTrackSegmentsDataType, 0);
214 //     }
215
216     // is this necessary? If yes, we have to keep all the created TObjArrays
217     // from the loop above
218     // clear clusters
219     //clusterArray->Clear();
220     //clusterArray->Delete();
221
222     // reset ESDs
223     fESD->Reset();
224   } else {
225     HLTError("component not initialized");
226     iResult=-ENOMEM;
227   }
228
229   return iResult;
230 }
231
232 int AliHLTTPCOfflineTrackerComponent::Configure(const char* arguments)
233 {
234   // see header file for class documentation
235   int iResult=0;
236   if (!arguments) return iResult;
237
238   TString allArgs=arguments;
239   TString argument;
240   int bMissingParam=0;
241
242   TObjArray* pTokens=allArgs.Tokenize(" ");
243   if (pTokens) {
244     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
245       argument=((TObjString*)pTokens->At(i))->GetString();
246       if (argument.IsNull()) continue;
247
248       if (argument.CompareTo("-something")==0) {
249         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
250
251       } else {
252         HLTError("unknown argument %s", argument.Data());
253         iResult=-EINVAL;
254         break;
255       }
256     }
257     delete pTokens;
258   }
259   if (bMissingParam) {
260     HLTError("missing parameter for argument %s", argument.Data());
261     iResult=-EINVAL;
262   }
263   return iResult;
264 }
265
266 int AliHLTTPCOfflineTrackerComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
267 {
268   // see header file for class documentation
269   int iResult=0;
270   return iResult;
271 }