]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/OnlineAnalysis/AliHLTMUONMansoTrackerComponent.cxx
--- Access to bad channel map implemented in reconstruction chain.
[u/mrichter/AliRoot.git] / HLT / MUON / OnlineAnalysis / AliHLTMUONMansoTrackerComponent.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 /**
19  *  @file   AliHLTMUONMansoTrackerComponent.cxx
20  *  @author Artur Szostak <artursz@iafrica.com>
21  *  @date   
22  *  @brief  Implementation of AliHLTMUONMansoTrackerComponent class.
23  */
24
25 #include "AliHLTMUONMansoTrackerComponent.h"
26 #include "Util/AliHLTMUONRecPoint.h"
27 #include <stdlib.h>
28 #include <errno.h>
29
30 namespace
31 {
32         // this is a global object used for automatic component registration, do not use this
33         AliHLTMUONMansoTrackerComponent gAliHLTMUONMansoTrackerComponent;
34 }
35
36
37 ClassImp(AliHLTMUONMansoTrackerComponent);
38
39
40 AliHLTMUONMansoTrackerComponent::AliHLTMUONMansoTrackerComponent()
41   :
42     fOutputPercentage(100) // By default we copy to the output exactly what we got as input
43     {
44     }
45
46 AliHLTMUONMansoTrackerComponent::~AliHLTMUONMansoTrackerComponent()
47     {
48     }
49
50 const char* AliHLTMUONMansoTrackerComponent::GetComponentID()
51     {
52     return "tracking"; // The ID of this component
53     }
54
55 void AliHLTMUONMansoTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
56     {
57       /* in order to be backward compatible we have to keep the old code, at
58        * least for a while. Remember to use the new const kAliHLTVoidDataType
59        * if you are using a more recent AliRoot version (from Jan 07)
60        list.push_back(kAliHLTAnyDataType); // We do not have any requirements for our input data type(s).
61       */
62
63       AliHLTComponentDataType dt = 
64         { sizeof(AliHLTComponentDataType),
65           {'*','*','*','*','*','*','*','\0'},
66           {'*','*','*','\0'}};
67        list.push_back(dt);
68     }
69
70 AliHLTComponentDataType AliHLTMUONMansoTrackerComponent::GetOutputDataType()
71     {
72       /* in order to be backward compatible we have to keep the old code, at
73        * least for a while. Remember to use the new const kAliHLTVoidDataType
74        * if you are using a more recent AliRoot version (from Jan 07)
75       return kAliHLTVoidDataType;
76       */
77       AliHLTComponentDataType dt = 
78         { sizeof(AliHLTComponentDataType),
79           {'\0','\0','\0','0','\0','\0','\0','\0'},
80           {'\0','\0','\0','\0'}};
81       return dt;
82     }
83
84 void AliHLTMUONMansoTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
85     {
86     constBase = 0;
87     inputMultiplier = ((double)fOutputPercentage)/100.0;
88     }
89
90
91
92 // Spawn function, return new instance of this class
93 AliHLTComponent* AliHLTMUONMansoTrackerComponent::Spawn()
94     {
95     return new AliHLTMUONMansoTrackerComponent;
96     }
97
98 int AliHLTMUONMansoTrackerComponent::DoInit( int argc, const char** argv )
99     {
100     // perform initialization. We check whether our relative output size is specified in the arguments.
101     fOutputPercentage = 100;
102                                                 
103     fTracker = new AliHLTMUONMansoTracker();
104
105     Logging(kHLTLogInfo, "dHLT", "Tracking", "hitrec, DoInit");
106     if (argc==0 && argv==NULL) {
107       // this is just to get rid of the warning "unused parameter"
108     }
109
110     int i = 0;
111     char* cpErr;
112     while ( i < argc )
113       {
114         Logging( kHLTLogDebug, "AliHLTMUONMansoTrackerComponent::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
115         if ( !strcmp( argv[i], "output_percentage" ) )
116             {
117             if ( i+1>=argc )
118                 {
119                 Logging(kHLTLogError, "AliHLTMUONMansoTrackerComponent::DoInit", "Missing Argument", "Missing output_percentage parameter");
120                 return ENOTSUP;
121                 }
122             Logging( kHLTLogDebug, "AliHLTMUONMansoTrackerComponent::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
123             fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
124             if ( *cpErr )
125                 {
126                   Logging(kHLTLogError, "AliHLTMUONMansoTrackerComponent::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
127                   return EINVAL;
128                 }
129             Logging( kHLTLogInfo, "AliHLTMUONMansoTrackerComponent::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
130             i += 2;
131             continue;
132             }
133         Logging(kHLTLogError, "AliHLTMUONMansoTrackerComponent::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
134         return EINVAL;
135       }// while loop
136     return 0;
137     }
138
139 int AliHLTMUONMansoTrackerComponent::DoDeinit()
140 {
141   if(fTracker)
142     delete fTracker;
143   return 0;
144 }
145
146 int AliHLTMUONMansoTrackerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
147                                       AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
148                                       AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
149 {
150   Logging( kHLTLogInfo, "AliHLTMUONMansoTrackerComponent::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
151   // Process an event
152   unsigned long totalSize = 0;
153   AliHLTUInt32_t maxTracksPerEvent = 1024;
154
155   fTracker->Reset();
156   fTracker->SetTrackOutputBuffer((AliHLTMUONTrackPoints*)outputPtr,maxTracksPerEvent);
157   
158 //  cout<<"BlockSize :"<<evtData.fBlockCnt<<" size :"<<outputBlocks.size()<<endl;
159   // Loop over all input blocks in the event
160   for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
161     {
162       // Align the beginning of this  block to the required value.
163 //       if ( totalSize % kAliHLTBlockAlignment )
164 //      totalSize += kAliHLTBlockAlignment-(totalSize % kAliHLTBlockAlignment);
165
166       if ( totalSize > size )
167         break;
168       // Determine the size we should use for the output for this block (the input block's size times the relative output size)
169       unsigned long mySize = (blocks[n].fSize * fOutputPercentage) / 100;
170       Logging( kHLTLogInfo, "AliHLTMUONMansoTrackerComponent::DoEvent", "mySize set (1)", "mySize == %lu B - blocks[%lu].fSize == %lu - fOutputPercentage == %lu - totalSize == %lu", 
171                mySize, n, blocks[n].fSize, fOutputPercentage, totalSize );
172
173       Int_t noftrigData,nofhitData;
174       if(n== (evtData.fBlockCnt - 1)){// for trigger
175         UInt_t trigDataSize;
176         memcpy(&trigDataSize,blocks[n].fPtr,sizeof(UInt_t));
177 //      cout<<"trigDataSize :"<<trigDataSize<<endl;
178         UInt_t trigOffSet;
179         memcpy(&trigOffSet,(UInt_t*)blocks[n].fPtr + 1,sizeof(UInt_t));
180 //      cout<<"trigOffSet :"<<trigOffSet<<endl;
181         noftrigData = (trigDataSize -  sizeof(UInt_t))*sizeof(AliHLTUInt32_t)/sizeof(AliHLTMUONCoreTriggerRecord) ;
182         fTrigData = new AliHLTMUONCoreTriggerRecord[noftrigData];
183
184         for(Int_t i=0;i<noftrigData;i++){
185           AliHLTMUONCoreTriggerRecord record;
186           memcpy(&record,(UInt_t*)blocks[n].fPtr + 2 + i*(sizeof(AliHLTMUONCoreTriggerRecord))/4,sizeof(AliHLTMUONCoreTriggerRecord));
187           fTrigData[i] = record;
188
189 //        cout<<" Sign : "<<fTrigData[i].fSign
190 //            <<" Pt : "<<fTrigData[i].fPt
191 //            <<"\t X1:"<<fTrigData[i].fStation1impact.X()<<" Y1 :"<<fTrigData[i].fStation1impact.Y()
192 //            <<"\t X2:"<<fTrigData[i].fStation2impact.X()<<" Y2 :"<<fTrigData[i].fStation2impact.Y()
193 //            << endl;
194         }// for
195         
196         fTracker->FindTracks(fTrigData,noftrigData);
197 //      cout<<"Nof tracks found :"<<fTracker->TrackCount()<<endl;
198 //      cout<<"Z7 : "<<AliHLTMUONCoreMansoTracker::GetZ7()<<endl;
199
200       }else{ // for hitrec
201         UInt_t hitDataSize;
202         memcpy(&hitDataSize,blocks[n].fPtr,sizeof(UInt_t));
203 //      cout<<"hitDataSize :"<<hitDataSize<<endl;
204         nofhitData = hitDataSize*sizeof(AliHLTUInt32_t)/sizeof(AliHLTMUONCorePoint) ;
205         
206         Int_t chamber = n + 6;
207         AliHLTMUONRecPoint *recHit = new AliHLTMUONRecPoint[nofhitData];
208         for(Int_t i=0;i<nofhitData;i++){
209           AliHLTMUONCorePoint point;
210           memcpy(&point,(UInt_t*)blocks[n].fPtr + 1 + i*(sizeof(AliHLTMUONCorePoint))/4,sizeof(AliHLTMUONCorePoint));
211 //        cout <<"chamber :"<<chamber<<"\tX : "<<point.X()<<"\t Y : "<<point.Y()<< endl;
212           recHit[i].fX = point.X();
213           recHit[i].fY = point.Y();
214         }// for
215         
216         fTracker->AddRecHits(chamber,recHit,nofhitData);
217
218       }// hit or trig condn
219       
220
221       //for(Int_t itrig = 0 ; itrig < nofTrigData ; itrig++){
222       
223       //}
224
225
226         // Check how much space we have left and adapt this output block's size accordingly.
227 //      if ( totalSize + mySize > size )
228 //          mySize = size-totalSize;
229 //      Logging( kHLTLogInfo, "AliHLTMUONMansoTrackerComponent::DoEvent", "mySize set (2)", "mySize == %lu B - totalSize == %lu - size == %lu", 
230 //               mySize, totalSize, size );
231 //      if ( mySize<=0 )
232 //          continue; // No room left to write a further block.
233 //      // Now copy the input block
234 //      unsigned long copied = 0;
235 //      // First copy all full multiples of the input block
236 //      while ( copied+blocks[n].fSize <= mySize )
237 //          {
238 //          Logging( kHLTLogInfo, "AliHLTMUONMansoTrackerComponent::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B", 
239 //                   blocks[n].fSize, copied, totalSize );
240 //          memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, blocks[n].fSize );
241 //          copied += blocks[n].fSize;
242 //          }
243 //      // And the copy the remaining fragment of the block
244 //      Logging( kHLTLogInfo, "AliHLTMUONMansoTrackerComponent::DoEvent", "Copying", "Copying %lu B - Copied: %lu B - totalSize: %lu B", 
245 //               mySize-copied, copied, totalSize );
246 //      memcpy( outputPtr+totalSize+copied, blocks[n].fPtr, mySize-copied );
247 //      Logging( kHLTLogInfo, "AliHLTMUONMansoTrackerComponent::DoEvent", "Copied", "Copied: %lu B - totalSize: %lu B", 
248 //               copied, totalSize );
249 //      // Fill a block data structure for our output block.
250 //      AliHLTComponentBlockData ob;
251 //      // Let the structure be filled with the default values.
252 //      // This takes care of setting the shared memory and data type values to default values,
253 //      // so that they can be filled in by the calling code.
254 //      FillBlockData( ob );
255 //      // This block's start (offset) is after all other blocks written so far
256 //      ob.fOffset = totalSize;
257 //      // the size of this block's data.
258 //      ob.fSize = mySize;
259 //      // The specification of the data is copied from the input block.
260 //      ob.fSpecification = blocks[n].fSpecification;
261 //      // The data type is set automatically to the component's specified output data type.
262 //      // Place this block into the list of output blocks
263 //      outputBlocks.push_back( ob );
264 //      // Increase the total amount of data written so far to our output memory
265 //      totalSize += mySize;
266     }
267     // Finally we set the total size of output memory we consumed.
268     size = totalSize;
269     return 0;
270 }