Cleaning up warnings and making some changes to memory handling to be more robust...
authoraszostak <aszostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 16 Apr 2008 17:59:50 +0000 (17:59 +0000)
committeraszostak <aszostak@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 16 Apr 2008 17:59:50 +0000 (17:59 +0000)
HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.cxx
HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructor.h
HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructorComponent.cxx
HLT/MUON/OnlineAnalysis/AliHLTMUONHitReconstructorComponent.h
HLT/MUON/OnlineAnalysis/AliHLTMUONMansoTrackerFSMComponent.cxx
HLT/MUON/OnlineAnalysis/AliHLTMUONMansoTrackerFSMComponent.h
HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructorComponent.cxx
HLT/MUON/OnlineAnalysis/AliHLTMUONTriggerReconstructorComponent.h

index 243bd5f..be5544a 100644 (file)
@@ -798,19 +798,19 @@ void AliHLTMUONHitReconstructor::Clear()
 
 AliHLTMUONHitReconstructor::AliHLTMUONRawDecoder::AliHLTMUONRawDecoder() :
        fBufferStart(NULL),
-  fDCCut(0),
-  fPadData(NULL),
-  fLookUpTableData(NULL),
-  fMaxFiredPerDetElem(NULL),
-  fNofFiredDetElem(NULL),
-  fBusPatchId(0),
-  fDataCount(1),
-  fPrevDetElemId(0),
-  fPadCharge(0),
-  fCharge(0.0),
-  fIdManuChannel(0x0),
-  fLutEntry(0),
-  fIdToEntry()
+       fBusPatchId(0),
+       fDCCut(0),
+       fPadData(NULL),
+       fLookUpTableData(NULL),
+       fNofFiredDetElem(NULL),
+       fMaxFiredPerDetElem(NULL),
+       fIdToEntry(),
+       fDataCount(1),
+       fPrevDetElemId(0),
+       fPadCharge(0),
+       fCharge(0.0),
+       fIdManuChannel(0x0),
+       fLutEntry(0)
 {
        // ctor
 }
index 83075b2..3af34be 100644 (file)
@@ -37,6 +37,7 @@
 
 extern "C" struct AliHLTMUONRecHitStruct;
 
+//TODO: Change code to not use std::map to avoid too many AliRoot coding rule violations.
 typedef std::map<AliHLTInt32_t, AliHLTInt32_t> IdManuChannelToEntry;
 
 
@@ -58,8 +59,6 @@ public:
                        AliHLTUInt32_t& nofHit
                );
        void SetDCCut(AliHLTInt32_t dcCut) {fDCCut = dcCut;}
-       //void SetDebugLevel(AliHLTInt32_t debugLevel) {fDebugLevel = debugLevel;} //TODO: remove
-       //int GetDebugLevel() const {return fDebugLevel;} //TODO: remove
        
        static AliHLTInt32_t GetkDetectorId() { return fgkDetectorId; }
        static AliHLTInt32_t GetkDDLOffSet() { return fgkDDLOffSet; }
@@ -179,8 +178,7 @@ private:
        AliHLTFloat32_t *fAvgChargeX, *fAvgChargeY;                  // average charge on central pad found using CG method
        AliHLTInt32_t *fNofBChannel, *fNofNBChannel;                 // number of channels bending and non-bending.
        AliHLTInt32_t fGetIdTotalData[336][237][2];                  // an array of idManuChannel with argument of centralX, centralY and planeType.
-       AliHLTInt32_t fNofFiredDetElem,fMaxFiredPerDetElem[13];      // counter for detector elements that are fired 
-       AliHLTInt32_t fDebugLevel;
+       AliHLTInt32_t fNofFiredDetElem,fMaxFiredPerDetElem[13];      // counter for detector elements that are fired
        IdManuChannelToEntry fIdToEntry;       // Mapping between Linenumber to IdManuChannel;
        
        //bool ReadDDL(const AliHLTUInt32_t* rawData, AliHLTUInt32_t rawDataSize);
