]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
HLT EMCAL DAs. Clusterizer and FillESD (Tracker) offline functionality implemented
authormploskon <mploskon@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 18 Jul 2008 21:31:39 +0000 (21:31 +0000)
committermploskon <mploskon@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 18 Jul 2008 21:31:39 +0000 (21:31 +0000)
HLT/EMCAL/AliHLTEMCALClusterizerComponent.cxx
HLT/EMCAL/AliHLTEMCALClusterizerComponent.h
HLT/EMCAL/AliHLTEMCALDefinitions.cxx
HLT/EMCAL/AliHLTEMCALDefinitions.h
HLT/EMCAL/AliHLTEMCALTrackerComponent.cxx
HLT/EMCAL/AliHLTEMCALTrackerComponent.h
HLT/EMCAL/AliHLTEMCALUtils.cxx
HLT/EMCAL/AliHLTEMCALUtils.h

index 3f801c891d525ed8f2019fe647e8e589c9bce201..4182a3a0509d9f0f8da2d99d982675a2ca114001 100644 (file)
@@ -26,12 +26,18 @@ using namespace std;
 
 #include "AliHLTEMCALClusterizerComponent.h"
 #include "AliHLTEMCALDefinitions.h"
+#include "AliHLTEMCALUtils.h"
 
 #include "TString.h"
 #include "TObjString.h"
 #include "TObjArray.h"
+#include "TTree.h"
 #include "AliCDBEntry.h"
 #include "AliCDBManager.h"
+#include "AliRawReaderMemory.h"
+
+// this is a global object used for automatic component registration, do not use this
+AliHLTEMCALClusterizerComponent gAliHLTEMCALClusterizerComponent;
 
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTEMCALClusterizerComponent)
@@ -40,12 +46,8 @@ AliHLTEMCALClusterizerComponent::AliHLTEMCALClusterizerComponent()
   : AliHLTProcessor()
   , fOutputPercentage(100)
   , fStorageDBpath("local://$ALICE_ROOT")
-  , fClusterizer(NULL)
   , fCDB(NULL)
-  , fMemReader(NULL)
   , fGeometryFileName("")
-  , fGeometryFile(NULL)
-  , fGeoManager(NULL)
 {
   // see header file for class documentation
   // or
@@ -58,12 +60,8 @@ AliHLTEMCALClusterizerComponent::AliHLTEMCALClusterizerComponent(const AliHLTEMC
   : AliHLTProcessor()
   , fOutputPercentage(100)
   , fStorageDBpath("local://$ALICE_ROOT")
-  , fClusterizer(NULL)
   , fCDB(NULL)
-  , fMemReader(NULL)
   , fGeometryFileName("")
-  , fGeometryFile(NULL)
-  , fGeoManager(NULL)
 {
   // may not use the copy contructor
   HLTError("May not use.");
@@ -83,9 +81,26 @@ AliHLTEMCALClusterizerComponent::~AliHLTEMCALClusterizerComponent()
 
 AliHLTComponentDataType AliHLTEMCALClusterizerComponent::GetOutputDataType()
 {
+  //return AliHLTEMCALDefinitions::fgkClusterDataType | AliHLTEMCALDefinitions::fgkDigitDataType;
   return AliHLTEMCALDefinitions::fgkClusterDataType;
 }
 
+const char* AliHLTEMCALClusterizerComponent::GetComponentID()
+{ 
+  return "EMCALClusterizer";
+}
+
+void AliHLTEMCALClusterizerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) 
+{
+  list.push_back(kAliHLTAnyDataType);
+}
+
+void AliHLTEMCALClusterizerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) 
+{
+  constBase = 0;
+  inputMultiplier = ((double)fOutputPercentage)/100.0;
+}
+
 int AliHLTEMCALClusterizerComponent::DoInit( int argc, const char** argv )
 {
   // see header file for class documentation
@@ -100,62 +115,112 @@ int AliHLTEMCALClusterizerComponent::DoInit( int argc, const char** argv )
 
   char *cpErr = 0;
 
-  for (int i=0; i<argc && iResult>=0; i++) {
-    argument=argv[i];
-    if (argument.IsNull()) continue;
+  for (int i=0; i<argc && iResult>=0; i++) 
+    {
+      argument=argv[i];
+      if (argument.IsNull()) continue;
 
     // -mandatory1
-    if (argument.CompareTo("-cdb")==0) {
-      bHaveMandatory1|=1;
-      if ((bMissingParam=(++i>=argc))) break;
-      HLTInfo("got \'-cdb\' argument: %s", argv[i]);
-      fStorageDBpath = argv[i];
-      HLTInfo("CDB path is: %s", fStorageDBpath.c_str());
-      // -mandatory2
-    } else if (argument.CompareTo("-geometry")==0) {
-      bHaveMandatory2|=1;
-      HLTInfo("got \'-geometry\' argument");
-      fGeometryFileName = argv[i];
-      HLTInfo("Geometry file is: %s", fGeometryFileName.c_str());
-      // -optional1
-    } else if (argument.CompareTo("-output_percentage")==0) {
-      if ((bMissingParam=(++i>=argc))) break;
-      HLTInfo("got \'-output_percentage\' argument: %s", argv[i]);
-      fOutputPercentage = strtoul(argv[i], &cpErr, 0);
-      if ( *cpErr )
-       {
-         HLTError("Unable to convert ouput_percentage to a number %s", argv[i]);
-         return -EINVAL;
-       }
+    if (argument.CompareTo("-cdb")==0) 
+      {
+       bHaveMandatory1|=1;
+       if ((bMissingParam=(++i>=argc))) break;
+       HLTInfo("got \'-cdb\' argument: %s", argv[i]);
+       fStorageDBpath = argv[i];
+       HLTInfo("CDB path is: %s", fStorageDBpath.c_str());
+       // -mandatory2
+      } 
+    else if (argument.CompareTo("-geometry")==0) 
+      {
+       bHaveMandatory2|=1;
+       if ((bMissingParam=(++i>=argc))) break;
+       HLTInfo("got \'-geometry\' argument");
+       fGeometryFileName = argv[i];
+       HLTInfo("Geometry file is: %s", fGeometryFileName.c_str());
+       // -optional1
+      } 
+    else if (argument.CompareTo("-output_percentage")==0) 
+      {
+       if ((bMissingParam=(++i>=argc))) break;
+       HLTInfo("got \'-output_percentage\' argument: %s", argv[i]);
+       fOutputPercentage = strtoul(argv[i], &cpErr, 0);
+       if ( *cpErr )
+         {
+           HLTError("Unable to convert ouput_percentage to a number %s", argv[i]);
+           return -EINVAL;
+         }
+      } 
+    else 
+      {
+       // the remaining arguments are treated as configuration
+       if (!configuration.IsNull()) configuration+=" ";
+       configuration+=argument;
+      }
+    }
 
-//       // -optional2
-//     } else if (argument.CompareTo("-optional2")==0) {
-//       HLTInfo("got \'-optional2\' argument");
+  if (bMissingParam) 
+    {
+      HLTError("missing parameter for argument %s", argument.Data());
+      iResult=-EINVAL;
+    }
 
-    } else {
-      // the remaining arguments are treated as configuration
-      if (!configuration.IsNull()) configuration+=" ";
-      configuration+=argument;
+  if (iResult>=0 && !bHaveMandatory1) 
+    {
+      HLTError("mandatory argument \'-cdb\' missing");
+      iResult=-EPROTO;
     }
-  }
-  if (bMissingParam) {
-    HLTError("missing parameter for argument %s", argument.Data());
-    iResult=-EINVAL;
-  }
 
-  if (iResult>=0 && !bHaveMandatory1) {
-    HLTError("mandatory argument \'-cdb\' missing");
-    iResult=-EPROTO;
-  }
-  if (iResult>=0 && !bHaveMandatory2) {
-    HLTError("mandatory argument \'-geometry\' missing");
-    iResult=-EPROTO;
-  }
-  if (iResult>=0 && !configuration.IsNull()) {
-    iResult=Configure(configuration.Data());
-  } else {
-    iResult=Reconfigure(NULL, NULL);
-  }
+  if (iResult>=0 && !bHaveMandatory2) 
+    {
+      HLTError("mandatory argument \'-geometry\' missing");
+      iResult=-EPROTO;
+    }
+  
+  if (iResult>=0 && !configuration.IsNull()) 
+    {
+      iResult=Configure(configuration.Data());
+    } 
+  else 
+    {
+      iResult=Reconfigure(NULL, NULL);
+    }
+  
+  // Initialize here
+  // raw reader
+
+  // geometry
+  if (AliHLTEMCALUtils::GetGeometry() == NULL)
+    {
+      HLTError("unable to init geometry");
+      iResult=-EPROTO;      
+    }
+
+  // OCDB
+
+  // clusterizer and raw utils
+  if (AliHLTEMCALUtils::GetRawUtils() == NULL)
+    {
+      HLTError("unable to init rawutils");
+      iResult=-EPROTO;      
+    }
+
+  if (AliHLTEMCALUtils::GetRawUtils() == NULL)
+    {
+      HLTError("unable to init rawutils");
+      iResult=-EPROTO;      
+    }
+
+  if (AliHLTEMCALUtils::GetRecParam() == NULL)
+    {
+      HLTError("unable to init reco params");
+      iResult=-EPROTO;      
+    }      
+
+  if (AliHLTEMCALUtils::GetClusterizer() == NULL)
+    {
+      HLTError("unable to init clusterizer");
+      iResult=-EPROTO;      
+    }      
 
   return iResult;
 }
@@ -163,6 +228,7 @@ int AliHLTEMCALClusterizerComponent::DoInit( int argc, const char** argv )
 int AliHLTEMCALClusterizerComponent::DoDeinit()
 {
   // see header file for class documentation
+  AliHLTEMCALUtils::Cleanup();
   HLTInfo("processing cleanup");
   return 0;
 }
@@ -171,13 +237,78 @@ int AliHLTEMCALClusterizerComponent::DoEvent( const AliHLTComponentEventData& ev
                                      AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
                                      AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks ) {
   // see header file for class documentation
-  HLTInfo("processing data");
+  // check if the input data are there at all - empty events possible
+  HLTDebug("processing data");
   if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0 &&
       outputPtr==0 && size==0)
   {
     outputBlocks.clear();
     // this is just to get rid of the warning "unused parameter"
+    return 0;
   }
+
+  UChar_t *buffer = 0;
+  ULong_t  buffSize = 0;
+  Int_t    eqID = 4608; //fixed for the moment - get this one from the input data
+  TString  recoOption = "";
+  AliHLTUInt32_t dBlockSpecification = 0;
+
+  // Loop over all input blocks in the event
+  for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
+    {
+      //if (blocks[i].fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginEMCAL))
+      if (blocks[i].fDataType != (kAliHLTDataTypeDDLRaw)) // for the moment until we have the EMCAL in the publisher setup
+       {
+         HLTWarning("COMPARE FAILED received type=%d expected-or-type=%d",
+                    blocks[i].fDataType, kAliHLTDataTypeDDLRaw | kAliHLTDataOriginEMCAL);
+         continue;
+       }
+
+      dBlockSpecification = blocks[i].fSpecification;
+      unsigned long blockSize = blocks[i].fSize;
+      buffSize += blockSize;
+    }
+
+  buffer = (UChar_t*)calloc(buffSize, 1);
+  AliHLTUInt8_t *pBuf = (AliHLTUInt8_t *)buffer;
+  if (buffer == NULL)
+    {
+      HLTError("Unable to allocate %lu bytes", buffSize);
+      return -1;
+    }
+
+  // Make the memory continous
+  unsigned long copied = 0;
+  for ( unsigned long i = 0; i < evtData.fBlockCnt; i++ )
+    {
+      // we process only the raw data from TRD
+      if ( blocks[i].fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginEMCAL) )
+       continue;
+
+      void *pos = (void*)(pBuf + copied);
+      void *copyret = memcpy(pos, blocks[i].fPtr, blocks[i].fSize);
+      if (copyret < 0)
+       {
+         HLTError("MEMORY Unable to copy %lu bytes", blocks[i].fSize);
+         return -1;
+       }
+      copied += blocks[i].fSize;
+    }
+
+  // do it all function RAW->ClusterTree
+  //   TTree* AliHLTEMCALUtils::RawBuffer2Clusters(UChar_t *buffer, ULong_t buffSize, 
+  //                                         Int_t eqID, 
+  //                                         Option_t* sDigitsOption)
+
+  AliHLTEMCALUtils::ResetReconstructionTrees();
+  TTree* outputTree = AliHLTEMCALUtils::RawBuffer2Clusters(buffer, buffSize, eqID, recoOption.Data());
+  PushBack(outputTree, AliHLTEMCALDefinitions::fgkClusterDataType);
+
+  TTree *digitsTree = AliHLTEMCALUtils::GetDigitsTree();
+  PushBack(digitsTree, AliHLTEMCALDefinitions::fgkDigitDataType);  
+  
+  free(buffer);
+  
   return 0;
 }
 
