CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // -*- C++ -*- 00002 // CLASSDOC OFF 00003 // --------------------------------------------------------------------------- 00004 // CLASSDOC ON 00005 // 00006 // This file is a part of the CLHEP - a Class Library for High Energy Physics. 00007 // 00008 // This software written by Nobu Katayama and Mike Smyth, Cornell University. 00009 // 00010 // This is the definition of the HepGenMatrix, base class for HepMatrix, 00011 // HepSymMatrix and HepDiagMatrix. This is an abstract cless. 00012 // See definitions in Matrix.h, SymMatrix.h, DiagMatrix.h and Vector.h 00013 00014 #ifndef _GENMatrix_H_ 00015 #define _GENMatrix_H_ 00016 00017 #ifdef GNUPRAGMA 00018 #pragma interface 00019 #endif 00020 00021 #include <vector> 00022 00023 #include <iostream> 00024 #include "CLHEP/Matrix/defs.h" 00025 00026 namespace CLHEP { 00027 00028 class HepGenMatrix_row; 00029 class HepGenMatrix_row_const; 00030 class HepGenMatrix; 00031 00036 class HepGenMatrix { 00037 00038 public: 00039 virtual ~HepGenMatrix() {} 00040 00041 00042 #ifdef DISABLE_ALLOC // disable this non-compliant allocator 00043 #else 00044 template <class T, size_t size> class Alloc 00045 { 00046 00047 public: 00048 typedef T value_type; 00049 typedef size_t size_type; 00050 typedef ptrdiff_t difference_type; 00051 typedef T* pointer; 00052 typedef const T* const_pointer; 00053 typedef T& reference; 00054 typedef const T& const_reference; 00055 00056 pointer address(reference r) const { return &r; } 00057 const_pointer address(const_reference r) const { return &r; } 00058 Alloc() throw() {} 00059 Alloc(const Alloc<T,size>&) throw() {} 00060 ~Alloc() throw() {} 00061 pointer allocate(size_type n, const void* hint=0 ) { if( n <= size ) return pool; else return new T[n]; } 00062 void deallocate(pointer p, size_type n) { if (p == pool ) return; delete [] p; } 00063 void construct(pointer p, const T& val ) { new(p) T(val); } 00064 void destroy(pointer p) { p->~T(); } 00065 size_type max_size() const throw() { size_type c = (size_type)(-1) /sizeof(T); return (0 < c ? c : 1); } 00066 template<class O> struct rebind { typedef Alloc<O,size> other; }; 00067 00068 private: 00069 T pool[size]; 00070 }; 00071 #endif 00072 00073 #ifdef DISABLE_ALLOC 00074 typedef std::vector<double >::iterator mIter; 00075 typedef std::vector<double >::const_iterator mcIter; 00076 #else 00077 typedef std::vector<double,Alloc<double,25> >::iterator mIter; 00078 typedef std::vector<double,Alloc<double,25> >::const_iterator mcIter; 00079 #endif 00080 00081 virtual int num_row() const = 0; 00082 virtual int num_col() const = 0; 00083 00084 virtual const double & operator()(int row, int col) const =0; 00085 virtual double & operator()(int row, int col) =0; 00086 // Read or write a matrix element. 00087 // ** Note that the indexing starts from (1,1). ** 00088 00089 virtual void invert(int&) = 0; 00090 00091 class HepGenMatrix_row { 00092 public: 00093 inline HepGenMatrix_row(HepGenMatrix&,int); 00094 double & operator[](int); 00095 private: 00096 HepGenMatrix& _a; 00097 int _r; 00098 }; 00099 class HepGenMatrix_row_const { 00100 public: 00101 inline HepGenMatrix_row_const (const HepGenMatrix&,int); 00102 const double & operator[](int) const; 00103 private: 00104 const HepGenMatrix& _a; 00105 int _r; 00106 }; 00107 // helper classes to implement m[i][j] 00108 00109 inline HepGenMatrix_row operator[] (int); 00110 inline const HepGenMatrix_row_const operator[] (int) const; 00111 // Read or write a matrix element. 00112 // While it may not look like it, you simply do m[i][j] to get an 00113 // element. 00114 // ** Note that the indexing starts from [0][0]. ** 00115 00116 inline static void swap(int&,int&); 00117 #ifdef DISABLE_ALLOC 00118 inline static void swap(std::vector<double >&, std::vector<double >&); 00119 #else 00120 inline static void swap(std::vector<double,Alloc<double,25> >&, std::vector<double,Alloc<double,25> >&); 00121 #endif 00122 00123 virtual bool operator== ( const HepGenMatrix& ) const; 00124 // equality operator for matrices (BaBar) 00125 00126 static void error(const char *s); 00127 00128 protected: 00129 virtual int num_size() const = 0; 00130 void delete_m(int size, double*); 00131 double* new_m(int size); 00132 00133 public: 00134 enum{size_max = 25}; 00135 // This is not the maximum size of the Matrix. It is the maximum length of 00136 // the array (1D) which can be put on the pile. 00137 // 00138 // This enum used to be private, but it then is not accessible 00139 // in the definition of array_pile in the .cc file for Sun CC 4.0.1. 00140 // efrank@upenn5.hep.upenn.edu 00141 00142 private: 00143 void operator=(const HepGenMatrix &) {} 00144 // Remove default operator for HepGenMatrix. 00145 00146 friend class HepGenMatrix_row; 00147 friend class HepGenMatrix_row_const; 00148 00149 //-ap: removed this as it is taken over by the std::vector<double> 00150 //-ap double data_array[size_max]; 00151 }; 00152 00153 double norm(const HepGenMatrix &m); 00154 double norm1(const HepGenMatrix &m); 00155 double norm_infinity(const HepGenMatrix &m); 00156 // 2, 1 or infinity-norm of a matrix. 00157 00158 } // namespace CLHEP 00159 00160 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00161 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00162 using namespace CLHEP; 00163 #endif 00164 00165 #ifndef HEP_DEBUG_INLINE 00166 #include "CLHEP/Matrix/GenMatrix.icc" 00167 #endif 00168 00169 00170 #endif