25 constexpr struct select2nd_t {
26 template <
typename S,
typename T>
27 const T& operator()(
const std::pair<S, T>& p )
const {
32 template <
typename InputIterator,
typename OutputIterator,
typename UnaryOperation,
typename UnaryPredicate>
33 OutputIterator transform_copy_if( InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op,
34 UnaryPredicate pred ) {
35 while ( first != last ) {
36 auto val = op( *first );
37 if ( pred( val ) ) *result++ = std::move( val );
48static std::set<std::string> s_badFiles;
91 []( ConnectionMap::const_reference i ) {
return i.second->connection; },
92 [&](
const IDataConnection* c ) {
return !owner || c->owner() == owner; } );
99 return connectDataIO( UNKNOWN, Connection::READ, con->name(),
"UNKNOWN", keep_open, con );
101 std::string dsn = con ? con->name() : std::string(
"Unknown" );
102 return error(
"Failed to connect to data:" + dsn );
108 std::string dsn = con ? con->name() : std::string(
"Unknown" );
109 return error(
"Failed to connect to data:" + dsn );
129 std::string dataset = con->name();
130 std::string dsn = dataset;
132 if ( ::strncasecmp( dsn.c_str(),
"FID:", 4 ) == 0 )
133 dsn = dataset.substr( 4 );
134 else if ( ::strncasecmp( dsn.c_str(),
"LFN:", 4 ) == 0 )
135 dsn = dataset.substr( 4 );
136 else if ( ::strncasecmp( dsn.c_str(),
"PFN:", 4 ) == 0 )
137 dsn = dataset.substr( 4 );
141 std::string fid = j->second;
142 std::string gfal_name =
"gfal:guid:" + fid;
150 if ( c->isConnected() ) {
152 c->disconnect().ignore( );
153 log <<
MSG::INFO <<
"Disconnect from dataset " << dsn <<
" [" << fid <<
"]" <<
endmsg;
168 case Connection::READ:
171 case Connection::UPDATE:
172 case Connection::CREATE:
173 case Connection::RECREATE:
180 std::vector<Entry*> to_retire;
183 select2nd, [&](
Entry* i ) {
187 if ( !to_retire.empty() ) {
189 std::for_each( std::begin( to_retire ), std::end( to_retire ), [&](
Entry* j ) {
191 c->disconnect().ignore( );
192 log <<
MSG::INFO <<
"Disconnect from dataset " << c->pfn() <<
" [" << c->fid() <<
"]" <<
endmsg;
203 if ( j ==
m_fidMap.end() )
return nullptr;
205 return ( i !=
m_connectionMap.end() ) ? i->second->connection :
nullptr;
209 if ( !con )
return error(
"Severe logic bug: No connection object avalible." );
211 if ( con->isConnected() ) {
217 Connection* c = i->second->connection;
219 m_incSvc->fireIncident(
Incident( con->name(), IncidentType::FailInputFile ) );
220 return error(
"Severe logic bug: Twice identical connection object for DSN:" + con->name() );
230 std::string dsn = dataset;
233 if ( ::strncasecmp( dsn.c_str(),
"FID:", 4 ) == 0 )
234 dsn = dataset.substr( 4 ), typ = FID;
235 else if ( ::strncasecmp( dsn.c_str(),
"LFN:", 4 ) == 0 )
236 dsn = dataset.substr( 4 ), typ = LFN;
237 else if ( ::strncasecmp( dsn.c_str(),
"PFN:", 4 ) == 0 )
238 dsn = dataset.substr( 4 ), typ = PFN;
239 else if ( typ == UNKNOWN )
242 if ( std::find( s_badFiles.begin(), s_badFiles.end(), dsn ) != s_badFiles.end() ) {
251 if ( files.empty() ) {
255 error(
"connectDataIO> failed to resolve FID:" + dsn ).ignore();
257 }
else if ( dsn.length() == 36 && dsn[8] ==
'-' && dsn[13] ==
'-' ) {
258 std::string gfal_name =
"gfal:guid:" + dsn;
266 error(
"connectDataIO> Failed to resolve FID:" + dsn ).ignore();
273 for (
auto i = files.cbegin(); i != files.cend(); ++i ) {
274 std::string pfn = i->first;
275 if ( i != files.cbegin() ) {
276 log <<
MSG::WARNING <<
"Attempt to connect dsn:" << dsn <<
" with next entry in data federation:" << pfn
290 log <<
MSG::ERROR <<
"Failed to open dsn:" << dsn <<
" Federated file could not be resolved from "
291 << files.size() <<
" entries." <<
endmsg;
305 log <<
MSG::ERROR <<
"Failed to resolve LFN:" << dsn <<
" Cannot access this dataset." <<
endmsg;
311 if ( !fid.empty() )
m_catalog->getPFN( fid, files );
312 if ( files.empty() ) {
313 if ( rw == Connection::CREATE || rw == Connection::RECREATE ) {
314 if ( fid.empty() ) fid =
m_catalog->createFID();
315 m_catalog->registerPFN( fid, dsn, technology );
316 log <<
MSG::INFO <<
"Referring to dataset " << dsn <<
" by its file ID:" << fid <<
endmsg;
338 error(
"connectDataIO> Cannot connect to database: PFN=" + dsn +
" FID=" + fid ).ignore();
343 if ( !( rw == Connection::CREATE || rw == Connection::RECREATE ) ) {
345 log <<
MSG::ERROR <<
"Referring to existing dataset " << dsn <<
" by its physical name." <<
endmsg;
346 log <<
"You may not be able to navigate back to the input file"
347 <<
" -- processing continues" <<
endmsg;
357 error(
"connectDataIO> Cannot connect to database: PFN=" + dsn +
" FID=" + fid ).ignore();
364 s_badFiles.insert( fid );
365 }
else if ( typ == LFN ) {
369 }
catch ( std::exception& e ) {
370 error( std::string(
"connectDataIO> Caught exception:" ) + e.what() ).ignore();
371 }
catch ( ... ) {
error( std::string(
"connectDataIO> Caught unknown exception" ) ).ignore(); }
373 error(
"connectDataIO> The dataset " + dsn +
" cannot be opened." ).ignore();
374 s_badFiles.insert( dsn );
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
ABC describing basic data connection.
void resetAge()
Reset age.
virtual StatusCode connectRead()=0
Open data stream in read mode.
virtual StatusCode connectWrite(IoType type)=0
Open data stream in write mode.
std::vector< NamedItem > Files
IDataConnection Connection
Connection type definition.
ConnectionMap m_connectionMap
Map with I/O descriptors.
StatusCode connectRead(bool keep_open, Connection *ioDesc) override
Open data stream in read mode.
FidMap m_fidMap
Map of FID to PFN.
Gaudi::Property< bool > m_quarantine
StatusCode write(Connection *con, const void *data, int len) override
Write raw byte buffer to output stream.
long long int seek(Connection *ioDesc, long long int where, int origin) override
Seek on the file described by ioDesc. Arguments as in seek()
StatusCode finalize() override
IService implementation: finalize the service.
StatusCode read(Connection *ioDesc, void *const data, size_t len) override
Read raw byte buffer from input stream.
SmartIF< IFileCatalog > m_catalog
Reference to file catalog.
StatusCode disconnect(Connection *ioDesc) override
Release data stream.
Gaudi::Property< std::string > m_catalogSvcName
StatusCode establishConnection(Connection *con)
StatusCode connectWrite(Connection *con, IoType mode=Connection::CREATE, CSTR doctype="UNKNOWN") override
Open data stream in write mode.
Gaudi::Property< bool > m_useGFAL
Connection * connection(const std::string &dsn) const override
Retrieve known connection.
StatusCode reconnect(Entry *e)
Gaudi::Property< bool > m_disablePFNWarning
Gaudi::Property< int > m_ageLimit
StatusCode initialize() override
IService implementation: initialize the service.
Connections connections(const IInterface *owner) const override
Get connection by owner instance (0=ALL)
SmartIF< IIncidentSvc > m_incSvc
StatusCode connectDataIO(int typ, IoType rw, CSTR fn, CSTR technology, bool keep, Connection *con)
Definition of the basic interface.
The IProperty is the basic interface for all components which have properties that can be set or get.
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
Base class for all Incidents (computing events).
Definition of the MsgStream class used to transmit messages.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
StatusCode finalize() override
const std::string & name() const override
Retrieve name of the service.
StatusCode initialize() override
This class is used for returning status codes from appropriate routines.
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
constexpr static const auto SUCCESS
constexpr static const auto FAILURE
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
int getAppReturnCode(const SmartIF< IProperty > &appmgr)
Get the application (current) return code.
StatusCode setAppReturnCode(SmartIF< IProperty > &appmgr, int value, bool force=false)
Set the application return code.
IDataConnection * connection