The Gaudi Framework  v32r2 (46d42edc)
IoComponentMgr Class Reference

#include <src/component/IoComponentMgr.h>

Inheritance diagram for IoComponentMgr:
Collaboration diagram for IoComponentMgr:

Classes

struct  IoComponentEntry
 

Public Member Functions

void handle (const Incident &) override
 
bool io_hasitem (IIoComponent *iocomponent) const override
 : check if the registry contains a given IIoComponent More...
 
bool io_contains (IIoComponent *iocomponent, const std::string &fname) const override
 : check if the registry contains a given IIoComponent and that component had More...
 
StatusCode io_register (IIoComponent *iocomponent) override
 : allow a IIoComponent to register itself with this manager so appropriate actions can be taken when e.g. More...
 
StatusCode io_register (IIoComponent *iocomponent, IIoComponentMgr::IoMode::Type iomode, const std::string &fname, const std::string &pfn) override
 : allow a IIoComponent to register itself with this manager so appropriate actions can be taken when e.g. More...
 
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 More...
 
StatusCode io_update (IIoComponent *iocomponent, const std::string &work_dir) override
 : allow a IIoComponent to update the contents of the registry with a new work directory More...
 
StatusCode io_update_all (const std::string &work_dir) override
 : Update all IIoComponents with a new work directory More...
 
std::vector< std::stringio_retrieve (IIoComponent *iocomponent) override
 : retrieve all registered filenames for a given IIoComponent More...
 
StatusCode io_retrieve (IIoComponent *iocomponent, std::string &fname) override
 : retrieve the new filename for a given IIoComponent and More...
 
StatusCode io_reinitialize () override
 : reinitialize the I/O subsystem. More...
 
StatusCode io_finalize () override
 : finalize the I/O subsystem. More...
 
StatusCode initialize () override
 Gaudi Service Implementation. More...
 
StatusCode finalize () override
 
- Public Member Functions inherited from extends< Service, IIoComponentMgr, IIncidentListener >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
- Public Member Functions inherited from Service
const std::stringname () const override
 Retrieve name of the service. More...
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service. More...
 
StatusCode sysStart () override
 Initialize Service. More...
 
StatusCode sysStop () override
 Initialize Service. More...
 
StatusCode sysFinalize () override
 Finalize Service. More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. More...
 
template<class T >
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. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode declareTool (ToolHandle< T > &handle, std::string toolTypeAndName, bool createIf=true)
 Declare used tool. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property. More...
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation. More...
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p) override
 set the property form another property More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 set the property from name and the value More...
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (const std::string &name) const override
 get the property by name More...
 
StatusCode getProperty (const std::string &n, std::string &v) const override
 convert the property to the string More...
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties More...
 
bool hasProperty (const std::string &name) const override
 Return true if we have a property with the given name. More...
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream) More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const
 Backward compatibility function for getting the output level. More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 

Private Types

typedef std::map< std::string, IIoComponent * > IoRegistry_t
 
typedef std::list< IIoComponent * > IoStack_t
 
typedef std::multimap< IIoComponent *, IoComponentEntryIoDict_t
 
typedef IoDict_t::const_iterator iodITR
 

Private Member Functions

 IoComponentMgr ()=delete
 Default constructor: More...
 
bool findComp (IIoComponent *, const std::string &, iodITR &) const
 
bool findComp (IIoComponent *, std::pair< iodITR, iodITR > &) const
 
bool findComp (const std::string &, std::pair< iodITR, iodITR > &) const
 
std::string list () const
 

Private Attributes

IoRegistry_t m_ioregistry
 Registry of IIoComponents. More...
 
IoStack_t m_iostack
 Stack of IIoComponents to properly handle order of registration. More...
 
IoDict_t m_cdict
 
std::string m_dict_location
 location of the python dictionary More...
 
Gaudi::Property< std::vector< std::string > > m_directio_patterns
 search patterns for special file names (direct I/O protocols) More...
 

Additional Inherited Members

