/********************************************************************** * * * Copyright (c) 2003 INFN - Sezione di Napoli * * * * For more information (including a list of authors) see * * the README file * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this library (see file COPYING); if not, write to the * * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * * Boston, MA 02111-1307 USA, or contact the authors. * * * **********************************************************************/ #include #include #include #include using namespace std; #include "makeHeader.h" #include "combinations.h" struct makeHeader_Independent : makeHeader { makeHeader_Independent( ostream& out, int n ) : makeHeader ( out ) { copyrightNotice(); head( "INDEPENDENT_H" ); _out << "#include \"StatTools/Pdf/Arguments.h\"\n" << "#include \"StatTools/Pdf/RandomGenerator.h\"\n"; ns( "Pdf" ); _out << "template< typename F, int n = F::vars >\n" << "struct Independent1 { };\n\n"; for ( int i = 1; i <= n; i++ ) { _out << "template< typename F >\n" << "struct Independent1< F, " << i << " > : \n" << " public InheritArguments < F > {\n" << " typedef F F0;\n" << " typedef Independent1< F, " << i << " > I;\n" << " Independent1( const F & f ) : _f ( &f ) { }\n" << " double operator() ( "; list2 ( "typename I::arg", i, " x" ); _out << " ) const\n" << " { return (*_f)( "; list ( "x", i ); _out << " ); }\n" << " const F& f() const { return *_f; }\n" << "private:\n" << " const F * _f;\n" << "};\n\n"; } _out << "template< typename F, typename C, int n = F::vars, int c = C::vars >\n" << "struct IndependentC { };\n\n"; for ( int m = 2; m <= n; m ++ ) { combinations comb( 2, m ); for( combinations::const_iterator c = comb.begin(); c != comb.end(); c++ ) { const vector & v = *c; _out << "template< typename F, typename C >\n" << "struct IndependentC < F, C, " << v[ 0 ] << ", " << v[ 1 ] << " > :\n" << " public Arguments< "; list ( "typename F::arg", v[ 0 ] ); _out << ", "; list ( "typename C::arg", v[ 1 ] ); _out << " > {\n" << " enum { vars = F::vars + C::vars }; \n" << " typedef F F0;\n" << " typedef C FF;\n" << " typedef IndependentC< F, C, " << v[ 0 ] << ", " << v[ 1 ] << "> I;\n" << " IndependentC( const F& f, const C& c ) : _f( &f ), _c( c ) { }\n" << " double operator()( "; list2 ( "typename I::arg", m, " x" ); _out << " ) const\n" << " { return (*_f)( "; list ( "x", v[ 0 ] ); _out << " ) * _c( "; list ( "x", v[ 0 ], v[ 0 ] + v[ 1 ] - 1 ); _out << " ); }\n" << " const F& f() const { return *_f; }\n" << " const FF& ff() const { return _c; }\n" << "protected:\n" << " const F* _f;\n" << " C _c;\n" << "};\n\n"; } } for ( int m = 2; m <= n; m ++ ) { _out << "template< "; list ( "typename F", m ); _out << " >\n" << "struct Independent" << m << " :\n" << " public IndependentC< F0, Independent" << m - 1 << "< "; list ( "F", 1, m - 1 ); _out << " > > {\n" << " Independent" << m << "( "; list2 ( "const F", m, " & f" ); _out << " ) :\n" << " IndependentC< F0, Independent" << m - 1 << "< "; list ( "F", 1, m - 1 ); _out << " > > \n" << " ( f0, Independent" << m - 1 << "< "; list ( "F", 1, m - 1 ); _out << " > ( "; list ( "f", 1, m - 1 ); _out << " ) )\n" << " { }\n" << "};\n\n"; } for ( int m = n; m >= 1; m -- ) { _out << "template<\n"; if ( n != m ) list ( " typename F", m, "", ",\n" ); else list ( " typename F", m, " = null_arg", ",\n" ); _out << "\n" << " >\n" << "struct Independent"; if ( n != m ) { _out << "< "; list( "F", m ); _out << ", "; repeat ( "null_arg", n - m ); _out << " >"; } _out << " :\n" << " public Independent" << m << "< "; list( "F", m ); _out << " > {\n" << " Independent( "; list2( "const F", m, " & f" ); _out << " ) :\n" << " Independent" << m << "< "; list( "F", m ); _out << " > ( "; list( "f", m ); _out << " )\n" << " { }\n" << "};\n\n"; } foot(); } }; int main( int argc, char ** argv ) { const char * header ="Independent.h"; if ( argc == 2 ) { cout << " generating header file " << header << endl; istringstream str( argv[ 1 ] ); int n; str >> n; cout << " maximum numger of arguments for Pdf's is " << n << endl; ofstream file( header ); makeHeader_Independent( file, n ); return 0; } cout << "usage: " << argv[ 0 ] << " \n" << " : maximum number of pdf arguments" << endl; return 0; }