| # Gaudi Framework, version v21r10p1 |

Home |  | Generated: 29 Jul 2010

# Gaudi::IODataManager Class Reference

`#include <IODataManager.h>`

Inheritance diagram for Gaudi::IODataManager:

[legend]
Collaboration diagram for Gaudi::IODataManager:

[legend]

List of all members.

## 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().
## Protected Types
typedef const std::string & | CSTR
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< IFileCatalog > | m_catalog
| Reference to file catalog.
FidMap | m_fidMap
| Map of FID to PFN.
SmartIF< IIncidentSvc > | m_incSvc
## Classes
struct | Entry

## Detailed Description

Definition at line 29 of file IODataManager.h.

## Member Typedef Documentation

typedef const std::string& Gaudi::IODataManager::CSTR`[protected]`

Definition at line 31 of file IODataManager.h.

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

Definition at line 41 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]` | nam | Name of the service
  `[in]` | loc | Pointer to the service locator object

Returns:
  Initialized reference to service object

Definition at line 22 of file IODataManager.cpp.

    00023   : base_class(nam, svcloc), m_ageLimit(2)
    00024 {
    00025   declareProperty("CatalogType",     m_catalogSvcName="Gaudi::MultiFileCatalog/FileCatalog");
    00026   declareProperty("UseGFAL",         m_useGFAL = true);
    00027   declareProperty("QuarantineFiles", m_quarantine = true);
    00028   declareProperty("AgeLimit",        m_ageLimit = 2);
    00029 }

virtual Gaudi::IODataManager::~IODataManager | ( |  | ) | `[inline, virtual]`

Standard destructor.

Definition at line 76 of file IODataManager.h.

    00076 {}

## 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.

    00234                                                                                                                      {
    00235   MsgStream log(msgSvc(),name());
    00236   std::string dsn = dataset;
    00237   try  {
    00238     StatusCode sc(StatusCode::SUCCESS,true);
    00239     if ( ::strncasecmp(dsn.c_str(),"FID:",4)==0 )
    00240       dsn = dataset.substr(4), typ = FID;
    00241     else if ( ::strncasecmp(dsn.c_str(),"LFN:",4)==0 )
    00242       dsn = dataset.substr(4), typ = LFN;
    00243     else if ( ::strncasecmp(dsn.c_str(),"PFN:",4)==0 )
    00244       dsn = dataset.substr(4), typ = PFN;
    00245     else if ( typ == UNKNOWN )
    00246       return connectDataIO(PFN, rw, dsn, technology, keep_open, connection);
    00247
    00248     if(std::find(s_badFiles.begin(),s_badFiles.end(),dsn) != s_badFiles.end())  {
    00249       m_incSvc->fireIncident(Incident(dsn,IncidentType::FailInputFile));
    00250       return IDataConnection::BAD_DATA_CONNECTION;
    00251     }
    00252     if ( typ == FID )  {
    00253       ConnectionMap::iterator fi = m_connectionMap.find(dsn);
    00254       if ( fi == m_connectionMap.end() )  {
    00255         IFileCatalog::Files files;
    00256         m_catalog->getPFN(dsn,files);
    00257         if ( files.size() == 0 ) {
    00258           if ( !m_useGFAL )   {
    00259             if ( m_quarantine ) s_badFiles.insert(dsn);
    00260             m_incSvc->fireIncident(Incident(dsn,IncidentType::FailInputFile));
    00261             error("connectDataIO> failed to resolve FID:"+dsn,false).ignore();
    00262             return IDataConnection::BAD_DATA_CONNECTION;
    00263           }
    00264           else if ( dsn.length() == 36 && dsn[8]=='-' && dsn[13]=='-' )  {
    00265             std::string gfal_name = "gfal:guid:" + dsn;
    00266             m_fidMap[dsn] = m_fidMap[dataset] = m_fidMap[gfal_name] = dsn;
    00267             sc = connectDataIO(PFN, rw, gfal_name, technology, keep_open, connection);
    00268             if ( sc.isSuccess() ) return sc;
    00269             if ( m_quarantine ) s_badFiles.insert(dsn);
    00270           }
    00271           if ( m_quarantine ) s_badFiles.insert(dsn);
    00272           m_incSvc->fireIncident(Incident(dsn,IncidentType::FailInputFile));
    00273           error("connectDataIO> Failed to resolve FID:"+dsn,false).ignore();
    00274           return IDataConnection::BAD_DATA_CONNECTION;
    00275         }
    00276         std::string pfn = files[0].first;
    00277         m_fidMap[dsn] = m_fidMap[dataset] = m_fidMap[pfn] = dsn;
    00278         sc = connectDataIO(PFN, rw, pfn, technology, keep_open, connection);
    00279         if ( !sc.isSuccess() )  {
    00280           if ( m_quarantine ) s_badFiles.insert(pfn);
    00281           m_incSvc->fireIncident(Incident(pfn,IncidentType::FailInputFile));
    00282           return IDataConnection::BAD_DATA_CONNECTION;
    00283         }
    00284
    00285         return sc;
    00286       }
    00287       return S_ERROR;
    00288       //Connection* c = (*fi).second->connection;
    00289       //sc = connectDataIO(PFN, rw, c->pfn(), technology, keep_open, connection);
    00290       //if ( !sc.isSuccess() && m_quarantine ) s_badFiles.insert(c->pfn());
    00291       //return sc;
    00292     }
    00293     std::string fid;
    00294     FidMap::iterator j = m_fidMap.find(dsn);
    00295     if ( j == m_fidMap.end() )  {
    00296       IFileCatalog::Files files;
    00297       switch(typ)  {
    00298       case LFN:
    00299         fid = m_catalog->lookupLFN(dsn);
    00300         if ( fid.empty() )  {
    00301           m_incSvc->fireIncident(Incident(dsn,IncidentType::FailInputFile));
    00302           log << MSG::ERROR << "Failed to resolve LFN:" << dsn
    00303               << " Cannot access this dataset." << endmsg;
    00304           return IDataConnection::BAD_DATA_CONNECTION;
    00305         }
    00306         break;
    00307       case PFN:
    00308         fid = m_catalog->lookupPFN(dsn);
    00309         if ( !fid.empty() ) m_catalog->getPFN(fid, files);
    00310         if ( files.empty() )   {
    00311           if ( rw == Connection::CREATE || rw == Connection::RECREATE )  {
    00312             if ( fid.empty() ) fid = m_catalog->createFID();
    00313             m_catalog->registerPFN(fid,dsn,technology);
    00314             log << MSG::INFO << "Referring to dataset " << dsn
    00315                 << " by its file ID:" << fid << endmsg;
    00316           }
    00317           else  {
    00318             fid = dsn;
    00319           }
    00320         }
    00321         break;
    00322       }
    00323     }
    00324     else {
    00325       fid = (*j).second;
    00326     }
    00327     if ( typ == PFN )  {
    00328       // Open PFN
    00329       ConnectionMap::iterator fi = m_connectionMap.find(fid);
    00330       if ( fi == m_connectionMap.end() )  {
    00331         connection->setFID(fid);
    00332         connection->setPFN(dsn);
    00333         Entry* e = new Entry(technology, keep_open, rw, connection);
    00334         // Here we open the file!
    00335         if ( !reconnect(e).isSuccess() )   {
    00336           delete e;
    00337           if ( m_quarantine ) s_badFiles.insert(dsn);
    00338           m_incSvc->fireIncident(Incident(dsn,IncidentType::FailInputFile));
    00339           error("connectDataIO> Cannot connect to database: PFN="+dsn+" FID="+fid,false).ignore();
    00340           return IDataConnection::BAD_DATA_CONNECTION;
    00341         }
    00342         fid = connection->fid();
    00343         m_fidMap[dataset] = m_fidMap[dsn] = m_fidMap[fid] = fid;
    00344         if (  !(rw==Connection::CREATE || rw==Connection::RECREATE) )  {
    00345           if ( strcasecmp(dsn.c_str(),fid.c_str()) == 0 )  {
    00346             log << MSG::ERROR << "Referring to existing dataset " << dsn
    00347                 << " by its physical name." << endmsg;
    00348             log << "You may not be able to navigate back to the input file"
    00349                 << " -- processing continues" << endmsg;
    00350           }
    00351         }
    00352         m_connectionMap.insert(std::make_pair(fid,e)).first;
    00353         return S_OK;
    00354       }
    00355       // Here we open the file!
    00356       if ( !reconnect((*fi).second).isSuccess() )   {
    00357         if ( m_quarantine ) s_badFiles.insert(dsn);
    00358         m_incSvc->fireIncident(Incident(dsn,IncidentType::FailInputFile));
    00359         error("connectDataIO> Cannot connect to database: PFN="+dsn+" FID="+fid,false).ignore();
    00360         return IDataConnection::BAD_DATA_CONNECTION;
    00361       }
    00362       return S_OK;
    00363     }
    00364     sc = connectDataIO(FID, rw, fid, technology, keep_open, connection);
    00365     if ( !sc.isSuccess() && m_quarantine ) {
    00366       s_badFiles.insert(fid);
    00367     }
    00368     else if ( typ == LFN ) {
    00369       m_fidMap[dataset] = fid;
    00370     }
    00371     return sc;
    00372   }
    00373   catch (std::exception& e)  {
    00374     error(std::string("connectDataIO> Caught exception:")+e.what(), false).ignore();
    00375   }
    00376   catch(...) {
    00377     error(std::string("connectDataIO> Caught unknown exception"), false).ignore();
    00378   }
    00379   m_incSvc->fireIncident(Incident(dsn,IncidentType::FailInputFile));
    00380   error("connectDataIO> The dataset "+dsn+" cannot be opened.",false).ignore();
    00381   s_badFiles.insert(dsn);
    00382   return IDataConnection::BAD_DATA_CONNECTION;
    00383 }

StatusCode IODataManager::reconnect | ( | Entry * | e | ) | `[protected]`

Definition at line 160 of file IODataManager.cpp.

    00160                                              {
    00161   StatusCode sc = S_ERROR;
    00162   if ( e && e->connection )  {
    00163     switch(e->ioType)  {
    00164     case Connection::READ:
    00165       sc = e->connection->connectRead();
    00166       break;
    00167     case Connection::UPDATE:
    00168     case Connection::CREATE:
    00169     case Connection::RECREATE:
    00170       sc = e->connection->connectWrite(e->ioType);
    00171       break;
    00172     default:
    00173       return S_ERROR;
    00174     }
    00175     if ( sc.isSuccess() && e->ioType == Connection::READ )  {
    00176       std::vector<Entry*> to_retire;
    00177       e->connection->resetAge();
    00178       for(ConnectionMap::iterator i=m_connectionMap.begin(); i!=m_connectionMap.end();++i) {
    00179         IDataConnection* c = (*i).second->connection;
    00180         if ( e->connection != c && c->isConnected() && !(*i).second->keepOpen )  {
    00181           c->ageFile();
    00182           if ( c->age() > m_ageLimit ) {
    00183             to_retire.push_back((*i).second);
    00184           }
    00185         }
    00186       }
    00187       if ( !to_retire.empty() )  {
    00188         MsgStream log(msgSvc(),name());
    00189         for(std::vector<Entry*>::iterator j=to_retire.begin(); j!=to_retire.end();++j)  {
    00190           IDataConnection* c = (*j)->connection;
    00191           c->disconnect();
    00192           log << MSG::INFO << "Disconnect from dataset " << c->pfn()
    00193               << " [" << c->fid() << "]" << endmsg;
    00194         }
    00195       }
    00196     }
    00197   }
    00198   return sc;
    00199 }

StatusCode IODataManager::error | ( | CSTR | msg,
|  | bool | rethrow |
| ) |  |  | `[protected]`

Definition at line 64 of file IODataManager.cpp.

    00064                                                        {
    00065   MsgStream log(msgSvc(),name());
    00066   log << MSG::ERROR << "Error: " << msg << endmsg;
    00067   if ( rethrow )  {
    00068     System::breakExecution();
    00069   }
    00070   return S_ERROR;
    00071 }

StatusCode IODataManager::establishConnection | ( | Connection * | con | ) | `[protected]`

Definition at line 211 of file IODataManager.cpp.

    00211                                                               {
    00212   if ( con )  {
    00213     if ( !con->isConnected() )  {
    00214       ConnectionMap::const_iterator i=m_connectionMap.find(con->name());
    00215       if ( i != m_connectionMap.end() )  {
    00216         Connection* c = (*i).second->connection;
    00217         if ( c != con )  {
    00218           m_incSvc->fireIncident(Incident(con->name(),IncidentType::FailInputFile));
    00219           return error("Severe logic bug: Twice identical connection object for DSN:"+con->name(),true);
    00220         }
    00221         if ( reconnect((*i).second).isSuccess() ) {
    00222           return S_OK;
    00223         }
    00224       }
    00225       return S_ERROR;
    00226     }
    00227     con->resetAge();
    00228     return S_OK;
    00229   }
    00230   return error("Severe logic bug: No connection object avalible.",true);
    00231 }

StatusCode IODataManager::initialize | ( |  | ) | `[virtual]`

IService implementation: initialize the service.

IService implementation: Db event selector override.

Definition at line 32 of file IODataManager.cpp.

    00032                                       {
    00033   // Initialize base class
    00034   StatusCode status = Service::initialize();
    00035   MsgStream log(msgSvc(), name());
    00036   if ( !status.isSuccess() )    {
    00037     log << MSG::ERROR << "Error initializing base class Service!" << endmsg;
    00038     return status;
    00039   }
    00040   // Retrieve conversion service handling event iteration
    00041   m_catalog = serviceLocator()->service(m_catalogSvcName);
    00042   if( !m_catalog.isValid() ) {
    00043     log << MSG::ERROR
    00044         << "Unable to localize interface IFileCatalog from service:"
    00045         << m_catalogSvcName << endmsg;
    00046     return StatusCode::FAILURE;
    00047   }
    00048   m_incSvc = serviceLocator()->service("IncidentSvc");
    00049   if( !m_incSvc.isValid() ) {
    00050     log << MSG::ERROR << "Error initializing IncidentSvc Service!" << endmsg;
    00051     return status;
    00052   }
    00053
    00054   return status;
    00055 }

StatusCode IODataManager::finalize | ( |  | ) | `[virtual]`

IService implementation: finalize the service.

Definition at line 58 of file IODataManager.cpp.

    00058                                     {
    00059   m_catalog = 0; // release
    00060   return Service::finalize();
    00061 }

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.

    00084                                                                       {
    00085   if ( !establishConnection(con) )  {
    00086     return connectDataIO(UNKNOWN,Connection::READ,con->name(),"UNKNOWN",keep_open,con);
    00087   }
    00088   std::string dsn = con ? con->name() : std::string("Unknown");
    00089   return error("Failed to connect to data:"+dsn,false);
    00090 }

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.

    00093                                                                                 {
    00094   if ( !establishConnection(con) )  {
    00095     return connectDataIO(UNKNOWN,mode,con->name(),doctype,true,con);
    00096   }
    00097   std::string dsn = con ? con->name() : std::string("Unknown");
    00098   return error("Failed to connect to data:"+dsn,false);
    00099 }

StatusCode IODataManager::disconnect | ( | Connection * | ioDesc | ) | `[virtual]`

Release data stream.

Definition at line 116 of file IODataManager.cpp.

    00116                                                        {
    00117   if ( con )  {
    00118     std::string dataset = con->name();
    00119     std::string dsn = dataset;
    00120     StatusCode sc = con->disconnect();
    00121     if ( ::strncasecmp(dsn.c_str(),"FID:",4)==0 )
    00122       dsn = dataset.substr(4);
    00123     else if ( ::strncasecmp(dsn.c_str(),"LFN:",4)==0 )
    00124       dsn = dataset.substr(4);
    00125     else if ( ::strncasecmp(dsn.c_str(),"PFN:",4)==0 )
    00126       dsn = dataset.substr(4);
    00127
    00128     FidMap::iterator j = m_fidMap.find(dataset);
    00129     if ( j != m_fidMap.end() )  {
    00130       std::string fid = (*j).second;
    00131       std::string gfal_name = "gfal:guid:" + fid;
    00132       ConnectionMap::iterator i=m_connectionMap.find(fid);
    00133       m_fidMap.erase(j);
    00134       if ( (j=m_fidMap.find(fid)) != m_fidMap.end() )
    00135         m_fidMap.erase(j);
    00136       if ( (j=m_fidMap.find(gfal_name)) != m_fidMap.end() )
    00137         m_fidMap.erase(j);
    00138       if ( i != m_connectionMap.end() ) {
    00139         if ( (*i).second )  {
    00140           IDataConnection* c = (*i).second->connection;
    00141           std::string pfn = c->pfn();
    00142           if ( (j=m_fidMap.find(pfn)) != m_fidMap.end() )
    00143             m_fidMap.erase(j);
    00144           if ( c->isConnected() )  {
    00145             MsgStream log(msgSvc(),name());
    00146             c->disconnect();
    00147             log << MSG::INFO << "Disconnect from dataset " << dsn
    00148                 << " [" << fid << "]" << endmsg;
    00149           }
    00150           delete (*i).second;
    00151           m_connectionMap.erase(i);
    00152         }
    00153       }
    00154     }
    00155     return sc;
    00156   }
    00157   return S_ERROR;
    00158 }

virtual Connection* Gaudi::IODataManager::connection | ( | const std::string & | dsn | ) | const`[virtual]`

Retrieve known connection.

IODataManager::Connections IODataManager::connections | ( | const IInterface * | owner | ) | const`[virtual]`

Get connection by owner instance (0=ALL).

Definition at line 73 of file IODataManager.cpp.

    00073                                                                                   {
    00074   Connections conns;
    00075   for(ConnectionMap::const_iterator i=m_connectionMap.begin(); i!=m_connectionMap.end();++i) {
    00076     IDataConnection* c = (*i).second->connection;
    00077     if ( 0 == owner || c->owner() == owner )
    00078       conns.push_back(c);
    00079   }
    00080   return conns;
    00081 }

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.

    00102                                                                              {
    00103   return establishConnection(con).isSuccess() ? con->read(data,len) : S_ERROR;
    00104 }

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.

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

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.

    00112                                                                                    {
    00113   return establishConnection(con).isSuccess() ? con->seek(where,origin) : -1;
    00114 }

## Member Data Documentation

std::string Gaudi::IODataManager::m_catalogSvcName`[protected]`

Property: Name of the file catalog service.

Definition at line 45 of file IODataManager.h.

int Gaudi::IODataManager::m_ageLimit`[protected]`

Property: Age limit.

Definition at line 47 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.

bool Gaudi::IODataManager::m_quarantine`[protected]`

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

Definition at line 51 of file IODataManager.h.

ConnectionMap Gaudi::IODataManager::m_connectionMap`[protected]`

Map with I/O descriptors.

Definition at line 54 of file IODataManager.h.

SmartIF<IFileCatalog> Gaudi::IODataManager::m_catalog`[protected]`

Reference to file catalog.

Definition at line 56 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.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r10p1/GaudiUtils/src/component/IODataManager.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v21r10p1/GaudiUtils/src/component/IODataManager.cpp