ATLAS Offline Software
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
IoSvc Class Reference

#include <IoSvc.h>

Inheritance diagram for IoSvc:
Collaboration diagram for IoSvc:

Classes

struct  FdInfos
 

Public Types

typedef IIoSvc::Fd Fd
 
enum  IoType {
  INVALID = 0, READ = 1<<1, UPDATE = 1<<2, CREATE = 1<<3,
  RECREATE = (1<<4)+(1<<3)
}
 I/O Connection types. More...
 

Public Member Functions

 IoSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Constructor with parameters: More...
 
virtual ~IoSvc ()
 Destructor: More...
 
virtual StatusCode initialize ()
 Gaudi Service Implementation. More...
 
virtual StatusCode finalize ()
 
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)
 
bool has_fd (Fd fd) const
 test if a given file descriptor fd is known to us More...
 
Fd fd (const std::string &fname) const
 retrieve the file descriptor associated with file fname More...
 
const std::string & fname (Fd fd) const
 retrieve the file fname associated with file descriptor fd More...
 
IoType mode (Fd fd) const
 retrieve the open mode associated with file descriptor fd More...
 
Fd open (const std::string &fname, IoType mode)
 open file fname with open mode mode More...
 
StatusCode close (Fd fd)
 close file fd More...
 
MsgStream & msg () const
 
MsgStream & msg (const MSG::Level lvl) const
 
bool msgLvl (const MSG::Level lvl) const
 

Static Public Member Functions

static const InterfaceID & interfaceID ()
 
static const std::string & IoTypeName (IoType mode)
 
static IoType IoTypeFromName (const std::string &name)
 

Private Types

typedef std::unordered_map< Fd, FdInfosFdMap_t
 

Private Member Functions

 IoSvc ()
 Default constructor: More...
 

Private Attributes

FdMap_t m_fds
 map of fd->fdinfos More...
 
Fd m_last_fd
 last created Fd More...
 

Friends

class SvcFactory< IoSvc >
 

Detailed Description

Definition at line 30 of file IoSvc.h.

Member Typedef Documentation

◆ Fd

Definition at line 40 of file IoSvc.h.

◆ FdMap_t

typedef std::unordered_map<Fd, FdInfos> IoSvc::FdMap_t
private

Definition at line 105 of file IoSvc.h.

Member Enumeration Documentation

◆ IoType

enum IIoSvc::IoType
inherited

I/O Connection types.

Enumerator
INVALID 
READ 
UPDATE 
CREATE 
RECREATE 

Definition at line 39 of file IIoSvc.h.

39  {
40  INVALID = 0,
41  READ = 1<<1,
42  UPDATE = 1<<2,
43  CREATE = 1<<3,
44  RECREATE = (1<<4)+(1<<3)
45  };

Constructor & Destructor Documentation

◆ IoSvc() [1/2]

IoSvc::IoSvc ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Constructor with parameters:

Definition at line 31 of file IoSvc.cxx.

32  :
33  ::AthService( name, pSvcLocator ),
34  m_fds(),
35  m_last_fd(3) // 1==cout, 2==cerr, 3==clog
36 {
37  //
38  // Property declaration
39  //
40  //declareProperty( "Property", m_nProperty );
41 
42 }

◆ ~IoSvc()

IoSvc::~IoSvc ( )
virtual

Destructor:

Definition at line 46 of file IoSvc.cxx.

47 {}

◆ IoSvc() [2/2]

IoSvc::IoSvc ( )
private

Default constructor:

Member Function Documentation

◆ close()

StatusCode IoSvc::close ( Fd  fd)
virtual

close file fd

Implements IIoSvc.

Definition at line 165 of file IoSvc.cxx.

166 {
167  FdMap_t::const_iterator itr = m_fds.find(fd);
168  if (itr != m_fds.end()) {
169  m_fds.erase(itr);
170  return StatusCode::SUCCESS;
171  }
172  return StatusCode::FAILURE;
173 }

