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; }
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;
143 DEBMSG <<
" registering IoComponent \"" << ioname <<
"\"" <<
endmsg;
148 info() <<
"IoComponent[" << iocomponent->
name() <<
"] already registered @" << (
void*)itr->second << endmsg;
167 << fname <<
")" <<
endmsg;
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;
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
264 debug() <<
"reinitializing I/O subsystem..." <<
endmsg;
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;
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;
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;
363 error() <<
"problem in [" << ( *io )->name() <<
"]->io_update() !" <<
endmsg;
378 debug() <<
"finalizing I/O subsystem..." <<
endmsg;
386 DEBMSG <<
" [" << ( *io )->name() <<
"]->io_finalize()..." <<
endmsg;
387 if ( !( *io )->io_finalize().isSuccess() ) {
389 error() <<
"problem in [" << ( *io )->name() <<
"]->io_finalize() !" <<
endmsg;
405 return std::any_of( pit.first, pit.second, [&]( IoDict_t::const_reference i ) { return i.second.m_oldfname == f; } );
413 return pit.first != pit.second;
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 ) {
453 while ( pit.first != pit.second ) {
464 }
else if ( i.
type() == IncidentType::BeginOutputFile ) {
472 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.
const std::string & fileName() 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
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
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
Gaudi::Property< std::vector< std::string > > m_directio_patterns
search patterns for special file names (direct I/O protocols)
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
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.
const std::string & fileGuid() const
AttribStringParser::Iterator begin(const AttribStringParser &parser)
IoStack_t m_iostack
Stack of IIoComponents to properly handle order of registration.
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