#include #include #include "SealKernel/Exception.h" #include "PersistencySvc/Placement.h" #include "FileCatalog/IFileCatalog.h" #include "DataSvc/IDataSvc.h" class PoolApplication { public: // Constructor. Initializes all the services. PoolApplication(); // Destructor ~PoolApplication(); // main method void run(); private: // The file catalog pool::IFileCatalog* fileCatalog; // The data service pool::IDataSvc* dataSvc; // The clustering hints pool::Placement placementECAL; pool::Placement placementHCAL; pool::Placement placementEvent; }; // 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" #include "FileCatalog/URIParser.h" #include "StorageSvc/DbType.h" #include "PersistencySvc/ISession.h" #include "PersistencySvc/DatabaseConnectionPolicy.h" #include "DataSvc/DataSvcFactory.h" // Constructor of PoolApplication PoolApplication::PoolApplication(): fileCatalog( 0 ), dataSvc( 0 ) { // 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() ); } // Create a file catalog and connect to it pool::URIParser p; p.parse(); fileCatalog = new pool::IFileCatalog; fileCatalog->setWriteCatalog( p.contactstring() ); fileCatalog->connect(); // create a data service and tell it which catalog to use dataSvc = pool::DataSvcFactory::instance( fileCatalog ); // 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 ); // ECAL Sector objects will be written into a database file called "ecal.root", // a container called "clusters", using a ROOT Tree storage technology. placementECAL.setDatabase( "ecal.root", pool::DatabaseSpecification::PFN ); placementECAL.setContainerName( "clusters" ); placementECAL.setTechnology( pool::ROOTTREE_StorageType.type() ); // HCAL Sector objects will be written into a database file called "hcal.root", // a container called "clusters", using a ROOT Tree storage technology. placementHCAL.setDatabase( "hcal.root", pool::DatabaseSpecification::PFN ); placementHCAL.setContainerName( "clusters" ); placementHCAL.setTechnology( pool::ROOTTREE_StorageType.type() ); // Event objects will be written into a database file called "events.root", // a container called "eventHeaders", using a ROOT Tree storage technology. placementEvent.setDatabase( "event.root", pool::DatabaseSpecification::PFN ); placementEvent.setContainerName( "eventHeaders" ); placementEvent.setTechnology( pool::ROOTTREE_StorageType.type() ); } // Destructor of PoolApplication PoolApplication::~PoolApplication() { if ( dataSvc ) delete dataSvc; if ( fileCatalog ) delete fileCatalog; } #include #include "PersistencySvc/ITransaction.h" #include "DataSvc/Ref.h" #include "Event.h" // Main method of PoolApplication void PoolApplication::run() { ::srand( 0 ); // Start a transaction for the file catalog fileCatalog->start(); // start an update transaction dataSvc->transaction().start( pool::ITransaction::UPDATE ); // Now loop over 10 events for ( int i = 0; i < 10; ++i ) { std::cout << "Writing event " << i + 1 << std::endl; pool::Ref< pool_tutorial::Event > event( dataSvc, new pool_tutorial::Event( i + 1 ) ); event.markWrite( placementEvent ); // Create the two sectors and attach them to the event pool::Ref< pool_tutorial::Sector > ecal( dataSvc, new pool_tutorial::Sector( "ECAL" ) ); pool::Ref< pool_tutorial::Sector > hcal( dataSvc, new pool_tutorial::Sector( "HCAL" ) ); ecal.markWrite( placementECAL ); hcal.markWrite( placementHCAL ); event->setECalData( ecal ); event->setHCalData( hcal ); // Fill in two clusters in each sector for ( int iCluster = 0; iCluster < 2; ++iCluster ) { double x = -100.0 + ( 200.0 * ::rand() ) / RAND_MAX; double y = -100.0 + ( 200.0 * ::rand() ) / RAND_MAX; double x_ecal = x + ( -1.0 + (2.0 * ::rand() ) / RAND_MAX ); double y_ecal = y + ( -1.0 + (2.0 * ::rand() ) / RAND_MAX ); double x_hcal = x + ( -5.0 + (10.0 * ::rand() ) / RAND_MAX ); double y_hcal = y + ( -5.0 + (10.0 * ::rand() ) / RAND_MAX ); double z_ecal = ( 100.0 * ::rand() ) / RAND_MAX; double z_hcal = 100 + ( 100.0 * ::rand() ) / RAND_MAX; double de_ecal = 50 + ( 10.0 * ::rand() ) / RAND_MAX; double de_hcal = 30 + ( 5.0 * ::rand() ) / RAND_MAX; pool_tutorial::Cluster e_cluster; e_cluster.setEnergyDeposited( de_ecal ); e_cluster.setPosition( x_ecal, y_ecal, z_ecal ); ecal->addCluster( e_cluster ); pool_tutorial::Cluster h_cluster; h_cluster.setEnergyDeposited( de_hcal ); h_cluster.setPosition( x_hcal, y_hcal, z_hcal ); hcal->addCluster( h_cluster ); } } // commit the transaction dataSvc->transaction().commit(); // Commit the file catalog transaction fileCatalog->commit(); }