LCOV - code coverage report
Current view: top level - EMCAL/EMCALTriggerBase - AliEMCALTriggerDataGrid.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 30 3.3 %
Date: 2016-06-14 17:26:59 Functions: 5 125 4.0 %

          Line data    Source code
       1             : #ifndef ALIEMCALTRIGGERDATAGRID_H
       2             : #define ALIEMCALTRIGGERDATAGRID_H
       3             : /* Copyright(c) 1998-2014, ALICE Experiment at CERN, All rights reserved. *
       4             :  * See cxx source for full Copyright notice                               */
       5             : 
       6             : #include <TObject.h>
       7             : #include <exception>
       8             : #include <sstream>
       9             : #include <string>
      10             : 
      11             : /**
      12             :  * \class AliEmcalTriggerDataGrid
      13             :  * \brief Container for ADC / Amplitudes from the EMCAL triggers
      14             :  *
      15             :  * Dynamical-size container for ADC values from the FASTOR
      16             :  */
      17             : template<typename T>
      18             : class AliEMCALTriggerDataGrid : public TObject {
      19             : public:
      20             :   /**
      21             :    * \class UninitException
      22             :    * \brief Error handling for uninitialized grid
      23             :    */
      24             :   class UninitException : public std::exception{
      25             :   public:
      26             :     /**
      27             :      * Constructor
      28             :      */
      29             :     UninitException():
      30           0 :       std::exception()
      31           0 :     {}
      32             :     /**
      33             :      * Destructor, nothing to do
      34             :      */
      35           0 :     virtual ~UninitException() throw() {}
      36             : 
      37             :     /**
      38             :      * Access error message connected to the exception
      39             :      * @return Error message
      40             :      */
      41           0 :     virtual const char *what() const throw() { return "Trigger channel map not initialized"; }
      42             :   };
      43             : 
      44             :   /**
      45             :    * \class OutOfBoundsException
      46             :    * \brief Exception class handling access to non-existing container element
      47             :    */
      48             :   class OutOfBoundsException : public std::exception{
      49             :   public:
      50             :     /**
      51             :      * Definition of directions
      52             :      */
      53             :     enum Direction_t {
      54             :       kColDir     = 0,///< Column direction (eta)
      55             :       kRowDir     = 1,///< Row direction (phi)
      56             :       kUndef      = 2 ///< Not defined
      57             :     };
      58             :     /**
      59             :      * Dumny constructor
      60             :      */
      61             :     OutOfBoundsException():
      62           0 :       std::exception(),
      63           0 :       fMessage(),
      64           0 :       fDir(kUndef),
      65           0 :       fSize(0),
      66           0 :       fIndex()
      67           0 :     {
      68           0 :     }
      69             :     /**
      70             :      * Regular constructor, to be called when exception is thrown
      71             :      * @param dir Direction (col or row)
      72             :      * @param index Index for which exception is thrown
      73             :      * @param size Size of the grid in direction
      74             :      */
      75             :     OutOfBoundsException(Direction_t dir, int index, int size):
      76           0 :       std::exception(),
      77           0 :       fMessage(""),
      78           0 :       fDir(dir),
      79           0 :       fSize(size),
      80           0 :       fIndex(index)
      81           0 :     {
      82           0 :       std::stringstream errormessage;
      83           0 :       errormessage << "Out-of-bounds access in " << fDir << "Direction: Element " << fIndex << ", Size " << fSize;
      84           0 :       fMessage = errormessage.str();
      85           0 :     }
      86             :     /**
      87             :      * Destructor
      88             :      */
      89           0 :     virtual ~OutOfBoundsException() throw() {}
      90             : 
      91             :     /**
      92             :      * Get error message
      93             :      * @return error message (created in constructor)
      94             :      */
      95           0 :     const char *what() const throw() { return fMessage.c_str(); }
      96             : 
      97             :     /**
      98             :      * Get the size of the grid in direction for which exception is thrown
      99             :      * @return Size of the grid in direction
     100             :      */
     101           0 :     int GetSize() const { return fSize; }
     102             : 
     103             :     /**
     104             :      * Get index for which exception is thrown
     105             :      * @return Index for which exception is thrown
     106             :      */
     107           0 :     int GetIndex() const { return fIndex;}
     108             : 
     109             :     /**
     110             :      * Get the direction for which exception is thrown.
     111             :      * @return Direction for which exception is thrown.
     112             :      */
     113           0 :     Direction_t GetDirection() const { return fDir; }
     114             : 
     115             :   private:
     116             :     std::string         fMessage; ///< Error message, accessible via "what"
     117             :     Direction_t         fDir;     ///< Direction
     118             :     int                 fSize;    ///< size of the container in direction
     119             :     int                 fIndex;   ///< Index requested
     120             :   };
     121             : 
     122             :   /**
     123             :    * Dummy constructor, does not allocate anything
     124             :    */
     125             :   AliEMCALTriggerDataGrid();
     126             : 
     127             :   /**
     128             :    * Constructror
     129             :    * Allocates also for storage for the ADC values / amplitudes
     130             :    * @param cols Number of cols
     131             :    * @param rows Number of rows
     132             :    */
     133             :   AliEMCALTriggerDataGrid(Int_t cols, Int_t rows);
     134             : 
     135             :   /**
     136             :    * Copy constructor
     137             :    * New channel map will get its own storage. The content
     138             :    * of the ref storage will be copied into this storage
     139             :    * @param ref Reference for the copy
     140             :    */
     141             :   AliEMCALTriggerDataGrid(const AliEMCALTriggerDataGrid<T> &ref);
     142             : 
     143             :   /**
     144             :    * Assignment operator
     145             :    * New channel map will get its own storage. The content
     146             :    * of the ref storage will be copied into this storage
     147             :    * @param ref Reference for the copy
     148             :    * @return This channel map
     149             :    */
     150             :   AliEMCALTriggerDataGrid<T> &operator=(const AliEMCALTriggerDataGrid<T> &ref);
     151             : 
     152             :   /**
     153             :    * Constant acces operator at position (col, row)
     154             :    * @param col Column
     155             :    * @param row Row
     156             :    * @return Constant reference to entry at that position (can not modify the entry)
     157             :    */
     158             :   const T &operator()(Int_t col, Int_t row) const;
     159             : 
     160             :   /**
     161             :    * Access operator at position (col, row)
     162             :    * @param col Column
     163             :    * @param row Row
     164             :    * @return Reference to entry at that position (can modify the entry)
     165             :    */
     166             :   T &operator()(Int_t col, Int_t row);
     167             : 
     168             :   /**
     169             :    * Destructor
     170             :    */
     171             :   virtual ~AliEMCALTriggerDataGrid();
     172             : 
     173             :   /**
     174             :    * Set the ADC values stored in the 2D map again to 0
     175             :    */
     176             :   void Reset();
     177             : 
     178             : 
     179           0 :   Bool_t IsAllocated() const { return fValues != NULL; }
     180             : 
     181             :   void Allocate(Int_t ncols, Int_t nrows);
     182             : 
     183             :   /**
     184             :    * Set ADC value for position (col, row). Checks for boundary.
     185             :    * @param col Column of the position
     186             :    * @param row Row of the position
     187             :    * @param ADC The value to set
     188             :    * @throw OutOfBoundsException in case the index in any direction is out of bounds
     189             :    * @throw UninitException in case the grid is not initialized (allocated)
     190             :    */
     191             :   void SetADC(Int_t col, Int_t row, const T &adc);
     192             : 
     193             :   /**
     194             :    * Get ADC value at position (col, row). Checks for boundary.
     195             :    * @param col
     196             :    * @param row
     197             :    * @return
     198             :    * @throw OutOfBoundsException in case the index in any direction is out of bounds
     199             :    * @throw UninitException in case the grid is not initialized (allocated)
     200             :    */
     201             :   const T &GetADC(Int_t col, Int_t row) const;
     202             : 
     203             :   /**
     204             :    * Get the number of columns in the map
     205             :    * @return The number of colums
     206             :    */
     207           0 :   Int_t GetNumberOfCols() const { return fNCols; }
     208             : 
     209             :   /**
     210             :    * Get the number of rows in the map
     211             :    * @return
     212             :    */
     213           0 :   Int_t GetNumberOfRows() const { return fNRows; }
     214             : 
     215             : protected:
     216             :   /**
     217             :    * Get grid index in the ADC value list
     218             :    * @param col Column of the grid
     219             :    * @param row Row of the grid
     220             :    * @return Grid index
     221             :    */
     222             :   Int_t GetIndex(Int_t col, Int_t row) const;
     223             : 
     224             :   Int_t                     fNCols;           ///< Number of columns
     225             :   Int_t                     fNRows;           ///< Number of rows
     226             :   T                         *fValues;         ///< Array of Trigger ADC values
     227             : 
     228             :   /// \cond
     229         110 :   ClassDef(AliEMCALTriggerDataGrid, 1);
     230             :   /// \endcond
     231             : };
     232             : 
     233             : 
     234             : #endif

Generated by: LCOV version 1.11