#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 << "Data Reader / Collection 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 << "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 #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 "AttributeList/AttributeList.h" #include "Event.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(); // Create a data service and tell it which catalog to use std::auto_ptr dataSvc( pool::DataSvcFactory::instance( fileCatalog.get() ) ); // Start a transaction for the file catalog fileCatalog->start(); // Start a read transaction dataSvc->transaction().start( pool::ITransaction::READ ); // Create a new explicit collection pool::Collection< pool_tutorial::Event > selectedEvents( dataSvc.get(), "RootCollection", "eventCollection", "", pool::ICollection::CREATE_AND_OVERWRITE ); pool::AttributeListSpecification& spec = selectedEvents.attributeListSpecification(); spec.push_back( "run", "int" ); spec.push_back( "event", "int" ); spec.push_back( "E_ecal", "double" ); spec.push_back( "E_hcal", "double" ); // Loop over the two runs for ( int iRun = 0; iRun < 2; ++iRun ) { std::ostringstream osdbfile; osdbfile << "PFN:events_run_" << iRun + 1 << ".root"; // Loop over the Event objects in the container "eventHeaders" in the database "event.root" pool::Collection eventCollection( dataSvc.get(), "ImplicitCollection", osdbfile.str(), "eventHeaders", pool::ICollection::READ ); pool::Collection::Iterator event = eventCollection.select(); // For every event read back the total deposited energy in each of the two sectors. while ( event.next() ) { const pool_tutorial::Sector& ecal = event->ecalData(); double totalEneryInECal = 0; for ( pool_tutorial::Sector::const_iterator iCluster = ecal.begin(); iCluster != ecal.end(); ++iCluster ) totalEneryInECal += iCluster->energyDeposited(); const pool_tutorial::Sector& hcal = event->hcalData(); double totalEneryInHCal = 0; for ( pool_tutorial::Sector::const_iterator iCluster = hcal.begin(); iCluster != hcal.end(); ++iCluster ) totalEneryInHCal += iCluster->energyDeposited(); // Insert in the explicit collection an entry if ( totalEneryInECal + totalEneryInHCal > 0 ) { pool::AttributeList attrList( spec ); attrList[ "run" ].setValue( iRun + 1 ); attrList[ "event" ].setValue( event->eventNumber() ); attrList[ "E_ecal" ].setValue( totalEneryInECal ); attrList[ "E_hcal" ].setValue( totalEneryInHCal ); selectedEvents.add( event.ref(), attrList ); } } } // Committing and closing the collection selectedEvents.commit(); selectedEvents.close(); // commit the transaction dataSvc->transaction().commit(); // Commit the file catalog transaction fileCatalog->commit(); }