index 282db30..b75b26d 100644 (file)
@@ -31,6 +31,7 @@
 #include "AliHLTMUONConstants.h"
 #include "AliHLTMUONUtils.h"
 #include "AliHLTMUONDataBlockWriter.h"
+#include "AliHLTMUONHitReconstructor.h"
 #include "AliHLTLogging.h"
 #include "AliHLTSystem.h"
 #include "AliHLTDefinitions.h"
@@ -47,7 +48,7 @@
 #include "AliMUONCalibrationData.h"
 #include "AliMUONVCalibParam.h"
 
-//MUON/mapping 
+//MUON/mapping
 #include "AliMpCDB.h"
 #include "AliMpPad.h"
 #include "AliMpSegmentation.h"
@@ -63,7 +64,7 @@ ClassImp(AliHLTMUONHitReconstructorComponent)
 AliHLTMUONHitReconstructorComponent::AliHLTMUONHitReconstructorComponent() :
        AliHLTProcessor(),
        fHitRec(NULL),
-       fDDL(0),
+       fDDL(-1),
        fIdToEntry(),
        fWarnForUnexpecedBlock(false)
 {
@@ -146,6 +147,10 @@ int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv)
 
        HLTInfo("Initialising dHLT hit reconstruction component.");
        
+       // Must make sure that fHitRec is deleted if it is still allocated for
+       // whatever reason.
+       FreeMemory();
+       
        try
        {
                fHitRec = new AliHLTMUONHitReconstructor();
@@ -156,8 +161,11 @@ int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv)
                return -ENOMEM;
        }
        
+       // Initialise fields with default values then parse the command line.
+       fDDL = -1;
+       fIdToEntry.clear();
        fWarnForUnexpecedBlock = false;
-
+       
        const char* lutFileName = NULL;
        const char* cdbPath = NULL;
        Int_t run = -1;
@@ -172,7 +180,8 @@ int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv)
                        if (argc <= i+1)
                        {
                                HLTError("The DDL number was not specified. Must be in the range [13..20].");
-                               return EINVAL;
+                               FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+                               return -EINVAL;
                        }
                        
                        char* cpErr = NULL;
@@ -180,12 +189,14 @@ int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv)
                        if (cpErr == NULL or *cpErr != '\0')
                        {
                                HLTError("Cannot convert '%s' to DDL Number ", argv[i+1] );
-                               return EINVAL;
+                               FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+                               return -EINVAL;
                        }
                        if (num < 13 or 20 < num)
                        {
                                HLTError("The DDL number must be in the range [13..20].");
-                               return EINVAL;
+                               FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+                               return -EINVAL;
                        }
                        fDDL = num - 1;
                        
@@ -198,7 +209,8 @@ int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv)
                        if (argc <= i+1)
                        {
                                HLTError("The lookup table filename was not specified.");
-                               return EINVAL;
+                               FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+                               return -EINVAL;
                        }
                        lutFileName = argv[i+1];
                        i++;
@@ -216,7 +228,8 @@ int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv)
                        if ( argc <= i+1 )
                        {
                                HLTError("The CDB path was not specified." );
-                               return EINVAL;
+                               FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+                               return -EINVAL;
                        }
                        cdbPath = argv[i+1];
                        useCDB = true;
@@ -229,7 +242,8 @@ int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv)
                        if ( argc <= i+1 )
                        {
                                HLTError("The RUN number was not specified." );
-                               return EINVAL;
+                               FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+                               return -EINVAL;
                        }
                        
                        char* cpErr = NULL;
@@ -239,7 +253,8 @@ int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv)
                                HLTError("Cannot convert '%s' to a valid run number."
                                        " Expected an integer value.", argv[i+1]
                                );
-                               return EINVAL;
+                               FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+                               return -EINVAL;
                        }
                        
                        i++;
@@ -253,41 +268,39 @@ int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv)
                }
        
                HLTError("Unknown option '%s'", argv[i]);
-               return EINVAL;
+               FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+               return -EINVAL;
        
        } // for loop
        
+       if (fDDL == -1)
+       {
+               HLTWarning("DDL number not specified. Cannot check if incomming data is valid.");
+       }
+       
        if (lutFileName == NULL) useCDB = true;
        
