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 );
44 using namespace Gaudi;
48 static std::set<std::string> s_badFiles;
91 []( ConnectionMap::const_reference i ) {
return i.second->connection; },
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;
171 case Connection::UPDATE:
173 case Connection::RECREATE:
180 std::vector<Entry*> to_retire;
183 select2nd, [&](
Entry* i ) {
187 if ( !to_retire.empty() ) {
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() );
228 Connection* connection ) {
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() ) {
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();
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 );