Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
Gaudi::IODataManager Class Reference

#include <IODataManager.h>

Inheritance diagram for Gaudi::IODataManager:
Inheritance graph
[legend]
Collaboration diagram for Gaudi::IODataManager:
Collaboration graph
[legend]

Classes

struct  Entry
 

Public Member Functions

 IODataManager (CSTR nam, ISvcLocator *loc)
 the incident service
 
virtual ~IODataManager ()
 Standard destructor.
 
virtual StatusCode initialize ()
 IService implementation: initialize the service.
 
virtual StatusCode finalize ()
 IService implementation: finalize the service.
 
virtual StatusCode connectRead (bool keep_open, Connection *ioDesc)
 Open data stream in read mode.
 
virtual StatusCode connectWrite (Connection *con, IoType mode=Connection::CREATE, CSTR doctype="UNKNOWN")
 Open data stream in write mode.
 
virtual StatusCode disconnect (Connection *ioDesc)
 Release data stream.
 
virtual Connection * connection (const std::string &dsn) const
 Retrieve known connection.
 
virtual Connections connections (const IInterface *owner) const
 Get connection by owner instance (0=ALL)
 
virtual StatusCode read (Connection *ioDesc, void *const data, size_t len)
 Read raw byte buffer from input stream.
 
virtual StatusCode write (Connection *con, const void *data, int len)
 Write raw byte buffer to output stream.
 
virtual long long int seek (Connection *ioDesc, long long int where, int origin)
 Seek on the file described by ioDesc. Arguments as in ::seek()
 
- Public Member Functions inherited from extends1< Service, IIODataManager >
 extends1 (A1 a1, A2 a2, A3 a3)
 Templated constructor with 3 arguments.
 
 extends1 (A1 a1, A2 a2)
 Templated constructor with 2 arguments.
 
 extends1 (A1 a1)
 Templated constructor with 1 argument.
 
 extends1 ()
 Default constructor.
 
virtual void * i_cast (const InterfaceID &tid) const
 Implementation of IInterface::i_cast.
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)
 Implementation of IInterface::queryInterface.
 
virtual std::vector< std::stringgetInterfaceNames () const
 Implementation of IInterface::getInterfaceNames.
 
virtual ~extends1 ()
 Virtual destructor.
 
- Public Member Functions inherited from Service
virtual unsigned long release ()
 Release Interface instance.
 
virtual const std::stringname () const
 Retrieve name of the service.
 
virtual StatusCode configure ()
 
virtual StatusCode start ()
 
virtual StatusCode stop ()
 
virtual StatusCode terminate ()
 
virtual Gaudi::StateMachine::State FSMState () const
 
virtual Gaudi::StateMachine::State targetFSMState () const
 
virtual StatusCode reinitialize ()
 
virtual StatusCode restart ()
 
virtual StatusCode sysInitialize ()
 Initialize Service.
 
virtual StatusCode sysStart ()
 Initialize Service.
 
virtual StatusCode sysStop ()
 Initialize Service.
 
virtual StatusCode sysFinalize ()
 Finalize Service.
 
virtual StatusCode sysReinitialize ()
 Re-initialize the Service.
 
virtual StatusCode sysRestart ()
 Re-initialize the Service.
 
virtual StatusCode setProperty (const Property &p)
 
virtual StatusCode setProperty (const std::string &s)
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 
virtual StatusCode getProperty (Property *p) const
 
virtual const PropertygetProperty (const std::string &name) const
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 
virtual const std::vector
< Property * > & 
getProperties () const
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 Service (const std::string &name, ISvcLocator *svcloc)
 Standard Constructor.
 
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator.
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job.
 
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.
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, 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.
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property.
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties.
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
 
- Public Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
 CommonMessaging (const A1 &a1, const A2 &a2, const A3 &a3)
 Templated constructor with 3 arguments.
 
 CommonMessaging (const A1 &a1, const A2 &a2)
 Templated constructor with 2 arguments.
 
 CommonMessaging (const A1 &a1)
 Templated constructor with 1 argument.
 
 CommonMessaging ()
 Default constructor.
 
virtual ~CommonMessaging ()
 Virtual destructor.
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from extend_interfaces1< IIODataManager >
virtual ~extend_interfaces1 ()
 Virtual destructor.
 

Protected Types

typedef const std::stringCSTR
 
typedef std::map< std::string,
Entry * > 
ConnectionMap
 