@@ -188,36 +319,51 @@ int AliHLTEMCALClusterizerComponent::Configure(const char* arguments)
   if (!arguments) return iResult;
   HLTInfo("parsing configuration string \'%s\'", arguments);
 
-  TString allArgs=arguments;
+  TString allArgs = arguments;
   TString argument;
   int bMissingParam=0;
 
-  TObjArray* pTokens=allArgs.Tokenize(" ");
-  if (pTokens) {
-    for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
-      argument=((TObjString*)pTokens->At(i))->GetString();
-      if (argument.IsNull()) continue;
+  TObjArray* pTokens = allArgs.Tokenize(" ");
+  if (pTokens) 
+    {
+      for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) 
+       {
+         argument=((TObjString*)pTokens->At(i))->GetString();
+         if (argument.IsNull()) continue;
+         HLTInfo("processing argument %\n", argument.Data());
+         // -config1
+         if (argument.CompareTo("-cdb")==0) 
+           {
+             if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+             HLTInfo("got \'-cdb\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());         
+             // -config2
+           } 
+         else if (argument.CompareTo("-geometry")==0) 
+           {
+             if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+             HLTInfo("got \'-geometry\'");
+           } 
+         else if (argument.CompareTo("-output_percentage")==0) 
+           {
+             if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+             HLTInfo("got \'-output_percentage\'");
+           } 
+         else 
+           {
+             HLTError("unknown argument %s", argument.Data());
+             iResult=-EINVAL;
+             break;
+           }
+       }
+      delete pTokens;
+    }
 
-      // -config1
-      if (argument.CompareTo("-config1")==0) {
-       if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
-       HLTInfo("got \'-config1\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
-
-       // -config2
-      } else if (argument.CompareTo("-config2")==0) {
-       HLTInfo("got \'-config2\'");
-      } else {
-       HLTError("unknown argument %s", argument.Data());
-       iResult=-EINVAL;
-       break;
-      }
+  if (bMissingParam) 
+    {
+      HLTError("missing parameter for argument %s", argument.Data());
+      iResult=-EINVAL;
     }
-    delete pTokens;
-  }
-  if (bMissingParam) {
-    HLTError("missing parameter for argument %s", argument.Data());
-    iResult=-EINVAL;
-  }
+
   return iResult;
 }
 
@@ -225,27 +371,34 @@ int AliHLTEMCALClusterizerComponent::Reconfigure(const char* cdbEntry, const cha
 {
   // see header file for class documentation
   int iResult=0;
-  const char* path="HLT/ConfigSample/EMCALClusterizerComponent";
+  const char* path="HLT/ConfigEMCAL/EMCALClusterizerComponent";
   const char* defaultNotify="";
-  if (cdbEntry) {
-    path=cdbEntry;
-    defaultNotify=" (default)";
-  }
-  if (path) {
-    HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
-    AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,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("can not fetch object \"%s\" from CDB", path);
+  if (cdbEntry) 
+    {
+      path=cdbEntry;
+      defaultNotify=" (default)";
+    }
+  if (path) 
+    {
+      HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
+      AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,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("can not fetch object \"%s\" from CDB", path);
+       }
     }
-  }
   return iResult;
 }
 
index f6794435f05432abd4e8c98f2bb869916fadd42c..7546000b2210dc9f1219aca947b5629e16d89d26 100644 (file)
@@ -33,12 +33,10 @@ public:
   AliHLTEMCALClusterizerComponent& operator=(const AliHLTEMCALClusterizerComponent&);
 
   // AliHLTComponent interface functions
-  const char* GetComponentID() { return "EMCALClusterizer";}
-  void GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
-    list.push_back(kAliHLTAnyDataType);
-  }
+  const char* GetComponentID();
+  void GetInputDataTypes( vector<AliHLTComponentDataType>& list);
   AliHLTComponentDataType GetOutputDataType();
-  virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {constBase = 0;inputMultiplier = 100;};
+  virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
 
   // Spawn function, return new class instance
   AliHLTComponent* Spawn() {return new AliHLTEMCALClusterizerComponent;};
@@ -69,13 +67,8 @@ private:
   unsigned             fOutputPercentage;    // Output volume in percentage of the input  
   string               fStorageDBpath;      // Default path for OCDB
   
-  AliEMCALClusterizer *fClusterizer;         //! Offline clusterizer
   AliCDBManager       *fCDB;                 //! Pointer to OCDB
-  AliRawReaderMemory  *fMemReader;           //! Input raw data reader
-  
-  string               fGeometryFileName;    // Path to geometry file 
-  TFile               *fGeometryFile;        //! Pointer to the geom root file
-  TGeoManager         *fGeoManager;          //! Pointer to geometry manager 
+  string               fGeometryFileName;    // Path to geometry file - geom handled by the utils
   
   ClassDef(AliHLTEMCALClusterizerComponent, 1)
 };
index 851f2e0c645339878059d3da54338bce40dad5d2..bd5582ff1a486dcf47b6c28c97d8f5cbb37db608 100644 (file)
@@ -27,6 +27,8 @@ ClassImp(AliHLTEMCALDefinitions)
 
 const AliHLTComponentDataType AliHLTEMCALDefinitions::fgkDDLRawDataType = { sizeof(AliHLTComponentDataType), {'D','D','L','_','R','A','W',' '},{'E','M','C','L'}};;
 
+const AliHLTComponentDataType AliHLTEMCALDefinitions::fgkDigitDataType = { sizeof(AliHLTComponentDataType), {'D','I','G','I','T',' ',' ',' '},{'E','M','C','L'}};;
+
 const AliHLTComponentDataType AliHLTEMCALDefinitions::fgkClusterDataType = { sizeof(AliHLTComponentDataType), {'C','L','U','S','T','E','R','S'},{'E','M','C','L'}};;
 
 const AliHLTComponentDataType AliHLTEMCALDefinitions::fgkESDDataType = { sizeof(AliHLTComponentDataType), {'G','L','O','B','L','E','S','D'},{'E','M','C','L'}};;
index b6b6379b48d5a20d1bd6e713541174278717c415..d1776242d2b3c52872425ff426975f7d2b45d8e5 100644 (file)
@@ -26,6 +26,7 @@ public:
   virtual ~AliHLTEMCALDefinitions();
   
   static const AliHLTComponentDataType fgkDDLRawDataType; // Raw Data
+  static const AliHLTComponentDataType fgkDigitDataType; // EMCAL Digits
   static const AliHLTComponentDataType fgkClusterDataType; // EMCAL Clusters
   static const AliHLTComponentDataType fgkESDDataType; // global ESD data type - may change!!!
   static const AliHLTComponentDataType fgkEMCALESDDataType; // ESD data type after emcal processing
