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

AIDA_StoreXML.cpp

Go to the documentation of this file.
00001 #include "AIDA_StoreXML.h"
00002 #include "StoreTranslator.h"
00003 #include "Histo1DTranslator.h"
00004 #include "Histo2DTranslator.h"
00005 #include "Histo3DTranslator.h"
00006 #include "Profile1DTranslator.h"
00007 #include "Profile2DTranslator.h"
00008 #include "Cloud1DTranslator.h"
00009 #include "Cloud2DTranslator.h"
00010 #include "Cloud3DTranslator.h"
00011 #include "DataPointSetTranslator.h"
00012 #include "FunctionTranslator.h"
00013 #include "AIDA_Dev/IDevManagedObject.h"
00014 #include "AIDA_Dev/ITupleFactoryProvider.h"
00015 #include <typeinfo>
00016 #include <set>
00017 #include "AIDA_Dev/IDevAnalysisFactory.h"
00018 #include "AIDA_Dev/IDevHistogramFactory.h"
00019 #include "AIDA_Dev/IDevHistogram1D.h"
00020 #include "AIDA_Dev/IDevHistogram2D.h"
00021 #include "AIDA_Dev/IDevHistogram3D.h"
00022 #include "AIDA_Dev/IDevCloud1D.h"
00023 #include "AIDA_Dev/IDevCloud2D.h"
00024 #include "AIDA_Dev/IDevCloud3D.h"
00025 #include "AIDA_Dev/IDevProfile1D.h"
00026 #include "AIDA_Dev/IDevProfile2D.h"
00027 #include "AIDA_Dev/IDevDataPointSet.h"
00028 #include "AIDA_Dev/IDevFunction.h"
00029 #include "AIDA_Dev/IHistogramFactoryProvider.h"
00030 #include "AIDA_Dev/IDevDataPointSetFactory.h"
00031 #include "AIDA_Dev/IDataPointSetFactoryProvider.h"
00032 #include "AIDA_Dev/IDevFunctionFactory.h"
00033 #include "AIDA_Dev/IFunctionFactoryProvider.h"
00034 
00035 #include "DataXML/DataObject.h"
00036 // for compressing
00037 #include "gzstream.h"
00038 
00039 #include <memory>
00040 #include <fstream>
00041 #include <iostream>
00042 
00043 #ifdef XML_STORE_NO_EXCEPTIONS_TO_USER
00044 #include <iostream>
00045 #define XML_STORE_REPORT_ERROR( XXX ) std::cerr << XXX << std::endl
00046 #else
00047 #include <stdexcept>
00048 #define XML_STORE_REPORT_ERROR( XXX ) throw std::runtime_error( XXX )
00049 #endif
00050 
00051 
00052 /* create the XML store
00053  *   - read always all the object - if file does not exists nothing 
00054  *       will be found 
00055  *   - always write again in a new file at commit all the objects    
00056  *     so createNew has no influence
00057  */ 
00058 
00059 Anaphe::AIDA_XMLStore::AIDA_StoreXML::AIDA_StoreXML( const std::string& name,
00060                                                      bool readOnly,
00061                                                      bool createNew,
00062                                                      const std::string& options):
00063   m_name( name )
00064 {
00065   // parse option
00066   m_compress = false; 
00067   if (!options.empty() ) { 
00068     if (options.find("compress") != std::string::npos )
00069       m_compress = true; 
00070   }
00071 
00072   // read all object from file 
00073   // if writing mode and creating new no need to read ! 
00074   if (readOnly || !createNew) 
00075     readAllObjects();
00076 }
00077 
00078 
00079 Anaphe::AIDA_XMLStore::AIDA_StoreXML::~AIDA_StoreXML()
00080 {
00081   close(); 
00082 }
00083 
00084 
00085 const std::string&
00086 Anaphe::AIDA_XMLStore::AIDA_StoreXML::name() const
00087 {
00088   return m_name;
00089 }
00090 
00091 
00092 bool
00093 Anaphe::AIDA_XMLStore::AIDA_StoreXML::writeObject( const AIDA::IManagedObject& dataObject,
00094                                                    const std::string& path )
00095 {
00096 
00098 
00099   if ( m_objectTypes.find( path ) != m_objectTypes.end() ) return false;
00100   AIDA::Dev::IDevManagedObject* object =
00101     dynamic_cast< AIDA::Dev::IDevManagedObject* >( &( const_cast<AIDA::IManagedObject&>( dataObject ) ) );
00102   if ( ! object ) return false;
00103 
00104   
00105   const std::string& type = object->userLevelClassType();
00106   /* 
00107   if ( ! Anaphe::AIDA_XMLStore::SupportedAIDATypes::supportedTypes().isTypeSupported( type ) ) {
00108     return false;
00109   }
00110   */
00111   //object->setUpToDate( false );
00112 
00113 
00114   m_objectTypes[ path ] = type;
00115   m_objectRefs[ path ] = object;
00116 
00117   /* 
00118   if ( m_objectsToDelete.find( path ) != m_objectsToDelete.end() ) {
00119     m_objectsToDelete.erase( path );
00120     m_objectsToUpdate.insert( path );
00121   }
00122   else {
00123     m_objectsToAdd.insert( path );
00124   }
00125   */
00126 
00127   return true; 
00128 }
00129 
00130 
00132 
00133 AIDA::IManagedObject*
00134 Anaphe::AIDA_XMLStore::AIDA_StoreXML::copyAndWrite( const AIDA::IManagedObject& dataObject,
00135                                                           const std::string& path )
00136 {
00137   // check first if original object exists
00138   if ( m_objectTypes.find( path ) != m_objectTypes.end() ) return 0;
00139 
00140   // Create factories to make copies 
00141   std::auto_ptr<AIDA::Dev::IDevAnalysisFactory> af( dynamic_cast<AIDA::Dev::IDevAnalysisFactory*>( AIDA_createAnalysisFactory() ) );
00142   if ( ! af.get() ) {
00143     XML_STORE_REPORT_ERROR( "The XML store could not instantiate an analysis factory" );
00144     return 0;
00145   }
00146 
00147 
00148 
00149   // Identify the type of the new object
00150 
00151   const AIDA::Dev::IDevManagedObject& object = dynamic_cast< const AIDA::Dev::IDevManagedObject& >( dataObject );
00152   const std::string& type = object.userLevelClassType();
00153 
00154   // Create the actual copy
00155   AIDA::Dev::IDevManagedObject* newObject = 0;
00156 
00157   if ( type == "IHistogram1D" || type == "IHistogram2D" || type == "IHistogram3D" ||
00158        type == "IProfile1D" || type == "IProfile2D" ||
00159        type == "ICloud1D" || type == "ICloud2D" || type == "ICloud3D" ) {
00160 
00161     AIDA::Dev::IHistogramFactoryProvider* fp = af->histogramFactoryProvider();
00162     if ( ! fp ) {
00163       XML_STORE_REPORT_ERROR( "The store could not retrieve the histogram factory provider from the analysis factory" );
00164       return 0;
00165     }
00166     AIDA::Dev::IDevHistogramFactory& hf = fp->devHistogramFactory();
00167 
00168     if ( type == "IHistogram1D" ) {
00169       newObject = hf.createCopy( dynamic_cast<const AIDA::IHistogram1D&>( dataObject ) );
00170     }
00171     else if ( type == "IHistogram2D" ) {
00172       newObject = hf.createCopy( dynamic_cast<const AIDA::IHistogram2D&>( dataObject ) );
00173     }
00174     else if ( type == "IHistogram3D" ) {
00175       newObject = hf.createCopy( dynamic_cast<const AIDA::IHistogram3D&>( dataObject ) );
00176     }
00177     else if ( type == "IProfile1D" ) {
00178       newObject = hf.createCopy( dynamic_cast<const AIDA::IProfile1D&>( dataObject ) );
00179     }
00180     else if ( type == "IProfile2D" ) {
00181       newObject = hf.createCopy( dynamic_cast<const AIDA::IProfile2D&>( dataObject ) );
00182     }
00183     else if ( type == "ICloud1D" ) {
00184       newObject = hf.createCopy( dynamic_cast<const AIDA::ICloud1D&>( dataObject ) );
00185     }
00186     else if ( type == "ICloud2D" ) {
00187       newObject = hf.createCopy( dynamic_cast<const AIDA::ICloud2D&>( dataObject ) );
00188     }
00189     else if ( type == "ICloud3D" ) {
00190       newObject = hf.createCopy( dynamic_cast<const AIDA::ICloud3D&>( dataObject ) );
00191     }
00192   }
00193   else if ( type == "IDataPointSet" ) {  // DataPointSet cases
00194     
00195     AIDA::Dev::IDataPointSetFactoryProvider* fp = af->dataPointSetFactoryProvider();
00196     if ( ! fp ) {
00197       XML_STORE_REPORT_ERROR( "The store could not retrieve the dataPointSet factory provider from the analysis factory" );
00198       return 0;
00199     }
00200     AIDA::Dev::IDevDataPointSetFactory& df = fp->devDataPointSetFactory();
00201     newObject = df.createCopy( dynamic_cast<const AIDA::IDataPointSet &>( dataObject ) );
00202   }
00203   else if ( type == "IFunction" ) {  // function cases
00204     
00205     AIDA::Dev::IFunctionFactoryProvider* fp = af->functionFactoryProvider();
00206     if ( ! fp ) {
00207       XML_STORE_REPORT_ERROR( "The store could not retrieve the function factory provider from the analysis factory" );
00208       return 0;
00209     }
00210     AIDA::Dev::IDevFunctionFactory& df = fp->devFunctionFactory();
00211     AIDA::IManagedObject * mo = const_cast<AIDA::IManagedObject *> (&dataObject); 
00212     newObject = df.cloneFunction( dynamic_cast<AIDA::IFunction *>( mo) );
00213   }
00214 
00215   // Others to be added...
00216 
00217   // Identify the name
00218   unsigned int pos = path.size();
00219   for ( unsigned int iChar = path.size() - 1; iChar >= 0; --iChar ) {
00220     if ( path[iChar] == '/' ) break;
00221     --pos;
00222   }
00223   const std::string name = path.substr( pos );
00224 
00225   // Register the new object
00226   if ( newObject ) {
00227     newObject->setName( name );
00228     writeObject( *newObject, path );
00229   }
00230 
00231   return newObject;
00232 }
00233 
00234 
00235 
00236 AIDA::IManagedObject*
00237 Anaphe::AIDA_XMLStore::AIDA_StoreXML::retrieveObject( const std::string & path )
00238 {
00239   // object should be in memory... 
00240   std::map< std::string, AIDA::Dev::IDevManagedObject* >::iterator iObjectRef = m_objectRefs.find( path );
00241   if ( iObjectRef == m_objectRefs.end() ) return 0;
00242   if ( iObjectRef->second != 0 ) return iObjectRef->second;
00243   // object not found 
00244   return 0; 
00245 }
00246 
00247 
00248 bool
00249 Anaphe::AIDA_XMLStore::AIDA_StoreXML::removeObject( const std::string& path )
00250 {
00251   // just erase object from maps 
00252   if ( m_objectTypes.find( path ) == m_objectTypes.end() ) return false;
00253   m_objectTypes.erase( path );
00254   m_objectRefs.erase( path );
00255   return true; 
00256 }
00257 
00258 // here is path or also changing object name ?? 
00259 
00260 bool
00261 Anaphe::AIDA_XMLStore::AIDA_StoreXML::moveObject(const std::string& from, const std::string& to )
00262 {
00263   // erase old object from maps and re-insert with new path 
00264 
00265   std::map< std::string, std::string >::const_iterator sourceType = m_objectTypes.find( from );
00266   if ( sourceType == m_objectTypes.end() ) return false;
00267 
00268   std::map< std::string, AIDA::Dev::IDevManagedObject *  >::const_iterator sourceRef = m_objectRefs.find( from );
00269   if ( sourceRef == m_objectRefs.end() ) return false;
00270 
00271 
00272   std::string type = sourceType->second;
00273   AIDA::Dev::IDevManagedObject* object = sourceRef->second; 
00274   m_objectTypes.erase( from );
00275   m_objectRefs.erase( from );
00276   m_objectTypes.insert( std::make_pair( to, type ) );
00277   m_objectRefs.insert( std::make_pair( to, object ) );
00278   return true;
00279 }
00280 
00281 
00282 std::vector< std::string >
00283 Anaphe::AIDA_XMLStore::AIDA_StoreXML::listObjectPaths( const std::string directory,
00284                                                        bool recursive ) const
00285 
00286   // This is just a exact copy from Memory Store 
00287 {
00288   std::string dir = directory;
00289   if ( dir[ dir.size() - 1 ] != '/' ) dir += "/";
00290 
00291   std::vector< std::string > result;
00292 
00293   std::set< std::string > directorySet;
00294   for ( std::map< std::string, std::string >::const_iterator iObj = m_objectTypes.begin();
00295         iObj != m_objectTypes.end(); ++iObj ) {
00296     const std::string& object = iObj->first;
00297     std::string::size_type p = object.find( dir );
00298     if ( p == 0 ) {
00299       std::string complement = object.substr( dir.size() );
00300       // Remove extra "/" characters in the begining
00301       while ( complement.size() > 0 && complement[0] == '/' ) complement = complement.substr( 1 );
00302       if ( complement.size() == 0 ) continue;
00303 
00304       // Check if it is a leaf object
00305       std::string::size_type n = complement.find( "/" );
00306       if ( n == std::string::npos ) {
00307         result.push_back( object );
00308       }
00309       else { // update the daughter directory list
00310         directorySet.insert( dir + complement.substr( 0, n ) + "/" );
00311       }
00312     }
00313   }
00314 
00315   for ( std::set< std::string >::const_iterator iDir = directorySet.begin();
00316         iDir != directorySet.end(); ++iDir ) {
00317     result.push_back( *iDir );
00318     if ( recursive ) {
00319       std::vector< std::string > subDirResults = listObjectPaths( *iDir, recursive );
00320       for ( unsigned int i = 0; i < subDirResults.size(); ++i ) result.push_back( subDirResults[ i ] );
00321     }
00322   }
00323 
00324   return result;
00325 }
00326 
00327 
00328 std::vector< std::string >
00329 Anaphe::AIDA_XMLStore::AIDA_StoreXML::listObjectTypes( const std::string directory,
00330                                                        bool recursive ) const
00331 {
00332 
00333   // This is exact copy from memory store 
00334 
00335   std::string dir = directory;
00336   if ( dir[ dir.size() - 1 ] != '/' ) dir += "/";
00337 
00338   std::vector< std::string > result;
00339 
00340   std::set< std::string > directorySet;
00341   for ( std::map< std::string, std::string >::const_iterator iObj = m_objectTypes.begin();
00342         iObj != m_objectTypes.end(); ++iObj ) {
00343     const std::string& object = iObj->first;
00344     std::string::size_type p = object.find( dir );
00345     if ( p == 0 ) {
00346       std::string complement = object.substr( dir.size() );
00347       // Remove extra "/" characters in the begining
00348       while ( complement.size() > 0 && complement[0] == '/' ) complement = complement.substr( 1 );
00349       if ( complement.size() == 0 ) continue;
00350 
00351       // Check if it is a leaf object
00352       std::string::size_type n = complement.find( "/" );
00353       if ( n == std::string::npos ) {
00354         result.push_back( iObj->second );
00355       }
00356       else { // update the daughter directory list
00357         directorySet.insert( dir + complement.substr( 0, n ) + "/" );
00358       }
00359     }
00360   }
00361 
00362   for ( std::set< std::string >::const_iterator iDir = directorySet.begin();
00363         iDir != directorySet.end(); ++iDir ) {
00364     result.push_back( "dir" );
00365     if ( recursive ) {
00366       std::vector< std::string > subDirResults = listObjectTypes( *iDir, recursive );
00367       for ( unsigned int i = 0; i < subDirResults.size(); ++i ) result.push_back( subDirResults[ i ] );
00368     }
00369   }
00370 
00371   return result;
00372 }
00373 
00374 
00375 bool
00376 Anaphe::AIDA_XMLStore::AIDA_StoreXML::commit()
00377 {
00378   // here I write XML store 
00379 
00380   // create output translator ( a new stream is created for every commit)
00381 
00382   std::ostream * stream = 0;
00383 
00384 
00385   if (m_compress) { 
00386     stream = new ogzstream(m_name.c_str());    
00387   } 
00388   else { 
00389     stream = new std::ofstream(m_name.c_str());
00390   }
00391   if (stream == 0) { 
00392     XML_STORE_REPORT_ERROR(" Error opening file " + m_name ); 
00393     return false; 
00394   }
00395   m_outputTranslator = new Anaphe::AIDA_XMLStore::StoreTranslator(*stream);
00396 
00397 
00398 
00399   for ( std::map< std::string, AIDA::Dev::IDevManagedObject* >::iterator iObj = m_objectRefs.begin(); iObj != m_objectRefs.end(); ++iObj ) {
00400     AIDA::Dev::IDevManagedObject* object = iObj->second;
00401     // why sometimes I have an empty objects entered ???
00402     if (object) { 
00403       std::string path = iObj->first;
00404       writeToXML(object,path);
00405     } 
00406   }
00407   // flush all to the file 
00408   if (!m_outputTranslator->write()) return false; 
00409 
00410 
00411   // delete translator to create a new file next commit time 
00412   delete m_outputTranslator; 
00413   delete stream; 
00414   return true; 
00415 }
00416 
00417 
00418 bool
00419 Anaphe::AIDA_XMLStore::AIDA_StoreXML::close()
00420 {
00421   // no operation - file is close at every commit
00422   return true;
00423 }
00424 
00425 
00426 bool Anaphe::AIDA_XMLStore::AIDA_StoreXML::canMoveTuples() const {return false;}
00427 bool Anaphe::AIDA_XMLStore::AIDA_StoreXML::canCopyTuples() const {return false;}
00428 
00429 
00430 bool
00431 Anaphe::AIDA_XMLStore::AIDA_StoreXML::writeTupleHeader( AIDA::Dev::ITupleHeader& header )
00432 {
00433   return false;
00434 }
00435 
00436 
00437 bool
00438 Anaphe::AIDA_XMLStore::AIDA_StoreXML::readTupleHeader( AIDA::Dev::ITupleHeader& header )
00439 {
00440   return false;
00441 }
00442 
00443 
00444 bool
00445 Anaphe::AIDA_XMLStore::AIDA_StoreXML::bindVariable( AIDA::Dev::ITupleHeader& header, int variableIndex )
00446 {
00447   return false;
00448 }
00449 
00450 
00451 void*
00452 Anaphe::AIDA_XMLStore::AIDA_StoreXML::variableAddress( AIDA::Dev::ITupleHeader& header, int variableIndex )
00453 {
00454   return 0;
00455 }
00456 
00457 
00458 const void*
00459 Anaphe::AIDA_XMLStore::AIDA_StoreXML::variableAddress( const AIDA::Dev::ITupleHeader& header, int variableIndex ) const
00460 {
00461   return 0;
00462 }
00463 
00464 
00465 bool
00466 Anaphe::AIDA_XMLStore::AIDA_StoreXML::clearBindings( const AIDA::Dev::ITupleHeader& header )
00467 {
00468   return false;
00469 }
00470 
00471 
00472 bool
00473 Anaphe::AIDA_XMLStore::AIDA_StoreXML::writeTupleRow( AIDA::Dev::ITupleHeader& header )
00474 {
00475   return false;
00476 }
00477 
00478 
00479 bool
00480 Anaphe::AIDA_XMLStore::AIDA_StoreXML::readTupleRow( AIDA::Dev::ITupleHeader& header )
00481 {
00482   return false;
00483 }
00484 
00485 
00486 bool
00487 Anaphe::AIDA_XMLStore::AIDA_StoreXML::resetTuple( AIDA::Dev::ITupleHeader& header )
00488 {
00489   return false;
00490 }
00491 
00492 // read all objects from the file and load then in memory creating new Managed 
00493 // Objects
00494 
00495 bool
00496 Anaphe::AIDA_XMLStore::AIDA_StoreXML::readAllObjects( )
00497 {
00498   
00499   Anaphe::AIDA_XMLStore::StoreTranslator * translator = 0; 
00500 
00501   std::istream * inputStream = 0; 
00502   if (m_compress) { 
00503     inputStream = new igzstream(m_name.c_str() );
00504   }
00505   else { 
00506     inputStream = new std::ifstream(m_name.c_str()); 
00507   }
00508 
00509   if (inputStream == 0 ) { 
00510     XML_STORE_REPORT_ERROR(" Error opening file " + m_name ); 
00511     return false; 
00512   }
00513   // check also the state
00514   if (! *inputStream ) { 
00515     XML_STORE_REPORT_ERROR(" Error opening file " + m_name ); 
00516     return false; 
00517   }
00518   translator = new Anaphe::AIDA_XMLStore::StoreTranslator(*inputStream); 
00519 
00520   // get the root element of the store parent to all objects (aida element) 
00521   DataXML::DataObject rootElement; 
00522   if (!translator->read(rootElement)) return false; 
00523  
00524   const std::vector<DataXML::DataObject> elements = rootElement.children();
00525 
00526   // check if any object is preset
00527   if (elements.size() == 0) return false; 
00528   
00529   // loop on all elements and build map of types and objects
00530   for (std::vector<DataXML::DataObject>::const_iterator iObj = elements.begin(); iObj != elements.end(); ++iObj) { 
00531 
00532     std::string type =  iObj->name();
00533     std::string path; 
00534     AIDA::Dev::IDevManagedObject * newObj = createFromXML( &(*iObj), path ); 
00535     // fill maps 
00536     if (newObj) { 
00537       m_objectTypes.insert( std::make_pair( path, newObj->userLevelClassType() ) );
00538       m_objectRefs.insert( std::make_pair( path, newObj ) );
00539     }
00540   }
00541 
00542 
00543   // delete the translator since is not needed anymore
00544   delete translator; 
00545   delete inputStream; 
00546   return true; 
00547 }
00548 
00550 
00551 AIDA::Dev::IDevManagedObject * 
00552   Anaphe::AIDA_XMLStore::AIDA_StoreXML::createFromXML(const DataXML::DataObject * xmlObj, std::string & path ) { 
00553 
00554   // Fetch the analysis factory
00555   std::auto_ptr<AIDA::Dev::IDevAnalysisFactory> af( dynamic_cast<AIDA::Dev::IDevAnalysisFactory*>( AIDA_createAnalysisFactory() ) );
00556   if ( ! af.get() ) {
00557     XML_STORE_REPORT_ERROR( "The store could not instantiate an analysis factory" );
00558     return 0;
00559   }
00560 
00561   // get type and then translate according the object
00562   std::string type = xmlObj->name();
00563   std::string name, dirPath; 
00564   AIDA::Dev::IDevManagedObject* newObject = 0;
00565 
00566 
00567 
00568   // case of object need to be created by the histogram factory
00569   // (histogram or profile or cloud ) 
00570   if (type.find("histogram") != std::string::npos  || 
00571       type.find("profile") != std::string::npos || 
00572       type.find("cloud") != std::string::npos ) { 
00573     AIDA::Dev::IHistogramFactoryProvider* fp = af->histogramFactoryProvider();
00574     if ( ! fp ) {
00575       XML_STORE_REPORT_ERROR( "The store could not retrieve the histogram factory provider from the analysis factory" );
00576       return 0;
00577     }
00578     AIDA::Dev::IDevHistogramFactory& factory = fp->devHistogramFactory();
00579 
00580     // create now according to specif type 
00581     if (type == "histogram1d") { 
00582       Anaphe::AIDA_XMLStore::Histo1DTranslator ht(xmlObj); 
00583       newObject = ht.createFromXML(factory); 
00584       name = ht.name(); 
00585       dirPath = ht.path();   // in XML is saved directory path 
00586     }
00587     if (type == "histogram2d") { 
00588       Anaphe::AIDA_XMLStore::Histo2DTranslator ht(xmlObj); 
00589       newObject = ht.createFromXML(factory); 
00590       name = ht.name(); 
00591       dirPath = ht.path();   // in XML is saved directory path 
00592     }
00593     if (type == "histogram3d") { 
00594       Anaphe::AIDA_XMLStore::Histo3DTranslator ht(xmlObj); 
00595       newObject = ht.createFromXML(factory); 
00596       name = ht.name(); 
00597       dirPath = ht.path();   // in XML is saved directory path 
00598     }
00599     if (type == "cloud1d") { 
00600       Anaphe::AIDA_XMLStore::Cloud1DTranslator ct(xmlObj); 
00601       newObject = ct.createFromXML(factory); 
00602       name = ct.name(); 
00603       dirPath = ct.path();   // in XML is saved directory path 
00604     }
00605     if (type == "cloud2d") { 
00606       Anaphe::AIDA_XMLStore::Cloud2DTranslator ct(xmlObj); 
00607       newObject = ct.createFromXML(factory); 
00608       name = ct.name(); 
00609       dirPath = ct.path();   // in XML is saved directory path 
00610     }
00611     if (type == "cloud3d") { 
00612       Anaphe::AIDA_XMLStore::Cloud3DTranslator ct(xmlObj); 
00613       newObject = ct.createFromXML(factory); 
00614       name = ct.name(); 
00615       dirPath = ct.path();   // in XML is saved directory path 
00616     }
00617     if (type == "profile1d") { 
00618       Anaphe::AIDA_XMLStore::Profile1DTranslator t(xmlObj); 
00619       newObject = t.createFromXML(factory); 
00620       name = t.name(); 
00621       dirPath = t.path();   // in XML is saved directory path 
00622     }
00623     if (type == "profile2d") { 
00624       Anaphe::AIDA_XMLStore::Profile2DTranslator t(xmlObj); 
00625       newObject = t.createFromXML(factory); 
00626       name = t.name(); 
00627       dirPath = t.path();   // in XML is saved directory path 
00628     }
00629   }
00630   else if (type == "dataPointSet") { 
00631     AIDA::Dev::IDataPointSetFactoryProvider* fp = af->dataPointSetFactoryProvider();
00632     if ( ! fp ) {
00633       XML_STORE_REPORT_ERROR( "The store could not retrieve the dataPointSet factory provider from the analysis factory" );
00634       return 0;
00635     }
00636     AIDA::Dev::IDevDataPointSetFactory& df = fp->devDataPointSetFactory();
00637     // translate the object from XML
00638     Anaphe::AIDA_XMLStore::DataPointSetTranslator t(xmlObj); 
00639     newObject = t.createFromXML(df); 
00640     name = t.name(); 
00641     dirPath = t.path();   // in XML is saved directory path 
00642   }
00643   else if (type == "function") { 
00644     AIDA::Dev::IFunctionFactoryProvider* fp = af->functionFactoryProvider();
00645     if ( ! fp ) {
00646       XML_STORE_REPORT_ERROR( "The store could not retrieve the dataPointSet factory provider from the analysis factory" );
00647       return 0;
00648     }
00649     AIDA::Dev::IDevFunctionFactory& ff = fp->devFunctionFactory();
00650     // translate the object from XML
00651     Anaphe::AIDA_XMLStore::FunctionTranslator t(xmlObj); 
00652     newObject = t.createFromXML(ff); 
00653     name = t.name(); 
00654     dirPath = t.path();   // in XML is saved directory path 
00655   }
00656 
00657   // set name for new object 
00658   if ( newObject ) {
00659 
00660     // path here is defined as "dirPath + name" 
00661     if (dirPath == "/") 
00662       path = dirPath + name; 
00663     else 
00664       path = dirPath + "/" + name; 
00665     //path = dirPath; 
00666 
00667     m_objectRefs[path] = newObject;
00668     newObject->setUpToDate( true );
00669     newObject->setName( name );
00670   }
00671 
00672   return newObject;
00673 
00674 }
00675 
00678  
00679 bool  Anaphe::AIDA_XMLStore::AIDA_StoreXML::writeToXML(AIDA::Dev::IDevManagedObject * object, const std::string & path ) { 
00680 
00681   if (!m_outputTranslator) return false; 
00682 
00683   // get type 
00684   const std::string&  type = object->userLevelClassType();
00685   std::string name = object->name(); 
00686   // extract directory path from full path 
00687 
00688   // check for first "/" staring from the end 
00689   std::string dirPath = path; 
00690   std::string lastItem = "";
00691   int iiii = 0; 
00692   for ( unsigned int iChar = path.size()-1; iChar >= 0; --iChar ) {
00693     const char& c = path[iChar];
00694     if ( c == '/' ) {
00695       if (iChar > 0) 
00696         dirPath = path.substr(0,iChar); 
00697       else 
00698         dirPath = path.substr(0,1);    // case of "/" 
00699 
00700       if (iChar < path.size()-1) 
00701         lastItem = path.substr(iChar+1,path.size()); 
00702       iiii = iChar;
00703       break;     
00704     }
00705 
00706   }
00707       
00708 
00709   if (lastItem != name) {
00710     XML_STORE_REPORT_ERROR( "AIDA_XMLStore:WritetoXML : Warning path is uncompatible with name ");
00711     return false;
00712   }
00713   
00714   //  std::string::size_type idx = path.rfind(name);
00715   //if ( idx != std::string::npos && idx == path.length() - name.length() ) 
00716   
00717   /* not working   
00718   if (path.substr(path.rfind(name)) == name) 
00719     // build dir eliminating extra "/" at the end 
00720     dirPath = path.substr(0,path.length()-name.length()-1);                     */
00721   
00722   if ( type == "IHistogram1D" ) {
00723     AIDA::IHistogram1D* p = dynamic_cast< AIDA::IHistogram1D* >( object );
00724     if ( !p ) return false;   
00725      // append object to store (but not write, that is done at commit time)
00726     if (!m_outputTranslator->append(*p,name,dirPath)) return false; 
00727   }
00728   if ( type == "IHistogram2D" ) {
00729     AIDA::IHistogram2D* p = dynamic_cast< AIDA::IHistogram2D* >( object );
00730     if ( !p ) return false;   
00731      // append object to store (but not write, that is done at commit time)
00732     if (!m_outputTranslator->append(*p,name,dirPath)) return false; 
00733   }
00734   if ( type == "IHistogram3d" ) {
00735     AIDA::IHistogram3D* p = dynamic_cast< AIDA::IHistogram3D* >( object );
00736     if ( !p ) return false;   
00737      // append object to store (but not write, that is done at commit time)
00738     if (!m_outputTranslator->append(*p,name,dirPath)) return false; 
00739   }
00740   if ( type == "ICloud1D" ) {
00741     AIDA::ICloud1D* p = dynamic_cast< AIDA::ICloud1D* >( object );
00742     if ( !p ) return false;   
00743      // append object to store (but not write, that is done at commit time)
00744     if (!m_outputTranslator->append(*p,name,dirPath)) return false; 
00745   }
00746   if ( type == "ICloud2D" ) {
00747     AIDA::ICloud2D* p = dynamic_cast< AIDA::ICloud2D* >( object );
00748     if ( !p ) return false;   
00749      // append object to store (but not write, that is done at commit time)
00750     if (!m_outputTranslator->append(*p,name,dirPath)) return false; 
00751   }
00752   if ( type == "ICloud3d" ) {
00753     AIDA::ICloud3D* p = dynamic_cast< AIDA::ICloud3D* >( object );
00754     if ( !p ) return false;   
00755      // append object to store (but not write, that is done at commit time)
00756     if (!m_outputTranslator->append(*p,name,dirPath)) return false; 
00757   }
00758   if ( type == "IProfile1D" ) {
00759     AIDA::IProfile1D* p = dynamic_cast< AIDA::IProfile1D* >( object );
00760     if ( !p ) return false;   
00761      // append object to store (but not write, that is done at commit time)
00762     if (!m_outputTranslator->append(*p,name,dirPath)) return false; 
00763   }
00764   if ( type == "IProfile2D" ) {
00765     AIDA::IProfile2D* p = dynamic_cast< AIDA::IProfile2D* >( object );
00766     if ( !p ) return false;   
00767      // append object to store (but not write, that is done at commit time)
00768     if (!m_outputTranslator->append(*p,name,dirPath)) return false; 
00769   }
00770   if ( type == "IDataPointSet" ) {
00771     AIDA::IDataPointSet* p = dynamic_cast< AIDA::IDataPointSet* >( object );
00772     if ( !p ) return false;   
00773      // append object to store (but not write, that is done at commit time)
00774     if (!m_outputTranslator->append(*p,name,dirPath)) return false; 
00775   }
00776   if ( type == "IFunction" ) {
00777     AIDA::IFunction* f = dynamic_cast< AIDA::IFunction* >( object );
00778     if ( !f ) return false;   
00779      // append object to store (but not write, that is done at commit time)
00780     if (!m_outputTranslator->append(*f,name,dirPath)) return false; 
00781   }
00782 
00783   return true; 
00784 }

Generated on Tue Nov 19 12:32:56 2002 for AIDA_XMLStore by doxygen1.2.16