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() 59 error() <<
"Unable to initialize Service base class" <<
endmsg;
65 if (
service(
"IncidentSvc", p_incSvc,
true ).isFailure() ) {
66 error() <<
"unable to get the IncidentSvc" <<
endmsg;
69 p_incSvc->
addListener(
this, IncidentType::BeginOutputFile, 100,
true );
70 p_incSvc->
addListener(
this, IncidentType::BeginInputFile, 100,
true );
92 if ( 0 == iocomponent ) {
108 if ( 0 == iocomponent ) {
113 DEBMSG <<
"io_contains: c: " << ioname <<
" f: " << fname <<
endmsg;
116 if ( fit.first == fit.second ) {
120 for ( it = fit.first; it != fit.second; ++it ) {
124 error() <<
"IIoComponent " << ioname <<
" has empty old filename" <<
endmsg;
145 if ( !iocomponent ) {
146 error() <<
"io_register (component) received a NULL pointer !" <<
endmsg;
150 DEBMSG <<
"--> io_register(" << ioname <<
")" <<
endmsg;
153 DEBMSG <<
" registering IoComponent \"" << ioname <<
"\"" <<
endmsg;
158 info() <<
"IoComponent[" << iocomponent->
name() <<
"] already registered @" << (
void*)itr->second << endmsg;
174 if ( 0 == iocomponent ) {
180 << fname <<
")" <<
endmsg;
184 error() <<
"could not register component [" << iocomponent->
name() <<
"] " 185 <<
"with the I/O component manager !" <<
endmsg;
191 if ( fit.first != fit.second ) {
192 for (
iodITR it = fit.first; it != fit.second; ++it ) {
196 info() <<
"IoComponent " << ioname <<
" has already had file " << fname <<
" registered with i/o mode " 200 warning() <<
"IoComponent " << ioname <<
" has already had file " << fname
201 <<
" registered with a different i/o mode " << ioe.
m_iomode <<
" - now trying " << iomode <<
endmsg;
211 [&](
const std::string& pf ) {
return boost::algorithm::contains( tmp_name, pf ); } );
212 IoComponentEntry ioc( fname, ( special_case ? tmp_name : boost::filesystem::absolute( tmp_name ).
string() ), iomode );
225 if ( 0 == iocomponent ) {
232 DEBMSG <<
"--> io_retrieve(" << ioname <<
"," << fname <<
")" <<
endmsg;
235 if ( !
findComp( iocomponent, ofname, it ) ) {
236 DEBMSG <<
"could not find c: " << ioname <<
" old_f: " << ofname <<
endmsg;
240 IoDict_t::iterator it;
243 if ( it->second.m_oldfname == ofname ) {
244 DEBMSG <<
"retrieving new name for the component " << iocomponent->
name() <<
" old name: " << ofname
245 <<
", new name: " << it->second.m_newfname <<
endmsg;
246 fname = it->second.m_newfname;
252 DEBMSG <<
"Unexpected error! Unable to find entry in the dictionary corresponding to old filename: " << ofname
268 debug() <<
"reinitializing I/O subsystem..." <<
endmsg;
275 DEBMSG <<
" [" << io->name() <<
"]->io_reinit()..." <<
endmsg;
276 if ( !io->io_reinit().isSuccess() ) {
278 error() <<
"problem in [" << io->name() <<
"]->io_reinit() !" <<
endmsg;
298 DEBMSG <<
"--> io_update(" << ioc->
name() <<
"," << old_fname <<
"," << new_fname <<
")" <<
endmsg;
300 IoDict_t::iterator it;
303 if ( it->second.m_oldfname == old_fname ) {
304 DEBMSG <<
"updating " << ioc->
name() <<
" f: " << old_fname <<
" -> " << new_fname <<
endmsg;
305 it->second.m_newfname = new_fname;
318 DEBMSG <<
"--> io_update(" << ioc->
name() <<
"," << work_dir <<
")" <<
endmsg;
320 IoDict_t::iterator it;
323 switch ( it->second.m_iomode ) {
325 it->second.m_newfname = it->second.m_oldabspath;
330 if ( oldPath.is_relative() && oldPath.filename() == oldPath.relative_path() ) {
341 it->second.m_newfname = newfname.string();
344 it->second.m_newfname = it->second.m_oldabspath;
351 error() <<
"Unable to update IoComponent for the mode " << it->second.m_iomode <<
endmsg;
365 DEBMSG <<
"-->io_update_all for the directory " << work_dir <<
endmsg;
370 error() <<
"problem in [" << ( *io )->name() <<
"]->io_update() !" <<
endmsg;
387 debug() <<
"finalizing I/O subsystem..." <<
endmsg;
395 DEBMSG <<
" [" << ( *io )->name() <<
"]->io_finalize()..." <<
endmsg;
396 if ( !( *io )->io_finalize().isSuccess() ) {
398 error() <<
"problem in [" << ( *io )->name() <<
"]->io_finalize() !" <<
endmsg;
415 return std::any_of( pit.first, pit.second, [&]( IoDict_t::const_reference i ) { return i.second.m_oldfname == f; } );
424 return pit.first != pit.second;
446 ost <<
"Listing all IoComponents (" <<
m_cdict.
size() <<
"): " <<
endl;
447 for (
const auto& i :
m_cdict ) {
448 ost <<
" " << i.first->name() <<
" " << i.second <<
endl;
461 if ( i.
type() == IncidentType::BeginInputFile ) {
469 while ( pit.first != pit.second ) {
480 }
else if ( i.
type() == IncidentType::BeginOutputFile ) {
488 while ( pit.first != pit.second ) {
StatusCode finalize() override
constexpr static const auto FAILURE
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
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 ...
constexpr static const auto SUCCESS
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.
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 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.
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