-       AliHLTMUONHitRecoLutRow* lookupTable;
+       AliHLTMUONHitRecoLutRow* lookupTable = NULL;
        
        if (useCDB)
        {
-               if(!ReadCDB(lookupTable,cdbPath,run))
+               if (not ReadCDB(lookupTable,cdbPath,run))
                {
                        HLTError("Failed to read cdb, cdb cannot be read, DoInit");
-                       
-                       if (fHitRec)
-                       {
-                               delete fHitRec;
-                               fHitRec = NULL;
-                       }
-                       if(lookupTable)
-                               delete []lookupTable;
-                       
-                       return ENOENT ; /* No such file or directory */
+                       FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+                       if (lookupTable != NULL)
+                               delete [] lookupTable;
+                       return -ENOENT;
                }
        }
        else
        {
                AliHLTUInt32_t lutLine;
-               if(!GetLutLine(lutFileName,fDDL,lutLine))
+               if (not GetLutLine(lutFileName, lutLine))
                {
                        HLTError("Failed for lookuptable count the number of lines in lookuptable, DoInit");
-                       
-                       if(fHitRec)
-                               delete fHitRec;
-                       return EIO;
+                       FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+                       return -EIO;
                }
        
                try
@@ -297,53 +310,36 @@ int AliHLTMUONHitReconstructorComponent::DoInit(int argc, const char** argv)
                catch(const std::bad_alloc&)
                {
                        HLTError("Dynamic memory allocation failed for lookuptable, DoInit");
-                       
-                       if(fHitRec)
-                               delete fHitRec;
-                       
-                       return ENOMEM;
+                       FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+                       return -ENOMEM;
                }
        
-       
-               if(!ReadLookUpTable(lookupTable,lutFileName))
+               if (not ReadLookUpTable(lookupTable, lutFileName))
                {
                        HLTError("Failed to read lut, lut cannot be read, DoInit");
-                       
-                       if(fHitRec)
-                               delete fHitRec;
-                       if(lookupTable)
-                               delete []lookupTable;
-                       
-                       return ENOENT ; /* No such file or directory */
+                       FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+                       if (lookupTable != NULL)
+                               delete [] lookupTable;
+                       return -ENOENT;
                }
        }
        
-       if(!fHitRec->SetIdManuChannelToEntry(fIdToEntry))
+       if (not fHitRec->SetIdManuChannelToEntry(fIdToEntry))
        {
                HLTError("Failed to set fIdToEntry mapping, DoInit");
-               
-               if(fHitRec)
-               delete fHitRec;
-               if(lookupTable)
-               delete []lookupTable;
-               
-               fIdToEntry.clear();
-               
-               return ENOENT ; /* No such file or directory */
+               FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+               if (lookupTable != NULL)
+                       delete [] lookupTable;
+               return -ENOENT;
        }
        
-       if(!fHitRec->LoadLookUpTable(lookupTable,fDDL))
+       if (not fHitRec->LoadLookUpTable(lookupTable, fDDL))
        {
                HLTError("Cannot Laod hitrec lookuptable , DoInit");
-               
-               if(fHitRec)
-               delete fHitRec;
-               if(lookupTable)
-               delete []lookupTable;
-               
-               fIdToEntry.clear();
-               
-               return ENOENT;
+               FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+               if (lookupTable != NULL)
+                       delete [] lookupTable;
+               return -ENOENT;
        }
        
        delete [] lookupTable;
@@ -359,15 +355,7 @@ int AliHLTMUONHitReconstructorComponent::DoDeinit()
        ///
        
        HLTInfo("Deinitialising dHLT hit reconstruction component.");
-       
-       if (fHitRec != NULL)
-       {
-               delete fHitRec;
-               fHitRec = NULL;
-       }
-       
-       fIdToEntry.clear();
-       
+       FreeMemory();
        return 0;
 }
 
@@ -438,11 +426,14 @@ int AliHLTMUONHitReconstructorComponent::DoEvent(
                        continue;
                }
                
