Main Page   Namespace List   Alphabetical List   Compound List   File List   Compound Members   File Members  

ObjyTuple.cpp

Go to the documentation of this file.
00001 #include "ObjyTuple.h"
00002 #include "HepODBMS/tagdb/HepExplorableGenericTags.h"
00003 #include "HepODBMS/tagdb/HepExplorableAttribute.h"
00004 #include "AIDA_Dev/ITupleHeader.h"
00005 #include "AIDA_Dev/ITupleVariableDescription.h"
00006 #include "AIDA_Dev/IDevTupleFactory.h"
00007 
00008 
00009 Anaphe::AIDA_ObjectivityStore::ObjyTuple::ObjyTuple( HepExplorable& e ):
00010   m_explorable( e ),
00011   m_tagCollection( 0 ),
00012   m_currentRowNumber( -1 )
00013 {}
00014 
00015 
00016 Anaphe::AIDA_ObjectivityStore::ObjyTuple::~ObjyTuple()
00017 {
00018   for ( unsigned int i = 0; i < m_variableAddresses.size(); ++i ) {
00019     if ( m_doubleVariables.find( i ) != m_doubleVariables.end() ) delete reinterpret_cast<double*>( m_variableAddresses[i] );
00020     else if ( m_floatVariables.find( i ) != m_floatVariables.end() ) delete reinterpret_cast<float*>( m_variableAddresses[i] );
00021     else if ( m_longVariables.find( i ) != m_longVariables.end() ) delete reinterpret_cast<long*>( m_variableAddresses[i] );
00022     else if ( m_shortVariables.find( i ) != m_shortVariables.end() ) delete reinterpret_cast<short*>( m_variableAddresses[i] );
00023     else if ( m_charVariables.find( i ) != m_charVariables.end() ) delete reinterpret_cast<char*>( m_variableAddresses[i] );
00024   }
00025   for ( std::map<unsigned int, HepExplorableAttribute<double>* >::iterator iAttribute = m_doubleVariables.begin();
00026         iAttribute != m_doubleVariables.end(); ++iAttribute ) if (iAttribute->second) delete iAttribute->second;
00027   for ( std::map<unsigned int, HepExplorableAttribute<float>* >::iterator iAttribute = m_floatVariables.begin();
00028         iAttribute != m_floatVariables.end(); ++iAttribute ) if (iAttribute->second) delete iAttribute->second;
00029   for ( std::map<unsigned int, HepExplorableAttribute<long>* >::iterator iAttribute = m_longVariables.begin();
00030         iAttribute != m_longVariables.end(); ++iAttribute ) if (iAttribute->second) delete iAttribute->second;
00031   for ( std::map<unsigned int, HepExplorableAttribute<short>* >::iterator iAttribute = m_shortVariables.begin();
00032         iAttribute != m_shortVariables.end(); ++iAttribute ) if (iAttribute->second) delete iAttribute->second;
00033   for ( std::map<unsigned int, HepExplorableAttribute<char>* >::iterator iAttribute = m_charVariables.begin();
00034         iAttribute != m_charVariables.end(); ++iAttribute ) if (iAttribute->second) delete iAttribute->second;
00035 }
00036 
00037 
00038 bool
00039 Anaphe::AIDA_ObjectivityStore::ObjyTuple::writeDescription( const AIDA::Dev::ITupleHeader& header )
00040 {
00041   for ( int i = 0; i < header.numberOfVariables(); ++i ) {
00042     const std::string& type = header.variableDescription( i )->variableType();
00043     if ( type != "double" && type != "float" &&
00044          type != "long" && type != "short" && type != "char" ) return false;
00045   }
00046 
00047   if ( header.numberOfVariables() > 0 ) {
00048     m_variableAddresses.reserve( header.numberOfVariables() );
00049     m_variableNames.reserve( header.numberOfVariables() );
00050   }
00051 
00052   for ( int i = 0; i < header.numberOfVariables(); ++i ) {
00053     const std::string& type = header.variableDescription( i )->variableType();
00054     const std::string& name = header.variableDescription( i )->variableName();
00055     void* p = 0;
00056     if ( type == "double" ) {
00057       p = new double;
00058       m_doubleVariables.insert( std::make_pair( static_cast<unsigned int>( i ),
00059                                                 static_cast< HepExplorableAttribute<double>* >( 0 ) ) );
00060     }
00061     else if ( type == "float" ) {
00062       p = new float;
00063       m_floatVariables.insert( std::make_pair( static_cast<unsigned int>( i ),
00064                                                static_cast< HepExplorableAttribute<float>* >( 0 ) ) );
00065     }
00066     else if ( type == "long" ) {
00067       p = new long;
00068       m_longVariables.insert( std::make_pair( static_cast<unsigned int>( i ),
00069                                               static_cast< HepExplorableAttribute<long>* >( 0 ) ) );
00070     }
00071     else if ( type == "short" ) {
00072       p = new short;
00073       m_shortVariables.insert( std::make_pair( static_cast<unsigned int>( i ),
00074                                                static_cast< HepExplorableAttribute<short>* >( 0 ) ) );
00075     }
00076     else if ( type == "char" ) {
00077       p = new char;
00078       m_charVariables.insert( std::make_pair( static_cast<unsigned int>( i ),
00079                                               static_cast< HepExplorableAttribute<char>* >( 0 ) ) );
00080     }
00081     m_variableNames.push_back( name );
00082     m_variableAddresses.push_back( p );
00083   }
00084 
00085   m_tagCollection = dynamic_cast<HepExplorableGenericTags*>( &m_explorable );
00086   return true;
00087 }
00088 
00089 
00090 bool
00091 Anaphe::AIDA_ObjectivityStore::ObjyTuple::readDescription( AIDA::Dev::ITupleHeader& header,
00092                                                            AIDA::Dev::IDevTupleFactory& factory )
00093 {
00094   int i = 0;
00095   const char* c = m_explorable.getFieldNameById( i );
00096   while ( c ) {
00097     const std::string name = c;
00098     HepExplorableFieldType eType = m_explorable.getFieldTypeById( i );
00099     void* p = 0;
00100     AIDA::Dev::ITupleVariableDescription* desc = factory.createDescription();
00101     desc->setVariableName( name );
00102     if ( eType == eTypeDouble ) {
00103       desc->setVariableType( std::string( "double" ) );
00104       p = new double;
00105       m_doubleVariables.insert( std::make_pair( static_cast<unsigned int>( i ),
00106                                                 static_cast< HepExplorableAttribute<double>* >( 0 ) ) );
00107     }
00108     else if ( eType == eTypeFloat ) {
00109       desc->setVariableType( std::string( "float" ) );
00110       p = new float;
00111       m_floatVariables.insert( std::make_pair( static_cast<unsigned int>( i ),
00112                                                static_cast< HepExplorableAttribute<float>* >( 0 ) ) );
00113     }
00114     else if ( eType == eTypeLong ) {
00115       desc->setVariableType( std::string( "long" ) );
00116       p = new long;
00117       m_longVariables.insert( std::make_pair( static_cast<unsigned int>( i ),
00118                                               static_cast< HepExplorableAttribute<long>* >( 0 ) ) );
00119     }
00120     else if ( eType == eTypeShort ) {
00121       desc->setVariableType( std::string( "short" ) );
00122       p = new short;
00123       m_shortVariables.insert( std::make_pair( static_cast<unsigned int>( i ),
00124                                                static_cast< HepExplorableAttribute<short>* >( 0 ) ) );
00125     }
00126     else if ( eType == eTypeChar ) {
00127       desc->setVariableType( std::string( "char" ) );
00128       p = new char;
00129       m_charVariables.insert( std::make_pair( static_cast<unsigned int>( i ),
00130                                               static_cast< HepExplorableAttribute<char>* >( 0 ) ) );
00131     }
00132     m_variableNames.push_back( name );
00133     m_variableAddresses.push_back( p );
00134     header.setVariableDescription( desc, true );
00135     ++i;
00136     c = m_explorable.getFieldNameById( i );
00137   }
00138   m_tagCollection = dynamic_cast<HepExplorableGenericTags*>( &m_explorable );
00139   return true;
00140 }
00141 
00142 
00143 bool
00144 Anaphe::AIDA_ObjectivityStore::ObjyTuple::bindVariable( int variableIndex )
00145 {
00146   unsigned int i = variableIndex;
00147   if ( m_doubleVariables.find(i) != m_doubleVariables.end() ) {
00148     if ( m_doubleVariables[i] == 0 ) {
00149       m_doubleVariables[i] = new HepExplorableAttribute<double>( &m_explorable, m_variableNames[i].c_str() );
00150     }
00151     return true;
00152   }
00153   else if ( m_floatVariables.find(i) != m_floatVariables.end() ) {
00154     if ( m_floatVariables[i] == 0 ) {
00155       m_floatVariables[i] = new HepExplorableAttribute<float>( &m_explorable, m_variableNames[i].c_str() );
00156     }
00157     return true;
00158   }
00159   else if ( m_longVariables.find(i) != m_longVariables.end() ) {
00160     if ( m_longVariables[i] == 0 ) {
00161       m_longVariables[i] = new HepExplorableAttribute<long>( &m_explorable, m_variableNames[i].c_str() );
00162     }
00163     return true;
00164   }
00165   else  if ( m_shortVariables.find(i) != m_shortVariables.end() ) {
00166     if ( m_shortVariables[i] == 0 ) {
00167       m_shortVariables[i] = new HepExplorableAttribute<short>( &m_explorable, m_variableNames[i].c_str() );
00168     }
00169     return true;
00170   }
00171   else if ( m_charVariables.find(i) != m_charVariables.end() ) {
00172     if ( m_charVariables[i] == 0 ) {
00173       m_charVariables[i] = new HepExplorableAttribute<char>( &m_explorable, m_variableNames[i].c_str() );
00174     }
00175     return true;
00176   }
00177   else return false;
00178 }
00179 
00180 
00181 bool
00182 Anaphe::AIDA_ObjectivityStore::ObjyTuple::clearBindings()
00183 {
00184   for ( std::map<unsigned int, HepExplorableAttribute<double>* >::iterator iAttribute = m_doubleVariables.begin();
00185         iAttribute != m_doubleVariables.end(); ++iAttribute ) {
00186     if (iAttribute->second) {
00187       delete iAttribute->second;
00188       iAttribute->second = 0;
00189     }
00190   }
00191 
00192   for ( std::map<unsigned int, HepExplorableAttribute<float>* >::iterator iAttribute = m_floatVariables.begin();
00193         iAttribute != m_floatVariables.end(); ++iAttribute ) {
00194     if (iAttribute->second) {
00195       delete iAttribute->second;
00196       iAttribute->second = 0;
00197     }
00198   }
00199 
00200   for ( std::map<unsigned int, HepExplorableAttribute<long>* >::iterator iAttribute = m_longVariables.begin();
00201         iAttribute != m_longVariables.end(); ++iAttribute ) {
00202     if (iAttribute->second) {
00203       delete iAttribute->second;
00204       iAttribute->second = 0;
00205     }
00206   }
00207 
00208   for ( std::map<unsigned int, HepExplorableAttribute<short>* >::iterator iAttribute = m_shortVariables.begin();
00209         iAttribute != m_shortVariables.end(); ++iAttribute ) {
00210     if (iAttribute->second) {
00211       delete iAttribute->second;
00212       iAttribute->second = 0;
00213     }
00214   }
00215 
00216   for ( std::map<unsigned int, HepExplorableAttribute<char>* >::iterator iAttribute = m_charVariables.begin();
00217         iAttribute != m_charVariables.end(); ++iAttribute ) {
00218     if (iAttribute->second) {
00219       delete iAttribute->second;
00220       iAttribute->second = 0;
00221     }
00222   }
00223   return true;
00224 }
00225 
00226 
00227 bool
00228 Anaphe::AIDA_ObjectivityStore::ObjyTuple::writeTupleRow( int rowNumber )
00229 {
00230   if ( ! m_tagCollection ) return false;
00231   if ( m_currentRowNumber > rowNumber ) m_currentRowNumber = rowNumber;
00232   while ( m_currentRowNumber < rowNumber ) {
00233     m_tagCollection->newTag();
00234     ++m_currentRowNumber;
00235   }
00236 
00237 
00238   for ( std::map<unsigned int, HepExplorableAttribute<double>* >::iterator iAttribute = m_doubleVariables.begin();
00239         iAttribute != m_doubleVariables.end(); ++iAttribute ) {
00240     if (iAttribute->second) {
00241       iAttribute->second->operator=( *( reinterpret_cast<double*>(m_variableAddresses[iAttribute->first]) ) );
00242     }
00243   }
00244 
00245   for ( std::map<unsigned int, HepExplorableAttribute<float>* >::iterator iAttribute = m_floatVariables.begin();
00246         iAttribute != m_floatVariables.end(); ++iAttribute ) {
00247     if (iAttribute->second) {
00248       iAttribute->second->operator=( *( reinterpret_cast<float*>(m_variableAddresses[iAttribute->first]) ) );
00249     }
00250   }
00251 
00252   for ( std::map<unsigned int, HepExplorableAttribute<long>* >::iterator iAttribute = m_longVariables.begin();
00253         iAttribute != m_longVariables.end(); ++iAttribute ) {
00254     if (iAttribute->second) {
00255       iAttribute->second->operator=( *( reinterpret_cast<long*>(m_variableAddresses[iAttribute->first]) ) );
00256     }
00257   }
00258 
00259   for ( std::map<unsigned int, HepExplorableAttribute<short>* >::iterator iAttribute = m_shortVariables.begin();
00260         iAttribute != m_shortVariables.end(); ++iAttribute ) {
00261     if (iAttribute->second) {
00262       iAttribute->second->operator=( *( reinterpret_cast<short*>(m_variableAddresses[iAttribute->first]) ) );
00263     }
00264   }
00265 
00266   for ( std::map<unsigned int, HepExplorableAttribute<char>* >::iterator iAttribute = m_charVariables.begin();
00267         iAttribute != m_charVariables.end(); ++iAttribute ) {
00268     if (iAttribute->second) {
00269       iAttribute->second->operator=( *( reinterpret_cast<char*>(m_variableAddresses[iAttribute->first]) ) );
00270     }
00271   }
00272 
00273   return true;
00274 }
00275 
00276 
00277 bool
00278 Anaphe::AIDA_ObjectivityStore::ObjyTuple::readTupleRow( int rowNumber )
00279 {
00280   if ( rowNumber < 0 ) return false;
00281   if ( rowNumber == 0 ) {
00282     if ( m_explorable.start() == 0 ) return false;
00283     m_currentRowNumber = 0;
00284   }
00285   else {
00286     if ( m_currentRowNumber > rowNumber ) {
00287       if ( m_explorable.start() == 0 ) return false;
00288       for ( m_currentRowNumber = 0; m_currentRowNumber < rowNumber - 1; ++m_currentRowNumber ) {
00289         if ( m_tagCollection->next() == 0 ) return false;
00290       }
00291     }
00292     while ( m_currentRowNumber < rowNumber ) {
00293       if ( m_tagCollection->next() == 0 ) return false;
00294       ++m_currentRowNumber;
00295     }
00296   }
00297 
00298   for ( std::map<unsigned int, HepExplorableAttribute<double>* >::iterator iAttribute = m_doubleVariables.begin();
00299         iAttribute != m_doubleVariables.end(); ++iAttribute ) {
00300     if (iAttribute->second) {
00301       *( reinterpret_cast<double*>(m_variableAddresses[iAttribute->first]) ) = *( iAttribute->second );
00302     }
00303   }
00304 
00305   for ( std::map<unsigned int, HepExplorableAttribute<float>* >::iterator iAttribute = m_floatVariables.begin();
00306         iAttribute != m_floatVariables.end(); ++iAttribute ) {
00307     if (iAttribute->second) {
00308       *( reinterpret_cast<float*>(m_variableAddresses[iAttribute->first]) ) = *( iAttribute->second );
00309     }
00310   }
00311 
00312   for ( std::map<unsigned int, HepExplorableAttribute<long>* >::iterator iAttribute = m_longVariables.begin();
00313         iAttribute != m_longVariables.end(); ++iAttribute ) {
00314     if (iAttribute->second) {
00315       *( reinterpret_cast<long*>(m_variableAddresses[iAttribute->first]) ) = *( iAttribute->second );
00316     }
00317   }
00318 
00319   for ( std::map<unsigned int, HepExplorableAttribute<short>* >::iterator iAttribute = m_shortVariables.begin();
00320         iAttribute != m_shortVariables.end(); ++iAttribute ) {
00321     if (iAttribute->second) {
00322       *( reinterpret_cast<short*>(m_variableAddresses[iAttribute->first]) ) = *( iAttribute->second );
00323     }
00324   }
00325 
00326   for ( std::map<unsigned int, HepExplorableAttribute<char>* >::iterator iAttribute = m_charVariables.begin();
00327         iAttribute != m_charVariables.end(); ++iAttribute ) {
00328     if (iAttribute->second) {
00329       *( reinterpret_cast<char*>(m_variableAddresses[iAttribute->first]) ) = *( iAttribute->second );
00330     }
00331   }
00332 
00333   return true;
00334 }
00335 
00336 
00337 bool
00338 Anaphe::AIDA_ObjectivityStore::ObjyTuple::reset()
00339 {
00340   if ( ! m_tagCollection ) return false;
00341   m_tagCollection->removeAllTags();
00342   m_currentRowNumber = -1;
00343   return true;
00344 }
00345 
00346 
00347 void*
00348 Anaphe::AIDA_ObjectivityStore::ObjyTuple::variableAddress( int variableIndex )
00349 {
00350   return m_variableAddresses[variableIndex];
00351 }
00352 
00353 
00354 const void*
00355 Anaphe::AIDA_ObjectivityStore::ObjyTuple::variableAddress( int variableIndex ) const
00356 {
00357   return m_variableAddresses[variableIndex];
00358 }

Generated on Tue Nov 19 12:32:34 2002 for AIDA_ObjectivityStore by doxygen1.2.16