◆ fd()

Fd IoSvc::fd ( const std::string &  fname) const
virtual

retrieve the file descriptor associated with file fname

Returns
-1 if no such fname is known

Implements IIoSvc.

Definition at line 97 of file IoSvc.cxx.

98 {
99  for (FdMap_t::const_iterator
100  itr = m_fds.begin(),
101  iend= m_fds.end();
102  itr != iend;
103  ++itr) {
104  if (itr->second.fname == fname) {
105  return itr->first;
106  }
107  }
108  return -1;
109 }

◆ finalize()

StatusCode IoSvc::finalize ( )
virtual

Definition at line 58 of file IoSvc.cxx.

59 {
60  ATH_MSG_INFO ("Finalizing " << name() << "...");
61 
62  return StatusCode::SUCCESS;
63 }

◆ fname()

const std::string & IoSvc::fname ( Fd  fd) const
virtual

retrieve the file fname associated with file descriptor fd

Returns
empty string if no such fd is known

Implements IIoSvc.

Definition at line 114 of file IoSvc.cxx.

115 {
116  FdMap_t::const_iterator itr = m_fds.find(fd);
117  if (itr != m_fds.end()) {
118  return itr->second.fname;
119  }
120  static const std::string s_empty = "";
121  return s_empty;
122 }

◆ has_fd()

bool IoSvc::has_fd ( Fd  fd) const
virtual

test if a given file descriptor fd is known to us

Implements IIoSvc.

Definition at line 89 of file IoSvc.cxx.

90 {
91  return m_fds.find(fd) != m_fds.end();
92 }

◆ initialize()

StatusCode IoSvc::initialize ( )
virtual

Gaudi Service Implementation.

Definition at line 51 of file IoSvc.cxx.

52 {
53  ATH_MSG_INFO ("Initializing " << name() << "...");
54 
55  return StatusCode::SUCCESS;
56 }

◆ interfaceID()

const InterfaceID & IoSvc::interfaceID ( )
inlinestatic

Definition at line 121 of file IoSvc.h.

122 {
123  return IIoSvc::interfaceID();
124 }

◆ IoTypeFromName()

static IoType IIoSvc::IoTypeFromName ( const std::string &  name)
inlinestaticinherited

Definition at line 61 of file IIoSvc.h.

61  {
62  static std::map<std::string, IoType> s_names;
63  if (s_names.empty()) {
64  s_names[""] = INVALID;
65  s_names["READ"] = READ;
66  s_names["UPDATE"] = UPDATE;
67  s_names["CREATE"] = CREATE;
68  s_names["RECREATE"] = RECREATE;
69  }
70  return s_names[name];
71  }

◆ IoTypeName()

static const std::string& IIoSvc::IoTypeName ( IoType  mode)
inlinestaticinherited

Definition at line 48 of file IIoSvc.h.

48  {
49  static std::map<IoType, std::string> s_names;
50  if (s_names.empty()) {
51  s_names[INVALID] = "";
52  s_names[READ] = "READ";
53  s_names[UPDATE] = "UPDATE";
54  s_names[CREATE] = "CREATE";
55  s_names[RECREATE] = "RECREATE";
56  }
57  return s_names[mode];
58  }

◆ mode()

IoType IoSvc::mode ( Fd  fd) const
virtual

retrieve the open mode associated with file descriptor fd

Implements IIoSvc.

Definition at line 126 of file IoSvc.cxx.

127 {
128  FdMap_t::const_iterator itr = m_fds.find(fd);
129  if (itr != m_fds.end()) {
130  return itr->second.mode;
131  }
132  return IIoSvc::INVALID;
133 }

◆ msg() [1/2]

MsgStream& AthCommonMsg< Service >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24  {
25  return this->msgStream();
26  }

◆ msg() [2/2]

MsgStream& AthCommonMsg< Service >::msg ( const MSG::Level  lvl) const
inlineinherited