-               bool ddl[22];
-               AliHLTMUONUtils::UnpackSpecBits(blocks[n].fSpecification, ddl);
-               if (not ddl[fDDL])
+               if (fDDL != -1)
                {
-                       HLTWarning("Received raw data from an unexpected DDL.");
+                       bool ddl[22];
+                       AliHLTMUONUtils::UnpackSpecBits(blocks[n].fSpecification, ddl);
+                       if (not ddl[fDDL])
+                       {
+                               HLTWarning("Received raw data from an unexpected DDL.");
+                       }
                }
                
                // Create a new output data block and initialise the header.
@@ -474,7 +465,7 @@ int AliHLTMUONHitReconstructorComponent::DoEvent(
                {
                        HLTError("Error while processing of hit reconstruction algorithm.");
                        size = totalSize; // Must tell the framework how much buffer space was used.
-                       return EIO;
+                       return -EIO;
                }
                
                // nofHit should now contain the number of reconstructed hits actually found
@@ -505,8 +496,25 @@ int AliHLTMUONHitReconstructorComponent::DoEvent(
 }
 
 
+void AliHLTMUONHitReconstructorComponent::FreeMemory()
+{
+       /// Deletes any allocated objects if they are allocated else nothing is
+       /// done for objects not yet allocated.
+       /// This is used as a helper method to make sure the corresponding pointers
+       /// are NULL and we are back to a well defined state.
+
+       if (fHitRec != NULL)
+       {
+               delete fHitRec;
+               fHitRec = NULL;
+       }
+       
+       fIdToEntry.clear();
+}
+
+
 bool AliHLTMUONHitReconstructorComponent::GetLutLine(
-               const char* lutFileName, AliHLTInt32_t /*iDDL*/, AliHLTUInt32_t& iLine
+               const char* lutFileName, AliHLTUInt32_t& iLine
        )
 {
   // Reads LUT from CDB.
@@ -547,7 +555,7 @@ bool AliHLTMUONHitReconstructorComponent::ReadLookUpTable(
   }
   
   AliHLTUInt32_t lutLine;
-  if(!GetLutLine(lutFileName,fDDL,lutLine)){
+  if(!GetLutLine(lutFileName, lutLine)){
     HLTError("Failed for lookuptable count the number of lines in lookuptable, DoInit");
     
     return false;
index a51dc0a..7e487be 100644 (file)
 ///  @file   AliHLTMUONHitReconstructorComponent.h
 ///  @author Indranil Das <indra.das@saha.ac.in> | <indra.ehep@gmail.com>
 ///  @date   
-///  @brief  Hit Reconstruction processing component for the dimuon HLT. 
+///  @brief  Hit Reconstruction processing component for the dimuon HLT.
 ///
 
 #include "AliHLTProcessor.h"
-#include <TString.h>
-#include "AliHLTMUONHitReconstructor.h"
 
 #if __GNUC__ && __GNUC__ < 3
 #define std
 #endif
 
+// TODO: see if we can remove the following header somehow.
+#include "AliHLTMUONHitReconstructor.h"
+//class AliHLTMUONHitReconstructor;
 
 extern "C" struct AliHLTMUONHitRecoLutRow;
 
@@ -65,12 +66,13 @@ private:
        AliHLTMUONHitReconstructorComponent(const AliHLTMUONHitReconstructorComponent& /*obj*/);
        AliHLTMUONHitReconstructorComponent& operator = (const AliHLTMUONHitReconstructorComponent& /*obj*/);
        
+       void FreeMemory();
        bool ReadLookUpTable(AliHLTMUONHitRecoLutRow* lookupTable, const char* lutpath);
        bool ReadCDB(AliHLTMUONHitRecoLutRow*& lookupTable, const char* cdbpath, Int_t run);
-       bool GetLutLine(const char* lutPath, AliHLTInt32_t iDDL, AliHLTUInt32_t& iLine); //To count the nof lines in lookuptable
+       bool GetLutLine(const char* lutPath, AliHLTUInt32_t& iLine); // To count the nof lines in lookuptable
  
-       AliHLTMUONHitReconstructor* fHitRec;   // Internal class instance implementing the hit reconstruction algorithm.
-       AliHLTInt32_t fDDL;        // DDL number in the range [13..20].
+       AliHLTMUONHitReconstructor* fHitRec;  // Internal class instance implementing the hit reconstruction algorithm.
+       AliHLTInt32_t fDDL;  // DDL number in the range [13..20]. Set to -1 for invalid/unspecified value.
        IdManuChannelToEntry fIdToEntry; // id to line mapping.
        bool fWarnForUnexpecedBlock;  // Flag indicating if we should log a warning if we got a block of an unexpected type.
        
index c810bbf..5d6f607 100644 (file)
@@ -66,8 +66,13 @@ AliHLTMUONMansoTrackerFSMComponent::~AliHLTMUONMansoTrackerFSMComponent()
        /// Default destructor.
        ///
        
-       assert( fTracker == NULL );
-       assert( fRecHitBlock[0] == NULL );
+       // Should never have the following 2 pointers non-NULL since DoDeinit
+       // should have been called before, but handle this case anyway.
+       if (fTracker != NULL) delete fTracker;
+       
+       // Remember that only fRecHitBlock[0] stores the pointer to the allocated
+       // memory. The other pointers are just reletive to this.
+       if (fRecHitBlock[0] != NULL) delete [] fRecHitBlock[0];
 }
 
 
@@ -137,6 +142,10 @@ int AliHLTMUONMansoTrackerFSMComponent::DoInit(int argc, const char** argv)
        
        HLTInfo("Initialising dHLT manso tracker FSM component.");
        
+       // Just in case for whatever reason we still have some of the internal
+       // object allocated previously still hanging around delete them now.
+       FreeMemory();
+       
        try
        {
                fTracker = new AliHLTMUONMansoTrackerFSM();
@@ -159,11 +168,12 @@ int AliHLTMUONMansoTrackerFSMComponent::DoInit(int argc, const char** argv)
                }
 
                HLTError("Unknown option '%s'.", argv[i]);
-               return EINVAL;
+               FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
+               return -EINVAL;
        }
        
        const int initArraySize = 10;
-       // allocate some initial memory for the reconstructed hit arrays.
+       // Allocate some initial memory for the reconstructed hit arrays.
        try
        {
                fRecHitBlock[0] = new AliRecHitBlockInfo[initArraySize*4];
@@ -171,6 +181,7 @@ int AliHLTMUONMansoTrackerFSMComponent::DoInit(int argc, const char** argv)
        catch (const std::bad_alloc&)
        {
                HLTError("Could not allocate more memory for the reconstructed hit arrays.");
+               FreeMemory(); // Make sure we cleanup to avoid partial initialisation.
                return -ENOMEM;
        }
        // Only set the arrays' size once we have successfully allocated the memory for the arrays.
@@ -197,25 +208,7 @@ int AliHLTMUONMansoTrackerFSMComponent::DoDeinit()
        ///
        
        HLTInfo("Deinitialising dHLT manso tracker FSM component.");
-       
-       if (fTracker != NULL)
-       {
-               delete fTracker;
-               fTracker = NULL;
-       }
-       
-       // Remember that only fRecHitBlock[0] stores the pointer to the allocated memory.
-       // The other pointers are just reletive to this.
-       if (fRecHitBlock[0] != NULL)
-               delete [] fRecHitBlock[0];
-       
-       fRecHitBlockArraySize = 0;
-       for (Int_t i = 0; i < 4; i++)
-       {
-               fRecHitBlockCount[i] = 0;
-               fRecHitBlock[i] = NULL;
-       }
-       
+       FreeMemory();
        return 0;
 }
 
@@ -236,12 +229,17 @@ int AliHLTMUONMansoTrackerFSMComponent::DoEvent(
        Reset();
        AliHLTUInt32_t specification = 0;  // Contains the output data block spec bits.
        
-       // Resize the rec hit arrays if we need to. To guarantee that they will not overflow
-       // we need to make sure each array is at least as big as the number of input data block.
+       // Resize the rec hit arrays if we possibly will need more space.
+       // To guarantee that they will not overflow we need to make sure each
+       // array is at least as big as the number of input data blocks.
        if (fRecHitBlockArraySize < evtData.fBlockCnt)
        {
                // Release the old memory block and allocate more memory.
-               delete [] fRecHitBlock[0];
+               if (fRecHitBlock[0] != NULL)
+               {
+                       delete [] fRecHitBlock[0];
+               }
+               
                // Reset the number of records actually stored in the arrays.
                for (Int_t i = 0; i < 4; i++)
                {
@@ -451,6 +449,34 @@ void AliHLTMUONMansoTrackerFSMComponent::Reset()
 }
 
 
+void AliHLTMUONMansoTrackerFSMComponent::FreeMemory()
+{
+       /// Deletes any objects and arrays allocated by this component and releases
+       /// the memory used. This is called as a helper routine by the init and deinit
+       /// methods. If some or all of the object pointers are already NULL then
+       /// nothing is done for those. This method guarantees that all the relevant
+       /// pointers will be NULL after returning from this method.
+
+       if (fTracker != NULL)
+       {
+               delete fTracker;
+               fTracker = NULL;
+       }
+       
+       // Remember that only fRecHitBlock[0] stores the pointer to the allocated memory.
+       // The other pointers are just reletive to this.
+       if (fRecHitBlock[0] != NULL)
+               delete [] fRecHitBlock[0];
+       
+       fRecHitBlockArraySize = 0;
+       for (Int_t i = 0; i < 4; i++)
+       {
+               fRecHitBlockCount[i] = 0;
+               fRecHitBlock[i] = NULL;
+       }
+}
+
+
 void AliHLTMUONMansoTrackerFSMComponent::AddRecHits(
                AliHLTUInt32_t specification,
                const AliHLTMUONRecHitStruct* recHits,
index b983b31..f42ae15 100644 (file)
@@ -100,6 +100,7 @@ private:
        AliHLTMUONMansoTrackerFSMComponent& operator = (const AliHLTMUONMansoTrackerFSMComponent& /*obj*/);
 
        void Reset();
+       void FreeMemory();
        
        void AddRecHits(
                        AliHLTUInt32_t specification,
index ae75634..d77fa94 100644 (file)
@@ -56,6 +56,8 @@ AliHLTMUONTriggerReconstructorComponent::~AliHLTMUONTriggerReconstructorComponen
        ///
        /// Default destructor.
        ///
+       
+       if (fTrigRec != NULL) delete fTrigRec;
 }
 
 
@@ -124,10 +126,26 @@ int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
        
        HLTInfo("Initialising dHLT trigger reconstructor component.");
        
+       // Make sure to cleanup fTrigRec if it is still there for some reason.
+       if (fTrigRec != NULL)
+       {
+               delete fTrigRec;
+               fTrigRec = NULL;
+       }
+       
+       try
+       {
+               fTrigRec = new AliHLTMUONTriggerReconstructor();
+       }
+       catch (const std::bad_alloc&)
+       {
+               HLTError("Could not allocate more memory for the trigger reconstructor component.");
+               return -ENOMEM;
+       }
+       
+       fDDL = -1;
        fWarnForUnexpecedBlock = false;
        fSuppressPartialTrigs = false;
-       assert(fTrigRec == NULL);
-       fTrigRec = new AliHLTMUONTriggerReconstructor();
        
        const char* lutFileName = NULL;
        
@@ -138,7 +156,10 @@ int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
                        if ( argc <= i+1 )
                        {
                                HLTError("LookupTable filename not specified." );
-                               return EINVAL; /* Invalid argument */ 
+                               // Make sure to delete fTrigRec to avoid partial initialisation.
+                               delete fTrigRec;
+                               fTrigRec = NULL;
+                               return -EINVAL;
                        }
                        
                        lutFileName = argv[i+1];
@@ -152,20 +173,29 @@ int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
                        if ( argc <= i+1 )
                        {
                                HLTError("DDL number not specified." );
-                               return EINVAL;  /* Invalid argument */
+                               // Make sure to delete fTrigRec to avoid partial initialisation.
+                               delete fTrigRec;
+                               fTrigRec = NULL;
+                               return -EINVAL;
                        }
                
                        char* cpErr = NULL;
                        unsigned long num = strtoul(argv[i+1], &cpErr, 0);
                        if (cpErr == NULL or *cpErr != '\0')
                        {
-                               HLTError("Cannot convert '%s' to a DDL Number.", argv[i+1] );
-                               return EINVAL;
+                               HLTError("Cannot convert '%s' to a DDL Number.", argv[i+1] );\
+                               // Make sure to delete fTrigRec to avoid partial initialisation.
+                               delete fTrigRec;
+                               fTrigRec = NULL;
+                               return -EINVAL;
                        }
                        if (num < 21 or 22 < num)
                        {
                                HLTError("The DDL number must be in the range [21..22].");
-                               return EINVAL;
+                               // Make sure to delete fTrigRec to avoid partial initialisation.
+                               delete fTrigRec;
+                               fTrigRec = NULL;
+                               return -EINVAL;
                        }
                        fDDL = num - 1; // Convert to DDL number in the range 0..21
                        
@@ -186,9 +216,12 @@ int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
                }
                
                HLTError("Unknown option '%s'.", argv[i] );
-               return EINVAL;
+               // Make sure to delete fTrigRec to avoid partial initialisation.
+               delete fTrigRec;
+               fTrigRec = NULL;
+               return -EINVAL;
                        
-       }//while loop
+       } // for loop
        
        if (fDDL == -1)
        {
@@ -199,8 +232,11 @@ int AliHLTMUONTriggerReconstructorComponent::DoInit(int argc, const char** argv)
        {
                if (not ReadLookUpTable(lutFileName))
                {
-                       HLTError("Failed to read lut, lut cannot be read");
-                       return ENOENT ; /* No such file or directory */
+                       HLTError("Failed to read lut from file.");
+                       // Make sure to delete fTrigRec to avoid partial initialisation.
+                       delete fTrigRec;
+                       fTrigRec = NULL;
+                       return -ENOENT;
                }
        }
        else
@@ -296,11 +332,14 @@ int AliHLTMUONTriggerReconstructorComponent::DoEvent(
                        continue;
                }
                
-               bool ddl[22];
-               AliHLTMUONUtils::UnpackSpecBits(blocks[n].fSpecification, ddl);
-               if (not ddl[fDDL])
+               if (fDDL != -1)
                {
-                       HLTWarning("Received raw data from an unexpected DDL.");
+                       bool ddl[22];
+                       AliHLTMUONUtils::UnpackSpecBits(blocks[n].fSpecification, ddl);
+                       if (not ddl[fDDL])
+                       {
+                               HLTWarning("Received raw data from an unexpected DDL.");
+                       }
                }
                
                // Create a new output data block and initialise the header.
@@ -329,7 +368,7 @@ int AliHLTMUONTriggerReconstructorComponent::DoEvent(
                {
                        HLTError("Error while processing of trigger DDL reconstruction algorithm.");
                        size = totalSize; // Must tell the framework how much buffer space was used.
-                       return EIO;
+                       return -EIO;
                }
                
                // nofTrigRec should now contain the number of triggers actually found
index 14fc170..dd6d990 100644 (file)
@@ -70,7 +70,7 @@ private:
        bool ReadLookUpTable(const char* lutpath);
        
        AliHLTMUONTriggerReconstructor* fTrigRec; // The trigger reconstructor class implementing the algorithm.
-       AliHLTInt32_t fDDL;   // The DDL number in the range 20..21 from which to expect input.
+       AliHLTInt32_t fDDL;   // The DDL number in the range 20..21 from which to expect input. Set to -1 for invalid/unspecified value.
        bool fWarnForUnexpecedBlock;  // Flag indicating if we should log a warning if we got a block of an unexpected type.
        bool fSuppressPartialTrigs;   // Flag indicating if we should suppress triggers that did not trigger the L0