typedef std::map< std::string,
std::string
FidMap
 

Protected Member Functions

StatusCode connectDataIO (int typ, IoType rw, CSTR fn, CSTR technology, bool keep, Connection *con)
 
StatusCode reconnect (Entry *e)
 
StatusCode error (CSTR msg, bool rethrow)
 
StatusCode establishConnection (Connection *con)
 

Protected Attributes

std::string m_catalogSvcName
 Property: Name of the file catalog service.
 
int m_ageLimit
 Property: Age limit.
 
bool m_useGFAL
 Property: Flag for auto gfal data access.
 
bool m_quarantine
 Property: Flag if unaccessible files should be quarantines in job.
 
ConnectionMap m_connectionMap
 Map with I/O descriptors.
 
SmartIF< IFileCatalogm_catalog
 Reference to file catalog.
 
FidMap m_fidMap
 Map of FID to PFN.
 
SmartIF< IIncidentSvcm_incSvc
 

Additional Inherited Members

- Public Types inherited from extends1< Service, IIODataManager >
typedef extends1 base_class
 Typedef to this class.
 
typedef extend_interfaces1
< IIODataManager
extend_interfaces_base
 Typedef to the base of this class.
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces.
 

Detailed Description

Definition at line 29 of file IODataManager.h.

Member Typedef Documentation

typedef std::map<std::string,Entry*> Gaudi::IODataManager::ConnectionMap
protected

Definition at line 41 of file IODataManager.h.

typedef const std::string& Gaudi::IODataManager::CSTR
protected

Definition at line 31 of file IODataManager.h.

typedef std::map<std::string, std::string> Gaudi::IODataManager::FidMap
protected

Definition at line 42 of file IODataManager.h.

Constructor & Destructor Documentation

IODataManager::IODataManager ( CSTR  nam,
ISvcLocator loc 
)

the incident service

Initializing constructor

Parameters
[in]namName of the service
[in]locPointer to the service locator object
Returns
Initialized reference to service object

Definition at line 22 of file IODataManager.cpp.

: base_class(nam, svcloc), m_ageLimit(2)
{
declareProperty("CatalogType", m_catalogSvcName="Gaudi::MultiFileCatalog/FileCatalog");
declareProperty("UseGFAL", m_useGFAL = true);
declareProperty("QuarantineFiles", m_quarantine = true);
declareProperty("AgeLimit", m_ageLimit = 2);
}
virtual Gaudi::IODataManager::~IODataManager ( )
inlinevirtual

Standard destructor.

Definition at line 76 of file IODataManager.h.

{}

Member Function Documentation

StatusCode IODataManager::connectDataIO ( int  typ,
IoType  rw,
CSTR  fn,
CSTR  technology,
bool  keep,
Connection *  con 
)
protected

Definition at line 234 of file IODataManager.cpp.

