#include #include #include "SealKernel/Exception.h" class PoolApplication { public: // Constructor. Initializes all the services. PoolApplication(); // Destructor ~PoolApplication(); // main method void run(); }; // The program main. int main( int, char** ) { std::cout << "Writer application starts." << std::endl; try { PoolApplication app; app.run(); } catch ( seal::Exception& e ) { std::cerr << e.what() << std::endl; return 1; } catch ( std::exception& e ) { std::cerr << e.what() << std::endl; return 1; } catch ( ... ) { std::cerr << "Funny error" << std::endl; return 1; } std::cout << "Writer application successfully finished." << std::endl; return 0; } #include #include "SealBase/SharedLibrary.h" #include "SealBase/SharedLibraryError.h" #include "POOLCore/POOLContext.h" // Constructor of PoolApplication PoolApplication::PoolApplication() { // Loads the seal message stream pool::POOLContext::loadComponent( "SEAL/Services/MessageService" ); // Set the verbosity threshold to warnings pool::POOLContext::setMessageVerbosityLevel( seal::Msg::Warning ); // Loads the dictionary const std::string dictlibrary = "EventModelDict"; try { seal::SharedLibrary::load( seal::SharedLibrary::libname( dictlibrary ) ); } catch ( seal::SharedLibraryError *error) { throw std::runtime_error( error->explainSelf().c_str() ); } std::cout << "Successfully loaded the services" << std::endl; } // Destructor of PoolApplication PoolApplication::~PoolApplication() {} #include #include #include "FileCatalog/URIParser.h" #include "FileCatalog/IFileCatalog.h" #include "StorageSvc/DbType.h" #include "PersistencySvc/Placement.h" #include "PersistencySvc/ITransaction.h" #include "PersistencySvc/ISession.h" #include "PersistencySvc/DatabaseConnectionPolicy.h" #include "DataSvc/IDataSvc.h" #include "DataSvc/DataSvcFactory.h" #include "DataSvc/Ref.h" #include "Hit.h" // Main method of PoolApplication void PoolApplication::run() { // Create a file catalog and connect to it pool::URIParser p; p.parse(); std::auto_ptr fileCatalog( new pool::IFileCatalog ); fileCatalog->setWriteCatalog( p.contactstring() ); fileCatalog->connect(); // Start a transaction for the file catalog fileCatalog->start(); // create a data service and tell it which catalog to use std::auto_ptr dataSvc( pool::DataSvcFactory::instance( fileCatalog.get() ) ); // Define the policy for the implicit file handling pool::DatabaseConnectionPolicy policy; // If the file does not exist, create a new one. policy.setWriteModeForNonExisting( pool::DatabaseConnectionPolicy::CREATE ); // If the file already exists, overwrite it. policy.setWriteModeForExisting( pool::DatabaseConnectionPolicy::OVERWRITE ); // set the policy dataSvc->session().setDefaultConnectionPolicy( policy ); // start an update transaction dataSvc->transaction().start( pool::ITransaction::UPDATE ); // Digits will be written into a database file called "pool_tutorial_5.root", // a container called "digits", using a ROOT Tree storage technology. pool::Placement placementDigits; placementDigits.setDatabase( "pool_tutorial_5.root", pool::DatabaseSpecification::PFN ); placementDigits.setContainerName( "digits" ); placementDigits.setTechnology( pool::ROOTTREE_StorageType.type() ); // Hits will be written into the same database file // a container called "hits", using a ROOT Tree storage technology. pool::Placement placementHits; placementHits.setDatabase( "pool_tutorial_5.root", pool::DatabaseSpecification::PFN ); placementHits.setContainerName( "hits" ); placementHits.setTechnology( pool::ROOTTREE_StorageType.type() ); // Now create and write 1000 Digit hits. // For each digit construct and write a hit associated to the digit ::srand(0); for ( int i = 0; i < 1000; ++i ) { // The digit pool::Ref< pool_tutorial::Digit > digit( dataSvc.get(), new pool_tutorial::Digit() ); digit.markWrite( placementDigits ); digit->setIndex( ::rand()%5 ); digit->setValue( ::rand()%100 ); // The hit pool::Ref< pool_tutorial::Hit > hit( dataSvc.get(), new pool_tutorial::Hit() ); hit.markWrite( placementHits ); // Establishing the hit->digit association hit->setDigit( digit ); } // commit the transaction dataSvc->transaction().commit(); // Commit the file catalog transaction fileCatalog->commit(); }