]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/MUON/OfflineInterface/AliHLTMUONRecHitsSource.cxx
Fixing coding violations and getting rid of warnings.
[u/mrichter/AliRoot.git] / HLT / MUON / OfflineInterface / AliHLTMUONRecHitsSource.cxx
index c60d310d11a56e48efa03859f3f88e4670a1b574..77b24b2508909bc2ac059940815dcfcb5ba25b7a 100644 (file)
 
 /* $Id$ */
 
-/**
- * @file   AliHLTMUONRecHitsSource.cxx
- * @author Artur Szostak <artursz@iafrica.com>
- * @date   
- * @brief  Implementation of the AliHLTMUONRecHitsSource component.
- */
+///
+/// @file   AliHLTMUONRecHitsSource.cxx
+/// @author Artur Szostak <artursz@iafrica.com>
+/// @date   
+/// @brief  Implementation of the AliHLTMUONRecHitsSource component.
+///
 
 #include "AliHLTMUONRecHitsSource.h"
 #include "AliHLTMUONConstants.h"
 #include "AliMUONMCDataInterface.h"
 #include "AliMUONDataInterface.h"
 #include "AliMUONHit.h"
-#include "AliMUONRawCluster.h"
+#include "AliMUONVCluster.h"
 #include "AliMUONConstants.h"
 #include "AliMUONVClusterStore.h"
 #include "AliMUONVHitStore.h"
 #include "mapping/AliMpCDB.h"
 #include "mapping/AliMpDEManager.h"
 #include "mapping/AliMpDetElement.h"
-#include "TClonesArray.h"
 #include <cstdlib>
 #include <cstdio>
 #include <cerrno>
 #include <cassert>
 #include <new>
 
-namespace
-{
-       // The global object used for automatic component registration.
-       // Note DO NOT use this component for calculation!
-       AliHLTMUONRecHitsSource gAliHLTMUONRecHitsSource;
-}
-
-
 ClassImp(AliHLTMUONRecHitsSource);
 
 
 AliHLTMUONRecHitsSource::AliHLTMUONRecHitsSource() :
        AliHLTOfflineDataSource(),
-       fMCDataInterface(NULL), fDataInterface(NULL),
-       fSelection(kWholePlane)
+       fMCDataInterface(NULL),
+       fDataInterface(NULL),
+       fSelection(kWholePlane),
+       fCurrentEventIndex(0)
 {
+       ///
+       /// Default constructor.
+       ///
+
        for (Int_t i = 0; i < AliMUONConstants::NTrackingCh(); i++)
                fServeChamber[i] = false;
 }
@@ -67,6 +64,10 @@ AliHLTMUONRecHitsSource::AliHLTMUONRecHitsSource() :
 
 AliHLTMUONRecHitsSource::~AliHLTMUONRecHitsSource()
 {
+       ///
+       /// Default destructor.
+       ///
+       
        assert( fMCDataInterface == NULL );
        assert( fDataInterface == NULL );
 }
