// Tuple.h #ifndef Tuple_H #define Tuple_H // Encapsulate ntuple definition. // // For forward declaration, use Tuple_fwd.h // // On plaforms which provide the FNAL package HepTuple, Tuple is // a typedef for class HepNtuple. If HepTuple is not available // (indicated by defining NO_HEPTUPLE), then CLHEP is used instead // and Tuple uses the CLHEP class HepTuple to implement part of // the HepNTuple interface. // #ifdef COMMENT // Here is an example of the part of the HepNTuple interface // that is supported with CLHEP. // Create ntuple. Tuple& tuple = hfile->ntuple("junk ntuple"); tuple.columnDirect("x",-100.); tuple.columnDirect("y", -100.); // Fill ntuple. for ( xvalues.begin(); xvalues.is_valid(); xvalues.next() ) { double x = xvalues.x(); if ( lprint ) cout << x << " " << fun(x) << endl; tuple.capture("x", x); tuple.capture("y", fun(x) ); tuple.storeCapturedData(); // if all data was captured // tuple.captureThenStore(); // if all data was not cptured above tuple.clearData(); } // Access tuple data int nrow = tuple.nrows(); // # rows #endif /* COMMENT */ //********************** HepTuple implementation ******************** #ifndef NO_HEPTUPLE #include "HepTuple/HepNtuple.h" typedef HepNtuple Tuple; //*********************** CLHEP implementation ********************** #else // The CLHEP implementation only encapsuates a small part of the // HepTuple interface. // // HepTuple users may use the full interface but should exclude // parts not defined here with the define NO_HEPTUPLE. // #include "CLHEP/Hist/Tuple.h" #include "ptr/Ptr.h" #include class Tuple { // attributes Ptr _phtup; // row counter int _nrow; public: // constructor // This is called by TupleManager. Tuple(HepTuple& htup) : _phtup(&htup), _nrow(0) { }; // Define a column. void columnDirect(string label, float defvalue) { _phtup->column(label.c_str(),0,defvalue); _phtup->clearData(); }; // Clear data (set values to defaults). void clearData() { _phtup->clearData(); }; // Capture data. bool capture (char nametag[], float value) { _phtup->column(nametag, value); return true; } // Store the captured data. bool storeCapturedData() { _phtup->dumpData(); ++_nrow; return true; }; // Store the captured data. bool captureThenStore() { ++_nrow; return storeCapturedData(); }; // Return the title of the ntuple. string title() const { const char* name = _phtup->title(); return string(name); }; // Return the number of rows. int nrows() const { return _nrow; } }; #endif /* CLHEP implementation */ #endif