]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCCalibTracksComponent.cxx
Remove compilser warnings
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCCalibTracksComponent.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: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no>          *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
10 //* Permission to use, copy, modify and distribute this software and its   *
11 //* documentation strictly for non-commercial purposes is hereby granted   *
12 //* without fee, provided that the above copyright notice appears in all   *
13 //* copies and that both the copyright notice and this permission notice   *
14 //* appear in the supporting documentation. The authors make no claims     *
15 //* about the suitability of this software for any purpose. It is          *
16 //* provided "as is" without express or implied warranty.                  *
17 //**************************************************************************
18
19 /** @file   AliHLTTPCCalibTracksComponent.cxx
20     @author Kalliopi Kanaki
21     @date   
22     @brief  A calibration component for the TPC.
23 */
24
25 // see header file for class documentation
26 // or
27 // refer to README to build package
28 // or
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt   
30
31 #if __GNUC__>= 3
32 using namespace std;
33 #endif
34
35 #include "AliHLTTPCCalibTracksComponent.h"
36
37 #include "AliHLTTPCLogging.h"
38 #include "AliHLTTPCTransform.h"
39 #include "AliHLTTPCClusterDataFormat.h"
40 #include "AliHLTTPCTrackletDataFormat.h"
41 #include "AliHLTTPCOfflineCluster.h"
42
43 #include "AliTPCcalibDB.h"
44 #include "AliTPCClusterParam.h"
45 #include "AliTPCcalibTracksCuts.h"
46 #include "AliTPCcalibTracksGain.h"
47 #include "AliTPCcalibTracks.h"
48 #include "AliTPCcalibAlign.h"
49
50 #include "AliTPCclusterMI.h"
51 #include "AliTPCseed.h"
52
53 #include "AliCDBEntry.h"
54 #include "AliCDBManager.h"
55
56 #include <stdlib.h>
57 #include <errno.h>
58 #include "TString.h"
59
60 //AliHLTTPCCalibTracksComponent gAliHLTTPCCalibTracksComponent;
61
62 /** ROOT macro for the implementation of ROOT specific class methods */
63 ClassImp(AliHLTTPCCalibTracksComponent)
64
65 AliHLTTPCCalibTracksComponent::AliHLTTPCCalibTracksComponent()
66   :
67   fClustParam(0),
68   fTrackCuts(0),
69   fCalibTracksGain(NULL),
70   fCalibAlign(NULL),
71   fCalibTracks(NULL),
72   fMinPatch(5),
73   fMaxPatch(0),
74   fSpecification(0),
75   fEnableAnalysis(kFALSE),
76   fSeed(0),
77   fClusters(),
78   fTracks(),
79   pConv(NULL),
80   fOffArray(),
81   fReadMergedTracks(0),
82   fReadSliceTracks(0)
83 {
84   // see header file for class documentation
85   // or
86   // refer to README to build package
87   // or
88   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
89 }
90
91 AliHLTTPCCalibTracksComponent::~AliHLTTPCCalibTracksComponent(){
92 // see header file for class documentation
93 }
94
95 const char* AliHLTTPCCalibTracksComponent::GetComponentID(){
96 // see header file for class documentation
97   return "TPCCalibTracks";
98 }
99
100 void AliHLTTPCCalibTracksComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list){
101 // see header file for class documentation
102
103   list.clear(); 
104   list.push_back(AliHLTTPCDefinitions::fgkClustersDataType);
105   list.push_back(AliHLTTPCDefinitions::fgkTrackSegmentsDataType);
106   list.push_back(AliHLTTPCDefinitions::fgkTracksDataType);
107 }
108
109 AliHLTComponentDataType AliHLTTPCCalibTracksComponent::GetOutputDataType(){
110 // see header file for class documentation
111
112   return kAliHLTMultipleDataType;
113 }
114
115 int AliHLTTPCCalibTracksComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList){
116 // create output data type
117
118   tgtList.clear();
119   tgtList.push_back(AliHLTTPCDefinitions::fgkOfflineCalibAlignDataType);
120   tgtList.push_back(AliHLTTPCDefinitions::fgkOfflineCalibTracksDataType);
121   tgtList.push_back(AliHLTTPCDefinitions::fgkOfflineCalibTracksGainDataType);
122
123   return tgtList.size();
124 }
125
126 void AliHLTTPCCalibTracksComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier){
127 // see header file for class documentation
128
129   constBase = 30000000;
130   inputMultiplier = 1;
131 }
132
133 AliHLTComponent* AliHLTTPCCalibTracksComponent::Spawn(){
134 // see header file for class documentation
135   
136   return new AliHLTTPCCalibTracksComponent();
137 }  
138
139
140 Int_t AliHLTTPCCalibTracksComponent::ScanArgument(Int_t argc, const char** argv){
141 // see header file for class documentation
142
143   Int_t iResult = 0;
144   TString argument = "";
145   TString parameter = "";
146
147   if(!argc) return -EINVAL;
148   argument = argv[iResult];
149   
150   if(argument.IsNull()) return -EINVAL;
151
152 //   // -rcuformat
153 //   if ( argument.CompareTo("-rcuformat") == 0 ) {
154 // 
155 //     if ( ++iResult >= argc  ) {
156 //       iResult = -EPROTO;
157 //     }
158 //     else {
159 //       parameter = argv[1];
160 //       if ( parameter.CompareTo("old") == 0 ) {
161 //         HLTInfo( "RCU Format is set to old." );
162 //       }
163 //       else if ( parameter.CompareTo("new") == 0 ) {
164 //         HLTInfo( "RCU Format is set to new." );
165 //       }
166 //       else {
167 //      HLTError( "Cannot convert rcu format specifier '%s'.", argv[1] );
168 //      iResult = -EPROTO;
169 //       }
170 //     } 
171 //   }
172
173
174   if(argument.CompareTo("-enable-analysis") == 0) {   
175   
176     HLTInfo( "Enable analysis before shipping data to FXS." );
177     fEnableAnalysis = kTRUE;
178     //cout << "fEnableAnalysis: " << fEnableAnalysis << endl;
179   }
180   else if(argument.CompareTo("-read-slice-tracks") == 0){
181     HLTInfo( "Reading slice tracks..." );
182     fReadSliceTracks = kTRUE;  
183     //cout << "fReadSliceTracks: " << fReadSliceTracks << endl;
184   }
185   else if(argument.CompareTo("-read-merged-tracks") == 0){
186     HLTInfo( "Reading merged tracks..." );
187     fReadMergedTracks = kTRUE; 
188     //cout << "fReadMergedTracks: " << fReadMergedTracks << endl;
189   }
190   else {
191     iResult = -EINVAL;
192   }
193   
194   return iResult;
195
196
197
198 //---------------------------------
199
200
201  
202 //   Int_t i = 0;
203 //   Char_t* cpErr;
204 //   
205 //   int iResult = 0;
206 //   
207 //   TString configuration = "";
208 //   TString argument = "";
209 //   for(int j=0; j<argc && iResult>=0; j++){
210 //     
211 //     argument=argv[j];
212 //     if (!configuration.IsNull()) configuration+=" ";
213 //     configuration+=argument;    
214 //   }
215 //    
216 //   if (!configuration.IsNull()) {
217 //     iResult = Configure(configuration.Data());
218 //   } else {
219 //     iResult = Reconfigure(NULL, NULL);
220 //   }
221 //  
222 //   while ( i < argc ) {      
223 //     if (!strcmp( argv[i], "-enable-analysis")) {
224 //         fEnableAnalysis = strtoul( argv[i+1], &cpErr ,0);
225 //             
226 //     if ( *cpErr ) {
227 //         HLTError("Cannot convert enable-analysis specifier '%s'.", argv[i+1]);
228 //         return EINVAL;
229 //     }
230 //       i+=2;
231 //       continue;
232 //     }
233 //     
234 //     if (!strcmp( argv[i], "-read-merged-tracks")) {
235 //         fReadMergedTracks = strtoul( argv[i+1], &cpErr ,0);
236 //             
237 //     if ( *cpErr ) {
238 //         HLTError("Cannot convert read-merged-tracks specifier '%s'.", argv[i+1]);
239 //         return EINVAL;
240 //     }
241 //       i+=2;
242 //       continue;
243 //     }
244 //     
245 //     if (!strcmp( argv[i], "-read-slice-tracks")) {
246 //         fReadSliceTracks = strtoul( argv[i+1], &cpErr ,0);
247 //     
248 //     if ( *cpErr ) {
249 //         HLTError("Cannot convert read-slice-tracks specifier '%s'.", argv[i+1]);
250 //         return EINVAL;
251 //     }
252 //       i+=2;
253 //       continue;
254 //     }
255 // 
256 //     Logging(kHLTLogError, "HLT::TPCCalibTracks::ScanArgument", "Unknown Option", "Unknown option '%s'", argv[i] );
257 //     return EINVAL;
258 // 
259 //   } // end while
260 //   
261 //   return 0;
262 }
263
264 Int_t AliHLTTPCCalibTracksComponent::InitCalibration(){
265 // see header file for class documentation
266   
267   HLTInfo("init calibration component");
268   int iResult=0;
269
270   if(fCalibTracksGain) return EINPROGRESS; 
271   fCalibTracksGain = new AliTPCcalibTracksGain();
272   
273   if(fCalibAlign) return EINPROGRESS;  
274   fCalibAlign = new AliTPCcalibAlign();
275  
276   if(fCalibTracks) return EINPROGRESS;  
277   fCalibTracks = new AliTPCcalibTracks();
278
279   
280 //   // Init parameters and cuts
281 //   fClustParam = AliTPCcalibDB::Instance()->GetClusterParam();
282 //   fTrackCuts = new AliTPCcalibTracksCuts(20, 0.4, 0.5, 0.13, 0.018);
283 // 
284 //   // Init calibration componenets
285 //   fCalibAlign           = new AliTPCcalibAlign("TPCcalibAlign","TPCcalibAlign");
286 //   fCalibTracksGain = new AliTPCcalibTracksGain("TPCcalibTracksGain","TPCcalibTracksGain",fTrackCuts);
287 //   fCalibTracks     = new AliTPCcalibTracks("TPCcalibTracks","TPCcalibTracks",fClustParam,fTrackCuts);
288 // 
289 //   if (!fTrackCuts || !fClustParam ||  !fCalibAlign || !fCalibTracksGain || !fCalibTracks) {
290 //     HLTError("failed creating internal objects");
291 //     iResult=-ENOMEM;
292 //   }
293   return iResult;  
294
295 }
296
297 Int_t AliHLTTPCCalibTracksComponent::DeinitCalibration(){
298 // see header file for class documentation
299    
300    if(fClustParam) delete fClustParam; fClustParam = 0; 
301    if(fTrackCuts)  delete fTrackCuts;  fTrackCuts  = 0; 
302
303    if(fCalibTracksGain) delete fCalibTracksGain; fCalibTracksGain = NULL;
304    if(fCalibAlign)      delete fCalibAlign;      fCalibAlign      = NULL;
305    //if(fCalibTracks)     delete fCalibTracks;   fCalibTracks     = NULL;
306    
307   return 0;
308 }
309
310 Int_t AliHLTTPCCalibTracksComponent::ProcessCalibration(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/){
311 // see header file for class documentation
312   
313   
314   const AliHLTComponentBlockData *iter = NULL;
315   //AliHLTUInt8_t slice = 0;
316   //AliHLTUInt8_t patch = 0;
317       
318   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR)) return 0;
319
320   Int_t TotalTrack = 0;
321
322   //if(fReadMergedTracks){ //Reading Merged Tracks 
323      for(iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkTracksDataType); iter != NULL; iter = GetNextInputBlock()){
324          if(iter->fDataType != AliHLTTPCDefinitions::fgkTracksDataType) continue; 
325          ReadTracks(iter,TotalTrack);  
326      }  
327   //} // end if reading merged tracks
328
329   //else 
330   //if(fReadSliceTracks){ //Reading Tracks from slice 
331      for(iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkTrackSegmentsDataType); iter != NULL; iter = GetNextInputBlock()){
332          if(iter->fDataType != AliHLTTPCDefinitions::fgkTrackSegmentsDataType) continue; 
333          ReadTracks(iter,TotalTrack);
334      }
335   //} // end if reading slice tracks
336           
337   //else HLTError("No input preference (merged/slice tracks) specified!");
338  
339   //int TotalSpacePoint = 0;
340   //Int_t nClustersUsed = 0;
341   //fOffArray.Clear();
342   
343   for(iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType); iter != NULL; iter = GetNextInputBlock()){
344       if(iter->fDataType!=AliHLTTPCDefinitions::fgkClustersDataType) continue;
345
346       //AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
347       //AliHLTUInt8_t patch = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
348
349       const AliHLTTPCClusterData *clusterData = (const AliHLTTPCClusterData*)iter->fPtr;
350       Int_t nSpacepoint = (Int_t)clusterData->fSpacePointCnt;   
351       
352       //cout << "nSpacepoint: " << nSpacepoint << endl;      
353       //TotalSpacePoint += nSpacepoint;
354       
355       AliHLTTPCSpacePointData *clusters = (AliHLTTPCSpacePointData*)clusterData->fSpacePoints;
356      
357       Int_t thissector, thisrow = -99;
358       pConv = new AliHLTTPCOfflineCluster();
359       
360       for(Int_t i=0; i<nSpacepoint; i++){
361        
362           UInt_t idCluster = clusters[i].fID;
363           Int_t  sliceCl   = (idCluster>>25) & 0x7f;
364           Int_t  patchCl   = (idCluster>>22) & 0x7;
365           UInt_t pos       = idCluster&0x3fffff;
366           
367           //cout << idCluster <<"\t"<< patchCl << "\t"<< pos << endl;
368           //cout << fTrackClusterID[sliceCl][patchCl].size()<< endl;
369               
370           for(UInt_t id=0; id<fTrackClusterID[sliceCl][patchCl].size(); id++){
371             //cout << "HELLOOOOOOOOOOOOO" << endl;
372               
373               if(fTrackClusterID[sliceCl][patchCl][id]==pos){
374                  clusters[i].fUsed = kTRUE;
375                  AliHLTTPCTransform::Slice2Sector(sliceCl,(Int_t)clusters[i].fPadRow,thissector,thisrow);
376                  //AliHLTTPCTransform::Slice2Sector(fCurrentslice,fCurrentRow,thissector,thisrow);
377                  //nClustersUsed++;     
378                  
379                  //cout <<  (Int_t)clusters[i].fPadRow << endl; 
380               
381                  
382                  AliTPCclusterMI *offClus = pConv->ConvertHLTToOffline(clusters[i]);
383                  offClus->SetDetector(thissector);
384                  //offClus->IsUsed(1);
385                  fOffArray.Add(pConv->ConvertHLTToOffline(clusters[i]));
386                  //delete pConv;
387                  //delete offClus;
388
389              } // end if setting used clusters
390           } //end for loop over cluster id       
391       } // end for loop over spacepoints
392       
393       //----- turn TObjArray of AliTPCclusterMI to AliTPCseed -----
394      
395       delete pConv;
396       for(Int_t k=0; k<fOffArray.GetSize(); k++) delete fOffArray.At(k);
397       
398       fOffArray.Clear();
399      
400       //fCalibTracksGain->Process(fSeed);
401       //fCalibAlign->Process(fSeed);
402       //fCalibTracks->Process(fSeed);
403   } // end for loop over cluster data type
404     
405   //fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, fMinPatch, fMaxPatch );
406
407   //PushBack((TObject*)fCalibTracksGain, AliHLTTPCDefinitions::fgkOfflineCalibTracksGainDataType, fSpecification);
408   //PushBack((TObject*)fCalibAlign,      AliHLTTPCDefinitions::fgkOfflineCalibAlignDataType,    fSpecification);
409   //PushBack((TObject*)fCalibTracks,     AliHLTTPCDefinitions::fgkOfflineCalibTracksDataType,   fSpecification);
410   
411   //fClusters.clear();
412   //fTracks.clear();
413
414   return 0;
415 } // end ProcessCalibration
416
417
418 Int_t AliHLTTPCCalibTracksComponent::ShipDataToFXS(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/){
419 // see header file for class documentation
420     
421   if(fEnableAnalysis){
422      fCalibTracksGain->Analyze();
423      fCalibAlign->Analyze();
424      fCalibTracks->Analyze();
425   }
426   
427   PushToFXS((TObject*)fCalibAlign,      "TPC", "TPCcalibAlign"); 
428   PushToFXS((TObject*)fCalibTracksGain, "TPC", "TPCcalibTracksGain");
429   PushToFXS((TObject*)fCalibTracks,     "TPC", "TPCcalibTracks");
430   
431   return 0;
432 } // end ShipDataToFXS
433
434
435 void AliHLTTPCCalibTracksComponent::ReadTracks(const AliHLTComponentBlockData *iter, Int_t &tt){
436
437   HLTDebug("Input Data - TPC cluster - Slice/Patch: %d/%d.", 
438            AliHLTTPCDefinitions::GetMinSliceNr( *iter ), 
439            AliHLTTPCDefinitions::GetMinPatchNr( *iter ));
440  
441
442   const AliHLTTPCTrackletData *trackData = (const AliHLTTPCTrackletData*)iter->fPtr;
443   AliHLTUInt32_t nTracks = trackData->fTrackletCnt;
444
445   tt += nTracks;
446  
447   //cout << "=============================================================================" << endl;
448   //cout << "=============================================================================" << endl;
449   //cout << nTracks << endl;
450  
451   AliHLTTPCTrackSegmentData *tracks = (AliHLTTPCTrackSegmentData*)trackData->fTracklets;
452   
453   for(AliHLTUInt32_t i=0;i<nTracks;i++){
454      
455       fTracks.push_back(tracks[i]);
456       UInt_t nHits = tracks->fNPoints;
457       const UInt_t *hitnum = tracks->fPointIDs;
458       
459       for(UInt_t h=0; h<nHits; h++){
460           
461           UInt_t idTrack = hitnum[h];
462           Int_t sliceTrack = (idTrack>>25) & 0x7f;
463           Int_t patchTrack = (idTrack>>22) & 0x7;
464           UInt_t pos = idTrack&0x3fffff;
465           fTrackClusterID[sliceTrack][patchTrack].push_back(pos);
466       } // end for loop over hits
467        
468       UChar_t *tmpP = (UChar_t*)tracks;
469       tmpP += sizeof(AliHLTTPCTrackSegmentData)+tracks->fNPoints*sizeof(UInt_t);
470       tracks = (AliHLTTPCTrackSegmentData*)tmpP;
471   } // end for loop over tracks
472 } // end ReadTracks()
473
474
475 Int_t AliHLTTPCCalibTracksComponent::Configure(const char* arguments){ 
476 // see header file for class documentation
477   
478   Int_t iResult=0;
479   if (!arguments) return iResult;
480   HLTInfo("parsing configuration string \'%s\'", arguments);
481
482   TString allArgs = arguments;
483   TString argument;
484   int bMissingParam = 0;
485
486   TObjArray* pTokens=allArgs.Tokenize(" ");
487   if (pTokens) {
488     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
489       argument=((TObjString*)pTokens->At(i))->GetString();
490       if (argument.IsNull()) continue;
491      
492       if (argument.CompareTo("-enable-analysis")==0) {
493         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
494         HLTInfo("got \'-enable-analysis\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
495         
496       } 
497       else if (argument.CompareTo("-read-merged-tracks")==0) {
498         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
499         HLTInfo("got \'-read-merged-tracks\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
500         
501       } 
502       else if (argument.CompareTo("-read-slice-tracks")==0) {
503         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
504         HLTInfo("got \'-read-slice-tracks\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
505         
506       } 
507       else {
508         HLTError("unknown argument %s", argument.Data());
509         iResult=-EINVAL;
510         break;
511       }
512     } // end for
513   
514     delete pTokens;
515   
516   } // end if pTokens
517   
518   if (bMissingParam) {
519     HLTError("missing parameter for argument %s", argument.Data());
520     iResult=-EINVAL;
521   }
522   return iResult;  
523 }
524
525 int AliHLTTPCCalibTracksComponent::Reconfigure(const char* cdbEntry, const char* chainId){ 
526 // see header file for class documentation
527  
528   int iResult=0;
529   const char* path = "HLT/ConfigTPC/TPCCalibTracksComponent";
530   const char* defaultNotify="";
531   if (cdbEntry) {
532       path=cdbEntry;
533       defaultNotify = " (default)";
534   }
535   
536   if (path) {
537     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
538     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
539     if (pEntry) {
540       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
541       if (pString) {
542         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
543         iResult=Configure(pString->GetString().Data());
544       } else {
545         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
546       }
547     } else {
548       HLTError("cannot fetch object \"%s\" from CDB", path);
549     }
550   }
551   return iResult;
552 }
553