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() ) {
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) ) {
89 return connectDataIO(
UNKNOWN,Connection::READ,con->name(),
"UNKNOWN",keep_open,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);
167 case Connection::READ:
170 case Connection::UPDATE:
171 case Connection::CREATE:
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 ) {
262 if ( m_quarantine ) s_badFiles.
insert(dsn);
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);
272 if ( m_quarantine ) s_badFiles.
insert(dsn);
274 if ( m_quarantine ) s_badFiles.
insert(dsn);
276 error(
"connectDataIO> Failed to resolve FID:"+dsn,
false).ignore();
277 return IDataConnection::BAD_DATA_CONNECTION;
280 m_fidMap[dsn] = m_fidMap[dataset] = m_fidMap[pfn] = dsn;
281 sc = connectDataIO(PFN, rw, pfn, technology, keep_open, connection);
283 if ( m_quarantine ) s_badFiles.
insert(pfn);
285 return IDataConnection::BAD_DATA_CONNECTION;
298 if ( j == m_fidMap.end() ) {
302 fid = m_catalog->lookupLFN(dsn);
305 log <<
MSG::ERROR <<
"Failed to resolve LFN:" << dsn
306 <<
" Cannot access this dataset." <<
endmsg;
307 return IDataConnection::BAD_DATA_CONNECTION;
311 fid = m_catalog->lookupPFN(dsn);
312 if ( !fid.empty() ) m_catalog->getPFN(fid, files);
313 if ( files.
empty() ) {
314 if ( rw == Connection::CREATE || rw == Connection::RECREATE ) {
315 if ( fid.empty() ) fid = m_catalog->createFID();
316 m_catalog->registerPFN(fid,dsn,technology);
317 log <<
MSG::INFO <<
"Referring to dataset " << dsn
318 <<
" by its file ID:" << fid <<
endmsg;
333 if ( fi == m_connectionMap.end() ) {
334 connection->setFID(fid);
335 connection->setPFN(dsn);
336 Entry* e =
new Entry(technology, keep_open, rw, connection);
338 if ( !reconnect(e).isSuccess() ) {
340 if ( m_quarantine ) s_badFiles.
insert(dsn);
342 error(
"connectDataIO> Cannot connect to database: PFN="+dsn+
" FID="+fid,
false).ignore();
343 return IDataConnection::BAD_DATA_CONNECTION;
345 fid = connection->fid();
346 m_fidMap[dataset] = m_fidMap[dsn] = m_fidMap[fid] = fid;
347 if ( !(rw==Connection::CREATE || rw==Connection::RECREATE) ) {
348 if ( ! m_disablePFNWarning && strcasecmp(dsn.c_str(),fid.c_str()) == 0 ) {
349 log <<
MSG::ERROR <<
"Referring to existing dataset " << dsn
350 <<
" by its physical name." <<
endmsg;
351 log <<
"You may not be able to navigate back to the input file"
352 <<
" -- processing continues" <<
endmsg;
359 if ( !reconnect((*fi).second).isSuccess() ) {
360 if ( m_quarantine ) s_badFiles.
insert(dsn);
362 error(
"connectDataIO> Cannot connect to database: PFN="+dsn+
" FID="+fid,
false).ignore();
363 return IDataConnection::BAD_DATA_CONNECTION;
367 sc = connectDataIO(FID, rw, fid, technology, keep_open, connection);
371 else if ( typ == LFN ) {
372 m_fidMap[dataset] = fid;
377 error(
std::string(
"connectDataIO> Caught exception:")+e.
what(),
false).ignore();
380 error(
std::string(
"connectDataIO> Caught unknown exception"),
false).ignore();
383 error(
"connectDataIO> The dataset "+dsn+
" cannot be opened.",
false).ignore();
385 return IDataConnection::BAD_DATA_CONNECTION;