25 template <
typename InputIterator,
typename OutputIterator,
typename UnaryOperation,
typename UnaryPredicate>
26 OutputIterator transform_copy_if( InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op,
27 UnaryPredicate pred ) {
28 while ( first != last ) {
29 auto val = op( *first );
30 if ( pred( val ) ) *result++ = std::move( val );
41static std::set<std::string> s_badFiles;
84 []( ConnectionMap::const_reference i ) {
return i.second->connection; },
85 [&](
const IDataConnection* c ) {
return !owner || c->owner() == owner; } );
92 return connectDataIO( UNKNOWN, Connection::READ, con->name(),
"UNKNOWN", keep_open, con );
94 std::string dsn = con ? con->name() : std::string(
"Unknown" );
95 return error(
"Failed to connect to data:" + dsn );
101 std::string dsn = con ? con->name() : std::string(
"Unknown" );
102 return error(
"Failed to connect to data:" + dsn );
122 std::string dataset = con->name();
123 std::string dsn = dataset;
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 );
134 std::string fid = j->second;
135 std::string gfal_name =
"gfal:guid:" + fid;
143 if ( c->isConnected() ) {
145 c->disconnect().ignore( );
146 log <<
MSG::INFO <<
"Disconnect from dataset " << dsn <<
" [" << fid <<
"]" <<
endmsg;
160 case Connection::READ:
163 case Connection::UPDATE:
164 case Connection::CREATE:
165 case Connection::RECREATE:
172 std::vector<Entry*> to_retire;
176 []( ConnectionMap::const_reference i ) {
return i.second.get(); },
181 if ( !to_retire.empty() ) {
183 std::for_each( std::begin( to_retire ), std::end( to_retire ), [&](
Entry* j ) {
185 c->disconnect().ignore( );
186 log <<
MSG::INFO <<
"Disconnect from dataset " << c->pfn() <<
" [" << c->fid() <<
"]" <<
endmsg;
197 if ( j ==
m_fidMap.end() )
return nullptr;
199 return ( i !=
m_connectionMap.end() ) ? i->second->connection :
nullptr;
203 if ( !con )
return error(
"Severe logic bug: No connection object avalible." );
205 if ( con->isConnected() ) {
211 Connection* c = i->second->connection;
213 m_incSvc->fireIncident(
Incident( con->name(), IncidentType::FailInputFile ) );
214 return error(
"Severe logic bug: Twice identical connection object for DSN:" + con->name() );
224 std::string dsn = dataset;
227 if ( ::strncasecmp( dsn.c_str(),
"FID:", 4 ) == 0 )
228 dsn = dataset.substr( 4 ), typ = FID;
229 else if ( ::strncasecmp( dsn.c_str(),
"LFN:", 4 ) == 0 )
230 dsn = dataset.substr( 4 ), typ = LFN;
231 else if ( ::strncasecmp( dsn.c_str(),
"PFN:", 4 ) == 0 )
232 dsn = dataset.substr( 4 ), typ = PFN;
233 else if ( typ == UNKNOWN )
236 if ( std::find( s_badFiles.begin(), s_badFiles.end(), dsn ) != s_badFiles.end() ) {
245 if ( files.empty() ) {
249 error(
"connectDataIO> failed to resolve FID:" + dsn ).ignore();
251 }
else if ( dsn.length() == 36 && dsn[8] ==
'-' && dsn[13] ==
'-' ) {
252 std::string gfal_name =
"gfal:guid:" + dsn;
260 error(
"connectDataIO> Failed to resolve FID:" + dsn ).ignore();
267 for (
auto i = files.cbegin(); i != files.cend(); ++i ) {
268 std::string pfn = i->first;
269 if ( i != files.cbegin() ) {
270 log <<
MSG::WARNING <<
"Attempt to connect dsn:" << dsn <<
" with next entry in data federation:" << pfn
284 log <<
MSG::ERROR <<
"Failed to open dsn:" << dsn <<
" Federated file could not be resolved from "
285 << files.size() <<
" entries." <<
endmsg;
299 log <<
MSG::ERROR <<
"Failed to resolve LFN:" << dsn <<
" Cannot access this dataset." <<
endmsg;
305 if ( !fid.empty() )
m_catalog->getPFN( fid, files );
306 if ( files.empty() ) {
307 if ( rw == Connection::CREATE || rw == Connection::RECREATE ) {
308 if ( fid.empty() ) fid =
m_catalog->createFID();
309 m_catalog->registerPFN( fid, dsn, technology );
310 log <<
MSG::INFO <<
"Referring to dataset " << dsn <<
" by its file ID:" << fid <<
endmsg;
326 auto e = std::make_unique<Entry>( technology, keep_open, rw,
connection );
331 error(
"connectDataIO> Cannot connect to database: PFN=" + dsn +
" FID=" + fid ).ignore();
340 log <<
MSG::DEBUG <<
"Dataset " << dsn <<
" has the same FID " << fid
341 <<
" as an already connected dataset, tracking it by its PFN" <<
endmsg;
345 if ( !( rw == Connection::CREATE || rw == Connection::RECREATE ) ) {
347 log <<
MSG::ERROR <<
"Referring to existing dataset " << dsn <<
" by its physical name." <<
endmsg;
348 log <<
"You may not be able to navigate back to the input file"
349 <<
" -- processing continues" <<
endmsg;
359 error(
"connectDataIO> Cannot connect to database: PFN=" + dsn +
" FID=" + fid ).ignore();
366 s_badFiles.insert( fid );
367 }
else if ( typ == LFN ) {
371 }
catch ( std::exception& e ) {
372 error( std::string(
"connectDataIO> Caught exception:" ) + e.what() ).ignore();
373 }
catch ( ... ) {
error( std::string(
"connectDataIO> Caught unknown exception" ) ).ignore(); }
375 error(
"connectDataIO> The dataset " + dsn +
" cannot be opened." ).ignore();
376 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.
void 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