15 #include "boost/lexical_cast.hpp" 
   16 #include "boost/tokenizer.hpp" 
   20 #ifdef __cpp_lib_ranges 
   22 namespace ranges = std::ranges;
 
   24 #  include "range/v3/algorithm/for_each.hpp" 
   25 #  include "range/v3/view/filter.hpp" 
   26 #  include "range/v3/view/reverse.hpp" 
   27 #  include "range/v3/view/transform.hpp" 
   29 #  if RANGE_V3_VERSION < 900 
   31   using namespace ranges::view;
 
   39   struct AlgorithmRepr {
 
   45       if ( a.parent.name() != typ ) 
s << 
"/" << a.parent.name();
 
   50   struct DataObjIDSorter {
 
   58     v.reserve( coll.
size() );
 
   59     for ( 
const DataObjID& 
id : coll ) 
v.push_back( &
id );
 
   75     m_algorithms = instantiateAndInitializeAlgorithms( m_producers );
 
   78     ranges::for_each( m_algorithms | ranges::views::transform( []( 
const auto& entry ) { 
return entry.second.alg; } ) |
 
   79                           ranges::views::filter( []( 
const auto* 
alg ) { 
return alg->cardinality() > 0; } ),
 
   81                         this->warning() << 
"non-reentrant algorithm: " << AlgorithmRepr{ *
alg } << 
endmsg;
 
   86       msg << 
"Available DataProducers: ";
 
   89             return os << AlgorithmRepr{ *e.second.alg };
 
   95     m_dependencies = mapProducers( m_algorithms );
 
  105   for ( 
auto& [
name, algEntry] : m_algorithms ) {
 
  106     ss = algEntry.alg->sysStart();
 
  108       error() << 
"Unable to start Algorithm: " << 
name << 
endmsg;
 
  120   for ( 
auto& [
name, algEntry] : m_algorithms ) {
 
  121     ss = algEntry.alg->sysStop();
 
  123       error() << 
"Unable to stop Algorithm: " << 
name << 
endmsg;
 
  131   for ( 
auto& [
name, algEntry] : m_algorithms ) {
 
  132     algEntry.alg->sysFinalize().
ignore(  );
 
  134   m_algorithms.clear();
 
  143   auto   appMgr = service<IAlgManager>( 
"ApplicationMgr" );
 
  152       myIAlg = createAlgorithm( *
appMgr, theType, theName );
 
  160       throw GaudiException{ 
"Failed to create " + boost::lexical_cast<std::string>( item ), __func__,
 
  167       throw GaudiException{ 
"Failed to initialize " + boost::lexical_cast<std::string>( item ), __func__,
 
  180     debug() << 
"Data Dependencies for Algorithms:";
 
  181     for ( 
const auto& [
name, entry] : m_algorithms ) {
 
  182       debug() << 
"\n " << 
name << 
" :";
 
  183       for ( 
const auto* 
id : sortedDataObjIDColl( entry.alg->inputDataObjs() ) ) {
 
  184         debug() << 
"\n    o INPUT  " << 
id->key();
 
  186       for ( 
const auto* 
id : sortedDataObjIDColl( entry.alg->outputDataObjs() ) ) {
 
  187         debug() << 
"\n    o OUTPUT " << 
id->key();
 
  196     const auto& 
output = 
alg.alg->outputDataObjs();
 
  197     if ( 
output.empty() ) { 
continue; }
 
  198     for ( 
auto id : 
output ) {
 
  202                                   producers[
id]->
alg->name() + 
" at least). This is not allowed",
 
  210     auto input = sortedDataObjIDColl( algEntry.alg->inputDataObjs() );
 
  213       auto      iproducer = producers.
find( 
id );
 
  214       if ( iproducer != producers.
end() ) {
 
  215         algEntry.dependsOn.insert( iproducer->second );
 
  218         error_message << 
"\nUnknown requested input by " << AlgorithmRepr{ *( algEntry.alg ) } << 
" : " 
  219                       << std::quoted( 
id.
key(), 
'\'' ) << 
".\n";
 
  220         error_message << 
"You can set the OutputLevel of HiveDataBrokerSvc to DEBUG to get a list of inputs and " 
  221                          "outputs of every registered algorithm.\n";
 
  237   assert( visited.
size() == m_algorithms.size() );
 
  238   assert( visiting.
size() == m_algorithms.size() );
 
  239   if ( visited[
alg.index] ) { 
return; }
 
  243                      [
alg]( 
auto& stopper ) { 
return alg.alg->name() == stopper; } ) ) {
 
  244     visiting[
alg.index] = 
true;
 
  245     for ( 
auto* dep : 
alg.dependsOn ) { visit( *dep, stoppers, sorted, visited, visiting ); }
 
  246     visiting[
alg.index] = 
false;
 
  249   visited[
alg.index] = 
true;
 
  262   for ( 
const auto& req : requested ) {
 
  264     auto      i  = m_dependencies.find( 
id );
 
  265     if ( i == m_dependencies.end() )
 
  275   for ( 
auto* 
alg : deps ) { visit( *
alg, stoppers, result, visited, visiting ); }
 
  284   auto it = m_algorithms.find( requested.
name() );
 
  285   if ( it == 
end( m_algorithms ) ) {
 
  286     throw GaudiException{ 
"No algorithm with name " + requested.
name() + 
" in DataProducers. Type is " +
 
  287                               ( requested.
haveType() ? requested.
type() : 
"not specified" ),
 
  290   auto const& 
alg = it->second;
 
  292     error() << 
"requested " << requested << 
" but have matching name with different type: " << 
alg.alg->type()
 
  295   assert( 
alg.alg != 
nullptr );
 
  299   visit( 
alg, stoppers, result, visited, visiting );
 
  302     debug() << 
std::endl << 
"requested " << requested << 
" returning " << 
std::endl << 
"  ";
 
  304         debug(), result, 
",\n  ",
 
  305         []( 
auto& os, 
const Gaudi::Algorithm* a ) -> decltype( 
auto ) { 
return os << AlgorithmRepr{ *a }; } );