index 2c86e2964a2cfcba67c64c39b8d2a7caaa7e3974..5699cec9ac8cd333bc847b710d336cbc486233c0 100644 (file)
@@ -1,11 +1,10 @@
-// $Id: AliHLTEMCALTrackerComponent.cxx 23618 2008-01-29 13:07:38Z hristov $
-
 /**************************************************************************
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * This file is property of and copyright by the ALICE HLT Project        * 
+ * ALICE Experiment at CERN, All rights reserved.                         *
  *                                                                        *
- * Authors: Matthias Richter <Matthias.Richter@ift.uib.no>                *
- *          Timm Steinbeck <timm@kip.uni-heidelberg.de>                   *
- *          for The ALICE Off-line Project.                               *
+ * 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   *
  **************************************************************************/
 
 /** @file   AliHLTEMCALTrackerComponent.cxx
-    @author Timm Steinbeck, Matthias Richter
+    @author Mateusz Ploskon
     @date   
-    @brief  A EMCALTracker processing component for the HLT. */
+    @brief  EMCAL tracker component for HLT. */
 
-#if __GNUC__ >= 3
+#if __GNUC__== 3
 using namespace std;
 #endif
 
-#include "TFolder.h"
-#include "TFile.h"
-
 #include "AliHLTEMCALTrackerComponent.h"
 #include "AliHLTEMCALDefinitions.h"
+#include "AliHLTEMCALUtils.h"
+
+#include "TString.h"
+#include "TObjString.h"
+#include "TObjArray.h"
+#include "TTree.h"
+#include "AliCDBEntry.h"
 #include "AliCDBManager.h"
-#include "AliEMCALTracker.h"
-#include "AliEMCALReconstructor.h"
+#include "AliRawReaderMemory.h"
 #include "AliESDEvent.h"
-#include "AliMagFMaps.h"
-#include "AliESDfriend.h"
-
-#include <cstdlib>
-#include <cerrno>
-#include <string>
 
 // this is a global object used for automatic component registration, do not use this
 AliHLTEMCALTrackerComponent gAliHLTEMCALTrackerComponent;
 
-ClassImp(AliHLTEMCALTrackerComponent);
-    
+/** ROOT macro for the implementation of ROOT specific class methods */
+ClassImp(AliHLTEMCALTrackerComponent)
+
 AliHLTEMCALTrackerComponent::AliHLTEMCALTrackerComponent()
   : AliHLTProcessor()
-  , fOutputPercentage(100) // By default we copy to the output exactly what we got as input  
-  , fStrorageDBpath("local://$ALICE_ROOT")
+  , fOutputPercentage(100)
+  , fStorageDBpath("local://$ALICE_ROOT")
   , fCDB(NULL)
-  , fField(NULL)
   , fGeometryFileName("")
-  , fGeometryFile(NULL)
-  , fGeoManager(NULL)
-  , fTracker(NULL)
-  , fInputFolder(new TFolder("EMCALtrackerFolder", "EMCALtrackerFolder"))
 {
-  // Default constructor
-  fInputFolder->SetOwner(kTRUE);
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+}
 
-  fGeometryFileName = getenv("ALICE_ROOT");
-  fGeometryFileName += "/HLT/EMCAL/geometry.root";
+AliHLTEMCALTrackerComponent::AliHLTEMCALTrackerComponent(const AliHLTEMCALTrackerComponent &/*c*/)
+  : AliHLTProcessor()
+  , fOutputPercentage(100)
+  , fStorageDBpath("local://$ALICE_ROOT")
+  , fCDB(NULL)
+  , fGeometryFileName("")
+{
+  // may not use the copy contructor
+  HLTError("May not use.");
 }
 
-AliHLTEMCALTrackerComponent::~AliHLTEMCALTrackerComponent()
+AliHLTEMCALTrackerComponent& AliHLTEMCALTrackerComponent::operator=(const AliHLTEMCALTrackerComponent&)
 {
-  // Destructor
-  delete fInputFolder;
-  fInputFolder = NULL;
+  // may not use the copy contructor
+  HLTError("May not use.");
+  return *this;
 }
 
-const char* AliHLTEMCALTrackerComponent::GetComponentID()
+AliHLTEMCALTrackerComponent::~AliHLTEMCALTrackerComponent()
 {
-  // Return the component ID const char *
-  return "EMCALTracker"; // The ID of this component
+  // see header file for class documentation
 }
 
-void AliHLTEMCALTrackerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
+AliHLTComponentDataType AliHLTEMCALTrackerComponent::GetOutputDataType()
 {
-  // Get the list of input data  
-  list.clear(); // We do not have any requirements for our input data type(s).
-  list.push_back( AliHLTEMCALDefinitions::fgkClusterDataType );
+  //return AliHLTEMCALDefinitions::fgkClusterDataType | AliHLTEMCALDefinitions::fgkDigitDataType;
+  return AliHLTEMCALDefinitions::fgkClusterDataType;
 }
 
-AliHLTComponent_DataType AliHLTEMCALTrackerComponent::GetOutputDataType()
+const char* AliHLTEMCALTrackerComponent::GetComponentID()
+{ 
+  return "EMCALTracker";
+}
+
+void AliHLTEMCALTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) 
 {
-  // Get the output data type
-  return AliHLTEMCALDefinitions::fgkEMCALESDDataType;
+  list.push_back(kAliHLTAnyDataType);
 }
 
-void AliHLTEMCALTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
+void AliHLTEMCALTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) 
 {
-  // Get the output data size
   constBase = 0;
   inputMultiplier = ((double)fOutputPercentage)/100.0;
 }
 
