16 using namespace
Gaudi;
30 "if set to True, we will not report when a file "
31 "is opened by it's physical name");
44 m_catalog = serviceLocator()->service(m_catalogSvcName);
45 if( !m_catalog.isValid() ) {
47 <<
"Unable to localize interface IFileCatalog from service:"
48 << m_catalogSvcName <<
endmsg;
51 m_incSvc = serviceLocator()->service(
"IncidentSvc");
52 if( !m_incSvc.isValid() ) {
77 IODataManager::Connections IODataManager::connections(
const IInterface* owner)
const {
81 if ( 0 == owner || c->
owner() == owner )
88 StatusCode IODataManager::connectRead(
bool keep_open, Connection* con) {
89 if ( !establishConnection(con) ) {
93 return error(
"Failed to connect to data:"+dsn,
false);
97 StatusCode IODataManager::connectWrite(Connection* con,IoType mode,
CSTR doctype) {
98 if ( !establishConnection(con) ) {
99 return connectDataIO(
UNKNOWN,mode,con->name(),doctype,
true,con);
102 return error(
"Failed to connect to data:"+dsn,
false);
106 StatusCode IODataManager::read(Connection* con,
void*
const data,
size_t len) {
107 return establishConnection(con).
isSuccess() ? con->read(data,len) :
S_ERROR;
111 StatusCode IODataManager::write(Connection* con,
const void* data,
int len) {
112 return establishConnection(con).
isSuccess() ? con->write(data,len) :
S_ERROR;
116 long long int IODataManager::seek(Connection* con,
long long int where,
int origin) {
117 return establishConnection(con).isSuccess() ? con->seek(where,origin) : -1;
125 if ( ::strncasecmp(dsn.c_str(),
"FID:",4)==0 )
126 dsn = dataset.substr(4);
127 else if ( ::strncasecmp(dsn.c_str(),
"LFN:",4)==0 )
128 dsn = dataset.substr(4);
129 else if ( ::strncasecmp(dsn.c_str(),
"PFN:",4)==0 )
130 dsn = dataset.substr(4);
133 if ( j != m_fidMap.end() ) {
138 if ( (j=m_fidMap.find(fid)) != m_fidMap.end() )
140 if ( (j=m_fidMap.find(gfal_name)) != m_fidMap.end() )
142 if ( i != m_connectionMap.end() ) {
146 if ( (j=m_fidMap.find(pfn)) != m_fidMap.end() )
151 log <<
MSG::INFO <<
"Disconnect from dataset " << dsn
152 <<
" [" << fid <<
"]" <<
endmsg;
155 m_connectionMap.erase(i);
171 case Connection::UPDATE:
173 case Connection::RECREATE:
186 if ( c->
age() > m_ageLimit ) {
191 if ( !to_retire.
empty() ) {
196 log <<
MSG::INFO <<
"Disconnect from dataset " << c->
pfn()
208 if ( j != m_fidMap.end() ) {
210 return (i != m_connectionMap.end()) ? (*i).second->connection : 0;
215 StatusCode IODataManager::establishConnection(Connection* con) {
217 if ( !con->isConnected() ) {
219 if ( i != m_connectionMap.end() ) {
220 Connection*
c = (*i).second->connection;
223 return error(
"Severe logic bug: Twice identical connection object for DSN:"+con->name(),
true);
225 if ( reconnect((*i).second).isSuccess() ) {
234 return error(
"Severe logic bug: No connection object avalible.",
true);
238 IODataManager::connectDataIO(
int typ, IoType rw,
CSTR dataset,
CSTR technology,
bool keep_open,Connection* connection) {
243 if ( ::strncasecmp(dsn.c_str(),
"FID:",4)==0 )
244 dsn = dataset.substr(4), typ = FID;
245 else if ( ::strncasecmp(dsn.c_str(),
"LFN:",4)==0 )
246 dsn = dataset.substr(4), typ = LFN;
247 else if ( ::strncasecmp(dsn.c_str(),
"PFN:",4)==0 )
248 dsn = dataset.substr(4), typ = PFN;
250 return connectDataIO(PFN, rw, dsn, technology, keep_open, connection);
254 return IDataConnection::BAD_DATA_CONNECTION;
258 if ( fi == m_connectionMap.end() ) {
260 m_catalog->getPFN(dsn,files);
261 if ( files.
size() == 0 ) {
263 if ( m_quarantine ) s_badFiles.
insert(dsn);
265 error(
"connectDataIO> failed to resolve FID:"+dsn,
false).ignore();
266 return IDataConnection::BAD_DATA_CONNECTION;
268 else if ( dsn.length() == 36 && dsn[8]==
'-' && dsn[13]==
'-' ) {
270 m_fidMap[dsn] = m_fidMap[dataset] = m_fidMap[gfal_name] = dsn;
271 sc = connectDataIO(PFN, rw, gfal_name, technology, keep_open, connection);
273 if ( m_quarantine ) s_badFiles.
insert(dsn);
275 if ( m_quarantine ) s_badFiles.
insert(dsn);
277 error(
"connectDataIO> Failed to resolve FID:"+dsn,
false).ignore();
278 return IDataConnection::BAD_DATA_CONNECTION;
280 for(IFileCatalog::Files::const_iterator
i=files.
begin();
i!=files.
end(); ++
i) {
282 if (
i != files.
begin() ) {
284 <<
" with next entry in data federation:" << pfn <<
"." <<
endmsg;
286 sc = connectDataIO(PFN, rw, pfn, technology, keep_open, connection);
288 if ( m_quarantine ) s_badFiles.
insert(pfn);
292 m_fidMap[dsn] = m_fidMap[dataset] = m_fidMap[pfn] = dsn;
296 log <<
MSG::ERROR <<
"Failed to open dsn:" << dsn
297 <<
" Federated file could not be resolved from "
299 return IDataConnection::BAD_DATA_CONNECTION;
305 if ( j == m_fidMap.end() ) {
309 fid = m_catalog->lookupLFN(dsn);
312 log <<
MSG::ERROR <<
"Failed to resolve LFN:" << dsn
313 <<
" Cannot access this dataset." <<
endmsg;
314 return IDataConnection::BAD_DATA_CONNECTION;
318 fid = m_catalog->lookupPFN(dsn);
319 if ( !fid.empty() ) m_catalog->getPFN(fid, files);
320 if ( files.
empty() ) {
322 if ( fid.empty() ) fid = m_catalog->createFID();
323 m_catalog->registerPFN(fid,dsn,technology);
324 log <<
MSG::INFO <<
"Referring to dataset " << dsn
325 <<
" by its file ID:" << fid <<
endmsg;
340 if ( fi == m_connectionMap.end() ) {
341 connection->setFID(fid);
342 connection->setPFN(dsn);
343 Entry* e =
new Entry(technology, keep_open, rw, connection);
345 if ( !reconnect(e).isSuccess() ) {
347 if ( m_quarantine ) s_badFiles.
insert(dsn);
349 error(
"connectDataIO> Cannot connect to database: PFN="+dsn+
" FID="+fid,
false).ignore();
350 return IDataConnection::BAD_DATA_CONNECTION;
352 fid = connection->fid();
353 m_fidMap[dataset] = m_fidMap[dsn] = m_fidMap[fid] = fid;
355 if ( ! m_disablePFNWarning && strcasecmp(dsn.c_str(),fid.c_str()) == 0 ) {
356 log <<
MSG::ERROR <<
"Referring to existing dataset " << dsn
357 <<
" by its physical name." <<
endmsg;
358 log <<
"You may not be able to navigate back to the input file"
359 <<
" -- processing continues" <<
endmsg;
366 if ( !reconnect((*fi).second).isSuccess() ) {
367 if ( m_quarantine ) s_badFiles.
insert(dsn);
369 error(
"connectDataIO> Cannot connect to database: PFN="+dsn+
" FID="+fid,
false).ignore();
370 return IDataConnection::BAD_DATA_CONNECTION;
374 sc = connectDataIO(FID, rw, fid, technology, keep_open, connection);
378 else if ( typ == LFN ) {
379 m_fidMap[dataset] = fid;
384 error(
std::string(
"connectDataIO> Caught exception:")+e.
what(),
false).ignore();
387 error(
std::string(
"connectDataIO> Caught unknown exception"),
false).ignore();
390 error(
"connectDataIO> The dataset "+dsn+
" cannot be opened.",
false).ignore();
392 return IDataConnection::BAD_DATA_CONNECTION;