26#include <boost/algorithm/string/predicate.hpp>
27#include <boost/filesystem.hpp>
32#define ON_DEBUG if ( outputLevel() <= MSG::DEBUG )
33#define ON_VERBOSE if ( outputLevel() <= MSG::VERBOSE )
35#define DEBMSG ON_DEBUG debug()
36#define VERMSG ON_VERBOSE verbose()
67 error() <<
"Unable to initialize Service base class" <<
endmsg;
74 error() <<
"unable to get the IncidentSvc" <<
endmsg;
77 p_incSvc->addListener(
this, IncidentType::BeginOutputFile, 100,
true );
78 p_incSvc->addListener(
this, IncidentType::BeginInputFile, 100,
true );
89 for (
auto& io :
m_iostack ) { io->release(); }
100 if ( 0 == iocomponent ) {
return false; }
101 const std::string& ioname = iocomponent->
name();
102 IoRegistry_t::const_iterator io =
m_ioregistry.find( ioname );
113 if ( 0 == iocomponent ) {
return false; }
114 const std::string& ioname = iocomponent->
name();
116 DEBMSG <<
"io_contains: c: " << ioname <<
" f: " << fname <<
endmsg;
118 pair<iodITR, iodITR> fit =
m_cdict.equal_range( iocomponent );
119 if ( fit.first == fit.second ) {
123 for ( it = fit.first; it != fit.second; ++it ) {
127 error() <<
"IIoComponent " << ioname <<
" has empty old filename" <<
endmsg;
147 if ( !iocomponent ) {
148 error() <<
"io_register (component) received a NULL pointer !" <<
endmsg;
151 const std::string& ioname = iocomponent->
name();
152 DEBMSG <<
"--> io_register(" << ioname <<
")" <<
endmsg;
155 DEBMSG <<
" registering IoComponent \"" << ioname <<
"\"" <<
endmsg;
160 info() <<
"IoComponent[" << iocomponent->
name() <<
"] already registered @" << (
void*)itr->second <<
endmsg;
174 const std::string& fname,
const std::string& pfn ) {
176 const std::string& ioname = iocomponent->
name();
179 << fname <<
")" <<
endmsg;
183 error() <<
"could not register component [" << iocomponent->
name() <<
"] "
184 <<
"with the I/O component manager !" <<
endmsg;
189 pair<iodITR, iodITR> fit =
m_cdict.equal_range( iocomponent );
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;
207 const std::string& tmp_name = ( pfn.empty() ? fname : pfn );
210 [&](
const std::string& pf ) { return boost::algorithm::contains( tmp_name, pf ); } );
211 IoComponentEntry ioc( fname, ( special_case ? tmp_name : boost::filesystem::absolute( tmp_name ).
string() ), iomode );
212 m_cdict.insert( pair<IIoComponent*, IoComponentEntry>( iocomponent, ioc ) );
220 std::vector<std::string> fnames;
221 pair<iodITR, iodITR> pit;
224 if ( iocomponent !=
nullptr &&
findComp( iocomponent, pit ) ) {
225 std::transform( pit.first, pit.second, std::back_inserter( fnames ),
226 [](
const auto& itr ) { return itr.second.m_oldfname; } );
239 std::string ofname = fname;
240 const std::string& ioname = iocomponent->
name();
242 DEBMSG <<
"--> io_retrieve(" << ioname <<
"," << fname <<
")" <<
endmsg;
245 if ( !
findComp( iocomponent, ofname, it ) ) {
246 DEBMSG <<
"could not find c: " << ioname <<
" old_f: " << ofname <<
endmsg;
250 IoDict_t::iterator it;
251 for ( it =
m_cdict.equal_range( iocomponent ).first; it !=
m_cdict.equal_range( iocomponent ).second; ++it ) {
253 if ( it->second.m_oldfname == ofname ) {
254 DEBMSG <<
"retrieving new name for the component " << iocomponent->
name() <<
" old name: " << ofname
255 <<
", new name: " << it->second.m_newfname <<
endmsg;
256 fname = it->second.m_newfname;
262 DEBMSG <<
"Unexpected error! Unable to find entry in the dictionary corresponding to old filename: " << ofname
276 debug() <<
"reinitializing I/O subsystem..." <<
endmsg;
277 debug() <<
"Listing all monitored entries: " << std::endl;
283 DEBMSG <<
" [" << io->name() <<
"]->io_reinit()..." <<
endmsg;
284 if ( !io->io_reinit().isSuccess() ) {
286 error() <<
"problem in [" << io->name() <<
"]->io_reinit() !" <<
endmsg;
297 DEBMSG <<
"--> io_update(" << ioc->
name() <<
"," << old_fname <<
"," << new_fname <<
")" <<
endmsg;
299 IoDict_t::iterator it;
300 for ( it =
m_cdict.equal_range( ioc ).first; it !=
m_cdict.equal_range( ioc ).second; ++it ) {
302 if ( it->second.m_oldfname == old_fname ) {
303 DEBMSG <<
"updating " << ioc->
name() <<
" f: " << old_fname <<
" -> " << new_fname <<
endmsg;
304 it->second.m_newfname = new_fname;
316 DEBMSG <<
"--> io_update(" << ioc->
name() <<
"," << work_dir <<
")" <<
endmsg;
318 IoDict_t::iterator it;
319 for ( it =
m_cdict.equal_range( ioc ).first; it !=
m_cdict.equal_range( ioc ).second; ++it ) {
321 switch ( it->second.m_iomode ) {
323 it->second.m_newfname = it->second.m_oldabspath;
327 boost::filesystem::path oldPath( it->second.m_oldfname );
328 if ( oldPath.is_relative() && oldPath.filename() == oldPath.relative_path() ) {
337 boost::filesystem::path newfname( work_dir );
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;
362 DEBMSG <<
"-->io_update_all for the directory " << work_dir <<
endmsg;
364 for ( IoStack_t::iterator io =
m_iostack.begin(), ioEnd =
m_iostack.end(); io != ioEnd; ++io ) {
365 if ( !
io_update( *io, work_dir ).isSuccess() ) {
367 error() <<
"problem in [" << ( *io )->name() <<
"]->io_update() !" <<
endmsg;
382 debug() <<
"finalizing I/O subsystem..." <<
endmsg;
383 debug() <<
"Listing all monitored entries: " << std::endl;
389 for ( IoStack_t::reverse_iterator io =
m_iostack.rbegin(), ioEnd =
m_iostack.rend(); io != ioEnd; ++io ) {
390 DEBMSG <<
" [" << ( *io )->name() <<
"]->io_finalize()..." <<
endmsg;
391 if ( !( *io )->io_finalize().isSuccess() ) {
393 error() <<
"problem in [" << ( *io )->name() <<
"]->io_finalize() !" <<
endmsg;
404 pair<iodITR, iodITR> pit;
409 return std::any_of( pit.first, pit.second, [&]( IoDict_t::const_reference i ) { return i.second.m_oldfname == f; } );
416 pit =
m_cdict.equal_range( c );
417 return pit.first != pit.second;
437 ost <<
"Listing all IoComponents (" <<
m_cdict.size() <<
"): " << endl;
438 for (
const auto& i :
m_cdict ) { ost <<
" " << i.first->name() <<
" " << i.second << endl; }
447 pair<iodITR, iodITR> pit;
449 if ( i.
type() == IncidentType::BeginInputFile ) {
457 while ( pit.first != pit.second ) {
468 }
else if ( i.
type() == IncidentType::BeginOutputFile ) {
476 while ( pit.first != pit.second ) {
This file contains the class definition for the FileIncident class.
std::ostream & operator<<(std::ostream &os, const IIoComponentMgr::IoMode::Type &m)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
This class is the FileIncident.
const std::string & fileName() const
const std::string & fileGuid() const
virtual unsigned long addRef() const =0
Increment the reference count of Interface instance.
virtual const std::string & name() const =0
Retrieve the name of the instance.
Base class for all Incidents (computing events).
const std::string & type() const
Access to the incident type.
const std::string & source() const
Access to the source of the incident.
bool io_hasitem(IIoComponent *iocomponent) const override
: check if the registry contains a given IIoComponent
StatusCode io_register(IIoComponent *iocomponent) override
: allow a IIoComponent to register itself with this manager so appropriate actions can be taken when ...
Gaudi::Property< std::vector< std::string > > m_directio_patterns
search patterns for special file names (direct I/O protocols)
StatusCode finalize() override
StatusCode io_update_all(const std::string &work_dir) override
: Update all IIoComponents with a new work directory
StatusCode initialize() override
Gaudi Service Implementation.
std::vector< std::string > io_retrieve(IIoComponent *iocomponent) override
: retrieve all registered filenames for a given IIoComponent
bool findComp(IIoComponent *, const std::string &, iodITR &) const
IoDict_t::const_iterator iodITR
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
StatusCode io_reinitialize() override
: reinitialize the I/O subsystem.
bool io_contains(IIoComponent *iocomponent, const std::string &fname) const override
: check if the registry contains a given IIoComponent and that component had
IoRegistry_t m_ioregistry
Registry of IIoComponents.
IoStack_t m_iostack
Stack of IIoComponents to properly handle order of registration.
StatusCode io_finalize() override
: finalize the I/O subsystem.
void handle(const Incident &) override
SmartIF< IFace > service(const std::string &name, bool createIf=true) const
StatusCode initialize() override
This class is used for returning status codes from appropriate routines.
constexpr static const auto SUCCESS
constexpr static const auto FAILURE
IIoComponentMgr::IoMode::Type m_iomode