Definition at line 27 of file AthCommonMsg.h.

27  {
28  return this->msgStream(lvl);
29  }

◆ msgLvl()

bool AthCommonMsg< Service >::msgLvl ( const MSG::Level  lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30  {
31  return this->msgLevel(lvl);
32  }

◆ open()

Fd IoSvc::open ( const std::string &  fname,
IoType  mode 
)
virtual

open file fname with open mode mode

Returns
-1 if not successful

Implements IIoSvc.

Definition at line 138 of file IoSvc.cxx.

139 {
140  // check this `fname` hasn't been already associated.
141  Fd fd = this->fd(fname);
142  if (fd == -1) {
143  // FIXME: use a recycle bin of fds ?
144  if ( m_last_fd == (std::numeric_limits<Fd>::max()-1)) {
145  ATH_MSG_ERROR("too many file descriptors opened!");
146  return -1;
147  }
148  fd = ++m_last_fd;
149  FdInfos infos = {fname, mode};
150  m_fds.insert(std::make_pair(fd, infos));
151  return fd;
152  }
153 
154  // check the previous open mode is the same
155  if (mode == this->mode(fd)) {
156  return fd;
157  }
158 
159  // inconsistency...
160  return -1;
161 }

◆ queryInterface()

StatusCode IoSvc::queryInterface ( const InterfaceID &  riid,
void **  ppvInterface 
)
virtual

Definition at line 71 of file IoSvc.cxx.

72 {
73  if ( IIoSvc::interfaceID().versionMatch(riid) ) {
74  *ppvInterface = dynamic_cast<IIoSvc*>(this);
75  } else {
76  // Interface is not directly available : try out a base class
77  return ::AthService::queryInterface(riid, ppvInterface);
78  }
79  addRef();
80  return StatusCode::SUCCESS;
81 }

Friends And Related Function Documentation

◆ SvcFactory< IoSvc >

friend class SvcFactory< IoSvc >
friend

Definition at line 121 of file IoSvc.h.

Member Data Documentation

◆ m_fds

FdMap_t IoSvc::m_fds
private

map of fd->fdinfos

Definition at line 108 of file IoSvc.h.

◆ m_last_fd

Fd IoSvc::m_last_fd
private

last created Fd

Definition at line 111 of file IoSvc.h.


The documentation for this class was generated from the following files:
AthService::AthService
AthService()
max
#define max(a, b)
Definition: cfImp.cxx:41
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
IIoSvc::RECREATE
@ RECREATE
Definition: IIoSvc.h:44
IIoSvc::interfaceID
static const InterfaceID & interfaceID()
Definition: IIoSvc.h:128
Fd
IIoSvc::Fd Fd
Definition: IoSvc.cxx:22
IIoSvc
Definition: IIoSvc.h:29
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IoSvc::m_last_fd
Fd m_last_fd
last created Fd
Definition: IoSvc.h:111
IIoSvc::CREATE
@ CREATE
Definition: IIoSvc.h:43
IoSvc::fname
const std::string & fname(Fd fd) const
retrieve the file fname associated with file descriptor fd
Definition: IoSvc.cxx:114
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
IoSvc::fd
Fd fd(const std::string &fname) const
retrieve the file descriptor associated with file fname
Definition: IoSvc.cxx:97
IIoSvc::UPDATE
@ UPDATE
Definition: IIoSvc.h:42
IIoSvc::mode
virtual IoType mode(Fd fd) const =0
retrieve the open mode associated with file descriptor fd
IIoSvc::READ
@ READ
Definition: IIoSvc.h:41
IoSvc::m_fds
FdMap_t m_fds
map of fd->fdinfos
Definition: IoSvc.h:108
IoSvc::mode
IoType mode(Fd fd) const
retrieve the open mode associated with file descriptor fd
Definition: IoSvc.cxx:126
IIoSvc::INVALID
@ INVALID
Definition: IIoSvc.h:40