]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/OnlineAnalysis/AliHLTMUONFullTrackerComponent.cxx
Reversing commit 42768 because it apparently breaks the code. Waiting for proper...
[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 "AliHLTMUONTracksBlockStruct.h"
37
38 ClassImp(AliHLTMUONFullTrackerComponent)
39
40 AliHLTMUONFullTrackerComponent::AliHLTMUONFullTrackerComponent() :
41   AliHLTMUONProcessor(),
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::TracksBlockDataType() );
94   return list.size();
95 }
96
97 void AliHLTMUONFullTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
98 {
99   // see header file for class documentation
100   constBase = sizeof(AliHLTMUONTracksBlockStruct) + 1024*1024;
101   inputMultiplier = 1;
102
103 }
104
105
106
107 // Spawn function, return new instance of this class
108 AliHLTComponent* AliHLTMUONFullTrackerComponent::Spawn()
109 {
110   // see header file for class documentation
111   return new AliHLTMUONFullTrackerComponent;
112 }
113
114 int AliHLTMUONFullTrackerComponent::DoInit( int argc, const char** argv )
115 {
116   // perform initialization
117   bool useFast = false;
118   int result = AliHLTMUONProcessor::DoInit(argc, argv);
119   if (result != 0) return result;
120   
121   
122   for (int i = 0; i < argc; i++){
123         
124     // To keep the legacy behaviour we need to have the following check
125     // for -cdbpath here, before ArgumentAlreadyHandled.
126     if (ArgumentAlreadyHandled(i, argv[i])) continue;
127
128     if (strcmp(argv[i], "-usefast") == 0)
129       {
130         useFast = true;
131       }
132     
133   }
134
135   
136   if (fTracker == NULL)
137   {
138     try
139     {
140       fTracker = new AliHLTMUONFullTracker;
141     }
142     catch (const std::bad_alloc&)
143     {
144       HLTError("Could not allocate a new AliHLTMUONFullTracker object. Ran out of memory.");
145       return -ENOMEM;
146     }
147   }
148   
149   result = FetchMappingStores();
150   fTracker->Init();
151   fTracker->FastTracking(useFast);
152   
153   return 0;
154 }
155
156 int AliHLTMUONFullTrackerComponent::DoDeinit()
157 {
158   // see header file for class documentation
159   
160   if (fTracker != NULL)
161   {
162     delete fTracker;
163     fTracker = NULL;
164   }
165   
166   return 0;
167 }
168
169 int AliHLTMUONFullTrackerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
170                                              AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
171                                              AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
172 {
173   // Process an event
174   unsigned long totalSize = 0;
175   AliHLTUInt32_t specification = 0;  // Contains the output data block spec bits.
176   bool resultOk = true;
177   // Loop over all input blocks in the event
178   
179   HLTDebug("Processing iEvent %llu with %u input data blocks.",
180          evtData.fEventID, evtData.fBlockCnt
181                );
182   
183   if (! IsDataEvent()){
184     size = totalSize;
185     resultOk = false;
186     return 0;
187   }
188   
189   //if(evtData.fBlockCnt==3) return 0;
190
191     AliHLTMUONTracksBlockWriter block(outputPtr, size);  
192     if (not block.InitCommonHeader())
193     {
194       Logging(kHLTLogError,
195               "AliHLTMUONFullTrackerComponent::DoEvent",
196               "Buffer overflow",
197               "The buffer is only %d bytes in size. We need a minimum of %d bytes.",
198               size, sizeof(AliHLTMUONTracksBlockWriter::HeaderType)
199               );
200       if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
201       size = 0; // Important to tell framework that nothing was generated.
202       resultOk = false;
203       return -ENOBUFS;
204     }
205
206   
207   for (AliHLTUInt32_t n = 0; n < evtData.fBlockCnt; n++){
208
209     HLTDebug("Handling block: %u, with fDataType = '%s', fPtr = %p and fSize = %u bytes.",
210              n, DataType2Text(blocks[n].fDataType).c_str(), blocks[n].fPtr, blocks[n].fSize
211              );
212
213     if (not resultOk) break;
214     
215     if (blocks[n].fDataType == AliHLTMUONConstants::RecHitsBlockDataType()){
216       specification |= blocks[n].fSpecification;
217                         
218       AliHLTMUONRecHitsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
219       if (not BlockStructureOk(inblock)){
220         if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
221         resultOk = false;
222       }
223       
224       if(resultOk){
225         resultOk = fTracker->SetInput(AliHLTMUONUtils::SpecToDDLNumber(blocks[n].fSpecification), 
226                                       inblock.GetArray(), inblock.Nentries());  
227       }
228
229
230     }else if (blocks[n].fDataType == AliHLTMUONConstants::TriggerRecordsBlockDataType()){
231       specification |= blocks[n].fSpecification;
232       AliHLTMUONTriggerRecordsBlockReader inblock(blocks[n].fPtr, blocks[n].fSize);
233       if (not BlockStructureOk(inblock)){
234         if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
235         resultOk = false;
236       }
237       
238       if(resultOk){
239         resultOk = fTracker->SetInput(AliHLTMUONUtils::SpecToDDLNumber(blocks[n].fSpecification), 
240                                       inblock.GetArray(),inblock.Nentries());   
241       }
242
243     }//check if trigger block
244   }//loop over blocks array of rechit and trigrecs
245
246   AliHLTUInt32_t nofTracks = 0;
247   AliHLTUInt32_t emptyTrackBlockSize = block.BytesUsed(); 
248   if( resultOk ){  
249     nofTracks   = block.MaxNumberOfEntries();
250     resultOk  = fTracker->Run(evtData.fEventID,block.GetArray(), nofTracks);
251   }
252
253   if (resultOk){
254     assert( nofTracks <= block.MaxNumberOfEntries() );
255     block.SetNumberOfEntries(nofTracks);
256     
257     HLTDebug("Number of reconstructed tracks found is %d, resultOk : %d, emptyTrackBlockSize : %d", 
258                  nofTracks,resultOk,emptyTrackBlockSize);
259     HLTDebug("sizeof  %d", sizeof(AliHLTMUONTrackStruct));
260     HLTDebug("Bytes Used  is %d",block.BytesUsed());    
261     HLTDebug("Specification is %d", specification);
262     
263     AliHLTComponentBlockData bd;
264     FillBlockData(bd);
265     bd.fPtr = outputPtr;
266     bd.fOffset = 0;
267     bd.fSize = block.BytesUsed();
268     bd.fDataType = AliHLTMUONConstants::TracksBlockDataType() ;      
269     bd.fSpecification = specification;
270
271     outputBlocks.push_back(bd);
272
273     totalSize = block.BytesUsed();
274     
275   }else{
276     
277     HLTDebug("Error while processing the full tracker algorithm.");
278     if (DumpDataOnError()) DumpEvent(evtData, blocks, trigData, outputPtr, size, outputBlocks);
279
280     HLTDebug("Number of reconstructed tracks found is %d, resultOk : %d, emptyTrackBlockSize : %d", 
281                  nofTracks,resultOk,emptyTrackBlockSize);
282     HLTDebug("sizeof  %d", sizeof(AliHLTMUONTrackStruct));
283     HLTDebug("Bytes Used  is %d",block.BytesUsed());    
284     HLTDebug("Specification is %d", specification);
285     
286     AliHLTComponentBlockData bd;
287     FillBlockData(bd);
288     bd.fPtr = outputPtr;
289     bd.fOffset = 0;
290     bd.fSize = emptyTrackBlockSize;
291     bd.fDataType = AliHLTMUONConstants::TracksBlockDataType() ;      
292     bd.fSpecification = specification;
293     
294     outputBlocks.push_back(bd);
295     
296     totalSize = emptyTrackBlockSize;
297
298     //return -EIO;
299   }
300
301   // Finally we set the total size of output memory we consumed.
302   size = totalSize;  // Must tell the framework how much buffer space was used.
303   return 0;
304
305 }
306
307
308 int AliHLTMUONFullTrackerComponent::Configure(const char* arguments)
309 {
310   // see header file for class documentation
311   int iResult=0;
312   if (!arguments) return iResult;
313   HLTInfo("parsing configuration string \'%s\'", arguments);
314
315   TString allArgs=arguments;
316   TString argument;
317   int bMissingParam=0;
318
319   TObjArray* pTokens=allArgs.Tokenize(" ");
320   if (pTokens) {
321     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
322       argument=((TObjString*)pTokens->At(i))->GetString();
323       if (argument.IsNull()) continue;
324
325       // -config1
326       if (argument.CompareTo("-config1")==0) {
327         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
328         HLTInfo("got \'-config1\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
329
330         // -config2
331       } else if (argument.CompareTo("-config2")==0) {
332         HLTInfo("got \'-config2\'");
333       } else {
334         HLTError("unknown argument %s", argument.Data());
335         iResult=-EINVAL;
336         break;
337       }
338     }
339     delete pTokens;
340   }
341   if (bMissingParam) {
342     HLTError("missing parameter for argument %s", argument.Data());
343     iResult=-EINVAL;
344   }
345   return iResult;
346 }
347
348 int AliHLTMUONFullTrackerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
349 {
350   // see header file for class documentation
351   int iResult=0;
352   const char* path="HLT/ConfigSample/FullTrackerComponent";
353   const char* defaultNotify="";
354   if (cdbEntry) {
355     path=cdbEntry;
356     defaultNotify=" (default)";
357   }
358   if (path) {
359     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
360     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
361     if (pEntry) {
362       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
363       if (pString) {
364         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
365         iResult=Configure(pString->GetString().Data());
366       } else {
367         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
368       }
369     } else {
370       HLTError("can not fetch object \"%s\" from CDB", path);
371     }
372   }
373   return iResult;
374 }
375
376 int AliHLTMUONFullTrackerComponent::ReadPreprocessorValues(const char* modules)
377 {
378   // see header file for class documentation
379   int iResult=0;
380   TString detectors(modules!=NULL?modules:"");
381   HLTInfo("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data());
382   return iResult;
383 }