Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

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 static const AlgFactory<EvtCollectionStream> s_factory;
00023 const IAlgFactory& EvtCollectionStreamFactory = s_factory;
00024 
00025 // Standard Constructor
00026 EvtCollectionStream::EvtCollectionStream(const std::string& name, ISvcLocator* pSvcLocator)
00027 : Algorithm(name, pSvcLocator)
00028 {
00029   m_pTupleSvc = 0;
00030   m_storeName = "NTupleSvc";
00031         declareProperty("ItemList",   m_itemNames);
00032         declareProperty("EvtDataSvc", m_storeName);
00033 }
00034 
00035 // Standard Destructor
00036 EvtCollectionStream::~EvtCollectionStream()   {
00037 }
00038 
00039 // initialize data writer
00040 StatusCode EvtCollectionStream::initialize() {
00041         MsgStream log(msgSvc(), name());
00042         // Use the Job options service to set the Algorithm's parameters
00043         setProperties();
00044   // Get access to the DataManagerSvc
00045   StatusCode status = serviceLocator()->getService(m_storeName, IID_INTupleSvc, (IInterface*&)m_pTupleSvc );
00046   if( !status.isSuccess() )   {
00047     log << MSG::FATAL << "Unable to locate IDataManagerSvc interface" << endreq;
00048     return status;
00049   }
00050   m_pTupleSvc->addRef();
00051   // Clear the item list
00052   clearItems();
00053   // Take the new item list from the properties.
00054   for(ItemNames::iterator i = m_itemNames.begin(); i != m_itemNames.end(); i++)   {
00055     addItem( *i );
00056   }
00057   log << MSG::INFO << "Data source:             " << m_storeName  << endreq;
00058   return status;
00059 }
00060 
00061 // terminate data writer
00062 StatusCode EvtCollectionStream::finalize()    {
00063   if ( 0 != m_pTupleSvc )   {
00064     m_pTupleSvc->release();
00065     m_pTupleSvc = 0;
00066   }
00067   clearItems();
00068   return StatusCode::SUCCESS;
00069 }
00070 
00071 // Work entry point
00072 StatusCode EvtCollectionStream::execute() {
00073   StatusCode status = (m_pTupleSvc) ? StatusCode::SUCCESS : StatusCode::FAILURE;
00074   if ( status.isSuccess() )   {
00075     for ( Items::iterator i = m_itemList.begin(); i != m_itemList.end(); i++ )    {
00076       StatusCode iret = m_pTupleSvc->writeRecord((*i)->path());
00077       if ( !iret.isSuccess() )    {
00078         status = iret;
00079       }
00080     }
00081   }
00082   return status;
00083 }
00084 
00085 // Remove all items from the output streamer list;
00086 void EvtCollectionStream::clearItems()     {
00087   for ( Items::iterator i = m_itemList.begin(); i != m_itemList.end(); i++ )    {  
00088     delete (*i);
00089   }
00090   m_itemList.erase(m_itemList.begin(), m_itemList.end());
00091 }
00092 
00093 // Add item to output streamer list
00094 void EvtCollectionStream::addItem(const std::string& descriptor)   {
00095         MsgStream log(msgSvc(), name());
00096   int sep = descriptor.rfind("#");
00097   int level = 0;
00098   std::string obj_path (descriptor,0,sep);
00099   std::string slevel   (descriptor,sep+1,descriptor.length());
00100   if ( slevel == "*" )  {
00101     level = 9999999;
00102   }
00103   else   {
00104     level = atoi(slevel.c_str());
00105   }
00106   DataStoreItem* item = new DataStoreItem(obj_path, level);
00107   log << MSG::INFO << "Adding OutputStream item " << item->path()
00108       << " with " << item->depth() 
00109       << " level(s)." << endreq;
00110   m_itemList.push_back( item );
00111 }

Generated at Wed Nov 21 12:22:29 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000