]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
cashing of EMCALMapper instances to avoid unnecessary allocations; removing global...
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 1 Jul 2012 10:44:35 +0000 (10:44 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 1 Jul 2012 10:44:35 +0000 (10:44 +0000)
HLT/EMCAL/AliHLTEMCALAgent.cxx
HLT/EMCAL/AliHLTEMCALAgent.h
HLT/EMCAL/AliHLTEMCALClusterizerComponent.cxx
HLT/EMCAL/AliHLTEMCALClusterizerComponentNbyN.cxx
HLT/EMCAL/AliHLTEMCALRawAnalyzerCrudeComponent.cxx
HLT/EMCAL/AliHLTEMCALRawAnalyzerFastFitComponent.cxx
HLT/EMCAL/AliHLTEMCALRawAnalyzerLMSComponent.cxx
HLT/EMCAL/AliHLTEMCALRawAnalyzerNNComponent.cxx
HLT/EMCAL/AliHLTEMCALRawAnalyzerPeakFinderComponent.cxx

index 729c535a3d4c6fe3cf893ac6e41a2f8b0b910288..fc9adf2a8b4692238adadc195d8ac91bf0d50f52 100644 (file)
@@ -26,6 +26,7 @@
 #include "AliHLTEMCALDefinitions.h"
 #include "AliHLTOUT.h"
 #include "AliHLTOUTHandlerChain.h"
+#include "AliHLTErrorGuard.h"
 #include "AliRunLoader.h"
 #include "AliCDBManager.h"
 #include "AliCDBEntry.h"
@@ -52,12 +53,17 @@ AliHLTEMCALAgent gAliHLTEMCALAgent;
 #include "AliHLTEMCALRawAnalyzerPeakFinderComponent.h"
 //#include "AliHLTEMCALRcuCalibrationProcessorComponent.h"
 //#include "AliHLTEMCALRcuDAComponent.h"
+#include "AliHLTEMCALRawAnalyzerLMSComponent.h"
+#include "AliHLTEMCALRawAnalyzerFastFitComponent.h"
+#include "AliHLTEMCALRawAnalyzerNNComponent.h"
+#include "AliHLTEMCALClusterizerComponentNbyN.h"
 
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTEMCALAgent)
 
