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
26namespace CLHEP {
27
28class HepGenMatrix_row;
29class HepGenMatrix_row_const;
30class HepGenMatrix;
31
36class HepGenMatrix {
37
38public:
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:
94 double & operator[](int);
95 private:
96 HepGenMatrix& _a;
97 int _r;
98 };
100 public:
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
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
128protected:
129 virtual int num_size() const = 0;
130 void delete_m(int size, double*);
131 double* new_m(int size);
132
133public:
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
142private:
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
153double norm(const HepGenMatrix &m);
154double norm1(const HepGenMatrix &m);
155double 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
162using namespace CLHEP;
163#endif
164
165#ifndef HEP_DEBUG_INLINE
166#include "CLHEP/Matrix/GenMatrix.icc"
167#endif
168
169
170#endif
void construct(pointer p, const T &val)
pointer address(reference r) const
Alloc(const Alloc< T, size > &)
const_pointer address(const_reference r) const
pointer allocate(size_type n, const void *hint=0)
void deallocate(pointer p, size_type n)
HepGenMatrix_row_const(const HepGenMatrix &, int)
HepGenMatrix_row(HepGenMatrix &, int)
virtual int num_row() const =0
virtual int num_size() const =0
std::vector< double, Alloc< double, 25 > >::iterator mIter
virtual void invert(int &)=0
static void error(const char *s)
virtual bool operator==(const HepGenMatrix &) const
Definition GenMatrix.cc:80
virtual double & operator()(int row, int col)=0
HepGenMatrix_row operator[](int)
static void swap(std::vector< double, Alloc< double, 25 > > &, std::vector< double, Alloc< double, 25 > > &)
std::vector< double, Alloc< double, 25 > >::const_iterator mcIter
static void swap(int &, int &)
virtual const double & operator()(int row, int col) const =0
virtual int num_col() const =0
double * new_m(int size)
void delete_m(int size, double *)
double norm(const HepGenMatrix &m)
Definition GenMatrix.cc:57
double norm1(const HepGenMatrix &m)
Definition GenMatrix.cc:46
double norm_infinity(const HepGenMatrix &m)
Definition GenMatrix.cc:34