InputCopyStream.cpp
Go to the documentation of this file.00001
00002 #define GAUDISVC_PERSISTENCYSVC_INPUTCOPYSTREAM_CPP
00003
00004
00005 #include "GaudiKernel/AlgFactory.h"
00006 #include "GaudiKernel/IRegistry.h"
00007 #include "GaudiKernel/IDataManagerSvc.h"
00008 #include "GaudiKernel/IDataProviderSvc.h"
00009 #include "GaudiKernel/IOpaqueAddress.h"
00010 #include "GaudiKernel/DataStoreItem.h"
00011 #include "GaudiKernel/DataObject.h"
00012 #include "GaudiKernel/MsgStream.h"
00013 #include "OutputStreamAgent.h"
00014 #include "InputCopyStream.h"
00015
00016
00017 DECLARE_ALGORITHM_FACTORY(InputCopyStream)
00018
00019
00020 InputCopyStream::InputCopyStream(const std::string& name, ISvcLocator* pSvcLocator)
00021 : OutputStream(name, pSvcLocator)
00022 {
00023 m_doPreLoad = false;
00024 m_doPreLoadOpt = false;
00025 m_itemNames.push_back("/Event#99999");
00026 declareProperty("TakeOptionalFromTES", m_takeOptionalFromTES = false,
00027 "Allow optional items to be on TES instead of input file") ;
00028 }
00029
00030
00031 InputCopyStream::~InputCopyStream() {
00032 }
00033
00034
00035 StatusCode InputCopyStream::collectLeaves(IRegistry* dir, int level) {
00036 MsgStream log(msgSvc(), name());
00037 if ( level < m_currentItem->depth() ) {
00038 if ( dir ) {
00039
00040 m_objects.push_back(dir->object());
00041 if ( dir->address() ) {
00042 std::vector<IRegistry*> lfs;
00043 const std::string& dbase = dir->address()->par()[0];
00044
00045 StatusCode iret, sc = m_pDataManager->objectLeaves(dir,lfs);
00046 if ( sc.isSuccess() ) {
00047 std::vector<IRegistry*>::iterator i=lfs.begin();
00048 for(; i!=lfs.end(); ++i) {
00049
00050 if ( (*i)->address() && (*i)->address()->par()[0] == dbase ) {
00051 DataObject* obj = 0;
00052 iret = m_pDataProvider->retrieveObject(dir, (*i)->name(), obj);
00053 if ( iret.isSuccess() ) {
00054 log << MSG::VERBOSE << "::collectLeaves Success retrieving " << (*i)->name() << endmsg ;
00055 iret = collectLeaves(*i, level+1);
00056 }
00057 if ( !iret.isSuccess() ) {
00058 log << MSG::VERBOSE << "::collectLeaves Failure retrieving " << (*i)->name() << endmsg ;
00059 sc = iret;
00060 }
00061 }
00062 }
00063 }
00064 return sc;
00065 }
00066 }
00067 return StatusCode::FAILURE;
00068 }
00069 return StatusCode::SUCCESS;
00070 }
00071
00073 StatusCode InputCopyStream::collectObjects() {
00074 MsgStream log(msgSvc(), name());
00075 StatusCode status = StatusCode::SUCCESS;
00076 Items::iterator i;
00077
00078 for ( i = m_itemList.begin(); i != m_itemList.end(); i++ ) {
00079 DataObject* obj = 0;
00080 m_currentItem = (*i);
00081 log << MSG::VERBOSE << "::collectObjects Looping over mandatory " << m_currentItem->path() << endmsg ;
00082 StatusCode iret = m_pDataProvider->retrieveObject(m_currentItem->path(), obj);
00083 if ( iret.isSuccess() ) {
00084 log << MSG::VERBOSE << "::collectObjects Success retrieving mandatory " << (*i)->path() << endmsg ;
00085 iret = collectLeaves(obj->registry(), 0);
00086 }
00087 if ( !iret.isSuccess() ) {
00088 log << MSG::ERROR << "Cannot write mandatory object(s) (Not found) "
00089 << m_currentItem->path() << endmsg;
00090 status = iret;
00091 }
00092 }
00093
00094 for ( i = m_optItemList.begin(); i != m_optItemList.end(); i++ ) {
00095 DataObject* obj = 0;
00096 m_currentItem = (*i);
00097 StatusCode iret = m_pDataProvider->retrieveObject(m_currentItem->path(), obj);
00098 if ( iret.isSuccess() ) {
00099 log << MSG::VERBOSE << "::collectObjects Success retrieving optional " << (*i)->path() << endmsg ;
00100 if ( m_takeOptionalFromTES ){
00101 iret = m_pDataManager->traverseSubTree(obj, m_agent);
00102 } else {
00103 iret = collectLeaves(obj->registry(), 0);
00104 }
00105 }
00106 if ( !iret.isSuccess() ) {
00107 log << MSG::DEBUG << "Ignore request to write non-mandatory object(s) "
00108 << m_currentItem->path() << endmsg;
00109 }
00110 }
00111 return status;
00112 }