]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/TRD/AliHLTTRDCalibrationComponent.cxx
correcting compilation warnings (Theodor)
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDCalibrationComponent.cxx
index f20f6fd9a58271eed052701560b4c2fa7bb713c1..a91b32486cdd22834e15ba4808db6a26b76b27b8 100644 (file)
@@ -18,7 +18,7 @@
 
 /** @file   AliHLTTRDCalibrationComponent.cxx
     @author Timm Steinbeck, Matthias Richter
-    @date   
+    @date
     @brief  A TRDCalibration processing component for the HLT. */
 
 #if __GNUC__ >= 3
@@ -31,25 +31,29 @@ using namespace std;
 
 #include "AliHLTTRDCalibrationComponent.h"
 #include "AliHLTTRDDefinitions.h"
+#include "AliHLTTRDUtils.h"
 
 #include "AliCDBManager.h"
-#include "AliTRDclusterizerHLT.h"
+#include "AliCDBStorage.h"
 #include "AliRawReaderMemory.h"
+#include "AliTRDCalibraFillHisto.h"
+#include "AliTRDtrackV1.h"
 
 #include <cstdlib>
 #include <cerrno>
 #include <string>
 
-// this is a global object used for automatic component registration, do not use this
-AliHLTTRDCalibrationComponent gAliHLTTRDCalibrationComponent;
-
 ClassImp(AliHLTTRDCalibrationComponent);
-   
+
 AliHLTTRDCalibrationComponent::AliHLTTRDCalibrationComponent()
-  : AliHLTCalibrationProcessor()
-  , fOutputPercentage(100) // By default we copy to the output exactly what we got as input  
-  , fStrorageDBpath("local://$ALICE_ROOT")
-  , fCDB(NULL)
+: AliHLTCalibrationProcessor(),
+  fTRDCalibraFillHisto(NULL),
+  fOutputSize(50000),
+  fTracksArray(NULL),
+  fOutArray(NULL),
+  fNevent(0),
+  feveryNevent(20),
+  fRecievedTimeBins(kFALSE)
 {
   // Default constructor
 }
@@ -57,7 +61,6 @@ AliHLTTRDCalibrationComponent::AliHLTTRDCalibrationComponent()
 AliHLTTRDCalibrationComponent::~AliHLTTRDCalibrationComponent()
 {
   // Destructor
-  ;
 }
 
 const char* AliHLTTRDCalibrationComponent::GetComponentID()
@@ -66,14 +69,14 @@ const char* AliHLTTRDCalibrationComponent::GetComponentID()
   return "TRDCalibration"; // The ID of this component
 }
 
-void AliHLTTRDCalibrationComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
+void AliHLTTRDCalibrationComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
 {
   // Get the list of input data
   list.clear(); // We do not have any requirements for our input data type(s).
-  list.push_back( AliHLTTRDDefinitions::fgkTRDSATracksDataType );
+  list.push_back(AliHLTTRDDefinitions::fgkTRDSATracksDataType);
 }
 
