]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TPCLib/AliHLTTPCSliceTrackerComponent.cxx
Coding violations
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCSliceTrackerComponent.cxx
index db58b09d668df57103d45458f6b03d5ed15130ea..00abc77b047bc6db432d92b1928a7c2359d7f7c7 100644 (file)
@@ -1,21 +1,21 @@
 // $Id$
 
-/**************************************************************************
- * This file is property of and copyright by the ALICE HLT Project        * 
- * ALICE Experiment at CERN, All rights reserved.                         *
- *                                                                        *
- * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
- *                  Timm Steinbeck <timm@kip.uni-heidelberg.de>           *
- *                  for The ALICE HLT Project.                            *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          *
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
+//**************************************************************************
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//*                                                                        *
+//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
+//*                  Timm Steinbeck <timm@kip.uni-heidelberg.de>           *
+//*                  for The ALICE HLT Project.                            *
+//*                                                                        *
+//* Permission to use, copy, modify and distribute this software and its   *
+//* documentation strictly for non-commercial purposes is hereby granted   *
+//* without fee, provided that the above copyright notice appears in all   *
+//* copies and that both the copyright notice and this permission notice   *
+//* appear in the supporting documentation. The authors make no claims     *
+//* about the suitability of this software for any purpose. It is          *
+//* provided "as is" without express or implied warranty.                  *
+//**************************************************************************
 
 /** @file   AliHLTTPCSliceTrackerComponent.cxx
     @author Timm Steinbeck, Matthias Richter
     @brief  The TPC conformal mapping tracker component.
 */
 
-// see header file for class documentation
-// or
-// refer to README to build package
-// or
-// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
-
 #if __GNUC__>= 3
 using namespace std;
 #endif
 
+#include <climits>
 #include "AliHLTTPCSliceTrackerComponent.h"
 #include "AliHLTTPCTransform.h"
 #include "AliHLTTPCConfMapper.h"
@@ -46,18 +41,18 @@ using namespace std;
 #include "AliHLTTPCInterMerger.h"
 #include "AliHLTTPCMemHandler.h"
 #include "AliHLTTPCDefinitions.h"
+#include "AliHLTCommonCDBEntries.h"
 #include "TString.h"
 #include "TObjString.h"
 #include "TObjArray.h"
 #include "AliCDBEntry.h"
 #include "AliCDBManager.h"
+#include "AliCDBStorage.h"
+#include "TGeoGlobalMagField.h"
 //#include "AliHLTTPC.h"
 //#include <stdlib.h>
 //#include <cerrno>
 
-// this is a global object used for automatic component registration, do not use this
-AliHLTTPCSliceTrackerComponent gAliHLTTPCSliceTrackerComponent;
-
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTTPCSliceTrackerComponent)
 
@@ -69,10 +64,9 @@ AliHLTTPCSliceTrackerComponent::AliHLTTPCSliceTrackerComponent()
   fDoPP(false),
   fDoPbPb(false),
   fMultiplicity(4000),
-  fBField(0.4),
+  fBField(0.5),
   fnonvertextracking(kFALSE),
   fmainvertextracking(kTRUE),
-  fpInterMerger(NULL),
   fPhisegment(50),
   fEtasegment(100),
   fTrackletlength(3),
@@ -87,7 +81,8 @@ AliHLTTPCSliceTrackerComponent::AliHLTTPCSliceTrackerComponent()
   fTrackChi2Cut(50),
   fMaxdist(50),
   fMaxphi(0.1),
