CLHEP 2.0.4.7 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 // 00009 // Copyright Cornell University 1993, 1996, All Rights Reserved. 00010 // 00011 // This software written by Nobu Katayama and Mike Smyth, Cornell University. 00012 // 00013 // Redistribution and use in source and binary forms, with or without 00014 // modification, are permitted provided that the following conditions 00015 // are met: 00016 // 1. Redistributions of source code must retain the above copyright 00017 // notice and author attribution, this list of conditions and the 00018 // following disclaimer. 00019 // 2. Redistributions in binary form must reproduce the above copyright 00020 // notice and author attribution, this list of conditions and the 00021 // following disclaimer in the documentation and/or other materials 00022 // provided with the distribution. 00023 // 3. Neither the name of the University nor the names of its contributors 00024 // may be used to endorse or promote products derived from this software 00025 // without specific prior written permission. 00026 // 00027 // Creation of derivative forms of this software for commercial 00028 // utilization may be subject to restriction; written permission may be 00029 // obtained from Cornell University. 00030 // 00031 // CORNELL MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. By way 00032 // of example, but not limitation, CORNELL MAKES NO REPRESENTATIONS OR 00033 // WARRANTIES OF MERCANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT 00034 // THE USE OF THIS SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, 00035 // COPYRIGHTS, TRADEMARKS, OR OTHER RIGHTS. Cornell University shall not be 00036 // held liable for any liability with respect to any claim by the user or any 00037 // other party arising from use of the program. 00038 // 00039 // 00040 // This is the definition of the HepGenMatrix, base class for HepMatrix, 00041 // HepSymMatrix and HepDiagMatrix. This is an abstract cless. 00042 // See definitions in Matrix.h, SymMatrix.h, DiagMatrix.h and Vector.h 00043 00044 #ifndef _GENMatrix_H_ 00045 #define _GENMatrix_H_ 00046 00047 #ifdef GNUPRAGMA 00048 #pragma interface 00049 #endif 00050 00051 #include <vector> 00052 00053 #include <iostream> 00054 #include "CLHEP/Matrix/defs.h" 00055 00056 namespace CLHEP { 00057 00058 class HepGenMatrix_row; 00059 class HepGenMatrix_row_const; 00060 class HepGenMatrix; 00061 00066 class HepGenMatrix { 00067 00068 public: 00069 virtual ~HepGenMatrix() {} 00070 00071 00072 #ifdef DISABLE_ALLOC // disable this non-compliant allocator 00073 #else 00074 template <class T, size_t size> class Alloc 00075 { 00076 00077 public: 00078 typedef T value_type; 00079 typedef size_t size_type; 00080 typedef ptrdiff_t difference_type; 00081 typedef T* pointer; 00082 typedef const T* const_pointer; 00083 typedef T& reference; 00084 typedef const T& const_reference; 00085 00086 pointer address(reference r) const { return &r; } 00087 const_pointer address(const_reference r) const { return &r; } 00088 Alloc() throw() {} 00089 Alloc(const Alloc<T,size>&) throw() {} 00090 ~Alloc() throw() {} 00091 pointer allocate(size_type n, const void* hint=0 ) { if( n <= size ) return pool; else return new T[n]; } 00092 void deallocate(pointer p, size_type n) { if (p == pool ) return; delete [] p; } 00093 void construct(pointer p, const T& val ) { new(p) T(val); } 00094 void destroy(pointer p) { p->~T(); } 00095 size_type max_size() const throw() { size_type c = (size_type)(-1) /sizeof(T); return (0 < c ? c : 1); } 00096 template<class O> struct rebind { typedef Alloc<O,size> other; }; 00097 00098 private: 00099 T pool[size]; 00100 }; 00101 #endif 00102 00103 #ifdef DISABLE_ALLOC 00104 typedef std::vector<double >::iterator mIter; 00105 typedef std::vector<double >::const_iterator mcIter; 00106 #else 00107 typedef std::vector<double,Alloc<double,25> >::iterator mIter; 00108 typedef std::vector<double,Alloc<double,25> >::const_iterator mcIter; 00109 #endif 00110 00111 virtual int num_row() const = 0; 00112 virtual int num_col() const = 0; 00113 00114 virtual const double & operator()(int row, int col) const =0; 00115 virtual double & operator()(int row, int col) =0; 00116 // Read or write a matrix element. 00117 // ** Note that the indexing starts from (1,1). ** 00118 00119 virtual void invert(int&) = 0; 00120 00121 class HepGenMatrix_row { 00122 public: 00123 inline HepGenMatrix_row(HepGenMatrix&,int); 00124 double & operator[](int); 00125 private: 00126 HepGenMatrix& _a; 00127 int _r; 00128 }; 00129 class HepGenMatrix_row_const { 00130 public: 00131 inline HepGenMatrix_row_const (const HepGenMatrix&,int); 00132 const double & operator[](int) const; 00133 private: 00134 const HepGenMatrix& _a; 00135 int _r; 00136 }; 00137 // helper classes to implement m[i][j] 00138 00139 inline HepGenMatrix_row operator[] (int); 00140 inline const HepGenMatrix_row_const operator[] (int) const; 00141 // Read or write a matrix element. 00142 // While it may not look like it, you simply do m[i][j] to get an 00143 // element. 00144 // ** Note that the indexing starts from [0][0]. ** 00145 00146 inline static void swap(int&,int&); 00147 #ifdef DISABLE_ALLOC 00148 inline static void swap(std::vector<double >&, std::vector<double >&); 00149 #else 00150 inline static void swap(std::vector<double,Alloc<double,25> >&, std::vector<double,Alloc<double,25> >&); 00151 #endif 00152 00153 virtual bool operator== ( const HepGenMatrix& ) const; 00154 // equality operator for matrices (BaBar) 00155 00156 static void error(const char *s); 00157 00158 protected: 00159 virtual int num_size() const = 0; 00160 void delete_m(int size, double*); 00161 double* new_m(int size); 00162 00163 public: 00164 enum{size_max = 25}; 00165 // This is not the maximum size of the Matrix. It is the maximum length of 00166 // the array (1D) which can be put on the pile. 00167 // 00168 // This enum used to be private, but it then is not accessible 00169 // in the definition of array_pile in the .cc file for Sun CC 4.0.1. 00170 // efrank@upenn5.hep.upenn.edu 00171 00172 private: 00173 void operator=(const HepGenMatrix &) {} 00174 // Remove default operator for HepGenMatrix. 00175 00176 friend class HepGenMatrix_row; 00177 friend class HepGenMatrix_row_const; 00178 00179 //-ap: removed this as it is taken over by the std::vector<double> 00180 //-ap double data_array[size_max]; 00181 }; 00182 00183 double norm(const HepGenMatrix &m); 00184 double norm1(const HepGenMatrix &m); 00185 double norm_infinity(const HepGenMatrix &m); 00186 // 2, 1 or infinity-norm of a matrix. 00187 00188 } // namespace CLHEP 00189 00190 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00191 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00192 using namespace CLHEP; 00193 #endif 00194 00195 #ifndef HEP_DEBUG_INLINE 00196 #include "CLHEP/Matrix/GenMatrix.icc" 00197 #endif 00198 00199 00200 #endif