-// Spawn function, return new instance of this class
-AliHLTComponent* AliHLTEMCALTrackerComponent::Spawn()
-{
-  // Spawn function, return new instance of this class
-  return new AliHLTEMCALTrackerComponent;
-};
-
 int AliHLTEMCALTrackerComponent::DoInit( 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::EMCALTracker::DoInit", "Arguments", "argv[%d] == %s", i, argv[i] );
-      if ( !strcmp( argv[i], "output_percentage" ) )
-       {
-         if ( i+1>=argc )
-           {
-             Logging(kHLTLogError, "HLT::EMCALTracker::DoInit", "Missing Argument", "Missing output_percentage parameter");
-             return ENOTSUP;
-           }
-         Logging( kHLTLogDebug, "HLT::EMCALTracker::DoInit", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
-         fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
-         if ( *cpErr )
-           {
-             Logging(kHLTLogError, "HLT::EMCALTracker::DoInit", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
-             return EINVAL;
-           }
-         Logging( kHLTLogInfo, "HLT::EMCALTracker::DoInit", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
-         i += 2;
-         continue;
-       }
+  // see header file for class documentation
+  int iResult=0;
+  HLTInfo("parsing %d arguments", argc);
 
-      if ( strcmp( argv[i], "-cdb" ) == 0)
-       {
-         if ( i+1 >= argc )
-           {
-             Logging(kHLTLogError, "HLT::EMCALTracker::DoInit", "Missing Argument", "Missing -cdb argument");
-             return ENOTSUP;         
-           }
-         fStrorageDBpath = argv[i+1];
-         Logging( kHLTLogInfo, "HLT::EMCALTracker::DoInit", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );     
-         i += 2;
-         continue;
-       }      
+  TString argument="";
+  TString configuration=""; 
+  int bMissingParam=0;
+  bool bHaveMandatory1=false;
+  bool bHaveMandatory2=false;
 
-      if ( strcmp( argv[i], "-geometry" ) == 0)
-       {
-         if ( i+1 >= argc )
-           {
-             Logging(kHLTLogError, "HLT::EMCALTracker::DoInit", "Missing Argument", "Missing -geometry argument");
-             return ENOTSUP;         
-           }
-         fGeometryFileName = argv[i+1];
-         Logging( kHLTLogInfo, "HLT::EMCALTracker::DoInit", "GeomFile storage set", "GeomFile storage is %s", 
-                  fGeometryFileName.c_str() );   
-         i += 2;
-         continue;
-       }      
-
-      Logging(kHLTLogError, "HLT::EMCALTracker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
-      return EINVAL;
-    }
+  char *cpErr = 0;
 
-  //init alifield map - temporarly fixed - should come from a DB
-  fField = new AliMagFMaps("Maps","Maps", 2, 1., 10., 1);
-  if (fField)
-    AliTracker::SetFieldMap(fField,1);
-  else
-    Logging(kHLTLogError, "HLT::EMCALTracker::DoInit", "Field", "Unable to init the field");
+  for (int i=0; i<argc && iResult>=0; i++) 
+    {
+      argument=argv[i];
+      if (argument.IsNull()) continue;
+
+    // -mandatory1
+    if (argument.CompareTo("-cdb")==0) 
+      {
+       bHaveMandatory1|=1;
+       if ((bMissingParam=(++i>=argc))) break;
+       HLTInfo("got \'-cdb\' argument: %s", argv[i]);
+       fStorageDBpath = argv[i];
+       HLTInfo("CDB path is: %s", fStorageDBpath.c_str());
+       // -mandatory2
+      } 
+    else if (argument.CompareTo("-geometry")==0) 
+      {
+       bHaveMandatory2|=1;
+       if ((bMissingParam=(++i>=argc))) break;
+       HLTInfo("got \'-geometry\' argument");
+       fGeometryFileName = argv[i];
+       HLTInfo("Geometry file is: %s", fGeometryFileName.c_str());
+       // -optional1
+      } 
+    else if (argument.CompareTo("-output_percentage")==0) 
+      {
+       if ((bMissingParam=(++i>=argc))) break;
+       HLTInfo("got \'-output_percentage\' argument: %s", argv[i]);
+       fOutputPercentage = strtoul(argv[i], &cpErr, 0);
+       if ( *cpErr )
+         {
+           HLTError("Unable to convert ouput_percentage to a number %s", argv[i]);
+           return -EINVAL;
+         }
+      } 
+    else 
+      {
+       // the remaining arguments are treated as configuration
+       if (!configuration.IsNull()) configuration+=" ";
+       configuration+=argument;
+      }
+    }
 
-  fCDB = AliCDBManager::Instance();
-  if (!fCDB)
+  if (bMissingParam) 
     {
-      Logging(kHLTLogError, "HLT::EMCALCalibration::DoInit", "Could not get CDB instance", "fCDB 0x%x", fCDB);
+      HLTError("missing parameter for argument %s", argument.Data());
+      iResult=-EINVAL;
     }
-  else
+
+  if (iResult>=0 && !bHaveMandatory1) 
     {
-      fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
-      fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
-      Logging(kHLTLogDebug, "HLT::EMCALCalibration::DoInit", "CDB instance", "fCDB 0x%x", fCDB);
+      HLTError("mandatory argument \'-cdb\' missing");
+      iResult=-EPROTO;
     }
-    
-  fGeometryFile = TFile::Open(fGeometryFileName.c_str());
-  if (fGeometryFile)
+
+  if (iResult>=0 && !bHaveMandatory2) 
     {
-      fGeoManager = (TGeoManager *)fGeometryFile->Get("Geometry");
-      fTracker = new AliEMCALTracker;
+      HLTError("mandatory argument \'-geometry\' missing");
+      iResult=-EPROTO;
     }
-  else
+  
+  if (iResult>=0 && !configuration.IsNull()) 
     {
-      Logging(kHLTLogError, "HLT::EMCALTracker::DoInit", "fGeometryFile", "Unable to open file. FATAL!");
-      return -1;
+      iResult=Configure(configuration.Data());
+    } 
+  else 
+    {
+      iResult=Reconfigure(NULL, NULL);
     }
+  
+  // Initialize here
+  // raw reader
 
-  return 0;
-}
+  // geometry
+  if (AliHLTEMCALUtils::GetGeometry() == NULL)
+    {
+      HLTError("unable to init geometry");
+      iResult=-EPROTO;      
+    }
 
-int AliHLTEMCALTrackerComponent::DoDeinit()
-{
-  // Deinitialization of the component
+  // OCDB
 
-  delete fField;
-  fField = 0;
+  // tracker and raw utils
+  if (AliHLTEMCALUtils::GetRawUtils() == NULL)
+    {
+      HLTError("unable to init rawutils");
+      iResult=-EPROTO;      
+    }
 
-  delete fTracker;
-  fTracker = 0;
-  
-  if (fGeometryFile)
+  if (AliHLTEMCALUtils::GetRawUtils() == NULL)
     {
-      fGeometryFile->Close();
-      delete fGeometryFile;
-      fGeometryFile = 0;
+      HLTError("unable to init rawutils");
+      iResult=-EPROTO;      
     }
 
-  fInputFolder->Clear();
+  if (AliHLTEMCALUtils::GetRecParam() == NULL)
+    {
+      HLTError("unable to init reco params");
+      iResult=-EPROTO;      
+    }      
+
+  return iResult;
+}
 
+int AliHLTEMCALTrackerComponent::DoDeinit()
+{
+  // see header file for class documentation
+  AliHLTEMCALUtils::Cleanup();
+  HLTInfo("processing cleanup");
   return 0;
 }
 
 int AliHLTEMCALTrackerComponent::DoEvent( const AliHLTComponentEventData & evtData,
                                        AliHLTComponentTriggerData & trigData )
 {
-  // Process an event
-  
-  Logging( kHLTLogInfo, "HLT::EMCALTracker::DoEvent", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
-  Logging( kHLTLogInfo, "HLT::EMCALTracker::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
+  //
+  // see header file for class documentation
+  //
 
-  AliHLTUInt32_t dBlockSpecification = 0;
+  // check if the input data are there at all - empty events possible
+  
+  HLTDebug("HLT::TRDTracker::DoEvent", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
 
   //implement a usage of the following
-//   AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
-//   AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
-//   void *triggerData = trigData.fData;
-  Logging( kHLTLogDebug, "HLT::EMCALTracker::DoEvent", "Trigger data received", 
-          "Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
-
-  AliHLTComponentBlockData *dblock = (AliHLTComponentBlockData *)GetFirstInputBlock( AliHLTEMCALDefinitions::fgkClusterDataType );
-  if (dblock != 0)
+  //   AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
+  //   AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
+  //   void *triggerData = trigData.fData;
+  HLTDebug("Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
+
+  //   another way to check the blocks
+  //   AliHLTComponentBlockData *dblock = (AliHLTComponentBlockData *)GetFirstInputBlock( AliHLTEMCALDefinitions::fgkClusterDataType );
+  //   if (dblock == 0)
+  //     {
+  //       HLTError(Form("First Input Block not found! 0x%x", dblock));
+  //       return -1;
+  //     }
+
+  // all those should be received by the component
+  AliESDEvent *esd = 0; // we assume we receive this one from a global merger component
+  TTree *clustersTree = 0;
+  TTree *digitsTree = 0;
+
+  Int_t ibForce = 0;
+  TObject  *tobjin = 0;
+  tobjin = (TObject *)GetFirstInputObject( AliHLTEMCALDefinitions::fgkClusterDataType, "TTree", ibForce);
+  if (tobjin)
     {
-      dBlockSpecification = dblock->fSpecification;
+      clustersTree = (TTree*)tobjin;
     }
-  else
+
+  tobjin = (TObject *)GetFirstInputObject( AliHLTEMCALDefinitions::fgkDigitDataType, "TTree", ibForce);
+  if (tobjin)
     {
-      Logging( kHLTLogWarning, "HLT::EMCALTracker::DoEvent", "DATAIN", "First Input Block not found! 0x%x", dblock);
-      return -1;
+      digitsTree = (TTree*)tobjin;
     }
 
-  fInputFolder->Clear();
-  AliESDEvent *esd = 0; // we assume we receive this one from a global merger component
-  TTree *clusterTree = 0;
-  
-  int ibForce = 0;
-  TObject *tobjin = 0;
+  // the data type used here is a prototype
+  // esd eventually should come from TPC alone or TPC+TRD matched tracks
+  // check the AliHLTEMCALDefinitions for extra comments
+  tobjin = (TObject *)GetFirstInputObject( AliHLTEMCALDefinitions::fgkESDDataType, "TTree", ibForce);
+  if (tobjin)
+    {
+      esd = (AliESDEvent*)tobjin;
+    }
 
-  // here getfirstinput finds the first object with spec type..
-  // get the clusters tree
-  tobjin = (TObject *)GetFirstInputObject( AliHLTEMCALDefinitions::fgkClusterDataType, "TTree", ibForce);
-  while (tobjin != 0)
+  if (digitsTree != 0 && clustersTree != 0 && esd != 0)
     {
-      tobjin = (TObject *)GetNextInputObject( ibForce );
-      Logging( kHLTLogInfo, "HLT::EMCALTracker::DoEvent", "nextBLOCK", "Pointer = 0x%x", tobjin);
-      clusterTree = (TTree*)tobjin;
-      if (clusterTree != 0)
+      Bool_t retValue = AliHLTEMCALUtils::FillESD(digitsTree, clustersTree, esd);
+      
+      if (retValue == kTRUE)
        {
-         Int_t iNentries = clusterTree->GetEntries();
-         Logging( kHLTLogInfo, "HLT::EMCALTracker::DoEvent", "COUNT", "N of tree entries = %d", iNentries);
-         fTracker->LoadClusters(clusterTree);
-         fInputFolder->Add(clusterTree);      
+         PushBack(esd, AliHLTEMCALDefinitions::fgkEMCALESDDataType);
+       }
+      else
+       {
+         HLTWarning("Fill ESD failed.");
        }
     }
+  
+  if (clustersTree)
+    delete clustersTree;
 
-  // now get the ESD(s) - should in principle be only one...
-  tobjin = (TObject *)GetFirstInputObject( AliHLTEMCALDefinitions::fgkESDDataType, "AliESDevent", ibForce);
-  while (tobjin != 0)
+  if (digitsTree)
+    delete digitsTree;
+  
+  if (esd)
+    delete esd;
+
+  return 0;
+}
+
+int AliHLTEMCALTrackerComponent::Configure(const char* arguments)
+{
+  // see header file for class documentation
+  int iResult=0;
+  if (!arguments) return iResult;
+  HLTInfo("parsing configuration string \'%s\'", arguments);
+
+  TString allArgs = arguments;
+  TString argument;
+  int bMissingParam=0;
+
+  TObjArray* pTokens = allArgs.Tokenize(" ");
+  if (pTokens) 
     {
-      esd = (AliESDEvent *)tobjin;
-      if (esd != 0)
+      for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) 
        {
-         HLTInfo("Got ESDevent");
-         fInputFolder->Add(esd);         
+         argument=((TObjString*)pTokens->At(i))->GetString();
+         if (argument.IsNull()) continue;
+         HLTInfo("processing argument %\n", argument.Data());
+         // -config1
+         if (argument.CompareTo("-cdb")==0) 
+           {
+             if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+             HLTInfo("got \'-cdb\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());         
+             // -config2
+           } 
+         else if (argument.CompareTo("-geometry")==0) 
+           {
+             if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+             HLTInfo("got \'-geometry\'");
+           } 
+         else if (argument.CompareTo("-output_percentage")==0) 
+           {
+             if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
+             HLTInfo("got \'-output_percentage\'");
+           } 
+         else 
+           {
+             HLTError("unknown argument %s", argument.Data());
+             iResult=-EINVAL;
+             break;
+           }
        }
-      tobjin = (TObject *)GetNextInputObject( ibForce );
-      Logging( kHLTLogInfo, "HLT::EMCALTracker::DoEvent", "nextBLOCK", "Pointer = 0x%x", tobjin);
-      clusterTree = (TTree*)tobjin;
+      delete pTokens;
     }
 
-  esd = (AliESDEvent*)fInputFolder->FindObject("AliESDevent");
-  if (esd != 0)
+  if (bMissingParam) 
     {
-      fTracker->PropagateBack(esd);
-      
-      //here transport the esd tracks further
-      Int_t nTracks = esd->GetNumberOfTracks();
-      HLTInfo("Number of tracks %d", nTracks);  
-      //esd->Print();
-      PushBack(esd, AliHLTEMCALDefinitions::fgkEMCALESDDataType);      
+      HLTError("missing parameter for argument %s", argument.Data());
+      iResult=-EINVAL;
+    }
+
+  return iResult;
+}
+
+int AliHLTEMCALTrackerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
+{
+  // see header file for class documentation
+  int iResult=0;
+  const char* path="HLT/ConfigEMCAL/EMCALTrackerComponent";
+  const char* defaultNotify="";
+  if (cdbEntry) 
+    {
+      path=cdbEntry;
+      defaultNotify=" (default)";
     }
-  else
+  if (path) 
     {
-      HLTError("No ESD events received!");
+      HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
+      AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,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("can not fetch object \"%s\" from CDB", path);
+       }
     }
+  return iResult;
+}
 
-  fTracker->UnloadClusters();  
-  fInputFolder->Clear();
-
-  HLTDebug("Event done.");
-  return 0;
+int AliHLTEMCALTrackerComponent::ReadPreprocessorValues(const char* modules)
+{
+  // see header file for class documentation
+  int iResult=0;
+  TString detectors(modules!=NULL?modules:"");
+  HLTInfo("read preprocessor values for detector(s): %s", detectors.IsNull()?"none":detectors.Data());
+  return iResult;
 }
index 31518c77704423e82f03349fb0b56011780cda03..a39f4f99e0b19d5b89b18fd7a922ca23351eea9f 100644 (file)
@@ -1,85 +1,74 @@
+//-*- Mode: C++ -*-
 #ifndef ALIHLTEMCALTRACKERCOMPONENT_H
 #define ALIHLTEMCALTRACKERCOMPONENT_H
-/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- * See cxx source for full Copyright notice                               */
+
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//* See cxx source for full Copyright notice                               */
 
 /** @file   AliHLTEMCALTrackerComponent.h
-    @author Mateusz Ploskon
+    @author Matthias Richter, Timm Steinbeck
     @date   
-    @brief  Declaration of a EMCALTracker component. */
-
+    @brief  A sample processing component for the HLT.
+*/
 
 #include "AliHLTProcessor.h"
-class TFolder;
-class TFile;
-class TGeoManager;
-
-class AliCDBManager;
-class AliMagFMaps;
-class AliEMCALTracker;
 
 /**
  * @class AliHLTEMCALTrackerComponent
- * @brief A EMCALTracker HLT processing component. 
- *
- * An implementiation of a EMCALTracker component that just copies its input data
- * as a test, demonstration, and example of the HLT component scheme.
- * @ingroup alihlt_tutorial
  */
-class AliHLTEMCALTrackerComponent : public AliHLTProcessor
-    {
-    public:
-       AliHLTEMCALTrackerComponent();
-       virtual ~AliHLTEMCALTrackerComponent();
-
-       // Public functions to implement AliHLTComponent's interface.
-       // These functions are required for the registration process
-
-       const char* GetComponentID();
-       void GetInputDataTypes( vector<AliHLTComponent_DataType>& list);
-       AliHLTComponent_DataType GetOutputDataType();
-       virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
-       AliHLTComponent* Spawn();
-       
-    protected:
-       
-       // Protected functions to implement AliHLTComponent's interface.
-       // These functions provide initialization as well as the actual processing
-       // capabilities of the component. 
-
-       int DoInit( int argc, const char** argv );
-       int DoDeinit();
-/*     int DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks,  */
-/*                  AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,  */
-/*                  AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks ); */
-       int DoEvent( const AliHLTComponentEventData & evtData,
-                    AliHLTComponentTriggerData & trigData );
-
-       using AliHLTProcessor::DoEvent;
-       
-    private:
-       /** copy constructor prohibited */
-       AliHLTEMCALTrackerComponent(const AliHLTEMCALTrackerComponent&);
-       /** assignment operator prohibited */
-       AliHLTEMCALTrackerComponent& operator=(const AliHLTEMCALTrackerComponent&);
 
-       // The size of the output data produced, as a percentage of the input data's size.
-       // Can be greater than 100 (%)
-       unsigned fOutputPercentage; // Output volume in percentage of the input
-
-       string fStrorageDBpath; // Default path for OCDB
-       AliCDBManager *fCDB; //! Pointer to OCDB
-
-       AliMagFMaps* fField; //! magn. field settings
-
-       string fGeometryFileName; // Path to geometry file 
-       TFile *fGeometryFile; //! // Pointer to the geom root file
-       TGeoManager *fGeoManager; //! Pointer to geometry manager 
-
-       AliEMCALTracker *fTracker;//! Offline emcal tracker
-
-       TFolder         *fInputFolder;//! input objects - convenient handling
-
-       ClassDef(AliHLTEMCALTrackerComponent, 0)
-    };
+class TFile;
+class TGeoManager;
+class AliEMCALTracker;
+class AliCDBManager;
+class AliRawReaderMemory;  
+
+class AliHLTEMCALTrackerComponent : public AliHLTProcessor {
+public:
+  AliHLTEMCALTrackerComponent();
+  AliHLTEMCALTrackerComponent(const AliHLTEMCALTrackerComponent& c);
+  virtual ~AliHLTEMCALTrackerComponent();
+
+  AliHLTEMCALTrackerComponent& operator=(const AliHLTEMCALTrackerComponent&);
+
+  // AliHLTComponent interface functions
+  const char* GetComponentID();
+  void GetInputDataTypes( vector<AliHLTComponentDataType>& list);
+  AliHLTComponentDataType GetOutputDataType();
+  virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier );
+
+  // Spawn function, return new class instance
+  AliHLTComponent* Spawn() {return new AliHLTEMCALTrackerComponent;};
+
+ protected:
+  // AliHLTComponent interface functions
+  int DoInit( int argc, const char** argv );
+  int DoDeinit();
+  int DoEvent( const AliHLTComponentEventData & evtData,
+              AliHLTComponentTriggerData & trigData );
+  int Reconfigure(const char* cdbEntry, const char* chainId);
+  int ReadPreprocessorValues(const char* modules);
+
+  using AliHLTProcessor::DoEvent;
+
+private:
+  /**
+   * Configure the component.
+   * Parse a string for the configuration arguments and set the component
+   * properties.
+   *
+   * This function illustrates the scanning of an argument string. The string
+   * was presumably fetched from the CDB.
+   */
+  int Configure(const char* arguments);
+
+  unsigned             fOutputPercentage;    // Output volume in percentage of the input  
+  string               fStorageDBpath;      // Default path for OCDB
+  
+  AliCDBManager       *fCDB;                 //! Pointer to OCDB
+  string               fGeometryFileName;    // Path to geometry file - geom handled by the utils
+  
+  ClassDef(AliHLTEMCALTrackerComponent, 1)
+};
 #endif
index 7e8c7ac1e5a205d5b797ec112e9f21999584c244..1e0390ee3efba3579b1bcffc3b9f4447a87ba88b 100644 (file)
@@ -1,23 +1,52 @@
 #include "AliHLTEMCALUtils.h"
 
 #include "TClass.h"
+#include "TFile.h"
+#include "TGeoManager.h"
+#include "TUnixSystem.h"
+#include "TTree.h"
+#include "TClonesArray.h"
+#include "TBranch.h"
+#include "TArrayS.h"
 
-#include "AliEMCALRecParam.h"
-#include "AliEMCALReconstructor.h"
 #include "AliCDBManager.h"
 #include "AliCDBEntry.h"
+#include "AliRawReaderMemory.h"
 
+#include "AliEMCALRecParam.h"
+#include "AliEMCALReconstructor.h"
 #include "AliEMCALGeometry.h"
 #include "AliEMCALClusterizerv1.h" 
 #include "AliEMCALRawUtils.h"      
 
+#include "AliESDCaloCells.h"
+#include "AliESDCaloCluster.h"
+#include "AliEMCALDigit.h"
+#include "AliESDEvent.h"
+#include "AliEMCALRecPoint.h"
+#include "AliEMCALPID.h"
+
+#include <fstream>
+#include <iostream>
+using namespace std;
+
 ClassImp(AliHLTEMCALUtils);
 
-AliEMCALGeometry*      AliHLTEMCALUtils::fgGeom        = NULL;
-AliEMCALClusterizerv1* AliHLTEMCALUtils::fgClusterizer = NULL;
-AliEMCALRecParam*      AliHLTEMCALUtils::fgRecParam    = NULL;
-AliEMCALRawUtils*      AliHLTEMCALUtils::fgRawUtils    = NULL;
+Int_t                  AliHLTEMCALUtils::fgDebug        = 0;
+AliEMCALGeometry*      AliHLTEMCALUtils::fgGeom         = NULL;
+AliEMCALClusterizerv1* AliHLTEMCALUtils::fgClusterizer  = NULL;
+AliEMCALRecParam*      AliHLTEMCALUtils::fgRecParam     = NULL;
+AliEMCALRawUtils*      AliHLTEMCALUtils::fgRawUtils     = NULL;
+TFile*                 AliHLTEMCALUtils::fgGeometryFile = NULL;
+TGeoManager*           AliHLTEMCALUtils::fgGeoManager   = NULL;
+
+TTree*                 AliHLTEMCALUtils::fgClustersTreeTmp = NULL;
+TTree*                 AliHLTEMCALUtils::fgDigitsTreeTmp   = NULL;  
+TClonesArray*          AliHLTEMCALUtils::fgDigitsArrTmp    = NULL;  
+TBranch*               AliHLTEMCALUtils::fgDigitsBranchTmp = NULL;  
+
 
+//____________________________________________________________________________
 AliHLTEMCALUtils::AliHLTEMCALUtils()
   : TObject()
 {
@@ -27,6 +56,7 @@ AliHLTEMCALUtils::AliHLTEMCALUtils()
   ;
 }
 
+//____________________________________________________________________________
 AliHLTEMCALUtils::~AliHLTEMCALUtils()
 {
   //
@@ -35,6 +65,35 @@ AliHLTEMCALUtils::~AliHLTEMCALUtils()
   ;
 }
 
+//____________________________________________________________________________
+void AliHLTEMCALUtils::Cleanup()
+{
+  DeleteStaticMembers();
+  DeleteReconstructionTrees();
+}
+
+//____________________________________________________________________________
+void AliHLTEMCALUtils::DeleteStaticMembers()
+{
+  if (fgRecParam != AliEMCALReconstructor::GetRecParam())
+    {
+      delete fgRecParam;
+      fgRecParam = NULL;
+    }
+
+  delete fgRawUtils;
+  fgRawUtils = NULL;
+
+  DeleteGeoManager();
+
+  delete fgGeom;
+  fgGeom = NULL;
+      
+  delete fgClusterizer;
+  fgClusterizer = NULL;
+}
+
+//____________________________________________________________________________
 AliHLTEMCALUtils::AliHLTEMCALUtils(const AliHLTEMCALUtils & /*t*/)  
   : TObject()
 {
@@ -44,6 +103,7 @@ AliHLTEMCALUtils::AliHLTEMCALUtils(const AliHLTEMCALUtils & /*t*/)
   AliFatal("May not use.");  
 }
   
+//____________________________________________________________________________
 AliHLTEMCALUtils& AliHLTEMCALUtils::operator = (const AliHLTEMCALUtils & /*t*/)  
 {
   //
@@ -53,6 +113,7 @@ AliHLTEMCALUtils& AliHLTEMCALUtils::operator = (const AliHLTEMCALUtils & /*t*/)
   return *this ; 
 }
 
+//____________________________________________________________________________
 void AliHLTEMCALUtils::InitRecParam()
 {
   //
@@ -86,25 +147,40 @@ void AliHLTEMCALUtils::InitRecParam()
   AliEMCALReconstructor::SetRecParam(fgRecParam);
 }
 
-const AliEMCALRecParam* AliHLTEMCALUtils::GetRecParam()
+//____________________________________________________________________________
+AliEMCALRecParam* AliHLTEMCALUtils::GetRecParam()
 {
   //
   // Init the parameters and reuse the Reconstructor
   //
+
   AliHLTEMCALUtils::InitRecParam();
   return fgRecParam;
 }
 
-const AliEMCALRawUtils*      AliHLTEMCALUtils::GetRawUtils()
+//____________________________________________________________________________
+AliEMCALRawUtils*      AliHLTEMCALUtils::GetRawUtils(AliEMCALGeometry *pGeometry)
 {
   //
   // Init EMCAL raw utils
+  // Use the geometry or try to figure out the default
+  // The OCDB must be initialized. 
+  // Otherwise the default contructor of the raw utils will complain.
   //
+
   if (fgRawUtils == NULL)
     {
       if (AliCDBManager::Instance()->IsDefaultStorageSet())
        {
-         fgRawUtils = new AliEMCALRawUtils;
+         if (pGeometry)
+           {
+             fgRawUtils = new AliEMCALRawUtils(pGeometry);
+           }
+         else
+           {
+             fgRawUtils = new AliEMCALRawUtils(AliHLTEMCALUtils::GetGeometry());
+           }
+
          AliInfoClass("Raw Utils initialized.");
        }
       else
@@ -116,25 +192,30 @@ const AliEMCALRawUtils*      AliHLTEMCALUtils::GetRawUtils()
   return fgRawUtils;
 }
 
-const AliEMCALClusterizerv1* AliHLTEMCALUtils::GetClusterizer()
+//____________________________________________________________________________
+AliEMCALClusterizerv1* AliHLTEMCALUtils::GetClusterizer()
 {
   //
   // Init EMCAL clusterizer
   //
+
   if (fgClusterizer == NULL)
     {
-      fgClusterizer = new AliEMCALClusterizerv1;
+      AliEMCALGeometry *geom = GetGeometry();
+      fgClusterizer = new AliEMCALClusterizerv1(geom);
       AliInfoClass("ClusterizerV1 initialized.");
    }
 
   return fgClusterizer;
 }
 
-const AliEMCALGeometry*      AliHLTEMCALUtils::GetGeometry()
+//____________________________________________________________________________
+AliEMCALGeometry*      AliHLTEMCALUtils::GetGeometry()
 {
   //
   // Init EMCAL geometry
   //
+
   if (fgGeom == NULL)
     {
       AliInfoClass(Form("Using default geometry"));
@@ -142,3 +223,620 @@ const AliEMCALGeometry*      AliHLTEMCALUtils::GetGeometry()
     }
   return fgGeom;
 }
+
+//____________________________________________________________________________
+void AliHLTEMCALUtils::DeleteGeoManager()
+{
+  //
+  // Delete the geom manager and the geom TFile
+  //
+
+  if (fgGeometryFile)
+    {
+      fgGeometryFile->Close();
+      delete fgGeometryFile;
+      fgGeometryFile = NULL;      
+    }
+  
+  if (fgGeoManager)
+    {
+      delete fgGeoManager;
+      fgGeoManager = NULL;
+    }
+}
+
+//____________________________________________________________________________
+Bool_t AliHLTEMCALUtils::LoadGeoManagerFromFile(const char *fname)
+{
+  //
+  // Open the geom file and get the geom manager
+  //
+
+  Bool_t bReturn = kFALSE;
+
+  DeleteGeoManager();
+
+  fgGeometryFile = TFile::Open(fname);
+  if (fgGeometryFile)
+    {
+      fgGeoManager = (TGeoManager *)fgGeometryFile->Get("Geometry");
+    }
+
+  if (!fgGeoManager)
+    {
+      DeleteGeoManager();
+      AliErrorClass(Form("Unable to retrieve TGeoManager <Geometry> from %s", fname));
+    }
+
+  bReturn = kTRUE;
+
+  return bReturn;
+}
+
+//____________________________________________________________________________
+Bool_t AliHLTEMCALUtils::InitFakeCDB(const char *cdbpath, Int_t runid)
+{
+  //
+  // Init fake OCDB - use with care.
+  // For dummy usage only!
+  // Make sure there is no conflict with the existing ocdb instance.
+  //
+
+  Bool_t bReturn = kFALSE;
+
+  TString sPath = cdbpath;
+
+  if (sPath.Length() <= 0)
+    {
+      sPath  = "local://";
+      sPath += gSystem->Getenv("ALICE_ROOT");
+      AliInfoClass(Form("Setting cdbpath to %s", sPath.Data()));
+    }
+
+  AliCDBManager* pCDB = AliCDBManager::Instance();
+  if (!pCDB)
+    {
+      AliErrorClass("Unable to get the CDBManager instance.");      
+    }
+  else
+    {
+      pCDB->SetRun(runid); // THIS HAS TO BE RETRIEVED !!!
+      pCDB->SetDefaultStorage(sPath.Data());
+      AliInfoClass(Form("Fake CDB initialized with path %s", sPath.Data()));
+      bReturn = kTRUE;
+    }
+  
+  return bReturn;
+}
+
+//____________________________________________________________________________
+Bool_t AliHLTEMCALUtils::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree, Option_t* sOption)
+{
+  // This method is a reusage the corresponding one of AliEMCALReconstructor
+  // Conversion from raw data to EMCAL digits.
+  // Works on a single-event basis
+
+  // Make sure raw utils are initialized (they depend on geometry and OCDB) !
+
+  // We Assume the rawReader, digitsTree and sOption are valid!
+
+  // Here we assume the raw reader is setup properly, so we do not need extra reset!
+  // rawReader->Reset() ; 
+
+  Bool_t bReturn = kFALSE;
+  if (!fgRawUtils)
+    {
+      // Try to initialize - this is potentially dangerous
+      // We will use default geometry - most probably
+      // The OCDB must exist! otherwise we will fail.
+
+      if (GetRawUtils() == NULL)
+       {
+         // This is no go.
+         AliErrorClass("Failed. No RawUtils.");
+         return bReturn;
+       }
+    }
+
+  if (!fgRecParam)
+    {
+      // Again we try to init the RecParams to default
+      // One should better do it properly before!
+      // The ocdb has to be there! for the recparams init
+      
+      if (GetRecParam() == NULL)
+       {
+         // This is no go.
+         AliErrorClass("Failed. No RecParams.");
+         return bReturn;
+       }      
+    }
+
+  TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",200);
+  Int_t bufsize = 32000;
+  digitsTree->Branch("EMCAL", &digitsArr, bufsize);
+
+  fgRawUtils->SetOption(sOption);
+
+  fgRawUtils->SetRawFormatHighLowGainFactor(fgRecParam->GetHighLowGainFactor());
+  fgRawUtils->SetRawFormatOrder(fgRecParam->GetOrderParameter());
+  fgRawUtils->SetRawFormatTau(fgRecParam->GetTau());
+  fgRawUtils->SetNoiseThreshold(fgRecParam->GetNoiseThreshold());
+  fgRawUtils->SetNPedSamples(fgRecParam->GetNPedSamples());
+
+  fgRawUtils->Raw2Digits(rawReader,digitsArr);
+
+  digitsTree->Fill();
+  digitsArr->Delete();
+  delete digitsArr;
+
+  bReturn = kTRUE;
+  return bReturn;
+}
+
+//____________________________________________________________________________
+TTree *AliHLTEMCALUtils::GetDigitsTree()
+{
+  // 
+  // Create the digits tree and the digits arrays
+  // 
+
+  if (fgDigitsTreeTmp == NULL)
+    {
+      fgDigitsTreeTmp = new TTree("EMCALdigits", "EMCAL digits default");      
+    }
+
+  if (fgDigitsArrTmp == NULL)
+    {
+      fgDigitsArrTmp = new TClonesArray("AliEMCALDigit",200);
+    }
+  
+  if (fgDigitsBranchTmp == NULL)
+    {
+      Int_t bufsize = 32000;
+      fgDigitsBranchTmp = fgDigitsTreeTmp->Branch("EMCAL", &fgDigitsArrTmp, bufsize);  
+    }
+
+  fgDigitsBranchTmp->SetAddress(&fgDigitsArrTmp);
+
+  return fgDigitsTreeTmp;
+}
+
+//____________________________________________________________________________
+TTree *AliHLTEMCALUtils::GetClustersTree()
+{
+  // 
+  // Create the clusters tree if necessary
+  // 
+  
+  if (fgClustersTreeTmp == NULL)
+    {
+      fgClustersTreeTmp = new TTree("EMCALclusters", "EMCAL clusters");
+    }
+  
+  return fgClustersTreeTmp;
+}
+
+//____________________________________________________________________________
+void AliHLTEMCALUtils::ResetReconstructionTrees()
+{
+  // 
+  // Reset the content of the reconstruction trees (digits and clusters)
+  //
+
+  TTree *tmp = 0;
+  tmp = GetDigitsTree();
+  if (tmp)
+    {
+      fgDigitsArrTmp->Delete();
+      tmp->Reset();
+    }
+
+  tmp = GetClustersTree();
+  if (tmp)
+    {
+      tmp->Reset();
+    }
+}
+
+//____________________________________________________________________________
+void AliHLTEMCALUtils::DeleteReconstructionTrees()
+{
+  // 
+  // Delete the reconstruction trees (digits and clusters)
+  //
+
+  TTree *tmp = 0;
+  tmp = GetDigitsTree();
+  if (tmp)
+    {
+      fgDigitsArrTmp->Delete();
+      delete fgClustersTreeTmp;
+      fgClustersTreeTmp = NULL;
+    }
+
+  tmp = GetClustersTree();
+  if (tmp)
+    {
+      delete fgDigitsTreeTmp;
+      fgDigitsTreeTmp = 0;
+    }
+}
+
+//____________________________________________________________________________
+Bool_t AliHLTEMCALUtils::Raw2Clusters(AliRawReader* rawReader, TTree* clustersTree, Option_t* sDigitsOption)
+{
+  //
+  // Here we go from raw to clusters (not realeasing digits on the way)
+  // This method combines ConvertDigits and Reconstruct of AliEMCALReconstructor
+  //
+  
+  // Here we assume the raw reader is setup properly, so we do not need extra reset!
+  // rawReader->Reset() ; 
+
+  Bool_t bReturn = kFALSE;
+  if (!fgRawUtils)
+    {
+      // Try to initialize - this is potentially dangerous
+      // We will use default geometry - most probably
+      // The OCDB must exist! otherwise we will fail.
+
+      if (GetRawUtils() == NULL)
+       {
+         // This is no go.
+         AliErrorClass("Failed. No RawUtils.");
+         return bReturn;
+       }
+    }
+
+  if (!fgRecParam)
+    {
+      // Again we try to init the RecParams to default
+      // One should better do it properly before!
+      // The ocdb has to be there! for the recparams init
+      
+      if (GetRecParam() == NULL)
+       {
+         // This is no go.
+         AliErrorClass("Failed. No RecParams.");
+         return bReturn;
+       }      
+    }
+
+  if (GetDigitsTree() == NULL)
+    {
+      // This is no go.
+      AliErrorClass("Failed. No Digits Tree.");
+      return bReturn;    
+    }
+  
+  if (GetClusterizer() == NULL)
+    {
+      // This is no go.
+      AliErrorClass("Failed. No clusterizer.");
+      return bReturn;    
+    }
+
+  // raw->digits
+  fgRawUtils->SetOption(sDigitsOption);
+  fgRawUtils->SetRawFormatHighLowGainFactor(fgRecParam->GetHighLowGainFactor());
+  fgRawUtils->SetRawFormatOrder(fgRecParam->GetOrderParameter());
+  fgRawUtils->SetRawFormatTau(fgRecParam->GetTau());
+  fgRawUtils->SetNoiseThreshold(fgRecParam->GetNoiseThreshold());
+  fgRawUtils->SetNPedSamples(fgRecParam->GetNPedSamples());
+
+  fgDigitsArrTmp->Delete();
+  fgRawUtils->Raw2Digits(rawReader, fgDigitsArrTmp);
+  fgDigitsTreeTmp->Fill();
+
+  // digits->clusters
+  fgClusterizer->SetOutput(clustersTree);
+
+  if (fgDigitsArrTmp->GetEntries() > 0) 
+    {
+      fgClusterizer->SetInput(fgDigitsTreeTmp);      
+
+      if (fgDebug > 0)
+       {
+         fgClusterizer->Digits2Clusters("deb all") ;
+       }
+      else
+       {
+         fgClusterizer->Digits2Clusters("");
+       }
+
+      fgClusterizer->Clear();      
+    }
+
+  bReturn = kTRUE;
+  return bReturn;  
+}
+
+//____________________________________________________________________________
+Bool_t AliHLTEMCALUtils::RawBuffer2Clusters(UChar_t *buffer, ULong_t buffSize, 
+                                           Int_t eqID, 
+                                           TTree* clustersTree, Option_t* sDigitsOption)
+{
+  //
+  // Method provided for convenience
+  // Take the raw (DDL) mem buffer and put the clusters into the tree
+  //
+
+  Bool_t bReturn = kFALSE;
+
+  AliRawReaderMemory rawReader;
+  rawReader.Reset();
+  rawReader.SetEquipmentID(eqID);
+  rawReader.SetMemory(buffer, buffSize);
+
+  bReturn = AliHLTEMCALUtils::Raw2Clusters(&rawReader, clustersTree, sDigitsOption);
+
+  return bReturn;  
+}
+
+//____________________________________________________________________________
+TTree* AliHLTEMCALUtils::RawBuffer2Clusters(UChar_t *buffer, ULong_t buffSize, 
+                                           Int_t eqID, 
+                                           Option_t* sDigitsOption)
+{
+  //
+  // Method provided for convenience
+  // Take the raw (DDL) mem buffer and put the clusters into the tree
+  //
+
+  Bool_t bReturn = kFALSE;
+
+  AliRawReaderMemory rawReader;
+  rawReader.Reset();
+  rawReader.SetMemory(buffer, buffSize);
+  rawReader.SetEquipmentID(eqID);
+
+  TTree *clustersTree = GetClustersTree();
+
+  bReturn = AliHLTEMCALUtils::Raw2Clusters(&rawReader, clustersTree, sDigitsOption);
+  if (bReturn == kFALSE)
+    {
+      clustersTree->Delete();
+      delete clustersTree;
+      clustersTree = 0;
+    }
+
+  return clustersTree;  
+}
+
+//____________________________________________________________________________
+UChar_t *AliHLTEMCALUtils::FileToMemory(const char *fname, UChar_t *outpbuffer, ULong_t &buffSize)
+{
+  //
+  // Method provided for convenience
+  // Take the raw (DDL) file and copy it to a mem buffer
+  //
+
+  buffSize = 0;
+  outpbuffer = NULL;
+  
+  ifstream inputFile(fname, ifstream::in);
+  if (!inputFile.good())
+    {
+      AliErrorClass(Form("Unable to open file", fname));
+      return outpbuffer;
+    }
+
+  inputFile.seekg (0, ios::end);
+  buffSize = inputFile.tellg();
+  inputFile.seekg (0, ios::beg);
+
+  void *buff = calloc(buffSize, sizeof(char));  
+
+  if (!buff)
+    {
+      AliErrorClass(Form("Unable to allocate memory: %d bytes", buffSize)); 
+      return outpbuffer;      
+    }
+
+  inputFile.read((char*)buff, buffSize);
+  outpbuffer = (UChar_t*)buff;
+
+  AliInfoClass(Form("File read: %s. Allocated %d bytes at 0x%x", fname, buffSize, outpbuffer)); 
+  return outpbuffer;
+}
+
+//____________________________________________________________________________
+Bool_t AliHLTEMCALUtils::FillESD(TTree* digitsTree, TTree* clustersTree, AliESDEvent* esd)
+{
+  //
+  // Fill the ESD just like the AliEMCALReconstructor
+  //
+  // This is offline code taken directly from the AliEMCALReconstructor
+  // Factorization of the function in the AliEMCALReconstructor should allow calling the code directly
+
+  // Trigger part on raw data has been removed.
+
+  //########################################
+  //##############Fill CaloCells############
+  //########################################
+
+  if (digitsTree == 0)
+    {
+      AliErrorClass("Digits tree is NULL!");
+      return kFALSE;
+    }
+
+  if (clustersTree == 0)
+    {
+      AliErrorClass("Clusters tree is NULL!");
+      return kFALSE;
+    }
+
+  if (esd == 0)
+    {
+      AliErrorClass("Pointer to ESD not set!");
+      return kFALSE;
+    }
+
+  TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
+  TBranch *branchdig = digitsTree->GetBranch("EMCAL");
+  if (!branchdig) 
+    { 
+      AliErrorClass("Can't get the branch with the PHOS digits !");
+      return kFALSE;
+    }
+
+  branchdig->SetAddress(&digits);
+  digitsTree->GetEvent(0);
+  Int_t nDigits = digits->GetEntries(), idignew = 0 ;
+
+  AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
+  emcCells.CreateContainer(nDigits);
+  emcCells.SetType(AliESDCaloCells::kEMCALCell);
+  for (Int_t idig = 0 ; idig < nDigits ; idig++) 
+    {
+      const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
+      if(dig->GetAmp() > 0 )
+       {
+         emcCells.SetCell(idignew,dig->GetId(),dig->GetAmp(), dig->GetTime());   
+         idignew++;
+       }
+    }
+  emcCells.SetNumberOfCells(idignew);
+  emcCells.Sort();
+  
+  //------------------------------------------------------------
+  //-----------------CLUSTERS-----------------------------
+  //------------------------------------------------------------
+
+  TObjArray *clusters = new TObjArray(100);
+  TBranch *branch = clustersTree->GetBranch("EMCALECARP");
+  branch->SetAddress(&clusters);
+  clustersTree->GetEvent(0);
+
+  Int_t nClusters = clusters->GetEntries(),  nClustersNew=0;
+
+  esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters 
+
+  //######################################################
+  //#######################TRACK MATCHING###############
+  //######################################################
+  //Fill list of integers, each one is index of track to which the cluster belongs.
+
+  // step 1 - initialize array of matched track indexes
+  Int_t *matchedTrack = new Int_t[nClusters];
+  for (Int_t iclus = 0; iclus < nClusters; iclus++)
+    matchedTrack[iclus] = -1;  // neg. index --> no matched track
+  
+  // step 2, change the flag for all matched clusters found in tracks
+  Int_t iemcalMatch = -1;
+  Int_t endtpc = esd->GetNumberOfTracks();
+  for (Int_t itrack = 0; itrack < endtpc; itrack++) 
+    {
+      AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
+      iemcalMatch = track->GetEMCALcluster();
+      if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
+    } 
+  
+  //########################################
+  //##############Fill CaloClusters#############
+  //########################################
+  esd->SetNumberOfEMCALClusters(nClusters);
+  for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) 
+    {
+      const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
+      //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
+
+      // Get information from EMCAL reconstruction points
+      Float_t xyz[3];
+      TVector3 gpos;
+      clust->GetGlobalPosition(gpos);
+      for (Int_t ixyz=0; ixyz<3; ixyz++)
+       xyz[ixyz] = gpos[ixyz];
+      Float_t elipAxis[2];
+      clust->GetElipsAxis(elipAxis);
+      //Create digits lists
+      Int_t cellMult = clust->GetMultiplicity();
+      //TArrayS digiList(digitMult);
+      Float_t *amplFloat = clust->GetEnergiesList();
+      Int_t   *digitInts = clust->GetAbsId();
+      TArrayS absIdList(cellMult);
+      //Uncomment when unfolding is done
+      //TArrayD fracList(cellMult);
+      
+      Int_t newCellMult = 0;
+      for (Int_t iCell=0; iCell<cellMult; iCell++) 
+       {
+         if (amplFloat[iCell] > 0) {
+           absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
+           //Uncomment when unfolding is done
+           //fracList[newCellMult] = amplFloat[iCell]/emcCells.GetCellAmplitude(digitInts[iCell]);
+           newCellMult++;
+         }
+       }
+
+      absIdList.Set(newCellMult);
+      //Uncomment when unfolding is done
+      //fracList.Set(newCellMult);
+
+      if(newCellMult > 0) { // accept cluster if it has some digit
+       nClustersNew++;
+       //Primaries
+       Int_t  parentMult  = 0;
+       Int_t *parentList =  clust->GetParents(parentMult);
+       // fills the ESDCaloCluster
+       AliESDCaloCluster * ec = new AliESDCaloCluster() ;
+       ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
+       ec->SetPosition(xyz);
+       ec->SetE(clust->GetEnergy());
+       ec->SetNCells(newCellMult);
+       //Change type of list from short to ushort
+       UShort_t *newAbsIdList  = new UShort_t[newCellMult];
+       //Uncomment when unfolding is done
+       //Double_t *newFracList  = new Double_t[newCellMult];
+       for(Int_t i = 0; i < newCellMult ; i++) 
+         {
+           newAbsIdList[i]=absIdList[i];
+           //Uncomment when unfolding is done
+           //newFracList[i]=fracList[i];
+         }
+       
+       ec->SetCellsAbsId(newAbsIdList);
+       //Uncomment when unfolding is done
+       //ec->SetCellsAmplitudeFraction(newFracList);
+       ec->SetClusterDisp(clust->GetDispersion());
+       ec->SetClusterChi2(-1); //not yet implemented
+       ec->SetM02(elipAxis[0]*elipAxis[0]) ;
+       ec->SetM20(elipAxis[1]*elipAxis[1]) ;
+       ec->SetTOF(clust->GetTime()) ; //time-of-fligh
+       ec->SetNExMax(clust->GetNExMax());          //number of local maxima
+       TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
+       arrayTrackMatched[0]= matchedTrack[iClust];
+       ec->AddTracksMatched(arrayTrackMatched);
+       
+       TArrayI arrayParents(parentMult,parentList);
+       ec->AddLabels(arrayParents);
+       
+       // add the cluster to the esd object
+       esd->AddCaloCluster(ec);
+       delete ec;
+       delete [] newAbsIdList ;
+       //delete [] newFracList ;
+      }
+    } // cycle on clusters
+  
+  delete [] matchedTrack;
+  
+  esd->SetNumberOfEMCALClusters(nClustersNew);
+  //if(nClustersNew != nClusters)
+  //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
+  
+  //Fill ESDCaloCluster with PID weights
+  AliEMCALPID *pid = new AliEMCALPID;
+  //pid->SetPrintInfo(kTRUE);
+  pid->SetReconstructor(kTRUE);
+  pid->RunPID(esd);
+  delete pid;
+
+  delete digits;
+  delete clusters;
+
+  // printf(" ## AliEMCALReconstructor::FillESD() is ended : ncl %i -> %i ### \n ",nClusters, nClustersNew); 
+  return kTRUE;
+}
index e1934792915b477cb3ec226859260d28941871d0..e2da4c2e59bd1794b7c5767cbeb262a5f2abbca9 100644 (file)
@@ -21,6 +21,15 @@ class AliEMCALGeometry;
 class AliEMCALClusterizerv1;
 class AliEMCALRecParam;    
 class AliEMCALRawUtils;
+class AliRawReader;
+class AliESDEvent;
+
+class TString;
+class TFile;
+class TGeoManager;
+class TTree;
+class TClonesArray;
+class TBranch;
 
 class AliHLTEMCALUtils : public TObject
 {
@@ -30,20 +39,62 @@ class AliHLTEMCALUtils : public TObject
   AliHLTEMCALUtils & operator = (const AliHLTEMCALUtils & /*t*/);
   virtual ~AliHLTEMCALUtils();
 
-  static void                         InitRecParam();
-  static const AliEMCALRecParam*      GetRecParam();
+  static void                   SetDebug(Int_t idbg) {fgDebug = idbg;}
+
+  static void                   DeleteStaticMembers();
+  static void                   Cleanup();
+  
+  static void                   InitRecParam();
+  static AliEMCALRecParam*      GetRecParam();
+
+  static AliEMCALRawUtils*      GetRawUtils(AliEMCALGeometry *pGeometry = 0);
+  static AliEMCALClusterizerv1* GetClusterizer();
+  static AliEMCALGeometry*      GetGeometry();
+
+  static void                   DeleteGeoManager();
+  static Bool_t                 LoadGeoManagerFromFile(const char *fname);
+  static TGeoManager*           GetGeoManager() {return fgGeoManager;}
+
+  static Bool_t                 InitFakeCDB(const char *cdbpath = "", Int_t runid = 0);
+  static Bool_t                 ConvertDigits(AliRawReader* rawReader, TTree* digitsTree, Option_t* sOption);
+  static Bool_t                 Raw2Clusters(AliRawReader* rawReader, TTree* clustersTree, Option_t* sDigitsOption);
+  static Bool_t                 RawBuffer2Clusters(UChar_t *buffer, ULong_t buffSize, 
+                                                  Int_t eqID, 
+                                                  TTree* clustersTree, Option_t* sDigitsOption);
+  static TTree*                 RawBuffer2Clusters(UChar_t *buffer, ULong_t buffSize, 
+                                                  Int_t eqID, 
+                                                  Option_t* sDigitsOption);
 
-  static const AliEMCALRawUtils*      GetRawUtils();
-  static const AliEMCALClusterizerv1* GetClusterizer();
-  static const AliEMCALGeometry*      GetGeometry();
+  static TTree*                 GetDigitsTree();
+  static TTree*                 GetClustersTree();
 
+  static UChar_t *              FileToMemory(const char *fname, UChar_t *outpbuffer, ULong_t &buffSize);
+
+  static void                   ResetReconstructionTrees();
+  static void                   DeleteReconstructionTrees();
+
+  static Bool_t                 FillESD(TTree* digitsTree, TTree* clustersTree, AliESDEvent* esd);
+    
  protected:
+
  private:
+  
+  static Int_t                  fgDebug; // debug flag
 
   static AliEMCALGeometry*      fgGeom;        // EMCAL geometry
   static AliEMCALClusterizerv1* fgClusterizer; // ECMAL clusterizer
   static AliEMCALRecParam*      fgRecParam;    // EMCAL reconstruction parameters
   static AliEMCALRawUtils*      fgRawUtils;    // EMCAL raw utilities 
+  
+  static TFile*                 fgGeometryFile; //! // Pointer to the geom root file
+  static TGeoManager*           fgGeoManager; //! Pointer to geometry manager 
+
+  static TTree*                 fgClustersTreeTmp; //! Clusters tree - depending on the reco scheme 
+                                                   //  use ResetReconstructionTrees
+  static TTree*                 fgDigitsTreeTmp;   //! Digits tree  - reset on each Raw2Clusters call
+  static TClonesArray*          fgDigitsArrTmp;    //! Digits array - reset on each Raw2Clusters call
+  static TBranch*               fgDigitsBranchTmp; //! Digits branch - reset on each Raw2Clusters call
+
   ClassDef(AliHLTEMCALUtils, 0)
 };