16 #include <boost/algorithm/string/predicate.hpp> 17 #include <boost/filesystem.hpp> 22 #define ON_DEBUG if ( UNLIKELY( outputLevel() <= MSG::DEBUG ) ) 23 #define ON_VERBOSE if ( UNLIKELY( outputLevel() <= MSG::VERBOSE ) ) 25 #define DEBMSG ON_DEBUG debug() 26 #define VERMSG ON_VERBOSE verbose() 57 error() <<
"Unable to initialize Service base class" <<
endmsg;
63 if ( service(
"IncidentSvc", p_incSvc,
true ).isFailure() ) {
64 error() <<
"unable to get the IncidentSvc" <<
endmsg;
67 p_incSvc->
addListener(
this, IncidentType::BeginOutputFile, 100,
true );
68 p_incSvc->
addListener(
this, IncidentType::BeginInputFile, 100,
true );
88 if ( 0 == iocomponent ) {
return false; }
90 IoRegistry_t::const_iterator io = m_ioregistry.
find( ioname );
91 return io != m_ioregistry.end();
101 if ( 0 == iocomponent ) {
return false; }
104 DEBMSG <<
"io_contains: c: " << ioname <<
" f: " << fname <<
endmsg;
107 if ( fit.first == fit.second ) {
111 for ( it = fit.first; it != fit.second; ++it ) {
115 error() <<
"IIoComponent " << ioname <<
" has empty old filename" <<
endmsg;
135 if ( !iocomponent ) {
136 error() <<
"io_register (component) received a NULL pointer !" <<
endmsg;
140 DEBMSG <<
"--> io_register(" << ioname <<
")" <<
endmsg;
141 auto itr = m_ioregistry.find( ioname );
142 if ( itr == m_ioregistry.end() ) {
143 DEBMSG <<
" registering IoComponent \"" << ioname <<
"\"" <<
endmsg;
145 m_ioregistry[ioname] = iocomponent;
146 m_iostack.push_back( iocomponent );
148 info() <<
"IoComponent[" << iocomponent->
name() <<
"] already registered @" << (
void*)itr->second <<
endmsg;
167 << fname <<
")" <<
endmsg;
169 if ( !io_hasitem( iocomponent ) ) {
170 if ( !io_register( iocomponent ).isSuccess() ) {
171 error() <<
"could not register component [" << iocomponent->
name() <<
"] " 172 <<
"with the I/O component manager !" <<
endmsg;
178 if ( fit.first != fit.second ) {
179 for (
iodITR it = fit.first; it != fit.second; ++it ) {
183 info() <<
"IoComponent " << ioname <<
" has already had file " << fname <<
" registered with i/o mode " 187 warning() <<
"IoComponent " << ioname <<
" has already had file " << fname
188 <<
" registered with a different i/o mode " << ioe.
m_iomode <<
" - now trying " << iomode <<
endmsg;
198 [&](
const std::string& pf ) {
return boost::algorithm::contains( tmp_name, pf ); } );
199 IoComponentEntry ioc( fname, ( special_case ? tmp_name : boost::filesystem::absolute( tmp_name ).
string() ), iomode );
212 if ( iocomponent !=
nullptr && findComp( iocomponent, pit ) ) {
214 [](
const auto& itr ) { return itr.second.m_oldfname; } );
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;
239 for ( it = m_cdict.equal_range( iocomponent ).first; it != m_cdict.equal_range( iocomponent ).second; ++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
263 debug() <<
"--> io_reinitialize()" <<
endmsg;
264 debug() <<
"reinitializing I/O subsystem..." <<
endmsg;
265 debug() <<
"Listing all monitored entries: " <<
std::endl;
270 for (
auto& io : m_iostack ) {
271 DEBMSG <<
" [" << io->name() <<
"]->io_reinit()..." <<
endmsg;
272 if ( !io->io_reinit().isSuccess() ) {
274 error() <<
"problem in [" << io->name() <<
"]->io_reinit() !" <<
endmsg;
293 DEBMSG <<
"--> io_update(" << ioc->
name() <<
"," << old_fname <<
"," << new_fname <<
")" <<
endmsg;
295 IoDict_t::iterator it;
296 for ( it = m_cdict.equal_range( ioc ).first; it != m_cdict.equal_range( ioc ).second; ++it ) {
298 if ( it->second.m_oldfname == old_fname ) {
299 DEBMSG <<
"updating " << ioc->
name() <<
" f: " << old_fname <<
" -> " << new_fname <<
endmsg;
300 it->second.m_newfname = new_fname;
312 DEBMSG <<
"--> io_update(" << ioc->
name() <<
"," << work_dir <<
")" <<
endmsg;
314 IoDict_t::iterator it;
315 for ( it = m_cdict.equal_range( ioc ).first; it != m_cdict.equal_range( ioc ).second; ++it ) {
317 switch ( it->second.m_iomode ) {
319 it->second.m_newfname = it->second.m_oldabspath;
324 if ( oldPath.is_relative() && oldPath.filename() == oldPath.relative_path() ) {
335 it->second.m_newfname = newfname.string();
338 it->second.m_newfname = it->second.m_oldabspath;
345 error() <<
"Unable to update IoComponent for the mode " << it->second.m_iomode <<
endmsg;
358 DEBMSG <<
"-->io_update_all for the directory " << work_dir <<
endmsg;
360 for ( IoStack_t::iterator io = m_iostack.begin(), ioEnd = m_iostack.end(); io != ioEnd; ++io ) {
361 if ( !io_update( *io, work_dir ).isSuccess() ) {
363 error() <<
"problem in [" << ( *io )->name() <<
"]->io_update() !" <<
endmsg;
377 debug() <<
"--> io_finalize()" <<
endmsg;
378 debug() <<
"finalizing I/O subsystem..." <<
endmsg;
379 debug() <<
"Listing all monitored entries: " <<
std::endl;
385 for ( IoStack_t::reverse_iterator io = m_iostack.rbegin(), ioEnd = m_iostack.rend(); io != ioEnd; ++io ) {
386 DEBMSG <<
" [" << ( *io )->name() <<
"]->io_finalize()..." <<
endmsg;
387 if ( !( *io )->io_finalize().isSuccess() ) {
389 error() <<
"problem in [" << ( *io )->name() <<
"]->io_finalize() !" <<
endmsg;
401 if ( !findComp(
c, pit ) ) {
405 return std::any_of( pit.first, pit.second, [&]( IoDict_t::const_reference i ) { return i.second.m_oldfname == f; } );
412 pit = m_cdict.equal_range(
c );
413 return pit.first != pit.second;
420 pit.first = m_cdict.end();
421 pit.second = m_cdict.end();
423 auto itr = m_ioregistry.find(
c );
424 return ( itr != m_ioregistry.end() ) && findComp( itr->second, pit );
433 ost <<
"Listing all IoComponents (" << m_cdict.size() <<
"): " <<
endl;
434 for (
const auto& i : m_cdict ) { ost <<
" " << i.first->name() <<
" " << i.second <<
endl; }
445 if ( i.
type() == IncidentType::BeginInputFile ) {
447 const FileIncident* fi = dynamic_cast<const FileIncident*>( &i );
451 if ( findComp( fi->
source(), pit ) ) {
453 while ( pit.first != pit.second ) {
464 }
else if ( i.
type() == IncidentType::BeginOutputFile ) {
466 const FileIncident* fi = dynamic_cast<const FileIncident*>( &i );
470 if ( findComp( fi->
source(), pit ) ) {
472 while ( pit.first != pit.second ) {
StatusCode finalize() override
StatusCode initialize() override
This class is the FileIncident.
bool io_hasitem(IIoComponent *iocomponent) const override
: check if the registry contains a given IIoComponent
const std::string & type() const
Access to the incident type.
This file contains the class definition for the FileIncident class.
bool findComp(IIoComponent *, const std::string &, iodITR &) const
std::vector< std::string > io_retrieve(IIoComponent *iocomponent) override
: retrieve all registered filenames for a given IIoComponent
constexpr static const auto SUCCESS
IoDict_t::const_iterator iodITR
void handle(const Incident &) override
const std::string & fileGuid() const
const std::string & source() const
Access to the source of the incident.
virtual const std::string & name() const =0
Retrieve the name of the instance.
#define DECLARE_COMPONENT(type)
StatusCode initialize() override
Gaudi Service Implementation.
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
const std::string & fileName() const
std::ostream & operator<<(std::ostream &os, const IIoComponentMgr::IoMode::Type &m)
IIoComponentMgr::IoMode::Type m_iomode
StatusCode io_update_all(const std::string &work_dir) override
: Update all IIoComponents with a new work directory
T back_inserter(T... args)
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.
constexpr static const auto FAILURE
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
StatusCode io_finalize() override
: finalize the I/O subsystem.
StatusCode io_reinitialize() override
: reinitialize the I/O subsystem.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
The interface implemented by the IncidentSvc service.
bool io_contains(IIoComponent *iocomponent, const std::string &fname) const override
: check if the registry contains a given IIoComponent and that component had