]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/MUON/OfflineInterface/AliHLTMUONTriggerRecordsSource.cxx
Fixing error codes so that components return negative codes according to HLT convention.
[u/mrichter/AliRoot.git] / HLT / MUON / OfflineInterface / AliHLTMUONTriggerRecordsSource.cxx
index 61a50a4a528ecde612d57bf13510e70f20195ea0..56e6feb5bde3eae4154433e89d8c9245042e5ad7 100644 (file)
@@ -1,5 +1,5 @@
 /**************************************************************************
- * This file is property of and copyright by the ALICE HLT Project        * 
+ * This file is property of and copyright by the ALICE HLT Project        *
  * All rights reserved.                                                   *
  *                                                                        *
  * Primary Authors:                                                       *
@@ -10,7 +10,7 @@
  * without fee, provided that the above copyright notice appears in all   *
  * copies and that both the copyright notice and this permission notice   *
  * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          * 
+ * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
@@ -51,9 +51,6 @@
 
 namespace
 {
-       // The global object used for automatic component registration.
-       // Note DO NOT use this component for calculation!
-       AliHLTMUONTriggerRecordsSource gAliHLTMUONTriggerRecordsSource;
        
        //TODO: The following method should be in MUON/mapping
        Int_t FindDDLOfDetElement(Int_t detElemId)
@@ -93,13 +90,21 @@ AliHLTMUONTriggerRecordsSource::AliHLTMUONTriggerRecordsSource() :
        fMCDataInterface(NULL),
        fDataInterface(NULL),
        fBuildFromHits(false),
-       fSelection(kWholePlane)
+       fSelection(kWholePlane),
+       fCurrentEventIndex(0)
 {
+       ///
+       /// Default constructor.
+       ///
 }
 
 
 AliHLTMUONTriggerRecordsSource::~AliHLTMUONTriggerRecordsSource()
 {
+       ///
+       /// Default destructor.
+       ///
+       
        assert( fMCDataInterface == NULL );
        assert( fDataInterface == NULL );
 }
@@ -107,6 +112,11 @@ AliHLTMUONTriggerRecordsSource::~AliHLTMUONTriggerRecordsSource()
 
 int AliHLTMUONTriggerRecordsSource::DoInit(int argc, const char** argv)
 {
+       ///
+       /// Inherited from AliHLTComponent.
+       /// Parses the command line parameters and initialises the component.
+       ///
+       
        assert( fMCDataInterface == NULL );
        assert( fDataInterface == NULL );
        
@@ -114,6 +124,9 @@ int AliHLTMUONTriggerRecordsSource::DoInit(int argc, const char** argv)
        bool hitdata = false;
        bool simdata = false;
        bool recdata = false;
+       fCurrentEventIndex = 0;
+       bool firstEventSet = false;
+       bool eventNumLitSet = false;
        
        for (int i = 0; i < argc; i++)
        {
@@ -139,7 +152,7 @@ int AliHLTMUONTriggerRecordsSource::DoInit(int argc, const char** argv)
                                        "Missing parameter",
                                        "Expected one of 'left', 'right' or 'all' after '-plane'."
                                );
-                               return EINVAL;
+                               return -EINVAL;
                        }
                        if (strcmp(argv[i], "left") == 0)
                                fSelection = kLeftPlane;
@@ -156,8 +169,46 @@ int AliHLTMUONTriggerRecordsSource::DoInit(int argc, const char** argv)
                                          " 'right' or 'all'.",
                                        argv[i]
                                );
-                               return EINVAL;
+                               return -EINVAL;
+                       }
+               }
+               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
                {
@@ -167,7 +218,7 @@ int AliHLTMUONTriggerRecordsSource::DoInit(int argc, const char** argv)
                                "The argument '%s' is invalid.",
                                argv[i]
                        );
-                       return EINVAL;
+                       return -EINVAL;
                }
        }
 
@@ -185,7 +236,7 @@ int AliHLTMUONTriggerRecordsSource::DoInit(int argc, const char** argv)
                        "Missing arguments",
                        "Must have one and only one of -hitdata, -simdata or -recdata specified."
                );
-               return EINVAL;
+               return -EINVAL;
        }
        
        // Must load the mapping data for AliMpTriggerCrate::GetDdlId()  //TODO AliMpTriggerCrate => AliMpDetElement
@@ -215,7 +266,7 @@ int AliHLTMUONTriggerRecordsSource::DoInit(int argc, const char** argv)
                                "Out of memory",
                                "Not enough memory to allocate AliMUONMCDataInterface."
                        );
-                       return ENOMEM;
+                       return -ENOMEM;
                }
        }
        else if (recdata)
@@ -237,16 +288,35 @@ int AliHLTMUONTriggerRecordsSource::DoInit(int argc, const char** argv)
                                "Out of memory",
                                "Not enough memory to allocate AliMUONDataInterface."
                        );
-                       return ENOMEM;
+                       return -ENOMEM;
                }
        }
        
+       // 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 AliHLTMUONTriggerRecordsSource::DoDeinit()
 {
+       ///
+       /// Inherited from AliHLTComponent. Performs a cleanup of the component.
+       ///
+       
        if (fMCDataInterface != NULL)
        {
                delete fMCDataInterface;
@@ -263,12 +333,20 @@ int AliHLTMUONTriggerRecordsSource::DoDeinit()
 
 const char* AliHLTMUONTriggerRecordsSource::GetComponentID()
 {
+       ///
+       /// Inherited from AliHLTComponent. Returns the component ID.
+       ///
+       
        return AliHLTMUONConstants::TriggerRecordsSourceId();
 }
 
 
 AliHLTComponentDataType AliHLTMUONTriggerRecordsSource::GetOutputDataType()
 {
+       ///
+       /// Inherited from AliHLTComponent. Returns the output data type.
+       ///
+       
        return AliHLTMUONConstants::TriggerRecordsBlockDataType();
 }
 
@@ -277,6 +355,10 @@ void AliHLTMUONTriggerRecordsSource::GetOutputDataSize(
                unsigned long& constBase, double& inputMultiplier
        )
 {
+       ///
+       /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size.
+       ///
+       
        constBase = sizeof(AliHLTMUONTriggerRecordsBlockStruct) +
                sizeof(AliHLTMUONTriggerRecordStruct) * AliMUONConstants::NTriggerCircuit();
        inputMultiplier = 0;
@@ -285,6 +367,10 @@ void AliHLTMUONTriggerRecordsSource::GetOutputDataSize(
 
 AliHLTComponent* AliHLTMUONTriggerRecordsSource::Spawn()
 {
+       ///
+       /// Inherited from AliHLTComponent. Creates a new object instance.
+       ///
+       
        return new AliHLTMUONTriggerRecordsSource();
 }
 
@@ -297,6 +383,10 @@ int AliHLTMUONTriggerRecordsSource::GetEvent(
                vector<AliHLTComponentBlockData>& outputBlocks
        )
 {
+       ///
+       /// Inherited from AliHLTOfflineDataSource. Creates new event data blocks.
+       ///
+       
        assert( fMCDataInterface != NULL or fDataInterface != NULL );
 
        AliHLTInt32_t trigRecId = 0;
@@ -314,15 +404,24 @@ int AliHLTMUONTriggerRecordsSource::GetEvent(
                        sizeof(AliHLTComponentEventData)
                );
                size = 0; // Important to tell framework that nothing was generated.
-               return EINVAL;
+               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,
@@ -334,7 +433,7 @@ int AliHLTMUONTriggerRecordsSource::GetEvent(
                        maxevent
                );
                size = 0; // Important to tell framework that nothing was generated.
-               return EINVAL;
+               return -EINVAL;
        }
        
        // Create and initialise a new data block.
@@ -350,7 +449,7 @@ int AliHLTMUONTriggerRecordsSource::GetEvent(
                        block.BufferSize()
                );
                size = 0; // Important to tell framework that nothing was generated.
-               return ENOBUFS;
+               return -ENOBUFS;
        }
        
        // Initialise the DDL list containing the DDLs which contributed to the
@@ -435,7 +534,7 @@ int AliHLTMUONTriggerRecordsSource::GetEvent(
                                        block.BufferSize()
                                );
                                size = 0; // Important to tell framework that nothing was generated.
-                               return ENOBUFS;
+                               return -ENOBUFS;
                        }
                        
                        // Fill the new trigger record with the hit information.
@@ -536,7 +635,7 @@ int AliHLTMUONTriggerRecordsSource::GetEvent(
                        "Neither AliMUONDataInterface nor AliMUONMCDataInterface were created."
                );
                size = 0; // Important to tell framework that nothing was generated.
-               return EFAULT;
+               return -EFAULT;
        }
        
        AliHLTComponentBlockData bd;