CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
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#include <vector>
18
19#include <iostream>
20#include "CLHEP/Matrix/defs.h"
21
22namespace CLHEP {
23
24class HepGenMatrix_row;
25class HepGenMatrix_row_const;
26class HepGenMatrix;
27
28/**
29 * @author
30 * @ingroup matrix
31 */
33
34public:
35 virtual ~HepGenMatrix() {}
36
37
38#ifdef DISABLE_ALLOC // disable this non-compliant allocator
39#else
40 template <class T, size_t size> class Alloc
41 {
42
43 public:
44 typedef T value_type;
45 typedef size_t size_type;
46 typedef ptrdiff_t difference_type;
47 typedef T* pointer;
48 typedef const T* const_pointer;
49 typedef T& reference;
50 typedef const T& const_reference;
51
52 pointer address(reference r) const { return &r; }
53 const_pointer address(const_reference r) const { return &r; }
54 Alloc() throw() {}
55 Alloc(const Alloc<T,size>&) throw() {}
56 ~Alloc() throw() {}
57 pointer allocate(size_type n, const void* hint=0 ) { if( n <= size ) return pool; else return new T[n]; }
58 void deallocate(pointer p, size_type n) { if (p == pool ) return; delete [] p; }
59 void construct(pointer p, const T& val ) { new(p) T(val); }
60 void destroy(pointer p) { p->~T(); }
61 size_type max_size() const throw() { size_type c = (size_type)(-1) /sizeof(T); return (0 < c ? c : 1); }
62 template<class O> struct rebind { typedef Alloc<O,size> other; };
63
64 private:
65 T pool[size];
66 };
67#endif
68
69#ifdef DISABLE_ALLOC
70 typedef std::vector<double >::iterator mIter;
71 typedef std::vector<double >::const_iterator mcIter;
72#else
73 typedef std::vector<double,Alloc<double,25> >::iterator mIter;
74 typedef std::vector<double,Alloc<double,25> >::const_iterator mcIter;
75#endif
76
77 virtual int num_row() const = 0;
78 virtual int num_col() const = 0;
79
80 virtual const double & operator()(int row, int col) const =0;
81 virtual double & operator()(int row, int col) =0;
82 // Read or write a matrix element.
83 // ** Note that the indexing starts from (1,1). **
84
85 virtual void invert(int&) = 0;
86
88 public:
90 double & operator[](int);
91 private:
92 HepGenMatrix& _a;
93 int _r;
94 };
96 public:
98 const double & operator[](int) const;
99 private:
100 const HepGenMatrix& _a;
101 int _r;
102 };
103 // helper classes to implement m[i][j]
104
106 inline const HepGenMatrix_row_const operator[] (int) const;
107 // Read or write a matrix element.
108 // While it may not look like it, you simply do m[i][j] to get an
109 // element.
110 // ** Note that the indexing starts from [0][0]. **
111
112 inline static void swap(int&,int&);
113#ifdef DISABLE_ALLOC
114 inline static void swap(std::vector<double >&, std::vector<double >&);
115#else
116 inline static void swap(std::vector<double,Alloc<double,25> >&, std::vector<double,Alloc<double,25> >&);
117#endif
118
119 virtual bool operator== ( const HepGenMatrix& ) const;
120 // equality operator for matrices (BaBar)
121
122 static void error(const char *s);
123
124protected:
125 virtual int num_size() const = 0;
126 void delete_m(int size, double*);
127 double* new_m(int size);
128
129public:
130 enum{size_max = 25};
131 // This is not the maximum size of the Matrix. It is the maximum length of
132 // the array (1D) which can be put on the pile.
133 //
134 // This enum used to be private, but it then is not accessible
135 // in the definition of array_pile in the .cc file for Sun CC 4.0.1.
137
138private:
139 void operator=(const HepGenMatrix &) {}
140 // Remove default operator for HepGenMatrix.
141
142 friend class HepGenMatrix_row;
144
145 //-ap: removed this as it is taken over by the std::vector<double>
146 //-ap double data_array[size_max];
147};
148
149double norm(const HepGenMatrix &m);
150double norm1(const HepGenMatrix &m);
151double norm_infinity(const HepGenMatrix &m);
152// 2, 1 or infinity-norm of a matrix.
153
154} // namespace CLHEP
155
156#ifdef ENABLE_BACKWARDS_COMPATIBILITY
157// backwards compatibility will be enabled ONLY in CLHEP 1.9
158using namespace CLHEP;
159#endif
160
161#ifndef HEP_DEBUG_INLINE
162#include "CLHEP/Matrix/GenMatrix.icc"
163#endif
164
165
166#endif
void construct(pointer p, const T &val)
Definition: GenMatrix.h:59
pointer address(reference r) const
Definition: GenMatrix.h:52
Alloc(const Alloc< T, size > &)
Definition: GenMatrix.h:55
const_pointer address(const_reference r) const
Definition: GenMatrix.h:53
void destroy(pointer p)
Definition: GenMatrix.h:60
pointer allocate(size_type n, const void *hint=0)
Definition: GenMatrix.h:57
void deallocate(pointer p, size_type n)
Definition: GenMatrix.h:58
size_type max_size() const
Definition: GenMatrix.h:61
HepGenMatrix_row_const(const HepGenMatrix &, int)
HepGenMatrix_row(HepGenMatrix &, int)
virtual int num_row() const =0
virtual int num_size() const =0
virtual void invert(int &)=0
virtual ~HepGenMatrix()
Definition: GenMatrix.h:35
virtual bool operator==(const HepGenMatrix &) const
Definition: GenMatrix.cc:77
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 > > &)
static void swap(int &, int &)
virtual const double & operator()(int row, int col) const =0
std::vector< double, Alloc< double, 25 > >::const_iterator mcIter
Definition: GenMatrix.h:74
std::vector< double, Alloc< double, 25 > >::iterator mIter
Definition: GenMatrix.h:73
static void error(const char *s)
Definition: GenMatrix.cc:70
virtual int num_col() const =0
double * new_m(int size)
Definition: GenMatrix.cc:97
void delete_m(int size, double *)
Definition: GenMatrix.cc:88
double norm(const HepGenMatrix &m)
Definition: GenMatrix.cc:54
double norm1(const HepGenMatrix &m)
Definition: GenMatrix.cc:43
double norm_infinity(const HepGenMatrix &m)
Definition: GenMatrix.cc:31