]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/OnlineAnalysis/AliHLTMUONFullTrackerComponent.cxx
Merge remote-tracking branch 'origin/flatdev' into mergeFlat2Master
[u/mrichter/AliRoot.git] / HLT / MUON / OnlineAnalysis / AliHLTMUONFullTrackerComponent.cxx
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        * 
3  * ALICE Experiment at CERN, All rights reserved.                         *
4  * Permission to use, copy, modify and distribute this software and its   *
5  * documentation strictly for non-commercial purposes is hereby granted   *
6  * without fee, provided that the above copyright notice appears in all   *
7  * copies and that both the copyright notice and this permission notice   *
8  * appear in the supporting documentation. The authors make no claims     *
9  * about the suitability of this software for any purpose. It is          *
10  * provided "as is" without express or implied warranty.                  *
11  **************************************************************************/
12 //-----------------------------------------------------------------------------
13 /// \class AliHLTMUONFullTrackerComponent
14 /// 
15 /// Component class for full tracker, see the detail description 
16 /// of the full tracker in the full tracker header file
17 ///  \author :Indranil Das, email : indra.das@saha.ac.in | indra.ehep@gmail.com , Saha Institute of Nuclear Physics
18 //-----------------------------------------------------------------------------
19
20 #include "AliHLTMUONFullTrackerComponent.h"
21 #include "TString.h"
22 #include "TObjString.h"
23 #include "TObjArray.h"
24 #include "AliCDBEntry.h"
25 #include "AliCDBManager.h"
26
27 #include "AliHLTDefinitions.h"
28
29 #include "AliHLTMUONConstants.h"
30
31 #include "AliHLTMUONTracksBlockStruct.h"
32
33 using namespace std;
34
35 ClassImp(AliHLTMUONFullTrackerComponent)
36
37 AliHLTMUONFullTrackerComponent::AliHLTMUONFullTrackerComponent() :
38   AliHLTMUONProcessor(),
39   fTracker(NULL)
40 {
41   // see header file for class documentation
42   
43 }
44
45 AliHLTMUONFullTrackerComponent::~AliHLTMUONFullTrackerComponent()
46 {
47   // see header file for class documentation
48   
49   if (fTracker != NULL) delete fTracker;
50 }
51
52 const char* AliHLTMUONFullTrackerComponent::GetComponentID()
53 {
54   // see header file for class documentation
55   return AliHLTMUONConstants::FullTrackerId();
56 }
57
58 void AliHLTMUONFullTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
59 {
60   // see header file for class documentation
61   /* in order to be backward compatible we have to keep the old code, at
62    * least for a while. Remember to use the new const kAliHLTVoidDataType
63    * if you are using a more recent AliRoot version (from Jan 07)
64    list.push_back(kAliHLTAnyDataType); // We do not have any requirements for our input data type(s).
65   */
66
67   assert( list.empty() );
68   list.push_back( AliHLTMUONConstants::TriggerRecordsBlockDataType() );
69   list.push_back( AliHLTMUONConstants::RecHitsBlockDataType() );
70
71 }
72
73 AliHLTComponentDataType AliHLTMUONFullTrackerComponent::GetOutputDataType()
74 {
75   // see header file for class documentation
76   /* in order to be backward compatible we have to keep the old code, at
77    * least for a while. Remember to use the new const kAliHLTVoidDataType
78    * if you are using a more recent AliRoot version (from Jan 07)
79    return kAliHLTVoidDataType;
80   */
81   return kAliHLTMultipleDataType;
82
83 }
84
85 int AliHLTMUONFullTrackerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& list)
86 {
87   /// Inherited from AliHLTComponent. Returns the output data types.
88         
89   assert( list.empty() );
90   list.push_back( AliHLTMUONConstants::TracksBlockDataType() );
91   return list.size();
92 }
93
94 void AliHLTMUONFullTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
95 {
96   // see header file for class documentation
97   constBase = sizeof(AliHLTMUONTracksBlockStruct) + 1024*1024;
98   inputMultiplier = 1;
99
100 }
101
102
103
104 // Spawn function, return new instance of this class
105 AliHLTComponent* AliHLTMUONFullTrackerComponent::Spawn()
106 {
107   // see header file for class documentation
108   return new AliHLTMUONFullTrackerComponent;
109 }
110
111 int AliHLTMUONFullTrackerComponent::DoInit( int argc, const char** argv )
112 {
113   // perform initialization
114   bool useFast = false;
115   int result = AliHLTMUONProcessor::DoInit(argc, argv);
116   if (result != 0) return result;
117   
118   
119   for (int i = 0; i < argc; i++){
120         
121     // To keep the legacy behaviour we need to have the following check
122     // for -cdbpath here, before ArgumentAlreadyHandled.
123     if (ArgumentAlreadyHandled(i, argv[i])) continue;
124
125     if (strcmp(argv[i], "-usefast") == 0)
126       {
127         useFast = true;
128       }
129     
130   }
131
132   
133   if (fTracker == NULL)
134   {
135     try
136     {
137       fTracker = new AliHLTMUONFullTracker;
138     }
139     catch (const std::bad_alloc&)
140     {
141       HLTError("Could not allocate a new AliHLTMUONFullTracker object. Ran out of memory.");
142       return -ENOMEM;
143     }
144   }
145   
146   result = FetchMappingStores();
147   fTracker->Init();
148   fTracker->FastTracking(useFast);
149   
150   return 0;
151 }
152
153 int AliHLTMUONFullTrackerComponent::DoDeinit()
154 {
155   // see header file for class documentation
156   
157   if (fTracker != NULL)
158   {
159     delete fTracker;
160     fTracker = NULL;
161   }
162   
163   return 0;
164 }
165
166 int AliHLTMUONFullTrackerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
167                                              AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
168                                              AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
169 {
170   // Process an event
171   unsigned long totalSize = 0;
172   AliHLTUInt32_t specification = 0;  // Contains the output data block spec bits.
173   bool resultOk = true;
174   // Loop over all input blocks in the event
175   
176   HLTDebug("Processing iEvent %llu with %u input data blocks.",
177          evtData.fEventID, evtData.fBlockCnt
178                );
179   
180   if (! IsDataEvent()){
181     size = totalSize;
182     resultOk = false;
183     return 0;
184   }
185   
186   //if(evtData.fBlockCnt==3) return 0;
187
188     AliHLTMUONTracksBlockWriter block(outputPtr, size);  
189     if (not block.InitCommonHeader())
190     {
191       Logging(kHLTLogError,
192               "AliHLTMUONFullTrackerComponent::DoEvent",
193               "Buffer overflow",
194               "The buffer is only %d bytes in size. We need a minimum of %d bytes.",
195               size, sizeof(AliHLTMUONTracksBlockWriter::HeaderType)
196               );
197       if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
198       size = 0; // Important to tell framework that nothing was generated.
199       resultOk = false;
200       return -ENOBUFS;
201     }
202
203   
204   for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++){
205
206     HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.",
207              n, DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fPtr, blocks[n].fSize
208              );
209
210     if (not resultOk) break;
211     
212     if (blocks[n].fDataType == AliHLTMUONConstants::RecHitsBlockDataType()){
213       specification |= blocks[n].fSpecification;
214                         
215       AliHLTMUONRecHitsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
216       if (not BlockStructureOk(inblock)){
217         if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
218         resultOk = false;
219       }
220       
221       if(resultOk){
222         resultOk = fTracker->SetInput(AliHLTMUONUtils::SpecToDDLNumber(blocks[n].fSpecification), 
223                                       inblock.GetArray(), inblock.Nentries());  
224       }
225
226
227     }else if (blocks[n].fDataType == AliHLTMUONConstants::TriggerRecordsBlockDataType()){
228       specification |= blocks[n].fSpecification;
229       AliHLTMUONTriggerRecordsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
230       if (not BlockStructureOk(inblock)){
231         if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
232         resultOk = false;
233       }
234       
235       if(resultOk){
236         resultOk = fTracker->SetInput(AliHLTMUONUtils::SpecToDDLNumber(blocks[n].fSpecification), 
237                                       inblock.GetArray(),inblock.Nentries());   
238       }
239
240     }//check if trigger block
241   }//loop over blocks array of rechit and trigrecs
242
243   AliHLTUInt32_t nofTracks = 0;
244   AliHLTUInt32_t emptyTrackBlockSize = block.BytesUsed(); 
245   if( resultOk ){  
246     nofTracks   = block.MaxNumberOfEntries();
247     resultOk  = fTracker->Run(evtData.fEventID,block.GetArray(), nofTracks);
248   }
249
250   if (resultOk){
251     assert( nofTracks <= block.MaxNumberOfEntries() );
252     block.SetNumberOfEntries(nofTracks);
253     
254     HLTDebug("Number of reconstructed tracks found is %d, resultOk : %d, emptyTrackBlockSize : %d", 
255                  nofTracks,resultOk,emptyTrackBlockSize);
256     HLTDebug("sizeof  %d", sizeof(AliHLTMUONTrackStruct));
257     HLTDebug("Bytes Used  is %d",block.BytesUsed());    
258     HLTDebug("Specification is %d", specification);
259     
260     AliHLTComponentBlockData bd;
261     FillBlockData(bd);
262     bd.fPtr = outputPtr;
263     bd.fOffset = 0;
264     bd.fSize = block.BytesUsed();
265     bd.fDataType = AliHLTMUONConstants::TracksBlockDataType() ;      
266     bd.fSpecification = specification;
267
268     outputBlocks.push_back(bd);
269
270     totalSize = block.BytesUsed();
271     
272   }else{
273     
274     HLTDebug("Error while processing the full tracker algorithm.");
275     if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
276
277     HLTDebug("Number of reconstructed tracks found is %d, resultOk : %d, emptyTrackBlockSize : %d", 
278                  nofTracks,resultOk,emptyTrackBlockSize);
279     HLTDebug("sizeof  %d", sizeof(AliHLTMUONTrackStruct));
280     HLTDebug("Bytes Used  is %d",block.BytesUsed());    
281     HLTDebug("Specification is %d", specification);
282     
283     AliHLTComponentBlockData bd;
284     FillBlockData(bd);
285     bd.fPtr = outputPtr;
286     bd.fOffset = 0;
287     bd.fSize = emptyTrackBlockSize;
288     bd.fDataType = AliHLTMUONConstants::TracksBlockDataType() ;      
289     bd.fSpecification = specification;
290     
291     outputBlocks.push_back(bd);
292     
293     totalSize = emptyTrackBlockSize;
294
295     //return -EIO;
296   }
297
298   // Finally we set the total size of output memory we consumed.
299   size = totalSize;  // Must tell the framework how much buffer space was used.
300   return 0;
301
302 }
303
304
305 int AliHLTMUONFullTrackerComponent::Configure(const char* arguments)
306 {
307   // see header file for class documentation
308   int iResult=0;
309   if (!arguments) return iResult;
310   HLTInfo("parsing configuration string \'%s\'", arguments);
311
312   TString allArgs=arguments;
313   TString argument;
314   int bMissingParam=0;
315
316   TObjArray* pTokens=allArgs.Tokenize(" ");
317   if (pTokens) {
318     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
319       argument=((TObjString*)pTokens->At(i))->GetString();
320       if (argument.IsNull()) continue;
321
322       // -config1
323       if (argument.CompareTo("-config1")==0) {
324         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
325         HLTInfo("got \'-config1\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
326
327         // -config2
328       } else if (argument.CompareTo("-config2")==0) {
329         HLTInfo("got \'-config2\'");
330       } else {
331         HLTError("unknown argument %s", argument.Data());
332         iResult=-EINVAL;
333         break;
334       }
335     }
336     delete pTokens;
337   }
338   if (bMissingParam) {
339     HLTError("missing parameter for argument %s", argument.Data());
340     iResult=-EINVAL;
341   }
342   return iResult;
343 }
344
345 int AliHLTMUONFullTrackerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
346 {
347   // see header file for class documentation
348   int iResult=0;
349   const char* path="HLT/ConfigSample/FullTrackerComponent";
350   const char* defaultNotify="";
351   if (cdbEntry) {
352     path=cdbEntry;
353     defaultNotify=" (default)";
354   }
355   if (path) {
356     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
357     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
358     if (pEntry) {
359       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
360       if (pString) {
361         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
362         iResult=Configure(pString->GetString().Data());
363       } else {
364         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
365       }
366     } else {
367       HLTError("can not fetch object \"%s\" from CDB", path);
368     }
369   }
370   return iResult;
371 }
372
373 int AliHLTMUONFullTrackerComponent::ReadPreprocessorValues(const char* modules)
374 {
375   // see header file for class documentation
376   int iResult=0;
377   TString detectors(modules!=NULL?modules:"");
378   HLTInfo("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data());
379   return iResult;
380 }