-AliHLTComponent_DataType AliHLTTRDCalibrationComponent::GetOutputDataType()
+AliHLTComponentDataType AliHLTTRDCalibrationComponent::GetOutputDataType()
 {
   // Get the output data type
   return AliHLTTRDDefinitions::fgkCalibrationDataType;
@@ -82,8 +85,8 @@ AliHLTComponent_DataType AliHLTTRDCalibrationComponent::GetOutputDataType()
 void AliHLTTRDCalibrationComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
 {
   // Get the output data size
-  constBase = 0;
-  inputMultiplier = ((double)fOutputPercentage)/100.0;
+  constBase = fOutputSize;
+  inputMultiplier = 0;
 }
 
 AliHLTComponent* AliHLTTRDCalibrationComponent::Spawn()
@@ -95,112 +98,199 @@ AliHLTComponent* AliHLTTRDCalibrationComponent::Spawn()
 Int_t AliHLTTRDCalibrationComponent::ScanArgument( int argc, const char** argv )
 {
   // perform initialization. We check whether our relative output size is specified in the arguments.
-  fOutputPercentage = 100;
   int i = 0;
   char* cpErr;
   while ( i < argc )
     {
-      Logging( kHLTLogDebug, "HLT::TRDCalibration::ScanArgument", "Arguments", "argv[%d] == %s", i, argv[i] );
-      if ( !strcmp( argv[i], "output_percentage" ) )
-       {
-         if ( i+1>=argc )
-           {
-             Logging(kHLTLogError, "HLT::TRDCalibration::ScanArgument", "Missing Argument", "Missing output_percentage parameter");
-             return ENOTSUP;
-           }
-         Logging( kHLTLogDebug, "HLT::TRDCalibration::ScanArgument", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
-         fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
-         if ( *cpErr )
-           {
-             Logging(kHLTLogError, "HLT::TRDCalibration::ScanArgument", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
-             return EINVAL;
-           }
-         Logging( kHLTLogInfo, "HLT::TRDCalibration::ScanArgument", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
-         i += 2;
-         continue;
-       }
-
-      if ( strcmp( argv[i], "-cdb" ) == 0)
-       {
-         if ( i+1 >= argc )
-           {
-             Logging(kHLTLogError, "HLT::TRDCalibration::ScanArgument", "Missing Argument", "Missing -cdb argument");
-             return ENOTSUP;         
-           }
-         fStrorageDBpath = argv[i+1];
-         Logging( kHLTLogInfo, "HLT::TRDCalibration::ScanArgument", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );     
-         i += 2;
-         continue;
-       }      
-
-      Logging(kHLTLogError, "HLT::TRDCalibration::ScanArgument", "Unknown Option", "Unknown option '%s'", argv[i] );
-      return EINVAL;
+      HLTDebug("argv[%d] == %s", i, argv[i] );
+      if ( !strcmp( argv[i], "output_size" ) )
+        {
+          if ( i+1>=argc )
+            {
+              HLTError("Missing output_size parameter");
+              return ENOTSUP;
+            }
+          HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
+          fOutputSize = strtoul( argv[i+1], &cpErr, 0 );
+          if ( *cpErr )
+            {
+              HLTError("Cannot convert output_size parameter '%s'", argv[i+1] );
+              return EINVAL;
+            }
+          HLTInfo("Output size set to %lu %%", fOutputSize );
+          i += 2;
+          continue;
+        }
+      if ( !strcmp( argv[i], "-everyNevent" ) )
+        {
+          if ( i+1>=argc )
+            {
+              HLTError("Missing everyNevent parameter");
+              return ENOTSUP;
+            }
+          HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
+          fOutputSize = strtoul( argv[i+1], &cpErr, 0 );
+          if ( *cpErr )
+            {
+              HLTError("Cannot convert everyNevent parameter '%s'", argv[i+1] );
+              return EINVAL;
+            }
+          HLTInfo("Pushing back every %d event", feveryNevent);
+          i += 2;
+          continue;
+        }
+
+      else {
+        HLTError("Unknown option '%s'", argv[i] );
+        return EINVAL;
+      }
     }
   return 0;
 }
 
 Int_t AliHLTTRDCalibrationComponent::InitCalibration()
 {
-  //init the calibration
-  fCDB = AliCDBManager::Instance();
-  if (!fCDB)
-    {
-      Logging(kHLTLogError, "HLT::TRDCalibration::InitCalibration", "Could not get CDB instance", "fCDB 0x%x", fCDB);
-    }
-  else
-    {
-      fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
-      fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
-      Logging(kHLTLogDebug, "HLT::TRDCalibration::InitCalibration", "CDB instance", "fCDB 0x%x", fCDB);
-    }
+  if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
+    HLTError("DefaultStorage is not set in CDBManager");
+    return -EINVAL;
+  }
+  if(AliCDBManager::Instance()->GetRun()<0){
+    HLTError("Run Number is not set in CDBManager");
+    return -EINVAL;
+  }
+  HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
+
+  fTRDCalibraFillHisto = AliTRDCalibraFillHisto::Instance();
+  fTRDCalibraFillHisto->SetHisto2d(); // choose to use histograms
+  fTRDCalibraFillHisto->SetCH2dOn();  // choose to calibrate the gain
+  fTRDCalibraFillHisto->SetPH2dOn();  // choose to calibrate the drift velocity
+  fTRDCalibraFillHisto->SetPRF2dOn(); // choose to look at the PRF
+  fTRDCalibraFillHisto->SetIsHLT(); // per detector
+  //fTRDCalibraFillHisto->SetDebugLevel(1);// debug
+  fTRDCalibraFillHisto->SetFillWithZero(kTRUE);
 
+  fTracksArray = new TClonesArray("AliTRDtrackV1");
+  fOutArray = new TObjArray(3);
+
+  return 0;
 }
 
 Int_t AliHLTTRDCalibrationComponent::DeinitCalibration()
 {
+  
   // Deinitialization of the component
-  if (fCDB)
-    {
-      Logging( kHLTLogDebug, "HLT::TRDCalibration::DeinitCalibration", "destroy", "fCDB");
-      fCDB->Destroy();
-      fCDB = 0;
-    }
+  
+  HLTDebug("DeinitCalibration");
+  fTracksArray->Delete();
+  delete fTracksArray;
+  fTRDCalibraFillHisto->Destroy();
+  //fOutArray->Delete();
+  delete fOutArray;
+
+  return 0;
 }
 
-Int_t AliHLTTRDCalibrationComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData)
+Int_t AliHLTTRDCalibrationComponent::ProcessCalibration(const AliHLTComponent_EventData& evtData,
+                                                        const AliHLTComponent_BlockData* blocks,
+                                                        AliHLTComponent_TriggerData& /*trigData*/,
+                                                        AliHLTUInt8_t* /*outputPtr*/,
+                                                        AliHLTUInt32_t& /*size*/,
+                                                        vector<AliHLTComponent_BlockData>& /*outputBlocks*/)
 {
+  HLTDebug("NofBlocks %lu", evtData.fBlockCnt );
   // Process an event
-//   Logging( kHLTLogInfo, "HLT::TRDCalibration::ProcessCalibration", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
-  Logging( kHLTLogDebug, "HLT::TRDCalibration::ProcessCalibration", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
-  // Process an event
-  unsigned long totalSize = 0;
-
-  //implement a usage of the following
-//   AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
-//   AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
-//   void *triggerData = trigData.fData;
-  Logging( kHLTLogDebug, "HLT::TRDCalibration::ProcessCalibration", "Trigger data received", 
-          "Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
 
   // Loop over all input blocks in the event
-  int ibForce = 0;
-  TObject *tobjin = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::fgkTRDSATracksDataType, "AliTRDtrack", ibForce);
-  Logging( kHLTLogInfo, "HLT::TRDCalibration::ProcessCalibration", "1stBLOCK", "Pointer = 0x%x", tobjin);
-  while (tobjin)
+  vector<AliHLTComponent_DataType> expectedDataTypes;
+  GetInputDataTypes(expectedDataTypes);
+  for ( unsigned long iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
     {
-      tobjin = (TObject *)GetNextInputObject( ibForce );
-      Logging( kHLTLogInfo, "HLT::TRDCalibration::ProcessCalibration", "nextBLOCK", "Pointer = 0x%x", tobjin);
-    }
+      const AliHLTComponentBlockData &block = blocks[iBlock];
+      AliHLTComponentDataType inputDataType = block.fDataType;
+      Bool_t correctDataType = kFALSE;
+
+      for(UInt_t i = 0; i < expectedDataTypes.size(); i++)
+        if( expectedDataTypes.at(i) == inputDataType)
+          correctDataType = kTRUE;
+      if (!correctDataType) {
+        HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - Skipping",
+                  iBlock, evtData.fBlockCnt,
+                  evtData.fEventID, evtData.fEventID,
+                  DataType2Text(inputDataType).c_str());
+        continue;
+      }
+      else {
+        HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
+                 iBlock, evtData.fBlockCnt-1,
+                 evtData.fEventID, evtData.fEventID,
+                 DataType2Text(inputDataType).c_str(),
+                block.fSize);
+      }
+
+      Int_t nTimeBins;
+      AliHLTTRDUtils::ReadTracks(fTracksArray, block.fPtr, block.fSize, &nTimeBins);
+      
+      if(!fRecievedTimeBins){
+       HLTDebug("Reading number of time bins from input block. Value is: %d", nTimeBins);
+       fTRDCalibraFillHisto->Init2Dhistos(); // initialise the histos
+       fTRDCalibraFillHisto->SetNumberClusters(0); // At least 1 clusters
+       fTRDCalibraFillHisto->SetNumberClustersf(nTimeBins); // Not more than %d  clusters
+       fRecievedTimeBins=kTRUE;
+      }
 
+      Int_t nbEntries = fTracksArray->GetEntries();
+      HLTDebug(" %i TRDtracks in tracksArray", nbEntries);
+      AliTRDtrackV1* trdTrack = 0x0;
+      for (Int_t i = 0; i < nbEntries; i++){
+       HLTDebug("%i/%i: ", i+1, nbEntries);
+       trdTrack = (AliTRDtrackV1*)fTracksArray->At(i);
+       trdTrack->Print();
+       fTRDCalibraFillHisto->UpdateHistogramsV1(trdTrack);
+      }
+      
+      if(!fOutArray->At(0))FormOutput();
+      if (fNevent%feveryNevent==0 && fOutArray) {
+        PushBack(fOutArray, AliHLTTRDDefinitions::fgkCalibrationDataType);
+      }
+
+      fTracksArray->Delete();
+      fNevent++;
+
+    }
   return 0;
+
 }
 
-Int_t AliHLTTRDCalibrationComponent::ShipDataToFXS( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData)
+/**
+ * Form output array of histrograms
+ */
+//============================================================================
+void AliHLTTRDCalibrationComponent::FormOutput()
 {
-  //Int_t PushToFXS(TObject* pObject, const char* pDetector, const char* pFileID, const char* pDDLNumber = "");
-  //ireturn = PushToFXS(object, "TRD ", "TRDCalib", "1024 ");
-  Logging( kHLTLogDebug, "HLT::TRDCalibration::ProcessCalibration", "Shipping data", 
-          "Nothing serious");
-  Int_t ireturn = 0;
-  return ireturn;
+  // gain histo
+  TH2I *hCH2d = fTRDCalibraFillHisto->GetCH2d();
+  fOutArray->Add(hCH2d);
+
+  // drift velocity histo
+  TProfile2D *hPH2d = fTRDCalibraFillHisto->GetPH2d();
+  fOutArray->Add(hPH2d);
+
+  // PRF histo
+  TProfile2D *hPRF2d = fTRDCalibraFillHisto->GetPRF2d();
+  fOutArray->Add(hPRF2d);
+
+  HLTDebug("GetCH2d = 0x%x; NEntries = %i; size = %i", hCH2d, hCH2d->GetEntries(), sizeof(hCH2d));
+  hCH2d->Print();
+  HLTDebug("GetPH2d = 0x%x; NEntries = %i; size = %i", hPH2d, hPH2d->GetEntries(), sizeof(hPH2d));
+  hPH2d->Print();
+  HLTDebug("GetPRF2d = 0x%x; NEntries = %i; size = %i", hPRF2d, hPRF2d->GetEntries(), sizeof(hPRF2d));
+  hPRF2d->Print();
+  HLTDebug("output Array: pointer = 0x%x; NEntries = %i; size = %i", fOutArray, fOutArray->GetEntries(), sizeof(fOutArray));
+}
+
+Int_t AliHLTTRDCalibrationComponent::ShipDataToFXS(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
+{
+  //fTRDCalibraFillHisto->DestroyDebugStreamer();
+  PushToFXS((TObject*)fOutArray, "TRD", "GAINDRIFTPRF");
+  return 0;
 }