// *********************************************************************** // HepNtuple-refine.cc - implementation of HepNtuple: routines // associated with refining a column. // // The following methods are in this file: // HepNtuple::pack // HepNtuple::span // HepNtuple::index // HepNtuple::dimension // HepNtuple::columnPacking // HepNtuple::columnSpan // HepNtuple::columnIndex // HepNtuple::columnDimensions // // *********************************************************************** #include "ZMutility/iostream" #include "HepTuple/HepFileManager.h" #include "HepTuple/HepNtuple.h" #include "HepTuple/Block.h" #include "HepTuple/Column.h" #include "HepTuple/TupleNameTag.h" #include USING( std::string ) ZM_BEGIN_NAMESPACE( zmht ) /* namespace zmht { */ // **************************************** // *** HepNtuple::pack() // **************************************** HepNtuple& HepNtuple::pack (const string& nametag, float low, float high, int nbits) { TupleNameTag tag; parseNameTag( tag, nametag); if (!tag.isValid()) { ZMthrow(ZMxHepUnknownColumn(string("Improper column name tag: ")+nametag)); isValid(false); return *this; } Column* col = findColumn(nametag); if ( !col ) { ZMthrow(ZMxHepUnknownColumn (string("Cannot refine a non-existent column: ")+nametag) ); return *this; } _currentColumn = col; if( col->setPacking(nbits, low, high) ) return *this; else { isValid(false); return *this; } } /* pack() */ HepNtuple& HepNtuple::pack (float low, float high, int nbits) { Column* col = currentColumn(); if ( col == NULL ) return *this; if( col->setPacking(nbits, low, high) ) return *this; else { isValid(false); return *this; } } /* pack() */ // **************************************** // *** HepNtuple::span() // **************************************** HepNtuple& HepNtuple::span (const string& nametag, int min, int max) { TupleNameTag tag; parseNameTag( tag, nametag); if (!tag.isValid()) { ZMthrow(ZMxHepUnknownColumn(string("Improper column name tag: ")+nametag)); return *this; } Column* col = findColumn(nametag); if ( !col ) { ZMthrow(ZMxHepUnknownColumn (string("Cannot refine a non-existent column: ")+nametag) ); return *this; } _currentColumn = col; if( ! col->setSpan(min, max) ) isValid(false); return *this; } /* span() */ HepNtuple& HepNtuple::span (int min, int max) { Column* col = currentColumn(); if ( col == NULL ) return *this; if( ! col->setSpan(min, max) ) isValid(false); return *this; } /* span() */ // **************************************** // *** HepNtuple::index() // **************************************** HepNtuple& HepNtuple::index (const string& nametag, const string& indextag) { TupleNameTag tag; parseNameTag( tag, nametag); if (!tag.isValid()) { ZMthrow(ZMxHepUnknownColumn(string("Improper column name tag: ")+nametag)); return *this; } Column* col = findColumn(nametag); if ( !col ) { ZMthrow(ZMxHepUnknownColumn (string("Cannot refine a non-existent column: ")+nametag) ); return *this; } _currentColumn = col; return index(indextag); } /* index() */ HepNtuple& HepNtuple::index (const string& indextag) { Column* col = currentColumn(); if ( col == NULL ) return *this; TupleNameTag tag; parseNameTag( tag, indextag); if (!tag.isValid()) { ZMthrow(ZMxHepUnknownColumn (string("Improper column name tag: ")+indextag)); isValid(false); return *this; } // Now see if the target tag exist. Column* index = col->block()->findColumn(tag.column()); if ( !index ) { ZMthrow(ZMxHepUnknownColumn (string("Cannot set index to a non-existent column: ")+indextag) ); return *this; } if ( col == index ) { ZMthrow(ZMxHepImproperUse (string("Index and column must be different: ") +indextag) ); isValid(false); return *this; } if ( col->block() != index->block() ) { ZMthrow(ZMxHepImproperUse (string("Index and column array have to be in the same block: ") +indextag) ); isValid(false); return *this; } index->isIndex(true); if( ! col->setIndex(indextag) ) isValid(false); return *this; } /* index() */ // **************************************** // *** HepNtuple::dimension() // **************************************** HepNtuple& HepNtuple::dimension (const string& nametag, int dim) { TupleNameTag tag; parseNameTag( tag, nametag); if (!tag.isValid()) { ZMthrow(ZMxHepUnknownColumn(string("Improper column name tag: ")+nametag)); return *this; } Column* col = findColumn(nametag); if ( !col ) { ZMthrow(ZMxHepUnknownColumn (string("Cannot refine a non-existent column: ")+nametag) ); return *this; } _currentColumn = col; if( ! col->setDimension(dim, 0, 0, 0, 0, 0, 0, 0, 0, 0) ) isValid(false); return *this; } /* dimension() */ HepNtuple& HepNtuple::dimension (int dim) { Column* col = currentColumn(); if ( col == NULL ) return *this; if( ! col->setDimension(dim, 0, 0, 0, 0, 0, 0, 0, 0, 0) ) isValid(false); return *this; } /* dimension() */ HepNtuple& HepNtuple::dimension (const string& nametag, int dim1, int dim2, int dim3, int dim4, int dim5, int dim6, int dim7, int dim8, int dim9, int dim10) { TupleNameTag tag; parseNameTag( tag, nametag); if (!tag.isValid()) { ZMthrow(ZMxHepUnknownColumn(string("Improper column name tag: ")+nametag)); return *this; } Column* col = findColumn(nametag); if ( !col ) { ZMthrow(ZMxHepUnknownColumn (string("Cannot refine a non-existent column: ")+nametag) ); return *this; } _currentColumn = col; if( ! col->setDimension(dim1,dim2,dim3,dim4,dim5,dim6,dim7,dim8,dim9,dim10) ) isValid(false); return *this; } /* dimension() */ HepNtuple& HepNtuple::dimension (int dim1, int dim2, int dim3, int dim4, int dim5, int dim6, int dim7, int dim8, int dim9, int dim10) { Column* col = currentColumn(); if ( col == NULL ) return *this; if( ! col->setDimension(dim1,dim2,dim3,dim4,dim5,dim6,dim7,dim8,dim9,dim10) ) isValid(false); return *this; } /* dimension() */ // **************************************** // *** HepNtuple::columnPacking() // **************************************** bool HepNtuple::columnPacking (const string& nametag, float* low, float* high, int* inbits) const { TupleNameTag tag; parseNameTag( tag, nametag); if (!tag.isValid()) { ZMthrow(ZMxHepUnknownColumn(string("Improper column name tag: ")+nametag)); return false; } Column* col = findColumn(nametag); if ( !col ) { ZMthrow(ZMxHepUnknownColumn (string("Cannot get info on a non-existent column: ")+nametag) ); return false; } return col->getPacking(inbits, low, high); } /* columnPacking() */ // **************************************** // *** HepNtuple::columnSpan() // **************************************** bool HepNtuple::columnSpan (const string& nametag, int* min, int* max) const { TupleNameTag tag; parseNameTag( tag, nametag); if (!tag.isValid()) { ZMthrow(ZMxHepUnknownColumn(string("Improper column name tag: ")+nametag)); return false; } Column* col = findColumn(nametag); if ( !col ) { ZMthrow(ZMxHepUnknownColumn (string("Cannot get info on a non-existent column: ")+nametag) ); return false; } _currentColumn = col; return col->getSpan(min, max); } /* columnSpan() */ // **************************************** // *** HepNtuple::columnIndex() // **************************************** string HepNtuple::columnIndex (const string& nametag) const { TupleNameTag tag; parseNameTag( tag, nametag); if (!tag.isValid()) { ZMthrow(ZMxHepUnknownColumn(string("Improper column name tag: ")+nametag)); return 0; } Column* col = findColumn(nametag); if ( !col ) { ZMthrow(ZMxHepUnknownColumn (string("Cannot get info on a non-existent column: ")+nametag) ); return 0; } _currentColumn = col; return col->getIndex(); } /* columnIndex() */ // **************************************** // *** HepNtuple::columnDimensions() // **************************************** int HepNtuple::columnDimensions (const string& nametag, int dims[] ) const { TupleNameTag tag; parseNameTag( tag, nametag); if (!tag.isValid()) { ZMthrow(ZMxHepUnknownColumn(string("Improper column name tag: ")+nametag)); return 0; } Column* col = findColumn(nametag); if ( !col ) { ZMthrow(ZMxHepUnknownColumn (string("Cannot get info on a non-existent column: ")+nametag) ); return 0; } _currentColumn = col; return col->getDimension(dims); } /* columnDimensions() */ ZM_END_NAMESPACE( zmht ) /* } // namespace zmht */