-  fMaxeta(0.1)
+  fMaxeta(0.1),
+  fpInterMerger(NULL)
 {
   // see header file for class documentation
   // or
@@ -214,8 +209,8 @@ void AliHLTTPCSliceTrackerComponent::SetTrackerParam( Bool_t doPP, Bool_t doPbPb
     {
       //tracker->SetClusterFinderParam(xyerror,zerror,kTRUE); // ??
       
-      SetTrackerParam( 50, 100, 3, 10,
-                      2, 2,
+      SetTrackerParam( 50, 100, 3, 60,
+                      6, 6,
                       0, 0.1745, 5, 100,
                       5, 50, 50, 0.1, 0.1);
     }
@@ -418,9 +413,14 @@ int AliHLTTPCSliceTrackerComponent::DoDeinit()
 int AliHLTTPCSliceTrackerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
                                              AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
                                              AliHLTUInt32_t& size, AliHLTComponentBlockDataList& outputBlocks )
-    {
+{
   // see header file for class documentation
-    Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "DoEvent", "DoEvent()" );
+  int iResult=0;
+  AliHLTUInt32_t capacity=size;
+  size=0;
+
+  if (!IsDataEvent()) return 0;
+
     if ( evtData.fBlockCnt<=0 )
       {
        Logging( kHLTLogWarning, "HLT::TPCSliceTracker::DoEvent", "DoEvent", "no blocks in event" );
@@ -455,12 +455,28 @@ int AliHLTTPCSliceTrackerComponent::DoEvent( const AliHLTComponentEventData& evt
        {
        iter = blocks+ndx;
 
-       if(iter->fDataType!=AliHLTTPCDefinitions::fgkClustersDataType){
-         HLTDebug("Data block type is not of type AliHLTTPCDefinitions::fgkClustersDataType");
+       bool bIsClusterDataBlock=false;
+       bool bIsVertexDataBlock=false;
+       if(!(bIsClusterDataBlock=(iter->fDataType==AliHLTTPCDefinitions::fgkClustersDataType)) &&
+          !(bIsVertexDataBlock=(iter->fDataType==AliHLTTPCDefinitions::fgkVertexDataType))){
          continue;
        }
 
        slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
+       if (slice<0 || slice>=AliHLTTPCTransform::GetNSlice()) {
+         HLTError("invalid slice number %d extracted from specification 0x%08lx,  skipping block of type %s",
+                  slice, iter->fSpecification, DataType2Text(iter->fDataType).c_str());
+         // just remember the error, if there are other valid blocks ignore the
+         // error, return code otherwise
+         iResult=-EBADF;
+         continue;
+       }
+       if (slice!=AliHLTTPCDefinitions::GetMaxSliceNr( *iter )) {
+         // the code was not written for/ never used with multiple slices
+         // in one data block/ specification
+         HLTWarning("specification 0x%08lx indicates multiple slices in data block %s: never used before, please audit the code",
+                    iter->fSpecification, DataType2Text(iter->fDataType).c_str());
+       }
        found = false;
        slIter = slices.begin();
        slEnd = slices.end();
@@ -483,7 +499,7 @@ int AliHLTTPCSliceTrackerComponent::DoEvent( const AliHLTComponentEventData& evt
        else
            *slCntIter++;
 
-       if ( iter->fDataType == AliHLTTPCDefinitions::fgkVertexDataType )
+       if (bIsVertexDataBlock)
            {
            inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
            vertexIter = iter;
@@ -491,7 +507,7 @@ int AliHLTTPCSliceTrackerComponent::DoEvent( const AliHLTComponentEventData& evt
            fVertex->Read( inPtrV );
            vertexSlice = slice;
            }
-       if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType )
+       if (bIsClusterDataBlock)
            {
            patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
            if ( minPatch>patch )
@@ -538,9 +554,13 @@ int AliHLTTPCSliceTrackerComponent::DoEvent( const AliHLTComponentEventData& evt
       }
     else
       {
-       slice = -1;
+       // there is no sense in running the tracker without input, do not send an
+       // empty output block
+       return iResult;
       }
     
+    iResult=0;
+
     if ( vertexSlice != slice )
        {
        // multiple vertex blocks in event and we used the wrong one...
@@ -591,11 +611,11 @@ int AliHLTTPCSliceTrackerComponent::DoEvent( const AliHLTComponentEventData& evt
            
        Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Reading hits",
                 "Reading hits for slice %d - patch %d", slice, patch );
-       fTracker->ReadHits( inPtrSP->fSpacePointCnt, inPtrSP->fSpacePoints );
+       //fTracker->ReadHits( inPtrSP->fSpacePointCnt, inPtrSP->fSpacePoints );
+       fTracker->ReadHitsChecked(inPtrSP->fSpacePointCnt, inPtrSP->fSpacePoints,iter->fSize );
        pIter++;
        }
 
-    outPtr = (AliHLTTPCTrackletData*)(outBPtr);
 
     if ( fmainvertextracking == kTRUE && fnonvertextracking == kFALSE){        
       Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracking", " ---MAINVERTEXTRACKING---");
@@ -630,25 +650,42 @@ int AliHLTTPCSliceTrackerComponent::DoEvent( const AliHLTComponentEventData& evt
     } 
     ntracks0=0;
     AliHLTTPCTrackArray* pArray=fTracker->GetTracks();
+    if (pArray->GetOutSize()+sizeof(AliHLTTPCTrackletData)<=capacity) {
+    outPtr = (AliHLTTPCTrackletData*)(outBPtr);
     mysize = pArray->WriteTracks( ntracks0, outPtr->fTracklets );
     outPtr->fTrackletCnt = ntracks0;
 
+    // Matthias 2009-05-22
+    // Somehow the ConfMapFit uses a different sign convention for the magnetic field.
+    // In order to avoid conversions further upstream we change the sign here.
+    // The CM tracker is not the first priority any more as the CA tracker is
+    // going to be used for online TPC reconstruction. But CM tracker has to
+    // remain functional.
+    // Further investigation is ongoing
+    AliHLTTPCTrackSegmentData* segment=outPtr->fTracklets;
+    for (unsigned int trackno=0; trackno<ntracks0; trackno++, segment++) {
+      segment->fCharge*=-1;
+    }
+
     Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracks",
             "Input: Number of tracks: %lu Slice/MinPatch/MaxPatch/RowMin/RowMax: %lu/%lu/%lu/%lu/%lu.", 
             ntracks0, slice, minPatch, maxPatch, row[0], row[1] );
 
     fTracker->Reset();
 
-    tSize += mysize+sizeof(AliHLTTPCTrackletData);
-    outBPtr += mysize+sizeof(AliHLTTPCTrackletData);
-    
     AliHLTComponentBlockData bd;
     FillBlockData( bd );
     bd.fOffset = offset;
-    bd.fSize = tSize;
+    bd.fSize = mysize+sizeof(AliHLTTPCTrackletData);
     bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, minPatch, maxPatch );
     outputBlocks.push_back( bd );
 
+    tSize += bd.fSize;
+    outBPtr += bd.fSize;
+    } else {
+      iResult=-ENOSPC;
+    }
+
 #ifdef FORWARD_VERTEX_BLOCK
     if ( vertexIter )
        {
@@ -659,7 +696,7 @@ int AliHLTTPCSliceTrackerComponent::DoEvent( const AliHLTComponentEventData& evt
 #endif // FORWARD_VERTEX_BLOCK
 
     size = tSize;
-    return 0;
+    return iResult;
     }
 
 int AliHLTTPCSliceTrackerComponent::Configure(const char* arguments)
@@ -668,6 +705,12 @@ int AliHLTTPCSliceTrackerComponent::Configure(const char* arguments)
   int iResult=0;
   if (!arguments) return iResult;
   
+  // Check field
+  if (!TGeoGlobalMagField::Instance()) {
+    HLTError("magnetic field not initialized, please set up TGeoGlobalMagField and AliMagF");
+    return -ENODEV;
+  }
+
   TString allArgs=arguments;
   TString argument;
   int bMissingParam=0;
@@ -710,10 +753,14 @@ int AliHLTTPCSliceTrackerComponent::Configure(const char* arguments)
        fMultiplicity=((TObjString*)pTokens->At(i))->GetString().Atoi();
        continue;
       } 
+      else if (argument.CompareTo("-solenoidBz")==0) {
+       if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+       HLTWarning("parameter -solenoidBz deprecated, magnetic field handled by global AliMagF object and TGeoGlobalMagField");
+       continue;
+      } 
       else if (argument.CompareTo("-bfield")==0) {
        if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
-       HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
-       fBField=((TObjString*)pTokens->At(i))->GetString().Atof();
+       HLTWarning("parameter -bfield deprecated, magnetic field handled by global AliMagF object and TGeoGlobalMagField");
        continue;
       } 
       else if (argument.CompareTo("-etarange")==0) {
@@ -758,6 +805,12 @@ int AliHLTTPCSliceTrackerComponent::Configure(const char* arguments)
        fTracklength=((TObjString*)pTokens->At(i))->GetString().Atoi();
        continue;
       }
+      else if (argument.CompareTo("-clusterZ")==0) {
+       if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+       HLTInfo("Minimum number of clusters on a Track: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
+       fTracker->SetClusterCutZ(((TObjString*)pTokens->At(i))->GetString().Atoi());
+       continue;
+      }
       else {
        HLTError("unknown argument %s", argument.Data());
        iResult=-EINVAL;
@@ -770,6 +823,7 @@ int AliHLTTPCSliceTrackerComponent::Configure(const char* arguments)
     HLTError("missing parameter for argument %s", argument.Data());
     iResult=-EINVAL;
   }
+  fBField=GetBz()/10.0;
   if (fBField == 0.){
     // parameter for B=0 T 
     fDoPP = kTRUE;
@@ -787,9 +841,49 @@ int AliHLTTPCSliceTrackerComponent::Configure(const char* arguments)
   return iResult;
 }
 
+int AliHLTTPCSliceTrackerComponent::ReadPreprocessorValues(const char* modules)
+{
+  // see header file for class documentation
+  
+  int iResult = 0;
+  TString str(modules);
+  if(str.Contains("HLT") || str.Contains("TPC") || str.Contains("GRP")){
+  
+    const char* pathBField=NULL;
+    if (pathBField) {
+
+      HLTInfo("reconfigure B-Field from entry %s, modules %s", pathBField,(modules!=NULL && modules[0]!=0)?modules:"<none>");
+      //AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(pathBField/*,GetRunNo()*/);
+      
+      AliCDBPath path(pathBField);
+      
+      AliCDBStorage *stor = AliCDBManager::Instance()->GetDefaultStorage();
+      Int_t version    = stor->GetLatestVersion(pathBField, GetRunNo());
+      Int_t subVersion = stor->GetLatestSubVersion(pathBField, GetRunNo(), version);
+      AliCDBEntry *pEntry = stor->Get(path,GetRunNo(), version, subVersion);
+      
+      HLTImportant("RunNo %d, Version %d, subversion %d", GetRunNo(), version, subVersion);
+      
+      if (pEntry) {
+       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
+       if (pString) {
+         HLTImportant("received configuration object string: \'%s\'", pString->GetString().Data());
+         iResult=Configure(pString->GetString().Data());
+       } else {
+         HLTError("configuration object \"%s\" has wrong type, required TObjString", pathBField);
+       }
+      } else {
+       HLTError("cannot fetch object \"%s\" from CDB", pathBField);
+      }
+    }
+  }  
+  return iResult;
+}
+
 int AliHLTTPCSliceTrackerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
 {
   // see header file for class documentation
+
   int iResult=0;
   const char* path="HLT/ConfigTPC/SliceTrackerComponent";
   const char* defaultNotify="";
@@ -809,10 +903,30 @@ int AliHLTTPCSliceTrackerComponent::Reconfigure(const char* cdbEntry, const char
        HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
       }
     } else {
-      HLTError("can not fetch object \"%s\" from CDB", path);
+      HLTError("cannot fetch object \"%s\" from CDB", path);
     }
   }
+
+  const char* pathBField=NULL;
+
+  if (pathBField) {
+    HLTInfo("reconfigure B-Field from entry %s, chain id %s", path,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
+    AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(pathBField/*,GetRunNo()*/);
+    if (pEntry) {
+      TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
+      if (pString) {
+       HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
+       iResult=Configure(pString->GetString().Data());
+      } else {
+       HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
+      }
+    } else {
+      HLTError("cannot fetch object \"%s\" from CDB", path);
+    }
+  }
+  
   return iResult;
+
 }
 
 void AliHLTTPCSliceTrackerComponent::SetTrackerParam1()