{
std::string dsn = dataset;
try {
if ( ::strncasecmp(dsn.c_str(),"FID:",4)==0 )
dsn = dataset.substr(4), typ = FID;
else if ( ::strncasecmp(dsn.c_str(),"LFN:",4)==0 )
dsn = dataset.substr(4), typ = LFN;
else if ( ::strncasecmp(dsn.c_str(),"PFN:",4)==0 )
dsn = dataset.substr(4), typ = PFN;
else if ( typ == UNKNOWN )
return connectDataIO(PFN, rw, dsn, technology, keep_open, connection);
return IDataConnection::BAD_DATA_CONNECTION;
}
if ( typ == FID ) {
ConnectionMap::iterator fi = m_connectionMap.find(dsn);
if ( fi == m_connectionMap.end() ) {
m_catalog->getPFN(dsn,files);
if ( files.size() == 0 ) {
if ( !m_useGFAL ) {
if ( m_quarantine ) s_badFiles.insert(dsn);
error("connectDataIO> failed to resolve FID:"+dsn,false).ignore();
return IDataConnection::BAD_DATA_CONNECTION;
}
else if ( dsn.length() == 36 && dsn[8]=='-' && dsn[13]=='-' ) {
std::string gfal_name = "gfal:guid:" + dsn;
m_fidMap[dsn] = m_fidMap[dataset] = m_fidMap[gfal_name] = dsn;
sc = connectDataIO(PFN, rw, gfal_name, technology, keep_open, connection);
if ( sc.isSuccess() ) return sc;
if ( m_quarantine ) s_badFiles.insert(dsn);
}
if ( m_quarantine ) s_badFiles.insert(dsn);
error("connectDataIO> Failed to resolve FID:"+dsn,false).ignore();
return IDataConnection::BAD_DATA_CONNECTION;
}
std::string pfn = files[0].first;
m_fidMap[dsn] = m_fidMap[dataset] = m_fidMap[pfn] = dsn;
sc = connectDataIO(PFN, rw, pfn, technology, keep_open, connection);
if ( !sc.isSuccess() ) {
if ( m_quarantine ) s_badFiles.insert(pfn);
return IDataConnection::BAD_DATA_CONNECTION;
}
return sc;
}
return S_ERROR;
//Connection* c = (*fi).second->connection;
//sc = connectDataIO(PFN, rw, c->pfn(), technology, keep_open, connection);
//if ( !sc.isSuccess() && m_quarantine ) s_badFiles.insert(c->pfn());
//return sc;
}
FidMap::iterator j = m_fidMap.find(dsn);
if ( j == m_fidMap.end() ) {
switch(typ) {
case LFN:
fid = m_catalog->lookupLFN(dsn);
if ( fid.empty() ) {
log << MSG::ERROR << "Failed to resolve LFN:" << dsn
<< " Cannot access this dataset." << endmsg;
return IDataConnection::BAD_DATA_CONNECTION;
}
break;
case PFN:
fid = m_catalog->lookupPFN(dsn);
if ( !fid.empty() ) m_catalog->getPFN(fid, files);
if ( files.empty() ) {
if ( rw == Connection::CREATE || rw == Connection::RECREATE ) {
if ( fid.empty() ) fid = m_catalog->createFID();
m_catalog->registerPFN(fid,dsn,technology);
log << MSG::INFO << "Referring to dataset " << dsn
<< " by its file ID:" << fid << endmsg;
}
else {
fid = dsn;
}
}
break;
}
}
else {
fid = (*j).second;
}
if ( typ == PFN ) {
// Open PFN
ConnectionMap::iterator fi = m_connectionMap.find(fid);
if ( fi == m_connectionMap.end() ) {
connection->setFID(fid);
connection->setPFN(dsn);
Entry* e = new Entry(technology, keep_open, rw, connection);
// Here we open the file!
if ( !reconnect(e).isSuccess() ) {
delete e;
if ( m_quarantine ) s_badFiles.insert(dsn);
error("connectDataIO> Cannot connect to database: PFN="+dsn+" FID="+fid,false).ignore();
return IDataConnection::BAD_DATA_CONNECTION;
}
fid = connection->fid();
m_fidMap[dataset] = m_fidMap[dsn] = m_fidMap[fid] = fid;
if ( !(rw==Connection::CREATE || rw==Connection::RECREATE) ) {
if ( strcasecmp(dsn.c_str(),fid.c_str()) == 0 ) {
log << MSG::ERROR << "Referring to existing dataset " << dsn
<< " by its physical name." << endmsg;
log << "You may not be able to navigate back to the input file"
<< " -- processing continues" << endmsg;
}
}
return S_OK;
}
// Here we open the file!
if ( !reconnect((*fi).second).isSuccess() ) {
if ( m_quarantine ) s_badFiles.insert(dsn);
error("connectDataIO> Cannot connect to database: PFN="+dsn+" FID="+fid,false).ignore();
return IDataConnection::BAD_DATA_CONNECTION;
}
return S_OK;
}
sc = connectDataIO(FID, rw, fid, technology, keep_open, connection);
if ( !sc.isSuccess() && m_quarantine ) {
}
else if ( typ == LFN ) {
m_fidMap[dataset] = fid;
}
return sc;
}
catch (std::exception& e) {
error(std::string("connectDataIO> Caught exception:")+e.what(), false).ignore();
}
catch(...) {
error(std::string("connectDataIO> Caught unknown exception"), false).ignore();
}
error("connectDataIO> The dataset "+dsn+" cannot be opened.",false).ignore();
return IDataConnection::BAD_DATA_CONNECTION;
}
IIODataManager::Connection * IODataManager::connection ( const std::string dsn) const
virtual

Retrieve known connection.

Definition at line 202 of file IODataManager.cpp.

