#include "HepTuple/HepNtuple.h" #include "HepTuple/Column.h" #include "HepTuple/ColumnT.h" #include "HepTuple/Block.h" #include #include USING( std::string ) ZM_BEGIN_NAMESPACE( zmht ) /* namespace zmht { */ // The following is use to set the strorage strategy. bool HepNtuple::setRowWise () { if ( isRowWise() ) { return true; } if ( isRowWiseEnabled() ) { changedDefinition(); return setStorageGeometry(ROW); } else { return false; } } bool HepNtuple::setColumnWise () { if ( isColumnWise() ) { return true; } if ( isColumnWiseEnabled() ) { changedDefinition(); return setStorageGeometry(COLUMN); } else { return false; } } bool HepNtuple::setBlockWise () { if ( isBlockWise() ) { return true; } if ( isBlockWiseEnabled() ) { changedDefinition(); return setStorageGeometry(BLOCK); } else { return false; } } bool HepNtuple::isRowWise() const { return ( storageGeometry() == ROW ); } bool HepNtuple::isColumnWise() const { return ( storageGeometry() == COLUMN ); } bool HepNtuple::isBlockWise() const { return ( storageGeometry() == BLOCK ); } HepNtuple::StorageGeometryName HepNtuple::storageGeometry() const { return _storageGeometry; } // simpleminded mutable accessor to the strategy ... it does // NOT verify if the newStrategy is possible. Use the // specify setter for that (setRowWise, setColumnWise etc...) bool HepNtuple::setStorageGeometry(StorageGeometryName newStrategy) { _storageGeometry = newStrategy; return true; } // ************************************************************************* // // // The following is for setting the storage location // // ************************************************************************* // bool HepNtuple::setDiskResident () { if ( resident() == 'D' ) { return true; } if ( isDiskResidentEnabled() ) { changedDefinition(); return setStorageLocation('D'); } else { return false; } } bool HepNtuple::setMemResident () { if ( resident() == 'M' ) { return true; } if ( isMemResidentEnabled() ) { changedDefinition(); return setStorageLocation('M'); } else { return false; } } bool HepNtuple::setSharedMemory (char sharedMemoryArea[]) { if ( resident() == 'S' ) { return true; } if ( isSharedMemoryEnabled() ) { changedDefinition(); return (setStorageLocation('S') && setSharedMemoryName(sharedMemoryArea)); } else { return false; } } unsigned char HepNtuple::resident() const { return _storageLocation; } bool HepNtuple::setStorageLocation(unsigned char newLocation) { _storageLocation = newLocation; return true; } bool HepNtuple::setSharedMemoryName(char sharedMemoryArea[]) { _sharedMemoryAreaName = sharedMemoryArea; return true; } // ****************************************************************** // // // // The following is for setting the size and style of memory storage // // // // ****************************************************************** // bool HepNtuple::setNwbuff (int newNwbuff) { if ( nwbuff() == newNwbuff ) { return true; } if ( isNwbuffEnabled(newNwbuff) ) { changedDefinition(); return setNwbuffValue(newNwbuff); } else { return false; } } int HepNtuple::nwbuff () const { return _nwbuff; } bool HepNtuple::setNwbuffValue (int newNwbuff) { _nwbuff = newNwbuff; return true; } bool HepNtuple::setBuffLimit (int nbytes) { if ( buffLimit() == nbytes ) { return true; } if ( isBuffLimitEnabled( nbytes) ) { changedDefinition(); return setBuffLimitValue( nbytes); } else { return false; } } int HepNtuple::buffLimit () const { return _buffLimit; } bool HepNtuple::setBuffLimitValue (int nbytes) { _buffLimit = nbytes; return true; } bool HepNtuple::setCircularBuffer (int newNwbuff) { if ( isCircularBuffer() ) { return true; } if ( isCircularBufferEnabled() ) { // setNwbuff is put first so that so NOTHING is set // if setNwbuff shall return false. changedDefinition(); return (setNwbuff(newNwbuff) && setBufferType(CIRCULAR) ); } else { return false; } } bool HepNtuple::isCircularBuffer() const { return (bufferType() == CIRCULAR); } bool HepNtuple::setDemandBuffers (int newNbytes) { if ( isDemandBuffers() ) { return true; } if ( isDemandBuffersEnabled() ) { // setNwbuff is put first so that so NOTHING is set // if setNwbuff shall return false. changedDefinition(); return (setBuffLimit(newNbytes) && setBufferType(DEMAND) ); } else { return false; } } bool HepNtuple::isDemandBuffers() const { return (bufferType() == DEMAND); } HepNtuple::BufferTypeName HepNtuple::bufferType() const { return _bufferType; } bool HepNtuple::setBufferType(BufferTypeName type) { _bufferType = type; return true; } // ************************************************************************* // // // The following is for getting simple information about Columns in the // HepNtuple // // ************************************************************************* // int HepNtuple::nColumns() const { return columns.size(); } int HepNtuple::nColumns(const string& blockname) const { Block *bk = findBlock(blockname); if ( bk == NULL ) { ZMthrow(ZMxHepUnknownBlock("blockname")); return 0; } return bk->nColumns(); } // Obtain the nametag (which can include blockname::tag), or just the column // tag, of the n-th column in the HepTUple, or the n-th column in a block. // The blockname can be blank (or empty) to find out about columns defined // by column(), with no block information supplied in their nametag. string HepNtuple::nametag(int colNumber) const { if ( (colNumber < 0) || (colNumber >= nColumns()) ) { char temp[32]; sprintf(temp,"%d",colNumber); ZMthrow(ZMxHepOutOfRangeValue(string("column indices out of bound: ") +string(temp))); return ""; } columnsMap::const_iterator iterateCol(columns.begin()); for ( int i = 0; i < colNumber; i++ ) { iterateCol++; } // iterateCol now points to object number colNumber in columns Column * c = (*iterateCol).second; if ( c == NULL ) { return ""; } else { return c->block()->name() + "::" + c->name(); } } string HepNtuple::nametag(int colNumber,const string& blockname) const { Block *bk = findBlock(blockname); if ( bk == NULL ) { ZMthrow(ZMxHepUnknownBlock("blockname")); return ""; } if ( colNumber >= bk->nColumns() ) { char temp[32]; sprintf(temp,"%d",colNumber); ZMthrow(ZMxHepOutOfRangeValue(string("column indices out of bound: ") +string(temp))); return ""; } Column * c = bk->columns()[colNumber]; if ( c == NULL ) { return ""; } else { return c->block()->name() + "::" + c->name(); } } string HepNtuple::tag(int colNumber) const { if ( (colNumber < 0) || (colNumber >= nColumns()) ) { char temp[32]; sprintf(temp,"%d",colNumber); ZMthrow(ZMxHepOutOfRangeValue(string("column indices out of bound: ") +string(temp))); return ""; } columnsMap::const_iterator iterateCol (columns.begin()); for ( int i = 0; i < colNumber; i++ ) { iterateCol++; } // iterateCol now points to object number colNumber in columns Column * c = (*iterateCol).second; if ( c == NULL ) { return ""; } else { return c->name(); } } string HepNtuple::tag(int colNumber,const string& blockname) const { Block *bk = findBlock(blockname); if ( bk == NULL ) { ZMthrow(ZMxHepUnknownBlock("blockname")); return ""; } if ( colNumber >= bk->nColumns() ) { char temp[32]; sprintf(temp,"%d",colNumber); ZMthrow(ZMxHepOutOfRangeValue(string("column indices out of bound: ") +string(temp))); return ""; } Column * c = bk->columns()[colNumber]; if ( c == NULL ) { return ""; } else { return c->name(); } } // Find out what block a column is in (meaningful because tags must // be unique). string HepNtuple::columnBlock(const string& tag) const { Column *c = findColumn(tag); if ( c == NULL ) { return ""; } else { return c->block()->name(); } } string HepNtuple::columnNametag(const string& tag) const { Column *c = findColumn(tag); if ( c == NULL ) { return ""; } else { return c->name() + "::" + c->block()->name(); } } /* type_info HepNtuple::columnType_info (char nametag[]) const { Column *c = findColumn(nametag); if ( c == NULL ) { ZMthrow(ZMxColumn("Unknown Column Name")); return 0; } return c->Type_info(); } */ ColumnData_t HepNtuple::columnDataType (const string& nametag) const { Column *c = findColumn(nametag); if ( c == NULL ) { ZMthrow(ZMxHepUnknownColumn(nametag)); return ColumnData_t_End; } return c->attributes().type; } void* HepNtuple::columnDesignatedVariable (const string& nametag) const { Column *c = findColumn(nametag); if ( c == NULL ) { ZMthrow(ZMxHepUnknownColumn(nametag)); return NULL; } return c->attributes().variable; } void* HepNtuple::columnDestinationVariable (const string& nametag) const { Column *c = findColumn(nametag); if ( c == NULL ) { ZMthrow(ZMxHepUnknownColumn(nametag)); return NULL; } return c->attributes().destination; } template bool columnDefaultTmpl(const string& nametag, T* def, const HepNtuple* hep) { ColumnT *c = (ColumnT*)hep->findColumn(nametag); if ( c == NULL ) { ZMthrow(ZMxHepUnknownColumn(nametag)); return false; } if (!c->checkType(T())) { ZMthrow(ZMxHepTypeMismatch(nametag)); return false; } if( c->attributes().defaultVal != NULL ) { *def = *(T*)(c->attributes().defaultVal); return true; } else { *def = 0; return false; } } /* columnDefaultTmpl */ /* #define columnDefault_MACRO(TYPE) \ template bool columnDefaultTmpl(const string& nametag, TYPE* def, \ const HepNtuple* hep); \ bool HepNtuple::columnDefault (const string& nametag, TYPE* def) const {\ return columnDefaultTmpl(nametag,def,this); \ } */ /* columnDefault */ #define columnDefault_MACRO(TYPE) \ bool HepNtuple::columnDefault (const string& nametag, TYPE* def) const {\ return columnDefaultTmpl(nametag,def,this); \ } /* columnDefault */ columnDefault_MACRO ( Int1 ) columnDefault_MACRO ( Int2 ) columnDefault_MACRO ( Int4 ) #ifdef Int8 columnDefault_MACRO ( Int8 ) #endif columnDefault_MACRO ( Float4 ) columnDefault_MACRO ( Float8 ) #ifdef Float16 columnDefault_MACRO ( Float16 ) #endif columnDefault_MACRO ( bool ) columnDefault_MACRO ( void* ) template bool setColumnDefaultTmpl(const string& nametag, T defaultValue, const HepNtuple* hep) { ColumnT *c = (ColumnT*)hep->findColumn(nametag); if ( c == NULL ) { ZMthrow(ZMxHepUnknownColumn(nametag)); return false; } if (!c->checkType(T())) { ZMthrow(ZMxHepTypeMismatch(nametag)); return false; } c->setDefaultValue(defaultValue); return true; } /* setDefaultValue */ #define setColumnDefault_MACRO(TYPE) \ bool HepNtuple::setColumnDefault(const string& nametag, TYPE def) const { \ return setColumnDefaultTmpl(nametag,def,this); \ } /* setColumnDefault */ setColumnDefault_MACRO ( Int1 ) setColumnDefault_MACRO ( Int2 ) setColumnDefault_MACRO ( Int4 ) #ifdef Int8 setColumnDefault_MACRO ( Int8 ) #endif setColumnDefault_MACRO ( Float4 ) setColumnDefault_MACRO ( Float8 ) #ifdef Float16 setColumnDefault_MACRO ( Float16 ) #endif setColumnDefault_MACRO ( bool ) setColumnDefault_MACRO ( void* ) // ************************************************************************* // // // The following is for getting simple information about Blocks in the // HepNtuple // // ************************************************************************* // int HepNtuple::nBlocks() const { return blocks.size(); } string HepNtuple::blockName(int blockNumber) const { if ( (blockNumber < 0 ) | ( blockNumber >= nBlocks() ) ) { char temp[32]; sprintf(temp,"%d",blockNumber); ZMthrow(ZMxHepOutOfRangeValue(string("block index out of bound: ") +string(temp))); return ""; } blocksMap::const_iterator iterateBlock (blocks.begin()); for ( int i = 0; i < blockNumber; i++ ) { iterateBlock++; } // iterateBlock now points to object number colNumber in blocks Block * bk = (*iterateBlock).second; return bk->name(); } string HepNtuple::blockFormat(int blockNumber) const { if ( (blockNumber < 0 ) | ( blockNumber >= nBlocks() ) ) { char temp[32]; sprintf(temp,"%d",blockNumber); ZMthrow(ZMxHepOutOfRangeValue(string("block index out of bound: ") +string(temp))); return ""; } blocksMap::const_iterator iterateBlock(blocks.begin()); for ( int i = 0; i < blockNumber; i++ ) { iterateBlock++; } // iterateBlock now points to object number colNumber in blocks Block * bk = (*iterateBlock).second; return bk->format(); } string HepNtuple::blockFormat(const string& blockName) const { Block *bk = findBlock(blockName); if ( bk == NULL ) { ZMthrow(ZMxHepUnknownBlock(blockName)); return 0; } return bk->format(); } ZM_END_NAMESPACE( zmht ) /* } // namespace zmht */