- Public Types inherited from extends< Service, IIoComponentMgr, IIncidentListener >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces... >
 Typedef to the base of this class. More...
 
- Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory< IService *(const std::string &, ISvcLocator *)>
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl = PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 Typedef used to refer to this class from derived classes, as in. More...
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Member Functions inherited from Service
 ~Service () override
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
Gaudi::Details::PropertyBaseproperty (const std::string &name) const
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches. More...
 
MSG::Level resetMessaging ()
 Reinitialize internal states. More...
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::Property< int > m_outputLevel {this, "OutputLevel", MSG::NIL, "output level"}
 
Gaudi::Property< bool > m_auditInit {this, "AuditServices", false, " unused"}
 
Gaudi::Property< bool > m_auditorInitialize {this, "AuditInitialize", false, "trigger auditor on initialize()"}
 
Gaudi::Property< bool > m_auditorStart {this, "AuditStart", false, "trigger auditor on start()"}
 
Gaudi::Property< bool > m_auditorStop {this, "AuditStop", false, "trigger auditor on stop()"}
 
Gaudi::Property< bool > m_auditorFinalize {this, "AuditFinalize", false, "trigger auditor on finalize()"}
 
Gaudi::Property< bool > m_auditorReinitialize {this, "AuditReinitialize", false, "trigger auditor on reinitialize()"}
 
Gaudi::Property< bool > m_auditorRestart {this, "AuditRestart", false, "trigger auditor on restart()"}
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service. More...
 

Detailed Description

Definition at line 29 of file IoComponentMgr.h.

Member Typedef Documentation

◆ IoDict_t

◆ iodITR

typedef IoDict_t::const_iterator IoComponentMgr::iodITR
private

Definition at line 162 of file IoComponentMgr.h.

◆ IoRegistry_t

Definition at line 152 of file IoComponentMgr.h.

◆ IoStack_t

Definition at line 156 of file IoComponentMgr.h.

Constructor & Destructor Documentation

◆ IoComponentMgr()

IoComponentMgr::IoComponentMgr ( )
privatedelete

Default constructor:

Member Function Documentation

◆ finalize()

StatusCode IoComponentMgr::finalize ( )
override

Definition at line 76 of file IoComponentMgr.cpp.

