CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Matrix/Matrix/GenMatrix.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // CLASSDOC OFF
3 // ---------------------------------------------------------------------------
4 // CLASSDOC ON
5 //
6 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
7 //
8 // This software written by Nobu Katayama and Mike Smyth, Cornell University.
9 //
10 // This is the definition of the HepGenMatrix, base class for HepMatrix,
11 // HepSymMatrix and HepDiagMatrix. This is an abstract cless.
12 // See definitions in Matrix.h, SymMatrix.h, DiagMatrix.h and Vector.h
13 
14 #ifndef _GENMatrix_H_
15 #define _GENMatrix_H_
16 
17 #ifdef GNUPRAGMA
18 #pragma interface
19 #endif
20 
21 #include <vector>
22 
23 #include <iostream>
24 #include "CLHEP/Matrix/defs.h"
25 
26 namespace CLHEP {
27 
28 class HepGenMatrix_row;
29 class HepGenMatrix_row_const;
30 class HepGenMatrix;
31 
36 class HepGenMatrix {
37 
38 public:
39  virtual ~HepGenMatrix() {}
40 
41 
42 #ifdef DISABLE_ALLOC // disable this non-compliant allocator
43 #else
44  template <class T, size_t size> class Alloc
45  {
46 
47  public:
48  typedef T value_type;
49  typedef size_t size_type;
50  typedef ptrdiff_t difference_type;
51  typedef T* pointer;
52  typedef const T* const_pointer;
53  typedef T& reference;
54  typedef const T& const_reference;
55 
56  pointer address(reference r) const { return &r; }
57  const_pointer address(const_reference r) const { return &r; }
58  Alloc() throw() {}
59  Alloc(const Alloc<T,size>&) throw() {}
60  ~Alloc() throw() {}
61  pointer allocate(size_type n, const void* hint=0 ) { if( n <= size ) return pool; else return new T[n]; }
62  void deallocate(pointer p, size_type n) { if (p == pool ) return; delete [] p; }
63  void construct(pointer p, const T& val ) { new(p) T(val); }
64  void destroy(pointer p) { p->~T(); }
65  size_type max_size() const throw() { size_type c = (size_type)(-1) /sizeof(T); return (0 < c ? c : 1); }
66  template<class O> struct rebind { typedef Alloc<O,size> other; };
67 
68  private:
69  T pool[size];
70  };
71 #endif
72 
73 #ifdef DISABLE_ALLOC
74  typedef std::vector<double >::iterator mIter;
75  typedef std::vector<double >::const_iterator mcIter;
76 #else
77  typedef std::vector<double,Alloc<double,25> >::iterator mIter;
78  typedef std::vector<double,Alloc<double,25> >::const_iterator mcIter;
79 #endif
80 
81  virtual int num_row() const = 0;
82  virtual int num_col() const = 0;
83 
84  virtual const double & operator()(int row, int col) const =0;
85  virtual double & operator()(int row, int col) =0;
86  // Read or write a matrix element.
87  // ** Note that the indexing starts from (1,1). **
88 
89  virtual void invert(int&) = 0;
90 
91  class HepGenMatrix_row {
92  public:
93  inline HepGenMatrix_row(HepGenMatrix&,int);
94  double & operator[](int);
95  private:
96  HepGenMatrix& _a;
97  int _r;
98  };
100  public:
101  inline HepGenMatrix_row_const (const HepGenMatrix&,int);
102  const double & operator[](int) const;
103  private:
104  const HepGenMatrix& _a;
105  int _r;
106  };
107  // helper classes to implement m[i][j]
108 
109  inline HepGenMatrix_row operator[] (int);
110  inline const HepGenMatrix_row_const operator[] (int) const;
111  // Read or write a matrix element.
112  // While it may not look like it, you simply do m[i][j] to get an
113  // element.
114  // ** Note that the indexing starts from [0][0]. **
115 
116  inline static void swap(int&,int&);
117 #ifdef DISABLE_ALLOC
118  inline static void swap(std::vector<double >&, std::vector<double >&);
119 #else
120  inline static void swap(std::vector<double,Alloc<double,25> >&, std::vector<double,Alloc<double,25> >&);
121 #endif
122 
123  virtual bool operator== ( const HepGenMatrix& ) const;
124  // equality operator for matrices (BaBar)
125 
126  static void error(const char *s);
127 
128 protected:
129  virtual int num_size() const = 0;
130  void delete_m(int size, double*);
131  double* new_m(int size);
132 
133 public:
134  enum{size_max = 25};
135  // This is not the maximum size of the Matrix. It is the maximum length of
136  // the array (1D) which can be put on the pile.
137  //
138  // This enum used to be private, but it then is not accessible
139  // in the definition of array_pile in the .cc file for Sun CC 4.0.1.
140  // efrank@upenn5.hep.upenn.edu
141 
142 private:
143  void operator=(const HepGenMatrix &) {}
144  // Remove default operator for HepGenMatrix.
145 
146  friend class HepGenMatrix_row;
147  friend class HepGenMatrix_row_const;
148 
149  //-ap: removed this as it is taken over by the std::vector<double>
150  //-ap double data_array[size_max];
151 };
152 
153 double norm(const HepGenMatrix &m);
154 double norm1(const HepGenMatrix &m);
155 double norm_infinity(const HepGenMatrix &m);
156 // 2, 1 or infinity-norm of a matrix.
157 
158 } // namespace CLHEP
159 
160 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
161 // backwards compatibility will be enabled ONLY in CLHEP 1.9
162 using namespace CLHEP;
163 #endif
164 
165 #ifndef HEP_DEBUG_INLINE
166 #include "CLHEP/Matrix/GenMatrix.icc"
167 #endif
168 
169 
170 #endif
CLHEP::HepGenMatrix::Alloc
Definition: Matrix/CLHEP/Matrix/GenMatrix.h:44
CLHEP::HepGenMatrix::Alloc::Alloc
Alloc()
Definition: Matrix/Matrix/GenMatrix.h:58
CLHEP::HepGenMatrix::Alloc::const_reference
const typedef T & const_reference
Definition: Matrix/CLHEP/Matrix/GenMatrix.h:54
CLHEP::HepGenMatrix::Alloc::destroy
void destroy(pointer p)
Definition: Matrix/Matrix/GenMatrix.h:64
CLHEP::HepGenMatrix::Alloc::~Alloc
~Alloc()
Definition: Matrix/Matrix/GenMatrix.h:60
CLHEP::HepGenMatrix::num_row
virtual int num_row() const =0
CLHEP::HepGenMatrix::invert
virtual void invert(int &)=0
CLHEP::HepGenMatrix::Alloc::reference
T & reference
Definition: Matrix/Matrix/GenMatrix.h:53
CLHEP::HepGenMatrix
Definition: Matrix/CLHEP/Matrix/GenMatrix.h:36
CLHEP::HepGenMatrix::num_col
virtual int num_col() const =0
CLHEP::HepGenMatrix::operator()
virtual const double & operator()(int row, int col) const =0
CLHEP::HepGenMatrix::Alloc::address
const_pointer address(const_reference r) const
Definition: Matrix/Matrix/GenMatrix.h:57
CLHEP::HepGenMatrix::Alloc::rebind
Definition: Matrix/CLHEP/Matrix/GenMatrix.h:66
CLHEP::HepGenMatrix::Alloc::const_pointer
const typedef T * const_pointer
Definition: Matrix/CLHEP/Matrix/GenMatrix.h:52
CLHEP::HepGenMatrix::Alloc::difference_type
ptrdiff_t difference_type
Definition: Matrix/Matrix/GenMatrix.h:50
CLHEP::HepGenMatrix::size_max
@ size_max
Definition: Matrix/CLHEP/Matrix/GenMatrix.h:134
CLHEP::HepGenMatrix::Alloc::construct
void construct(pointer p, const T &val)
Definition: Matrix/Matrix/GenMatrix.h:63
CLHEP::detail::n
n
Definition: Ranlux64Engine.cc:85
size
user code seldom needs to call this function directly ZMerrno whether or not they are still recorded ZMerrno size() Return the(integer) number of ZMthrow 'n exceptions currently recorded. 5) ZMerrno.clear() Set an internal counter to zero. This counter is available(see next function) to user code to track ZMthrow 'n exceptions that have occurred during any arbitrary time interval. 6) ZMerrno.countSinceCleared() Return the(integer) number of ZMthrow 'n exceptions that have been recorded via ZMerrno.write()
CLHEP::HepGenMatrix::Alloc::allocate
pointer allocate(size_type n, const void *hint=0)
Definition: Matrix/Matrix/GenMatrix.h:61
CLHEP::HepGenMatrix::swap
static void swap(int &, int &)
CLHEP::HepGenMatrix::Alloc::deallocate
void deallocate(pointer p, size_type n)
Definition: Matrix/Matrix/GenMatrix.h:62
CLHEP::HepGenMatrix::HepGenMatrix_row_const
friend class HepGenMatrix_row_const
Definition: Matrix/CLHEP/Matrix/GenMatrix.h:147
CLHEP::HepGenMatrix::Alloc::Alloc
Alloc(const Alloc< T, size > &)
Definition: Matrix/Matrix/GenMatrix.h:59
CLHEP
Definition: ClhepVersion.h:13
CLHEP::HepGenMatrix::HepGenMatrix_row::HepGenMatrix_row
HepGenMatrix_row(HepGenMatrix &, int)
CLHEP::HepGenMatrix::mcIter
std::vector< double, Alloc< double, 25 > >::const_iterator mcIter
Definition: Matrix/CLHEP/Matrix/GenMatrix.h:78
CLHEP::HepGenMatrix::~HepGenMatrix
virtual ~HepGenMatrix()
Definition: Matrix/Matrix/GenMatrix.h:39
CLHEP::HepGenMatrix::operator[]
HepGenMatrix_row operator[](int)
CLHEP::HepGenMatrix::HepGenMatrix_row::operator[]
double & operator[](int)
CLHEP::HepGenMatrix::num_size
virtual int num_size() const =0
CLHEP::HepGenMatrix::HepGenMatrix_row_const::operator[]
const double & operator[](int) const
CLHEP::HepGenMatrix::Alloc::size_type
size_t size_type
Definition: Matrix/Matrix/GenMatrix.h:49
CLHEP::HepGenMatrix::mIter
std::vector< double, Alloc< double, 25 > >::iterator mIter
Definition: Matrix/CLHEP/Matrix/GenMatrix.h:77
CLHEP::HepGenMatrix::HepGenMatrix_row
Definition: Matrix/CLHEP/Matrix/GenMatrix.h:91
CLHEP::HepGenMatrix::Alloc::max_size
size_type max_size() const
Definition: Matrix/Matrix/GenMatrix.h:65
CLHEP::HepGenMatrix::Alloc::pointer
T * pointer
Definition: Matrix/Matrix/GenMatrix.h:51
CLHEP::HepGenMatrix::Alloc::address
pointer address(reference r) const
Definition: Matrix/Matrix/GenMatrix.h:56
CLHEP::HepGenMatrix::error
static void error(const char *s)
Definition: GenMatrix.cc:73
CLHEP::HepGenMatrix::new_m
double * new_m(int size)
Definition: GenMatrix.cc:100
CLHEP::HepGenMatrix::HepGenMatrix_row_const::HepGenMatrix_row_const
HepGenMatrix_row_const(const HepGenMatrix &, int)
CLHEP::HepGenMatrix::HepGenMatrix_row
friend class HepGenMatrix_row
Definition: Matrix/CLHEP/Matrix/GenMatrix.h:146
CLHEP::HepGenMatrix::Alloc::value_type
T value_type
Definition: Matrix/Matrix/GenMatrix.h:48
CLHEP::HepGenMatrix::Alloc::rebind::other
Alloc< O, size > other
Definition: Matrix/Matrix/GenMatrix.h:66
CLHEP::HepGenMatrix::delete_m
void delete_m(int size, double *)
Definition: GenMatrix.cc:91
CLHEP::norm_infinity
double norm_infinity(const HepGenMatrix &m)
Definition: GenMatrix.cc:34
CLHEP::norm
double norm(const HepGenMatrix &m)
Definition: GenMatrix.cc:57
CLHEP::norm1
double norm1(const HepGenMatrix &m)
Definition: GenMatrix.cc:46
CLHEP::HepGenMatrix::operator==
virtual bool operator==(const HepGenMatrix &) const
Definition: GenMatrix.cc:80