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