13 using namespace Gaudi;
29 "if set to True, we will not report when a file "
30 "is opened by it's physical name");
43 m_catalog = serviceLocator()->service(m_catalogSvcName);
44 if( !m_catalog.isValid() ) {
46 <<
"Unable to localize interface IFileCatalog from service:"
47 << m_catalogSvcName <<
endmsg;
50 m_incSvc = serviceLocator()->service(
"IncidentSvc");
51 if( !m_incSvc.isValid() ) {
76 IODataManager::Connections IODataManager::connections(
const IInterface* owner)
const {
80 if ( 0 == owner || c->
owner() == owner )
87 StatusCode IODataManager::connectRead(
bool keep_open, Connection* con) {
88 if ( !establishConnection(con) ) {
92 return error(
"Failed to connect to data:"+dsn,
false);
96 StatusCode IODataManager::connectWrite(Connection* con,IoType mode,
CSTR doctype) {
97 if ( !establishConnection(con) ) {
98 return connectDataIO(
UNKNOWN,mode,con->name(),doctype,
true,con);
101 return error(
"Failed to connect to data:"+dsn,
false);
105 StatusCode IODataManager::read(Connection* con,
void*
const data,
size_t len) {
106 return establishConnection(con).
isSuccess() ? con->read(data,len) :
S_ERROR;
110 StatusCode IODataManager::write(Connection* con,
const void* data,
int len) {
111 return establishConnection(con).
isSuccess() ? con->write(data,len) :
S_ERROR;
115 long long int IODataManager::seek(Connection* con,
long long int where,
int origin) {
116 return establishConnection(con).isSuccess() ? con->seek(where,origin) : -1;
124 if ( ::strncasecmp(dsn.c_str(),
"FID:",4)==0 )
125 dsn = dataset.substr(4);
126 else if ( ::strncasecmp(dsn.c_str(),
"LFN:",4)==0 )
127 dsn = dataset.substr(4);
128 else if ( ::strncasecmp(dsn.c_str(),
"PFN:",4)==0 )
129 dsn = dataset.substr(4);
132 if ( j != m_fidMap.end() ) {
137 if ( (j=m_fidMap.find(fid)) != m_fidMap.end() )
139 if ( (j=m_fidMap.find(gfal_name)) != m_fidMap.end() )
141 if ( i != m_connectionMap.end() ) {
145 if ( (j=m_fidMap.find(pfn)) != m_fidMap.end() )
150 log <<
MSG::INFO <<
"Disconnect from dataset " << dsn
151 <<
" [" << fid <<
"]" <<
endmsg;
154 m_connectionMap.erase(i);
170 case Connection::UPDATE:
172 case Connection::RECREATE:
185 if ( c->
age() > m_ageLimit ) {
190 if ( !to_retire.
empty() ) {
195 log <<
MSG::INFO <<
"Disconnect from dataset " << c->
pfn()
207 if ( j != m_fidMap.end() ) {
209 return (i != m_connectionMap.end()) ? (*i).second->connection : 0;
214 StatusCode IODataManager::establishConnection(Connection* con) {
216 if ( !con->isConnected() ) {
218 if ( i != m_connectionMap.end() ) {
219 Connection*
c = (*i).second->connection;
222 return error(
"Severe logic bug: Twice identical connection object for DSN:"+con->name(),
true);
224 if ( reconnect((*i).second).isSuccess() ) {
233 return error(
"Severe logic bug: No connection object avalible.",
true);
237 IODataManager::connectDataIO(
int typ, IoType rw,
CSTR dataset,
CSTR technology,
bool keep_open,Connection* connection) {
242 if ( ::strncasecmp(dsn.c_str(),
"FID:",4)==0 )
243 dsn = dataset.substr(4), typ = FID;
244 else if ( ::strncasecmp(dsn.c_str(),
"LFN:",4)==0 )
245 dsn = dataset.substr(4), typ = LFN;
246 else if ( ::strncasecmp(dsn.c_str(),
"PFN:",4)==0 )
247 dsn = dataset.substr(4), typ = PFN;
249 return connectDataIO(PFN, rw, dsn, technology, keep_open, connection);
253 return IDataConnection::BAD_DATA_CONNECTION;
257 if ( fi == m_connectionMap.end() ) {
259 m_catalog->getPFN(dsn,files);
260 if ( files.
size() == 0 ) {
264 error(
"connectDataIO> failed to resolve FID:"+dsn,
false).ignore();
265 return IDataConnection::BAD_DATA_CONNECTION;
267 else if ( dsn.length() == 36 && dsn[8]==
'-' && dsn[13]==
'-' ) {
269 m_fidMap[dsn] = m_fidMap[dataset] = m_fidMap[gfal_name] = dsn;
270 sc = connectDataIO(PFN, rw, gfal_name, technology, keep_open, connection);
276 error(
"connectDataIO> Failed to resolve FID:"+dsn,
false).ignore();
277 return IDataConnection::BAD_DATA_CONNECTION;
279 for(IFileCatalog::Files::const_iterator
i=files.
begin();
i!=files.
end(); ++
i) {
281 if (
i != files.
begin() ) {
283 <<
" with next entry in data federation:" << pfn <<
"." <<
endmsg;
285 sc = connectDataIO(PFN, rw, pfn, technology, keep_open, connection);
291 m_fidMap[dsn] = m_fidMap[dataset] = m_fidMap[pfn] = dsn;
295 log <<
MSG::ERROR <<
"Failed to open dsn:" << dsn
296 <<
" Federated file could not be resolved from "
298 return IDataConnection::BAD_DATA_CONNECTION;
304 if ( j == m_fidMap.end() ) {
308 fid = m_catalog->lookupLFN(dsn);
311 log <<
MSG::ERROR <<
"Failed to resolve LFN:" << dsn
312 <<
" Cannot access this dataset." <<
endmsg;
313 return IDataConnection::BAD_DATA_CONNECTION;
317 fid = m_catalog->lookupPFN(dsn);
318 if ( !fid.empty() ) m_catalog->getPFN(fid, files);
319 if ( files.
empty() ) {
321 if ( fid.empty() ) fid = m_catalog->createFID();
322 m_catalog->registerPFN(fid,dsn,technology);
323 log <<
MSG::INFO <<
"Referring to dataset " << dsn
324 <<
" by its file ID:" << fid <<
endmsg;
339 if ( fi == m_connectionMap.end() ) {
340 connection->setFID(fid);
341 connection->setPFN(dsn);
342 Entry* e =
new Entry(technology, keep_open, rw, connection);
344 if ( !reconnect(e).isSuccess() ) {
348 error(
"connectDataIO> Cannot connect to database: PFN="+dsn+
" FID="+fid,
false).ignore();
349 return IDataConnection::BAD_DATA_CONNECTION;
351 fid = connection->fid();
352 m_fidMap[dataset] = m_fidMap[dsn] = m_fidMap[fid] = fid;
354 if ( ! m_disablePFNWarning && strcasecmp(dsn.c_str(),fid.c_str()) == 0 ) {
355 log <<
MSG::ERROR <<
"Referring to existing dataset " << dsn
356 <<
" by its physical name." <<
endmsg;
357 log <<
"You may not be able to navigate back to the input file"
358 <<
" -- processing continues" <<
endmsg;
365 if ( !reconnect((*fi).second).isSuccess() ) {
368 error(
"connectDataIO> Cannot connect to database: PFN="+dsn+
" FID="+fid,
false).ignore();
369 return IDataConnection::BAD_DATA_CONNECTION;
373 sc = connectDataIO(FID, rw, fid, technology, keep_open, connection);
377 else if ( typ == LFN ) {
378 m_fidMap[dataset] = fid;
383 error(
std::string(
"connectDataIO> Caught exception:")+e.
what(),
false).ignore();
386 error(
std::string(
"connectDataIO> Caught unknown exception"),
false).ignore();
389 error(
"connectDataIO> The dataset "+dsn+
" cannot be opened.",
false).ignore();
391 return IDataConnection::BAD_DATA_CONNECTION;