@@ -74,6 +75,11 @@ AliHLTMUONRecHitsSource::~AliHLTMUONRecHitsSource()
 
 int AliHLTMUONRecHitsSource::DoInit(int argc, const char** argv)
 {
+       ///
+       /// Inherited from AliHLTComponent.
+       /// Parses the command line parameters and initialises the component.
+       ///
+
        assert( fMCDataInterface == NULL );
        assert( fDataInterface == NULL );
        
@@ -81,6 +87,9 @@ int AliHLTMUONRecHitsSource::DoInit(int argc, const char** argv)
        bool simdata = false;
        bool recdata = false;
        bool chamberWasSet = false;
+       fCurrentEventIndex = 0;
+       bool firstEventSet = false;
+       bool eventNumLitSet = false;
        
        for (int i = 0; i < argc; i++)
        {
@@ -139,6 +148,44 @@ int AliHLTMUONRecHitsSource::DoInit(int argc, const char** argv)
                        if (result != 0) return result;
                        chamberWasSet = true;
                }
+               else if (strcmp(argv[i], "-firstevent") == 0)
+               {
+                       if (eventNumLitSet)
+                       {
+                               HLTWarning("The -firstevent flag is overridden by a"
+                                       " previous use of -event_number_literal."
+                               );
+                       }
+                       i++;
+                       if (i >= argc)
+                       {
+                               HLTError("Expected a positive number after -firstevent.");
+                               return EINVAL;
+                       }
+                       char* end = "";
+                       long num = strtol(argv[i], &end, 0);
+                       if (*end != '\0' or num < 0) // Check if the conversion is OK.
+                       {
+                               HLTError(Form(
+                                       "Expected a positive number after -firstevent"
+                                       " but got: %s", argv[i]
+                               ));
+                               return EINVAL;
+                       }
+                       fCurrentEventIndex = Int_t(num);
+                       firstEventSet = true;
+               }
+               else if (strcmp(argv[i], "-event_number_literal") == 0)
+               {
+                       if (firstEventSet)
+                       {
+                               HLTWarning("The -event_number_literal option will"
+                                       " override -firstevent."
+                               );
+                       }
+                       fCurrentEventIndex = -1;
+                       eventNumLitSet = true;
+               }
                else
                {
                        Logging(kHLTLogError,
@@ -233,12 +280,31 @@ int AliHLTMUONRecHitsSource::DoInit(int argc, const char** argv)
                }
        }
        
+       // Check that the fCurrentEventIndex number falls within the correct range.
+       UInt_t maxevent = 0;
+       if (fMCDataInterface != NULL)
+               maxevent = UInt_t(fMCDataInterface->NumberOfEvents());
+       else if (fDataInterface != NULL)
+               maxevent = UInt_t(fDataInterface->NumberOfEvents());
+       if (fCurrentEventIndex != -1 and UInt_t(fCurrentEventIndex) >= maxevent and maxevent != 0)
+       {
+               fCurrentEventIndex = 0;
+               HLTWarning(Form("The selected first event number (%d) was larger than"
+                       " the available number of events (%d). Resetting the event"
+                       " counter to zero.", fCurrentEventIndex, maxevent
+               ));
+       }
+       
        return 0;
 }
 
 
 int AliHLTMUONRecHitsSource::DoDeinit()
 {
+       ///
+       /// Inherited from AliHLTComponent. Performs a cleanup of the component.
+       ///
+       
        if (fMCDataInterface != NULL)
        {
                delete fMCDataInterface;
@@ -255,12 +321,20 @@ int AliHLTMUONRecHitsSource::DoDeinit()
 
 const char* AliHLTMUONRecHitsSource::GetComponentID()
 {
+       ///
+       /// Inherited from AliHLTComponent. Returns the component ID.
+       ///
+       
        return AliHLTMUONConstants::RecHitsSourceId();
 }
 
 
 AliHLTComponentDataType AliHLTMUONRecHitsSource::GetOutputDataType()
 {
+       ///
+       /// Inherited from AliHLTComponent. Returns the output data type.
+       ///
+       
        return AliHLTMUONConstants::RecHitsBlockDataType();
 }
 
@@ -269,6 +343,10 @@ void AliHLTMUONRecHitsSource::GetOutputDataSize(
                unsigned long& constBase, double& inputMultiplier
        )
 {
+       ///
+       /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size.
+       ///
+       
        constBase = sizeof(AliHLTMUONRecHitsBlockStruct)
                + 256*16*sizeof(AliHLTMUONRecHitStruct);
        inputMultiplier = 0;
@@ -277,6 +355,10 @@ void AliHLTMUONRecHitsSource::GetOutputDataSize(
 
 AliHLTComponent* AliHLTMUONRecHitsSource::Spawn()
 {
+       ///
+       /// Inherited from AliHLTComponent. Creates a new object instance.
+       ///
+       
        return new AliHLTMUONRecHitsSource();
 }
 
@@ -289,6 +371,10 @@ int AliHLTMUONRecHitsSource::GetEvent(
                vector<AliHLTComponentBlockData>& outputBlocks
        )
 {
+       ///
+       /// Inherited from AliHLTOfflineDataSource. Creates new event data blocks.
+       ///
+       
        assert( fMCDataInterface != NULL or fDataInterface != NULL );
 
        // Check the size of the event descriptor structure.
@@ -307,12 +393,21 @@ int AliHLTMUONRecHitsSource::GetEvent(
                return EINVAL;
        }
        
-       // Use the fEventID as the event number to load, check it and load that
-       // event with the runloader.
+       // Use the fEventID as the event number to load if fCurrentEventIndex == -1,
+       // check it and load that event with the runloader.
+       // If fCurrentEventIndex is a positive number then us it instead and
+       // increment it.
        UInt_t eventnumber = UInt_t(evtData.fEventID);
        UInt_t maxevent = fMCDataInterface != NULL ?
                UInt_t(fMCDataInterface->NumberOfEvents())
                : UInt_t(fDataInterface->NumberOfEvents());
+       if (fCurrentEventIndex != -1)
+       {
+               eventnumber = UInt_t(fCurrentEventIndex);
+               fCurrentEventIndex++;
+               if (UInt_t(fCurrentEventIndex) >= maxevent)
+                       fCurrentEventIndex = 0;
+       }
        if ( eventnumber >= maxevent )
        {
                Logging(kHLTLogError,
@@ -426,8 +521,8 @@ int AliHLTMUONRecHitsSource::GetEvent(
                        if (not fServeChamber[chamber]) continue;
                        
                        TIter next(clusterStore->CreateChamberIterator(chamber,chamber));
-                       AliMUONRawCluster* cluster;
-                       while ( ( cluster = static_cast<AliMUONRawCluster*>(next()) ) )
+                       AliMUONVCluster* cluster;
+                       while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) )
                        {
                                // Only select hits from the given part of the plane
                                if (fSelection == kLeftPlane and not (cluster->GetX() < 0)) continue;
@@ -452,7 +547,7 @@ int AliHLTMUONRecHitsSource::GetEvent(
                                rechit->fZ = cluster->GetZ();
                                
                                // Workout which DDL this hit will be readout of.
-                               AliMpDetElement* de = AliMpDEManager::GetDetElement(cluster->DetElemId());
+                               AliMpDetElement* de = AliMpDEManager::GetDetElement(cluster->GetDetElemId());
                                if (de != NULL and (0 <= de->GetDdlId() and de->GetDdlId() < 22))
                                        ddlList[de->GetDdlId()] = true;
                                else
@@ -491,6 +586,16 @@ int AliHLTMUONRecHitsSource::GetEvent(
 
 int AliHLTMUONRecHitsSource::ParseChamberString(const char* str)
 {
+       ///
+       /// Parses a string with the following format:
+       ///   <number>|<number>-<number>[,<number>|<number>-<number>]...
+       /// For example: 1  1,2,3  1-2   1,2-4,5  etc...
+       /// Flags in the fServeChamber will be set to 'true' for all appropriate
+       /// values parsed.
+       /// @param str  The string to parse.
+       /// @return  Zero on success and EINVAL if there is a parse error.
+       ///
+       
        char* end = const_cast<char*>(str);
        long lastChamber = -1;
        do