14 #include <boost/filesystem.hpp> 21 #define ON_DEBUG if ( UNLIKELY( outputLevel() <= MSG::DEBUG ) ) 22 #define ON_VERBOSE if ( UNLIKELY( outputLevel() <= MSG::VERBOSE ) ) 24 #define DEBMSG ON_DEBUG debug() 25 #define VERMSG ON_VERBOSE verbose() 58 error() <<
"Unable to initialize Service base class" <<
endmsg;
64 if (
service(
"IncidentSvc", p_incSvc,
true ).isFailure() ) {
65 error() <<
"unable to get the IncidentSvc" <<
endmsg;
68 p_incSvc->
addListener(
this, IncidentType::BeginOutputFile, 100,
true );
69 p_incSvc->
addListener(
this, IncidentType::BeginInputFile, 100,
true );
91 if ( 0 == iocomponent ) {
107 if ( 0 == iocomponent ) {
112 DEBMSG <<
"io_contains: c: " << ioname <<
" f: " << fname <<
endmsg;
115 if ( fit.first == fit.second ) {
119 for ( it = fit.first; it != fit.second; ++it ) {
123 error() <<
"IIoComponent " << ioname <<
" has empty old filename" <<
endmsg;
144 if ( !iocomponent ) {
145 error() <<
"io_register (component) received a NULL pointer !" <<
endmsg;
149 DEBMSG <<
"--> io_register(" << ioname <<
")" <<
endmsg;
152 DEBMSG <<
" registering IoComponent \"" << ioname <<
"\"" <<
endmsg;
157 info() <<
"IoComponent[" << iocomponent->
name() <<
"] already registered @" << (
void*)itr->second << endmsg;
173 if ( 0 == iocomponent ) {
179 << fname <<
")" <<
endmsg;
183 error() <<
"could not register component [" << iocomponent->
name() <<
"] " 184 <<
"with the I/O component manager !" <<
endmsg;
190 if ( fit.first != fit.second ) {
191 for (
iodITR it = fit.first; it != fit.second; ++it ) {
195 info() <<
"IoComponent " << ioname <<
" has already had file " << fname <<
" registered with i/o mode " 199 warning() <<
"IoComponent " << ioname <<
" has already had file " << fname
200 <<
" registered with a different i/o mode " << ioe.
m_iomode <<
" - now trying " << iomode <<
endmsg;
209 bool from_eos = tmp_name.
find(
"root:" ) == 0;
210 IoComponentEntry ioc( fname, ( from_eos ? tmp_name : boost::filesystem::absolute( tmp_name ).
string() ), iomode );
223 if ( 0 == iocomponent ) {
230 DEBMSG <<
"--> io_retrieve(" << ioname <<
"," << fname <<
")" <<
endmsg;
233 if ( !
findComp( iocomponent, ofname, it ) ) {
234 DEBMSG <<
"could not find c: " << ioname <<
" old_f: " << ofname <<
endmsg;
238 IoDict_t::iterator it;
241 if ( it->second.m_oldfname == ofname ) {
242 DEBMSG <<
"retrieving new name for the component " << iocomponent->
name() <<
" old name: " << ofname
243 <<
", new name: " << it->second.m_newfname <<
endmsg;
244 fname = it->second.m_newfname;
250 DEBMSG <<
"Unexpected error! Unable to find entry in the dictionary corresponding to old filename: " << ofname
266 debug() <<
"reinitializing I/O subsystem..." <<
endmsg;
273 DEBMSG <<
" [" << io->name() <<
"]->io_reinit()..." <<
endmsg;
274 if ( !io->io_reinit().isSuccess() ) {
276 error() <<
"problem in [" << io->name() <<
"]->io_reinit() !" <<
endmsg;
296 DEBMSG <<
"--> io_update(" << ioc->
name() <<
"," << old_fname <<
"," << new_fname <<
")" <<
endmsg;
298 IoDict_t::iterator it;
301 if ( it->second.m_oldfname == old_fname ) {
302 DEBMSG <<
"updating " << ioc->
name() <<
" f: " << old_fname <<
" -> " << new_fname <<
endmsg;
303 it->second.m_newfname = new_fname;
316 DEBMSG <<
"--> io_update(" << ioc->
name() <<
"," << work_dir <<
")" <<
endmsg;
318 IoDict_t::iterator it;
321 switch ( it->second.m_iomode ) {
323 it->second.m_newfname = it->second.m_oldabspath;
328 if ( oldPath.is_relative() && oldPath.filename() == oldPath.relative_path() ) {
339 it->second.m_newfname = newfname.string();
342 it->second.m_newfname = it->second.m_oldabspath;
349 error() <<
"Unable to update IoComponent for the mode " << it->second.m_iomode <<
endmsg;
363 DEBMSG <<
"-->io_update_all for the directory " << work_dir <<
endmsg;
368 error() <<
"problem in [" << ( *io )->name() <<
"]->io_update() !" <<
endmsg;
385 debug() <<
"finalizing I/O subsystem..." <<
endmsg;
392 DEBMSG <<
" [" << ( *io )->name() <<
"]->io_finalize()..." <<
endmsg;
393 if ( !( *io )->io_finalize().isSuccess() ) {
395 error() <<
"problem in [" << ( *io )->name() <<
"]->io_finalize() !" <<
endmsg;
412 return std::any_of( pit.first, pit.second, [&]( IoDict_t::const_reference i ) { return i.second.m_oldfname == f; } );
421 return pit.first != pit.second;
443 ost <<
"Listing all IoComponents (" <<
m_cdict.
size() <<
"): " <<
endl;
444 for (
const auto& i :
m_cdict ) {
445 ost <<
" " << i.first->name() <<
" " << i.second <<
endl;
458 if ( i.
type() == IncidentType::BeginInputFile ) {
466 while ( pit.first != pit.second ) {
477 }
else if ( i.
type() == IncidentType::BeginOutputFile ) {
485 while ( pit.first != pit.second ) {
StatusCode finalize() override
StatusCode initialize() override
This class is the FileIncident.
const std::string & type() const
Access to the incident type.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
bool io_contains(IIoComponent *iocomponent, const std::string &fname) const override
: check if the registry contains a given IIoComponent and that component had
This file contains the class definition for the FileIncident class.
const std::string & source() const
Access to the source of the incident.
bool isSuccess() const
Test for a status code of SUCCESS.
IoDict_t::const_iterator iodITR
IoRegistry_t m_ioregistry
Registry of IIoComponents.
void handle(const Incident &) override
#define DECLARE_COMPONENT(type)
StatusCode initialize() override
Gaudi Service Implementation.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
bool findComp(IIoComponent *, const std::string &, iodITR &) const
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
This class is used for returning status codes from appropriate routines.
StatusCode io_register(IIoComponent *iocomponent) override
: allow a IIoComponent to register itself with this manager so appropriate actions can be taken when ...
StatusCode io_update(IIoComponent *iocomponent, const std::string &old_fname, const std::string &new_fname) override
: allow a IIoComponent to update the contents of the registry with a new file name ...
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
IIoComponentMgr::IoMode::Type m_iomode
StatusCode io_update_all(const std::string &work_dir) override
: Update all IIoComponents with a new work directory
Base class for all Incidents (computing events).
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
const std::string & fileGuid() const
StatusCode io_retrieve(IIoComponent *iocomponent, std::string &fname) override
: retrieve the new filename for a given IIoComponent and
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
StatusCode io_finalize() override
: finalize the I/O subsystem.
StatusCode io_reinitialize() override
: reinitialize the I/O subsystem.
IoStack_t m_iostack
Stack of IIoComponents to properly handle order of registration.
const std::string & fileName() const
Type
the list of available types for ntuples
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
virtual const std::string & name() const =0
Retrieve the name of the instance.
The interface implemented by the IncidentSvc service.
bool io_hasitem(IIoComponent *iocomponent) const override
: check if the registry contains a given IIoComponent