00001 // -*- C++ -*- 00002 // CLASSDOC OFF 00003 // $Id: GenMatrix.h,v 1.13 2002/04/12 15:02:44 evc Exp $ 00004 // --------------------------------------------------------------------------- 00005 // CLASSDOC ON 00006 // 00007 // This file is a part of the CLHEP - a Class Library for High Energy Physics. 00008 // 00009 // 00010 // Copyright Cornell University 1993, 1996, All Rights Reserved. 00011 // 00012 // This software written by Nobu Katayama and Mike Smyth, Cornell University. 00013 // 00014 // Redistribution and use in source and binary forms, with or without 00015 // modification, are permitted provided that the following conditions 00016 // are met: 00017 // 1. Redistributions of source code must retain the above copyright 00018 // notice and author attribution, this list of conditions and the 00019 // following disclaimer. 00020 // 2. Redistributions in binary form must reproduce the above copyright 00021 // notice and author attribution, this list of conditions and the 00022 // following disclaimer in the documentation and/or other materials 00023 // provided with the distribution. 00024 // 3. Neither the name of the University nor the names of its contributors 00025 // may be used to endorse or promote products derived from this software 00026 // without specific prior written permission. 00027 // 00028 // Creation of derivative forms of this software for commercial 00029 // utilization may be subject to restriction; written permission may be 00030 // obtained from Cornell University. 00031 // 00032 // CORNELL MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. By way 00033 // of example, but not limitation, CORNELL MAKES NO REPRESENTATIONS OR 00034 // WARRANTIES OF MERCANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT 00035 // THE USE OF THIS SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, 00036 // COPYRIGHTS, TRADEMARKS, OR OTHER RIGHTS. Cornell University shall not be 00037 // held liable for any liability with respect to any claim by the user or any 00038 // other party arising from use of the program. 00039 // 00040 // 00041 // This is the definition of the HepGenMatrix, base class for HepMatrix, 00042 // HepSymMatrix and HepDiagMatrix. This is an abstract cless. 00043 // See definitions in Matrix.h, SymMatrix.h, DiagMatrix.h and Vector.h 00044 00045 #ifndef _GENMatrix_H_ 00046 #define _GENMatrix_H_ 00047 00048 #ifdef GNUPRAGMA 00049 #pragma interface 00050 #endif 00051 00052 #include "CLHEP/config/CLHEP.h" 00053 #include "CLHEP/config/iostream.h" 00054 00055 class HepGenMatrix_row; 00056 class HepGenMatrix_row_const; 00057 class HepGenMatrix; 00058 00063 class HepGenMatrix { 00064 00065 public: 00066 virtual ~HepGenMatrix() {} 00067 00068 virtual int num_row() const = 0; 00069 virtual int num_col() const = 0; 00070 00071 virtual const double & operator()(int row, int col) const =0; 00072 virtual double & operator()(int row, int col) =0; 00073 // Read or write a matrix element. 00074 // ** Note that the indexing starts from (1,1). ** 00075 00076 virtual void invert(int&) = 0; 00077 00078 class HepGenMatrix_row { 00079 public: 00080 inline HepGenMatrix_row(HepGenMatrix&,int); 00081 double & operator[](int); 00082 private: 00083 HepGenMatrix& _a; 00084 int _r; 00085 }; 00086 class HepGenMatrix_row_const { 00087 public: 00088 inline HepGenMatrix_row_const (const HepGenMatrix&,int); 00089 const double & operator[](int) const; 00090 private: 00091 const HepGenMatrix& _a; 00092 int _r; 00093 }; 00094 // helper classes to implement m[i][j] 00095 00096 inline HepGenMatrix_row operator[] (int); 00097 inline const HepGenMatrix_row_const operator[] (int) const; 00098 // Read or write a matrix element. 00099 // While it may not look like it, you simply do m[i][j] to get an 00100 // element. 00101 // ** Note that the indexing starts from [0][0]. ** 00102 00103 inline static void swap(int&,int&); 00104 inline static void swap(double *&, double *&); 00105 00106 virtual bool operator== ( const HepGenMatrix& ) const; 00107 // equality operator for matrices (BaBar) 00108 00109 static void error(const char *s); 00110 00111 protected: 00112 virtual int num_size() const = 0; 00113 void delete_m(int size, double*); 00114 double* new_m(int size); 00115 00116 public: 00117 enum{size_max = 25}; 00118 // This is not the maximum size of the Matrix. It is the maximum length of 00119 // the array (1D) which can be put on the pile. 00120 // 00121 // This enum used to be private, but it then is not accessible 00122 // in the definition of array_pile in the .cc file for Sun CC 4.0.1. 00123 // efrank@upenn5.hep.upenn.edu 00124 00125 private: 00126 void operator=(const HepGenMatrix &) {} 00127 // Remove default operator for HepGenMatrix. 00128 00129 friend class HepGenMatrix_row; 00130 friend class HepGenMatrix_row_const; 00131 00132 double data_array[size_max]; 00133 00134 }; 00135 00136 double norm(const HepGenMatrix &m); 00137 double norm1(const HepGenMatrix &m); 00138 double norm_infinity(const HepGenMatrix &m); 00139 // 2, 1 or infinity-norm of a matrix. 00140 00141 #ifdef HEP_NO_INLINE_IN_DECLARATION 00142 #undef inline 00143 #endif 00144 00145 #ifdef HEP_SHORT_NAMES 00146 typedef HepGenMatrix GenMatrix; 00147 #endif 00148 00149 #ifndef HEP_DEBUG_INLINE 00150 #include "CLHEP/Matrix/GenMatrix.icc" 00151 #endif 00152 00153 00154 #endif