76  {
77  DEBMSG << "--> finalize()" << endmsg;
78 
79  return StatusCode::SUCCESS;
80 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
#define DEBMSG
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ findComp() [1/3]

bool IoComponentMgr::findComp ( IIoComponent c,
const std::string f,
iodITR itr 
) const
private

Definition at line 398 of file IoComponentMgr.cpp.

398  {
399 
401  if ( !findComp( c, pit ) ) {
402  itr = pit.first;
403  return false;
404  }
405  return std::any_of( pit.first, pit.second, [&]( IoDict_t::const_reference i ) { return i.second.m_oldfname == f; } );
406 }
bool findComp(IIoComponent *, const std::string &, iodITR &) const
T any_of(T... args)

◆ findComp() [2/3]

bool IoComponentMgr::findComp ( IIoComponent c,
std::pair< iodITR, iodITR > &  pit 
) const
private

Definition at line 410 of file IoComponentMgr.cpp.

410  {
411 
412  pit = m_cdict.equal_range( c );
413  return pit.first != pit.second;
414 }
T equal_range(T... args)

◆ findComp() [3/3]

bool IoComponentMgr::findComp ( const std::string c,
std::pair< iodITR, iodITR > &  pit 
) const
private

Definition at line 418 of file IoComponentMgr.cpp.

418  {
419 
420  pit.first = m_cdict.end();
421  pit.second = m_cdict.end();
422 
423  auto itr = m_ioregistry.find( c );
424  return ( itr != m_ioregistry.end() ) && findComp( itr->second, pit );
425 }
bool findComp(IIoComponent *, const std::string &, iodITR &) const
IoRegistry_t m_ioregistry
Registry of IIoComponents.
T end(T... args)
T find(T... args)

◆ handle()

void IoComponentMgr::handle ( const Incident i)
override

Definition at line 441 of file IoComponentMgr.cpp.

441  {
442 
444 
445  if ( i.type() == IncidentType::BeginInputFile ) {
446 
447  const FileIncident* fi = dynamic_cast<const FileIncident*>( &i );
448  DEBMSG << "BeginInputFile: s: " << fi->source() << " t: " << fi->type() << " n: " << fi->fileName()
449  << " g: " << fi->fileGuid() << endmsg;
450 
451  if ( findComp( fi->source(), pit ) ) {
452  DEBMSG << " found component: " << endmsg;
453  while ( pit.first != pit.second ) {
454  IIoComponent* c = pit.first->first;
455  IoComponentEntry e = pit.first->second;
456  DEBMSG << " c: " << c->name() << " " << e << endmsg;
457 
458  ++pit.first;
459  }
460  } else {
461  DEBMSG << " could not find component \"" << fi->source() << "\"!" << endmsg;
462  }
463 
464  } else if ( i.type() == IncidentType::BeginOutputFile ) {
465 
466  const FileIncident* fi = dynamic_cast<const FileIncident*>( &i );
467  DEBMSG << "BeginOutputFile: s: " << fi->source() << " t: " << fi->type() << " n: " << fi->fileName()
468  << " g: " << fi->fileGuid() << endmsg;
469 
470  if ( findComp( fi->source(), pit ) ) {
471  DEBMSG << " found component: " << endmsg;
472  while ( pit.first != pit.second ) {
473  IIoComponent* c = pit.first->first;
474  IoComponentEntry e = pit.first->second;
475  DEBMSG << " c: " << c->name() << " " << e << endmsg;
476 
477  ++pit.first;
478  }
479  } else {
480  DEBMSG << " could not find component \"" << fi->source() << "\"!" << endmsg;
481  }
482  }
483 }
This class is the FileIncident.
Definition: FileIncident.h:17
const std::string & type() const
Access to the incident type.
Definition: Incident.h:38
bool findComp(IIoComponent *, const std::string &, iodITR &) const
const std::string & fileGuid() const
Definition: FileIncident.h:24
#define DEBMSG
const std::string & source() const
Access to the source of the incident.
Definition: Incident.h:44
const std::string & fileName() const
Definition: FileIncident.h:23
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ initialize()

StatusCode IoComponentMgr::initialize ( )
override

Gaudi Service Implementation.

Definition at line 53 of file IoComponentMgr.cpp.

53  {
54  DEBMSG << "--> initialize()" << endmsg;
55 
56  if ( Service::initialize().isFailure() ) {
57  error() << "Unable to initialize Service base class" << endmsg;
58  return StatusCode::FAILURE;
59  }
60 
61  IIncidentSvc* p_incSvc( 0 );
62 
63  if ( service( "IncidentSvc", p_incSvc, true ).isFailure() ) {
64  error() << "unable to get the IncidentSvc" << endmsg;
65  return StatusCode::FAILURE;
66  } else {
67  p_incSvc->addListener( this, IncidentType::BeginOutputFile, 100, true );
68  p_incSvc->addListener( this, IncidentType::BeginInputFile, 100, true );
69  }
70 
71  return StatusCode::SUCCESS;
72 }
StatusCode initialize() override
Definition: Service.cpp:60
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
#define DEBMSG
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
constexpr static const auto FAILURE
Definition: StatusCode.h:86
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.
Definition: Service.h:83
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23

◆ io_contains()

bool IoComponentMgr::io_contains ( IIoComponent iocomponent,
const std::string fname 
) const
override

: check if the registry contains a given IIoComponent and that component had

Parameters
<tt>fname</tt>as a filename

Definition at line 99 of file IoComponentMgr.cpp.

99  {
100  DEBMSG << "--> io_contains()" << endmsg;
101  if ( 0 == iocomponent ) { return false; }
102  const std::string& ioname = iocomponent->name();
103 
104  DEBMSG << "io_contains: c: " << ioname << " f: " << fname << endmsg;
105 
106  pair<iodITR, iodITR> fit = m_cdict.equal_range( iocomponent );
107  if ( fit.first == fit.second ) {
108  return false;
109  } else {
110  iodITR it;
111  for ( it = fit.first; it != fit.second; ++it ) {
112  IoComponentEntry ioe = it->second;
113  DEBMSG << " " << ioe << endmsg;
114  if ( ioe.m_oldfname == "" ) {
115  error() << "IIoComponent " << ioname << " has empty old filename" << endmsg;
116  return false;
117  } else if ( ioe.m_oldfname == fname ) {
118  return true;
119  }
120  }
121  }
122 
123  return false;
124 }
IoDict_t::const_iterator iodITR
#define DEBMSG
virtual const std::string & name() const =0
Retrieve the name of the instance.
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T equal_range(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ io_finalize()

StatusCode IoComponentMgr::io_finalize ( )
override

: finalize the I/O subsystem.

Hook to allow to e.g. give a chance to I/O subsystems to merge output files. Not sure how to do this correctly though...

Definition at line 375 of file IoComponentMgr.cpp.

375  {
376  ON_DEBUG {
377  debug() << "--> io_finalize()" << endmsg;
378  debug() << "finalizing I/O subsystem..." << endmsg;
379  debug() << "Listing all monitored entries: " << std::endl;
380  debug() << list() << endmsg;
381  }
382 
383  bool allgood = true;
384  // reverse iteration to unwind component dependencies
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() ) {
388  allgood = false;
389  error() << "problem in [" << ( *io )->name() << "]->io_finalize() !" << endmsg;
390  }
391  }
392 
393  return allgood ? StatusCode::SUCCESS : StatusCode::FAILURE;
394 }
T rend(T... args)
T endl(T... args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
#define DEBMSG
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
#define ON_DEBUG
std::string list() const
constexpr static const auto FAILURE
Definition: StatusCode.h:86
IoStack_t m_iostack
Stack of IIoComponents to properly handle order of registration.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
T rbegin(T... args)

◆ io_hasitem()

bool IoComponentMgr::io_hasitem ( IIoComponent iocomponent) const
override

: check if the registry contains a given IIoComponent

Definition at line 86 of file IoComponentMgr.cpp.

86  {
87  DEBMSG << "--> io_hasitem()" << endmsg;
88  if ( 0 == iocomponent ) { return false; }
89  const std::string& ioname = iocomponent->name();
90  IoRegistry_t::const_iterator io = m_ioregistry.find( ioname );
91  return io != m_ioregistry.end();
92 }
IoRegistry_t m_ioregistry
Registry of IIoComponents.
T end(T... args)
#define DEBMSG
virtual const std::string & name() const =0
Retrieve the name of the instance.
STL class.
T find(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ io_register() [1/2]

StatusCode IoComponentMgr::io_register ( IIoComponent iocomponent)
override

: allow a IIoComponent to register itself with this manager so appropriate actions can be taken when e.g.

a fork(2) has been issued (this is usually handled by calling IIoComponent::io_reinit on every registered component)

Definition at line 134 of file IoComponentMgr.cpp.

134  {
135  if ( !iocomponent ) {
136  error() << "io_register (component) received a NULL pointer !" << endmsg;
137  return StatusCode::FAILURE;
138  }
139  const std::string& ioname = iocomponent->name();
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;
144  iocomponent->addRef(); // ownership...
145  m_ioregistry[ioname] = iocomponent;
146  m_iostack.push_back( iocomponent );
147  } else {
148  info() << "IoComponent[" << iocomponent->name() << "] already registered @" << (void*)itr->second << endmsg;
149  }
150  return StatusCode::SUCCESS;
151 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
IoRegistry_t m_ioregistry
Registry of IIoComponents.
T end(T... args)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
#define DEBMSG
virtual const std::string & name() const =0
Retrieve the name of the instance.
STL class.
T push_back(T... args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
T find(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:86
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
IoStack_t m_iostack
Stack of IIoComponents to properly handle order of registration.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ io_register() [2/2]

StatusCode IoComponentMgr::io_register ( IIoComponent iocomponent,
IIoComponentMgr::IoMode::Type  iomode,
const std::string fname,
const std::string pfn 
)
override

: allow a IIoComponent to register itself with this manager so appropriate actions can be taken when e.g.

a fork(2) has been issued (this is usually handled by calling IIoComponent::io_reinit on every registered component)

Definition at line 161 of file IoComponentMgr.cpp.

162  {
163  if ( 0 == iocomponent ) { return StatusCode::FAILURE; }
164  const std::string& ioname = iocomponent->name();
165 
166  DEBMSG << "--> io_register(" << ioname << "," << ( ( iomode == IIoComponentMgr::IoMode::READ ) ? "R" : "W" ) << ","
167  << fname << ")" << endmsg;
168 
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;
173  return StatusCode::FAILURE;
174  }
175  }
176 
177  pair<iodITR, iodITR> fit = m_cdict.equal_range( iocomponent );
178  if ( fit.first != fit.second ) {
179  for ( iodITR it = fit.first; it != fit.second; ++it ) {
180  IoComponentEntry ioe = it->second;
181  if ( ioe.m_oldfname == fname ) {
182  if ( ioe.m_iomode == iomode ) {
183  info() << "IoComponent " << ioname << " has already had file " << fname << " registered with i/o mode "
184  << iomode << endmsg;
185  return StatusCode::SUCCESS;
186  } else {
187  warning() << "IoComponent " << ioname << " has already had file " << fname
188  << " registered with a different i/o mode " << ioe.m_iomode << " - now trying " << iomode << endmsg;
189  }
190  }
191  }
192  }
193 
194  // We need to take into account that boost::filesystem::absolute() does not work with direct I/O inputs
195  const std::string& tmp_name = ( pfn.empty() ? fname : pfn );
196  bool special_case =
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 );
201 
202  return StatusCode::SUCCESS;
203 }
T empty(T... args)
bool io_hasitem(IIoComponent *iocomponent) const override
: check if the registry contains a given IIoComponent
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
IoDict_t::const_iterator iodITR
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
#define DEBMSG
virtual const std::string & name() const =0
Retrieve the name of the instance.
STL class.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
StatusCode io_register(IIoComponent *iocomponent) override
: allow a IIoComponent to register itself with this manager so appropriate actions can be taken when ...
def end
Definition: IOTest.py:113
bool isSuccess() const
Definition: StatusCode.h:267
T insert(T... args)
T any_of(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:86
Gaudi::Property< std::vector< std::string > > m_directio_patterns
search patterns for special file names (direct I/O protocols)
AttribStringParser::Iterator begin(const AttribStringParser &parser)
T equal_range(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ io_reinitialize()

StatusCode IoComponentMgr::io_reinitialize ( )
override

: reinitialize the I/O subsystem.

This effectively calls IIoComponent::io_reinit on all the registered IIoComponent.

Definition at line 261 of file IoComponentMgr.cpp.

261  {
262  ON_DEBUG {
263  debug() << "--> io_reinitialize()" << endmsg;
264  debug() << "reinitializing I/O subsystem..." << endmsg;
265  debug() << "Listing all monitored entries: " << std::endl;
266  debug() << list() << endmsg;
267  }
268 
269  bool allgood = true;
270  for ( auto& io : m_iostack ) {
271  DEBMSG << " [" << io->name() << "]->io_reinit()..." << endmsg;
272  if ( !io->io_reinit().isSuccess() ) {
273  allgood = false;
274  error() << "problem in [" << io->name() << "]->io_reinit() !" << endmsg;
275  }
276  // we are done with this guy... release it
277  io->release();
278  }
279 
280  // we are done.
281  // FIXME: shall we allow for multiple io_reinitialize ?
282  // m_iostack.clear();
283  // m_ioregistry.clear();
284  // m_cdict.clear();
285 
286  return allgood ? StatusCode::SUCCESS : StatusCode::FAILURE;
287 }
T endl(T... args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
#define DEBMSG
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
#define ON_DEBUG
std::string list() const
constexpr static const auto FAILURE
Definition: StatusCode.h:86
IoStack_t m_iostack
Stack of IIoComponents to properly handle order of registration.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ io_retrieve() [1/2]

std::vector< std::string > IoComponentMgr::io_retrieve ( IIoComponent iocomponent)
override

: retrieve all registered filenames for a given IIoComponent

Definition at line 207 of file IoComponentMgr.cpp.

207  {
210 
211  // Find component and copy all registered file names
212  if ( iocomponent != nullptr && findComp( iocomponent, pit ) ) {
213  std::transform( pit.first, pit.second, std::back_inserter( fnames ),
214  []( const auto& itr ) { return itr.second.m_oldfname; } );
215  }
216  return fnames;
217 }
bool findComp(IIoComponent *, const std::string &, iodITR &) const
T back_inserter(T... args)
T transform(T... args)

◆ io_retrieve() [2/2]

StatusCode IoComponentMgr::io_retrieve ( IIoComponent iocomponent,
std::string fname 
)
override

: retrieve the new filename for a given IIoComponent and

Parameters
<tt>fname</tt>filename

Definition at line 224 of file IoComponentMgr.cpp.

224  {
225  if ( 0 == iocomponent ) { return StatusCode::FAILURE; }
226 
227  std::string ofname = fname;
228  const std::string& ioname = iocomponent->name();
229 
230  DEBMSG << "--> io_retrieve(" << ioname << "," << fname << ")" << endmsg;
231 
232  iodITR it;
233  if ( !findComp( iocomponent, ofname, it ) ) {
234  DEBMSG << "could not find c: " << ioname << " old_f: " << ofname << endmsg;
235  return StatusCode::FAILURE;
236  } else {
237 
238  IoDict_t::iterator it;
239  for ( it = m_cdict.equal_range( iocomponent ).first; it != m_cdict.equal_range( iocomponent ).second; ++it ) {
240 
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;
245  return StatusCode::SUCCESS;
246  }
247  }
248  }
249 
250  DEBMSG << "Unexpected error! Unable to find entry in the dictionary corresponding to old filename: " << ofname
251  << endmsg;
252  return StatusCode::FAILURE;
253 }
bool findComp(IIoComponent *, const std::string &, iodITR &) const
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
IoDict_t::const_iterator iodITR
#define DEBMSG
virtual const std::string & name() const =0
Retrieve the name of the instance.
STL class.
constexpr static const auto FAILURE
Definition: StatusCode.h:86
T equal_range(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ io_update() [1/2]

StatusCode IoComponentMgr::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

Definition at line 291 of file IoComponentMgr.cpp.

291  {
292 
293  DEBMSG << "--> io_update(" << ioc->name() << "," << old_fname << "," << new_fname << ")" << endmsg;
294 
295  IoDict_t::iterator it;
296  for ( it = m_cdict.equal_range( ioc ).first; it != m_cdict.equal_range( ioc ).second; ++it ) {
297 
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;
301  return StatusCode::SUCCESS;
302  }
303  }
304 
305  return StatusCode::FAILURE;
306 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
#define DEBMSG
constexpr static const auto FAILURE
Definition: StatusCode.h:86
T equal_range(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ io_update() [2/2]

StatusCode IoComponentMgr::io_update ( IIoComponent iocomponent,
const std::string work_dir 
)
override

: allow a IIoComponent to update the contents of the registry with a new work directory

Definition at line 310 of file IoComponentMgr.cpp.

310  {
311 
312  DEBMSG << "--> io_update(" << ioc->name() << "," << work_dir << ")" << endmsg;
313 
314  IoDict_t::iterator it;
315  for ( it = m_cdict.equal_range( ioc ).first; it != m_cdict.equal_range( ioc ).second; ++it ) {
316 
317  switch ( it->second.m_iomode ) {
319  it->second.m_newfname = it->second.m_oldabspath;
320  break;
321  }
323  boost::filesystem::path oldPath( it->second.m_oldfname );
324  if ( oldPath.is_relative() && oldPath.filename() == oldPath.relative_path() ) {
325 
326  // Only file name was provided for writing. This is the usual mode of operation
327  // ***
328  // NB. In such cases it would make sense to set newfname=oldfname, however this will break
329  // existing client codes, which assume that newfname contains "/"
330  // Thus we set newfname=workdir/oldfname
331  // ***
332 
333  boost::filesystem::path newfname( work_dir );
334  newfname /= oldPath;
335  it->second.m_newfname = newfname.string();
336  } else {
337  // New name should be the old absolute path
338  it->second.m_newfname = it->second.m_oldabspath;
339  }
340 
341  break;
342  }
343  default: {
344  // Don't know how to deal with either RW or INVALID
345  error() << "Unable to update IoComponent for the mode " << it->second.m_iomode << endmsg;
346  return StatusCode::FAILURE;
347  }
348  }
349 
350  } // for
351 
352  return StatusCode::SUCCESS;
353 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
#define DEBMSG
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
constexpr static const auto FAILURE
Definition: StatusCode.h:86
T equal_range(T... args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ io_update_all()

StatusCode IoComponentMgr::io_update_all ( const std::string work_dir)
override

: Update all IIoComponents with a new work directory

Definition at line 357 of file IoComponentMgr.cpp.

357  {
358  DEBMSG << "-->io_update_all for the directory " << work_dir << endmsg;
359  bool allgood = true;
360  for ( IoStack_t::iterator io = m_iostack.begin(), ioEnd = m_iostack.end(); io != ioEnd; ++io ) {
361  if ( !io_update( *io, work_dir ).isSuccess() ) {
362  allgood = false;
363  error() << "problem in [" << ( *io )->name() << "]->io_update() !" << endmsg;
364  }
365  }
366  return allgood ? StatusCode::SUCCESS : StatusCode::FAILURE;
367 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
T end(T... args)
#define DEBMSG
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
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
bool isSuccess() const
Definition: StatusCode.h:267
T begin(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:86
IoStack_t m_iostack
Stack of IIoComponents to properly handle order of registration.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192

◆ list()

std::string IoComponentMgr::list ( ) const
private

Definition at line 429 of file IoComponentMgr.cpp.

429  {
430 
431  ostringstream ost;
432 
433  ost << "Listing all IoComponents (" << m_cdict.size() << "): " << endl;
434  for ( const auto& i : m_cdict ) { ost << " " << i.first->name() << " " << i.second << endl; }
435 
436  return ost.str();
437 }
T endl(T... args)
T str(T... args)
T size(T... args)

Member Data Documentation

◆ m_cdict

IoDict_t IoComponentMgr::m_cdict
private

Definition at line 164 of file IoComponentMgr.h.

◆ m_dict_location

std::string IoComponentMgr::m_dict_location
private

location of the python dictionary

Definition at line 167 of file IoComponentMgr.h.

◆ m_directio_patterns

Gaudi::Property<std::vector<std::string> > IoComponentMgr::m_directio_patterns
private
Initial value:
{this,
"DirectIOPatterns",
{
"://",
},
"Search patterns for direct I/O input names"}

search patterns for special file names (direct I/O protocols)

Definition at line 170 of file IoComponentMgr.h.

◆ m_ioregistry

IoRegistry_t IoComponentMgr::m_ioregistry
private

Registry of IIoComponents.

Definition at line 154 of file IoComponentMgr.h.

◆ m_iostack

IoStack_t IoComponentMgr::m_iostack
private

Stack of IIoComponents to properly handle order of registration.

Definition at line 158 of file IoComponentMgr.h.


The documentation for this class was generated from the following files: