| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# EvtCollectionStream.cpp

Go to the documentation of this file.

    00001 //      ====================================================================
    00002 //  EvtCollectionStream.cpp
    00003 //      --------------------------------------------------------------------
    00004 //
    00005 //      Package   : GaudiSvc/PersistencySvc
    00006 //
    00007 //      Author    : Markus Frank
    00008 //
    00009 //      ====================================================================
    00010 #define GAUDISVC_PERSISTENCYSVC_EVTCOLLECTIONSTREAM_CPP
    00011
    00012 // Framework include files
    00013 #include "GaudiKernel/AlgFactory.h"
    00014 #include "GaudiKernel/MsgStream.h"
    00015 #include "GaudiKernel/INTupleSvc.h"
    00016 #include "GaudiKernel/IDataProviderSvc.h"
    00017
    00018 #include "GaudiKernel/DataStoreItem.h"
    00019 #include "EvtCollectionStream.h"
    00020
    00021 // Define the algorithm factory for the standard output data writer
    00022 DECLARE_ALGORITHM_FACTORY(EvtCollectionStream)
    00023
    00024 // Standard Constructor
    00025 EvtCollectionStream::EvtCollectionStream(const std::string& name, ISvcLocator* pSvcLocator)
    00026 : Algorithm(name, pSvcLocator)
    00027 {
    00028   m_pTupleSvc = 0;
    00029   m_storeName = "TagCollectionSvc";
    00030   declareProperty("ItemList",   m_itemNames);
    00031   declareProperty("EvtDataSvc", m_storeName);
    00032 }
    00033
    00034 // Standard Destructor
    00035 EvtCollectionStream::~EvtCollectionStream()   {
    00036 }
    00037
    00038 // initialize data writer
    00039 StatusCode EvtCollectionStream::initialize() {
    00040   MsgStream log(msgSvc(), name());
    00041   // Use the Job options service to set the Algorithm's parameters
    00042   setProperties();
    00043   // Get access to the DataManagerSvc
    00044   StatusCode status = serviceLocator()->service(m_storeName, m_pTupleSvc, true );
    00045   if( !status.isSuccess() )   {
    00046     log << MSG::FATAL << "Unable to locate IDataManagerSvc interface" << endreq;
    00047     return status;
    00048   }
    00049   m_pTupleSvc->addRef();
    00050   // Clear the item list
    00051   clearItems();
    00052   // Take the new item list from the properties.
    00053   for(ItemNames::iterator i = m_itemNames.begin(); i != m_itemNames.end(); i++)   {
    00054     addItem( *i );
    00055   }
    00056   log << MSG::INFO << "Data source:             " << m_storeName  << endreq;
    00057   return status;
    00058 }
    00059
    00060 // terminate data writer
    00061 StatusCode EvtCollectionStream::finalize()    {
    00062   if ( 0 != m_pTupleSvc )   {
    00063     m_pTupleSvc->release();
    00064     m_pTupleSvc = 0;
    00065   }
    00066   clearItems();
    00067   return StatusCode::SUCCESS;
    00068 }
    00069
    00070 // Work entry point
    00071 StatusCode EvtCollectionStream::execute() {
    00072   StatusCode status = (m_pTupleSvc) ? StatusCode::SUCCESS : StatusCode::FAILURE;
    00073   if ( status.isSuccess() )   {
    00074     for ( Items::iterator i = m_itemList.begin(); i != m_itemList.end(); i++ )    {
    00075       StatusCode iret = m_pTupleSvc->writeRecord((*i)->path());
    00076       if ( !iret.isSuccess() )    {
    00077         status = iret;
    00078       }
    00079     }
    00080   }
    00081   return status;
    00082 }
    00083
    00084 // Remove all items from the output streamer list;
    00085 void EvtCollectionStream::clearItems()     {
    00086   for ( Items::iterator i = m_itemList.begin(); i != m_itemList.end(); i++ )    {
    00087     delete (*i);
    00088   }
    00089   m_itemList.erase(m_itemList.begin(), m_itemList.end());
    00090 }
    00091
    00092 // Add item to output streamer list
    00093 void EvtCollectionStream::addItem(const std::string& descriptor)   {
    00094   MsgStream log(msgSvc(), name());
    00095   int sep = descriptor.rfind("#");
    00096   int level = 0;
    00097   std::string obj_path (descriptor,0,sep);
    00098   std::string slevel   (descriptor,sep+1,descriptor.length());
    00099   if ( slevel == "*" )  {
    00100     level = 9999999;
    00101   }
    00102   else   {
    00103     level = ::atoi(slevel.c_str());
    00104   }
    00105   DataStoreItem* item = new DataStoreItem(obj_path, level);
    00106   log << MSG::INFO << "Adding OutputStream item " << item->path()
    00107       << " with " << item->depth()
    00108       << " level(s)." << endreq;
    00109   m_itemList.push_back( item );
    00110 }