{
FidMap::const_iterator j = m_fidMap.find(dataset);
if ( j != m_fidMap.end() ) {
ConnectionMap::const_iterator i=m_connectionMap.find((*j).second);
return (i != m_connectionMap.end()) ? (*i).second->connection : 0;
}
return 0;
}
IODataManager::Connections IODataManager::connections ( const IInterface owner) const
virtual

Get connection by owner instance (0=ALL)

Definition at line 73 of file IODataManager.cpp.

{
Connections conns;
for(ConnectionMap::const_iterator i=m_connectionMap.begin(); i!=m_connectionMap.end();++i) {
IDataConnection* c = (*i).second->connection;
if ( 0 == owner || c->owner() == owner )
conns.push_back(c);
}
return conns;
}
StatusCode IODataManager::connectRead ( bool  keep_open,
Connection *  ioDesc 
)
virtual

Open data stream in read mode.

Connect data file for writing.

Definition at line 84 of file IODataManager.cpp.

{
if ( !establishConnection(con) ) {
return connectDataIO(UNKNOWN,Connection::READ,con->name(),"UNKNOWN",keep_open,con);
}
std::string dsn = con ? con->name() : std::string("Unknown");
return error("Failed to connect to data:"+dsn,false);
}
StatusCode IODataManager::connectWrite ( Connection *  con,
IoType  mode = Connection::CREATE,
CSTR  doctype = "UNKNOWN" 
)
virtual

Open data stream in write mode.

Connect data file for reading.

Definition at line 93 of file IODataManager.cpp.

{
if ( !establishConnection(con) ) {
return connectDataIO(UNKNOWN,mode,con->name(),doctype,true,con);
}
std::string dsn = con ? con->name() : std::string("Unknown");
return error("Failed to connect to data:"+dsn,false);
}
StatusCode IODataManager::disconnect ( Connection *  ioDesc)
virtual

Release data stream.

Definition at line 116 of file IODataManager.cpp.

{
if ( con ) {
std::string dataset = con->name();
std::string dsn = dataset;
StatusCode sc = con->disconnect();
if ( ::strncasecmp(dsn.c_str(),"FID:",4)==0 )
dsn = dataset.substr(4);
else if ( ::strncasecmp(dsn.c_str(),"LFN:",4)==0 )
dsn = dataset.substr(4);
else if ( ::strncasecmp(dsn.c_str(),"PFN:",4)==0 )
dsn = dataset.substr(4);
FidMap::iterator j = m_fidMap.find(dataset);
if ( j != m_fidMap.end() ) {
std::string fid = (*j).second;
std::string gfal_name = "gfal:guid:" + fid;
ConnectionMap::iterator i=m_connectionMap.find(fid);
if ( (j=m_fidMap.find(fid)) != m_fidMap.end() )
if ( (j=m_fidMap.find(gfal_name)) != m_fidMap.end() )
if ( i != m_connectionMap.end() ) {
if ( (*i).second ) {
IDataConnection* c = (*i).second->connection;
std::string pfn = c->pfn();
if ( (j=m_fidMap.find(pfn)) != m_fidMap.end() )
if ( c->isConnected() ) {
c->disconnect();
log << MSG::INFO << "Disconnect from dataset " << dsn
<< " [" << fid << "]" << endmsg;
}
delete (*i).second;
}
}
}
return sc;
}
return S_ERROR;
}
StatusCode IODataManager::error ( CSTR  msg,
bool  rethrow 
)
protected

Definition at line 64 of file IODataManager.cpp.

{
log << MSG::ERROR << "Error: " << msg << endmsg;
if ( rethrow ) {
}
return S_ERROR;
}
StatusCode IODataManager::establishConnection ( Connection *  con)
protected

Definition at line 211 of file IODataManager.cpp.

{
if ( con ) {
if ( !con->isConnected() ) {
ConnectionMap::const_iterator i=m_connectionMap.find(con->name());
if ( i != m_connectionMap.end() ) {
Connection* c = (*i).second->connection;
if ( c != con ) {
m_incSvc->fireIncident(Incident(con->name(),IncidentType::FailInputFile));
return error("Severe logic bug: Twice identical connection object for DSN:"+con->name(),true);
}
if ( reconnect((*i).second).isSuccess() ) {
return S_OK;
}
}
return S_ERROR;
}
con->resetAge();
return S_OK;
}
return error("Severe logic bug: No connection object avalible.",true);
}
StatusCode IODataManager::finalize ( )
virtual

IService implementation: finalize the service.

Reimplemented from Service.

Definition at line 58 of file IODataManager.cpp.

{
m_catalog = 0; // release
}
StatusCode IODataManager::initialize ( )
virtual

IService implementation: initialize the service.

IService implementation: Db event selector override.

Reimplemented from Service.

Definition at line 32 of file IODataManager.cpp.

{
// Initialize base class
if ( !status.isSuccess() ) {
log << MSG::ERROR << "Error initializing base class Service!" << endmsg;
return status;
}
// Retrieve conversion service handling event iteration
m_catalog = serviceLocator()->service(m_catalogSvcName);
if( !m_catalog.isValid() ) {
<< "Unable to localize interface IFileCatalog from service:"
}
m_incSvc = serviceLocator()->service("IncidentSvc");
if( !m_incSvc.isValid() ) {
log << MSG::ERROR << "Error initializing IncidentSvc Service!" << endmsg;
return status;
}
return status;
}
StatusCode IODataManager::read ( Connection *  ioDesc,
void *const  data,
size_t  len 
)
virtual

Read raw byte buffer from input stream.

Definition at line 102 of file IODataManager.cpp.

{
return establishConnection(con).isSuccess() ? con->read(data,len) : S_ERROR;
}
StatusCode IODataManager::reconnect ( Entry e)
protected

Definition at line 160 of file IODataManager.cpp.

{
if ( e && e->connection ) {
switch(e->ioType) {
case Connection::READ:
sc = e->connection->connectRead();
break;
case Connection::UPDATE:
case Connection::CREATE:
case Connection::RECREATE:
sc = e->connection->connectWrite(e->ioType);
break;
default:
return S_ERROR;
}
if ( sc.isSuccess() && e->ioType == Connection::READ ) {
e->connection->resetAge();
for(ConnectionMap::iterator i=m_connectionMap.begin(); i!=m_connectionMap.end();++i) {
IDataConnection* c = (*i).second->connection;
if ( e->connection != c && c->isConnected() && !(*i).second->keepOpen ) {
c->ageFile();
if ( c->age() > m_ageLimit ) {
to_retire.push_back((*i).second);
}
}
}
if ( !to_retire.empty() ) {
for(std::vector<Entry*>::iterator j=to_retire.begin(); j!=to_retire.end();++j) {
IDataConnection* c = (*j)->connection;
c->disconnect();
log << MSG::INFO << "Disconnect from dataset " << c->pfn()
<< " [" << c->fid() << "]" << endmsg;
}
}
}
}
return sc;
}
long long int IODataManager::seek ( Connection *  ioDesc,
long long int  where,
int  origin 
)
virtual

Seek on the file described by ioDesc. Arguments as in ::seek()

Definition at line 112 of file IODataManager.cpp.

{
return establishConnection(con).isSuccess() ? con->seek(where,origin) : -1;
}
StatusCode IODataManager::write ( Connection *  con,
const void *  data,
int  len 
)
virtual

Write raw byte buffer to output stream.

Definition at line 107 of file IODataManager.cpp.

{
return establishConnection(con).isSuccess() ? con->write(data,len) : S_ERROR;
}

Member Data Documentation

int Gaudi::IODataManager::m_ageLimit
protected

Property: Age limit.

Definition at line 47 of file IODataManager.h.

SmartIF<IFileCatalog> Gaudi::IODataManager::m_catalog
protected

Reference to file catalog.

Definition at line 56 of file IODataManager.h.

std::string Gaudi::IODataManager::m_catalogSvcName
protected

Property: Name of the file catalog service.

Definition at line 45 of file IODataManager.h.

ConnectionMap Gaudi::IODataManager::m_connectionMap
protected

Map with I/O descriptors.

Definition at line 54 of file IODataManager.h.

FidMap Gaudi::IODataManager::m_fidMap
protected

Map of FID to PFN.

Definition at line 58 of file IODataManager.h.

SmartIF<IIncidentSvc> Gaudi::IODataManager::m_incSvc
protected

Definition at line 64 of file IODataManager.h.

bool Gaudi::IODataManager::m_quarantine
protected

Property: Flag if unaccessible files should be quarantines in job.

Definition at line 51 of file IODataManager.h.

bool Gaudi::IODataManager::m_useGFAL
protected

Property: Flag for auto gfal data access.

Definition at line 49 of file IODataManager.h.


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

Generated at Wed Nov 28 2012 12:17:36 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004