/[PAMELA software]/PamCut/CommonDefs.h
ViewVC logotype

Annotation of /PamCut/CommonDefs.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Tue Oct 27 10:26:40 2009 UTC (15 years, 1 month ago) by pam-fi
Branch: MAIN
Changes since 1.4: +1 -1 lines
File MIME type: text/plain
Default parameters for SimpleMatrix constructor added.

1 pam-fi 1.1 /*
2     * CommonDefs.h
3     *
4     * Created on: 10-mar-2009
5     * Author: Nicola Mori
6     */
7    
8     /*! @file CommonDefs.h A header file with all the common definitions for the PamCut framework.
9     */
10    
11     #ifndef COMMONDEFS_H_
12     #define COMMONDEFS_H_
13    
14     /*! @brief The implementations of PamCut::Check() must return this value if the event satisfy the cut*/
15     const int CUTOK = -1;
16    
17     /*! @enum DETECTORCODE
18     * The values for each detector correspond to a binary code associated to that detector.
19     * These can be arithmetically added to create a binary code for a set of detectors.
20     */
21     enum DETECTORCODE {
22     TRK = 1, ///< Code for Tracker
23 pam-fi 1.2 CALO = 2, ///< Code for Calorimeter level2
24 pam-fi 1.1 TOF = 4, ///< Code for ToF
25     AC = 8, ///< Code for AntiCoincidence
26     TRIG = 16, ///< Code for Trigger
27     ORB = 32, ///< Code for Orbital Info
28 pam-fi 1.2 ALL = 63, ///< Sum of all the above codes
29 pam-fi 1.3 CALO_L1 = 64
30     ///< Code for Calorimeter level1
31 pam-fi 1.2 };
32    
33 pam-fi 1.4 /*! @enum TOFLAYERS Flags to identify layers. */
34     enum TOFLAYERS {
35     S11 = 1, ///< S11.
36     S12 = 2, ///< S12.
37     S21 = 4, ///< S21.
38     S22 = 8, ///< S22.
39     S31 = 16, ///< S31.
40     S32 = 32
41     ///< S32.
42     };
43    
44 pam-fi 1.2 /*! @var TOFNPADLAYER
45     * The number of pads in each ToF layer. S11 corresponds to element 0, S12 to element 1 and so on.
46     */
47     const int TOFNPADLAYER[6] = { 8, 6, 2, 2, 3, 3 };
48    
49     /*! @brief A simple matrix class.
50     *
51     * This class defines a matrix built by STL vectors. It is basically a variable-dimension
52 pam-fi 1.3 * vector of vectors. It is intended as a container and not for algebraic manipulations.
53     * The class provides a standard access operator [] and a resize method.
54 pam-fi 1.2 */
55     template<class T>
56     class SimpleMatrix {
57    
58     public:
59     /*! @brief Constructor
60     *
61     * The constructor will build an nRows x nCols matrix, initialized with a default value. If T
62     * is a class with no default constructor, a default value for T must be provided, which will
63     * be replicated in every matrix element.
64     *
65     * @param nRows The number of rows.
66     * @param nCols The number of columns
67     * @param elements The initialization value for the matrix elements.
68     */
69 pam-fi 1.5 SimpleMatrix(unsigned int nRows = 0, unsigned int nCols = 0, T elements = T()) :
70 pam-fi 1.3 _matrix(nRows, std::vector<T>(nCols, elements)) {
71 pam-fi 1.2
72     }
73    
74     /*! @brief Standard accessor.
75     *
76     * @param i The desired row.
77     * @return The i-th row (a vector).
78     */
79     std::vector<T>& operator[](int i) {
80     return _matrix[i];
81     }
82    
83     /*! @brief Returns the number of rows.
84     *
85     * @return The number of rows.
86     */
87     unsigned int GetNRows() {
88 pam-fi 1.3 return _matrix.size();
89 pam-fi 1.2 }
90    
91     /*! @brief Returns the number of columns.
92     *
93     * @return The number of columns.
94     */
95     unsigned int GetNCols() {
96 pam-fi 1.3 return _matrix[0].size();
97     }
98    
99     /*! @brief Resizes the matrix.
100     *
101     * If new rows or columns are added, they are initialized to the default value; if T
102     * is a class with no default constructor, a default value for T must be provided, which will
103     * be replicated in every new matrix element. No modification
104     * is done to existing elements (except for those that will be eventually removed).
105     *
106     * @param nRows The new number of rows.
107     * @param nCols The new number of columns.
108     * @param elements The initialization value for the new matrix elements.
109     */
110     void Resize(unsigned int nRows, unsigned int nCols, T elements = T()) {
111    
112     _matrix.resize(nRows, std::vector<T>(nCols, elements));
113     for (unsigned int i = 0; i < _matrix.size(); i++)
114     _matrix[i].resize(nCols, elements);
115 pam-fi 1.2 }
116    
117     private:
118    
119     std::vector<std::vector<T> > _matrix;
120 pam-fi 1.1 };
121    
122     #endif /* COMMONDEFS_H_ */

  ViewVC Help
Powered by ViewVC 1.1.23