26 constexpr
struct select2nd_t {
27 template <
typename S,
typename T>
28 const T& operator()(
const std::pair<S, T>& p )
const {
33 template <
typename InputIterator,
typename OutputIterator,
typename UnaryOperation,
typename UnaryPredicate>
34 OutputIterator transform_copy_if( InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op,
35 UnaryPredicate pred ) {
36 while ( first != last ) {
37 auto val = op( *first );
38 if ( pred( val ) ) *result++ = std::move( val );
45 using namespace Gaudi;
49 static std::set<std::string> s_badFiles;
93 []( ConnectionMap::const_reference i ) {
return i.second->connection; },
103 std::string dsn = con ? con->name() : std::string(
"Unknown" );
104 return error(
"Failed to connect to data:" + dsn,
false );
110 std::string dsn = con ? con->name() : std::string(
"Unknown" );
111 return error(
"Failed to connect to data:" + dsn,
false );
131 std::string dataset = con->name();
132 std::string dsn = dataset;
134 if ( ::strncasecmp( dsn.c_str(),
"FID:", 4 ) == 0 )
135 dsn = dataset.substr( 4 );
136 else if ( ::strncasecmp( dsn.c_str(),
"LFN:", 4 ) == 0 )
137 dsn = dataset.substr( 4 );
138 else if ( ::strncasecmp( dsn.c_str(),
"PFN:", 4 ) == 0 )
139 dsn = dataset.substr( 4 );
143 std::string fid =
j->second;
144 std::string gfal_name =
"gfal:guid:" + fid;
152 if (
c->isConnected() ) {
154 c->disconnect().ignore( );
155 log <<
MSG::INFO <<
"Disconnect from dataset " << dsn <<
" [" << fid <<
"]" <<
endmsg;
173 case Connection::UPDATE:
175 case Connection::RECREATE:
182 std::vector<Entry*> to_retire;
185 select2nd, [&](
Entry* i ) {
189 if ( !to_retire.empty() ) {
193 c->disconnect().ignore( );
194 log <<
MSG::INFO <<
"Disconnect from dataset " <<
c->pfn() <<
" [" <<
c->fid() <<
"]" <<
endmsg;
205 if (
j ==
m_fidMap.end() )
return nullptr;
207 return ( i !=
m_connectionMap.end() ) ? i->second->connection :
nullptr;
211 if ( !con )
return error(
"Severe logic bug: No connection object avalible.",
true );
213 if ( con->isConnected() ) {
219 Connection*
c = i->second->connection;
221 m_incSvc->fireIncident(
Incident( con->name(), IncidentType::FailInputFile ) );
222 return error(
"Severe logic bug: Twice identical connection object for DSN:" + con->name(),
true );
230 Connection* connection ) {
232 std::string dsn = dataset;
235 if ( ::strncasecmp( dsn.c_str(),
"FID:", 4 ) == 0 )
236 dsn = dataset.substr( 4 ), typ = FID;
237 else if ( ::strncasecmp( dsn.c_str(),
"LFN:", 4 ) == 0 )
238 dsn = dataset.substr( 4 ), typ = LFN;
239 else if ( ::strncasecmp( dsn.c_str(),
"PFN:", 4 ) == 0 )
240 dsn = dataset.substr( 4 ), typ = PFN;
244 if ( std::find( s_badFiles.begin(), s_badFiles.end(), dsn ) != s_badFiles.end() ) {
253 if ( files.empty() ) {
257 error(
"connectDataIO> failed to resolve FID:" + dsn,
false ).
ignore();
259 }
else if ( dsn.length() == 36 && dsn[8] ==
'-' && dsn[13] ==
'-' ) {
260 std::string gfal_name =
"gfal:guid:" + dsn;
268 error(
"connectDataIO> Failed to resolve FID:" + dsn,
false ).
ignore();
275 for (
auto i = files.cbegin(); i != files.cend(); ++i ) {
276 std::string pfn = i->first;
277 if ( i != files.cbegin() ) {
278 log <<
MSG::WARNING <<
"Attempt to connect dsn:" << dsn <<
" with next entry in data federation:" << pfn
292 log <<
MSG::ERROR <<
"Failed to open dsn:" << dsn <<
" Federated file could not be resolved from "
293 << files.size() <<
" entries." <<
endmsg;
307 log <<
MSG::ERROR <<
"Failed to resolve LFN:" << dsn <<
" Cannot access this dataset." <<
endmsg;
313 if ( !fid.empty() )
m_catalog->getPFN( fid, files );
314 if ( files.empty() ) {
316 if ( fid.empty() ) fid =
m_catalog->createFID();
317 m_catalog->registerPFN( fid, dsn, technology );
318 log <<
MSG::INFO <<
"Referring to dataset " << dsn <<
" by its file ID:" << fid <<
endmsg;
340 error(
"connectDataIO> Cannot connect to database: PFN=" + dsn +
" FID=" + fid,
false ).
ignore();
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,
false ).
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(),
false ).
ignore();
373 }
catch ( ... ) {
error( std::string(
"connectDataIO> Caught unknown exception" ),
false ).
ignore(); }
375 error(
"connectDataIO> The dataset " + dsn +
" cannot be opened.",
false ).
ignore();
376 s_badFiles.insert( dsn );