#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 << "Reader 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 << "Reader 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 "FileCatalog/URIParser.h" #include "FileCatalog/IFileCatalog.h" #include "PersistencySvc/ITransaction.h" #include "PersistencySvc/ISession.h" #include "DataSvc/IDataSvc.h" #include "DataSvc/DataSvcFactory.h" #include "Collection/Collection.h" #include "Hit.h" #include "Transformation.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->addReadCatalog( 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() ) ); // Start a read transaction dataSvc->transaction().start( pool::ITransaction::READ ); // Define a transformation object pool_tutorial::Transformation transformation; // Loop over the Hit objects in the container "hits" in the database "pool_tutorial_5.root" pool::Collection hitCollection( dataSvc.get(), "ImplicitCollection", "PFN:pool_tutorial_5.root", "hits", pool::ICollection::READ ); pool::Collection::Iterator hit = hitCollection.select(); // For every hit read back its contents as well as the contents of the associated digit // Calculate the average hit value double value = 0; int nHits = 0; while ( hit.next() ) { hit->setTransformation( &transformation ); value += hit->value(); ++nHits; } std::cout << "Average hit value : " << value/nHits << std::endl; // commit the transaction dataSvc->transaction().commit(); // Commit the file catalog transaction fileCatalog->commit(); }