-AliHLTEMCALAgent::AliHLTEMCALAgent() : AliHLTModuleAgent("EMCAL"),
-fRawDataHandler(NULL)
+AliHLTEMCALAgent::AliHLTEMCALAgent() : AliHLTModuleAgent("EMCAL")
+  , fRawDataHandler(NULL)
+  , fMappers()
 {
     // see header file for class documentation
     // or
@@ -193,8 +199,13 @@ int AliHLTEMCALAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
     if (!pHandler) return -EINVAL;
     
     pHandler->AddComponent(new AliHLTEMCALRawAnalyzerCrudeComponent);
+    pHandler->AddComponent(new AliHLTEMCALRawAnalyzerLMSComponent);
+    pHandler->AddComponent(new AliHLTEMCALRawAnalyzerPeakFinderComponent);
+    pHandler->AddComponent(new AliHLTEMCALRawAnalyzerFastFitComponent);
+    pHandler->AddComponent(new AliHLTEMCALRawAnalyzerNNComponent);
     pHandler->AddComponent(new AliHLTEMCALDigitMakerComponent);
     pHandler->AddComponent(new AliHLTEMCALClusterizerComponent);
+    pHandler->AddComponent(new AliHLTEMCALClusterizerComponentNbyN);
     //pHandler->AddComponent(new AliHLTCaloClusterAnalyserComponent);                   
     //pHandler->AddComponent(new AliHLTEMCALESDEntriesMakerComponent);
     
@@ -208,19 +219,21 @@ int AliHLTEMCALAgent::GetHandlerDescription(AliHLTComponentDataType dt,
 {
     // see header file for class documentation
 
-    // FIXME: there is memory allocated in the mapper, this happens for every event
-    // and is time consuming, think about initializing the mappers only once, or make
-    // the mapper class more flexible to handle more than one specification
-    AliHLTEMCALMapper mapper(spec);
-    
     // raw data blocks to be fed into offline reconstruction
     if (dt==(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginEMCAL)) 
     {
-        if(mapper.GetDDLFromSpec(spec) >= 0)
+        AliHLTEMCALMapper* pMapper=GetMapper(spec);
+    
+        if(pMapper && pMapper->GetDDLFromSpec(spec) >= 0)
         {
             desc=AliHLTOUTHandlerDesc(kRawReader, dt, GetModuleId());
             return 1;
         } 
+       else if (pMapper==NULL)
+        {
+           ALIHLTERRORGUARD(5, "failed to create EMCAL mapper");
+            return 0;
+        }
         else 
         {
             HLTWarning("Handler can not process data inconsistent with a single EMCAL DDL from specification % d", spec);
@@ -240,7 +253,7 @@ AliHLTOUTHandler* AliHLTEMCALAgent::GetOutputHandler(AliHLTComponentDataType dt,
     {
         if (!fRawDataHandler) 
         {
-            fRawDataHandler = new AliHLTEMCALAgent::AliHLTEMCALRawDataHandler;
+            fRawDataHandler = new AliHLTEMCALAgent::AliHLTEMCALRawDataHandler(this);
         }
         return fRawDataHandler;
     }
@@ -260,7 +273,8 @@ int AliHLTEMCALAgent::DeleteOutputHandler(AliHLTOUTHandler* pInstance)
     return 0;
 }
 
-AliHLTEMCALAgent::AliHLTEMCALRawDataHandler::AliHLTEMCALRawDataHandler()
+AliHLTEMCALAgent::AliHLTEMCALRawDataHandler::AliHLTEMCALRawDataHandler(AliHLTEMCALAgent* pAgent)
+  : fpAgent(pAgent)
 {
     // see header file for class documentation
 }
@@ -278,14 +292,17 @@ int AliHLTEMCALAgent::AliHLTEMCALRawDataHandler::ProcessData(AliHLTOUT* pData)
     AliHLTComponentDataType dt = kAliHLTVoidDataType;
     AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
     
-    AliHLTEMCALMapper mapper(spec);
-    mapper.InitDDLSpecificationMapping();
+    AliHLTEMCALMapper* pMapper=fpAgent?fpAgent->GetMapper(spec):NULL;
+    if (!pMapper) {
+      ALIHLTERRORGUARD(5, "%s", fpAgent?"can not retrieve EMCAL mapper from agent":"agent not available to retrieve EMCAL mapper");
+      return -ENODEV;
+    }
     
     int iResult = pData->GetDataBlockDescription(dt, spec);
     if (iResult>=0) 
     {
         int ddl = -1;
-        if((ddl = mapper.GetDDLFromSpec(spec)) >=0)
+        if((ddl = pMapper->GetDDLFromSpec(spec)) >=0)
         {
             iResult = ddl;
         }
@@ -297,3 +314,16 @@ int AliHLTEMCALAgent::AliHLTEMCALRawDataHandler::ProcessData(AliHLTOUT* pData)
     }
     return iResult;
 }
+
+AliHLTEMCALMapper* AliHLTEMCALAgent::GetMapper(AliHLTUInt32_t spec) const
+{
+  // get the mapper instance for a specification
+  std::map<AliHLTUInt32_t, AliHLTEMCALMapper*>::const_iterator element=fMappers.find(spec);
+  if (element!=fMappers.end()) return element->second;
+
+  AliHLTEMCALMapper* mapper=new AliHLTEMCALMapper(spec);
+  if (!mapper) return NULL;
+  mapper->InitDDLSpecificationMapping();
+  const_cast<AliHLTEMCALAgent*>(this)->fMappers[spec]=mapper;
+  return mapper;
+}
index d38054197b02df46d6feacbdd22472306d34d712..6b0fba892d59ae029c47153a2950bb1960726b69 100644 (file)
 
 #include "AliHLTModuleAgent.h"
 #include "AliHLTOUTHandlerEquId.h"
+#include <map>
 
 class AliHLTOUTHandlerChain;
+class AliHLTEMCALMapper;
 
 /**
  * @class AliHLTEMCALAgent
@@ -102,7 +104,7 @@ class AliHLTEMCALAgent : public AliHLTModuleAgent {
   class AliHLTEMCALRawDataHandler : public AliHLTOUTHandlerEquId {
   public:
     /** constructor */
-    AliHLTEMCALRawDataHandler();
+    AliHLTEMCALRawDataHandler(AliHLTEMCALAgent* pAgent=NULL);
     /** destructor */
     ~AliHLTEMCALRawDataHandler();
 
@@ -115,6 +117,12 @@ class AliHLTEMCALAgent : public AliHLTModuleAgent {
     int ProcessData(AliHLTOUT* pData);
 
   private:
+    /// copy constructor prohibited
+    AliHLTEMCALRawDataHandler(const AliHLTEMCALRawDataHandler&);
+    /// assignment operator prohibited
+    AliHLTEMCALRawDataHandler& operator=(const AliHLTEMCALRawDataHandler&);
+
+    AliHLTEMCALAgent* fpAgent; //! agent instance to retrieve mapper
 
   };
 
@@ -126,10 +134,16 @@ class AliHLTEMCALAgent : public AliHLTModuleAgent {
   /** assignment operator prohibited */
   AliHLTEMCALAgent& operator=(const AliHLTEMCALAgent&);
 
+  /// get mapper for a specification
+  AliHLTEMCALMapper* GetMapper(AliHLTUInt32_t spec) const;
+
   /** handler for EMCAL raw data in the HLTOUT stream */
   AliHLTEMCALRawDataHandler* fRawDataHandler; //!transient
 
-  ClassDef(AliHLTEMCALAgent, 1);
+  // mappers for different specifications
+  std::map<AliHLTUInt32_t, AliHLTEMCALMapper*> fMappers; //! transient
+
+  ClassDef(AliHLTEMCALAgent, 0);
 };
 
 #endif
index 01cb3c0d0d1073cadccfcff930449a87ecb140a4..9f842f8a58b45078e0ad3368e91590099aca7038 100644 (file)
@@ -42,9 +42,6 @@
 #include "AliHLTEMCALDefinitions.h"
 #include "AliHLTCaloClusterizer.h"
 
-
-AliHLTEMCALClusterizerComponent gAliHLTEMCALClusterizerComponent;
-
 AliHLTEMCALClusterizerComponent::AliHLTEMCALClusterizerComponent(): 
   AliHLTCaloClusterizerComponent("EMCAL")
 {
index 9dee6c40b07783c623ce7d44db7541723be8021a..83fce08e7e08901811931862c546be06245d623d 100644 (file)
@@ -20,8 +20,6 @@
 
 ClassImp(AliHLTEMCALClusterizerComponentNbyN);
 
-AliHLTEMCALClusterizerComponentNbyN gAliHLTEMCALClusterizerComponentNbyN;
-
 AliHLTEMCALClusterizerComponentNbyN::AliHLTEMCALClusterizerComponentNbyN() : AliHLTEMCALClusterizerComponent()
 {
 // Constructor
index a4d540e065f0186cf4e4cdc858ec24661605980a..387b275e43e8d1d9955703d33a4cace30761423c 100644 (file)
@@ -30,9 +30,6 @@
 #include "AliCaloRawAnalyzerCrude.h"
 
 
-AliHLTEMCALRawAnalyzerCrudeComponent  gAliHLTEMCALRawAnalyzerCrudeComponent;
-
-
 //AliHLTEMCALRawAnalyzerCrudeComponent::AliHLTEMCALRawAnalyzerCrudeComponent : AliHLTEMCALRawAnalyzerComponent() 
 AliHLTEMCALRawAnalyzerCrudeComponent::AliHLTEMCALRawAnalyzerCrudeComponent() : AliHLTEMCALRawAnalyzerComponent( kCrude )
 {
index c613db8d54a20e43be9a3d056f3b3392df8a7907..121c01939d98720ed85adb06cd976fd8b8769485 100644 (file)
@@ -26,8 +26,6 @@
 //-----------
 
 
-AliHLTEMCALRawAnalyzerFastFitComponent  gAliHLTEMCALRawAnalyzerFastFitComponent;
-
 AliHLTEMCALRawAnalyzerFastFitComponent::AliHLTEMCALRawAnalyzerFastFitComponent() : AliHLTEMCALRawAnalyzerComponent(kFastFit)
 {
   // fAnalyzerPtr
index 7393193ddecce75d028e16755217132d651d785f..3c48ba18f0eb39c9ec39db9a92c58c8d39d7bd6f 100644 (file)
@@ -27,8 +27,6 @@
 //-----------
 
 
-AliHLTEMCALRawAnalyzerLMSComponent  gAliHLTEMCALRawAnalyzerLMSComponent;
-
 //AliHLTEMCALRawAnalyzerLMSComponent::AliHLTEMCALRawAnalyzerLMSComponent() : AliHLTEMCALRawAnalyzerComponent(kLMS)
 AliHLTEMCALRawAnalyzerLMSComponent::AliHLTEMCALRawAnalyzerLMSComponent() : AliHLTEMCALRawAnalyzerComponent(kStandard)
 {
index 60689d07eca56f7a5b9a2db3f15daf29b09af6fd..10695b196b6d0d5308eafd9acfee04e5d1fd0275 100644 (file)
@@ -26,8 +26,6 @@
 //-----------
 
 
-AliHLTEMCALRawAnalyzerNNComponent  gAliHLTEMCALRawAnalyzerNNComponent;
-
 AliHLTEMCALRawAnalyzerNNComponent::AliHLTEMCALRawAnalyzerNNComponent() : AliHLTEMCALRawAnalyzerComponent(kNeuralNet)
 {
   // fAnalyzerPtr
index fcfcf387b0f0ec8ad1b26c8967c96bc36c33b3f5..f62b0c6dd7c26cab09afa8c020f2acb32996d33f 100644 (file)
@@ -27,9 +27,6 @@
 #include "AliCaloRawAnalyzerPeakFinder.h"
 
 
-AliHLTEMCALRawAnalyzerPeakFinderComponent  gAliHLTEMCALRawAnalyzerPeakFinderComponent;
-
-
 AliHLTEMCALRawAnalyzerPeakFinderComponent::AliHLTEMCALRawAnalyzerPeakFinderComponent (): AliHLTEMCALRawAnalyzerComponent(kPeakFinder)
 {
   // constructor