5 #include "boost/lexical_cast.hpp" 6 #include "boost/tokenizer.hpp" 7 #include "range/v3/algorithm/for_each.hpp" 8 #include "range/v3/view/remove_if.hpp" 9 #include "range/v3/view/reverse.hpp" 10 #include "range/v3/view/transform.hpp" 17 struct AlgorithmRepr {
23 if ( a.parent.name() != typ )
s <<
"/" << a.parent.name();
28 struct DataObjIDSorter {
46 return {sc.
isSuccess() ? dynamic_cast<Gaudi::Algorithm*>( tmp ) : nullptr};
58 ranges::for_each(
m_algorithms | ranges::view::transform( [](
const auto& entry ) {
return entry.alg; } ) |
59 ranges::view::remove_if( [](
const auto*
alg ) {
return alg->cardinality() == 0; } ),
61 this->
warning() <<
"non-reentrant algorithm: " << AlgorithmRepr{*
alg} <<
endmsg;
66 msg <<
"Available DataProducers: ";
69 [](
auto& os,
const AlgEntry& e ) -> decltype(
auto ) {
return os << AlgorithmRepr{*e.
alg}; } );
85 ss = algEntry.alg->sysStart();
87 error() <<
"Unable to start Algorithm: " << algEntry.alg->name() <<
endmsg;
93 ss = algEntry.alg->sysStart();
95 error() <<
"Unable to start Algorithm: " << algEntry.alg->name() <<
endmsg;
108 ss = algEntry.alg->sysStop();
110 error() <<
"Unable to stop Algorithm: " << algEntry.alg->name() <<
endmsg;
116 ss = algEntry.alg->sysStop();
118 error() <<
"Unable to stop Algorithm: " << algEntry.alg->name() <<
endmsg;
138 auto appMgr = service<IAlgManager>(
"ApplicationMgr" );
146 myIAlg = createAlgorithm( *
appMgr, theType, theName );
154 throw GaudiException{
"Failed to create " + boost::lexical_cast<std::string>( item ), __func__,
161 throw GaudiException{
"Failed to initialize " + boost::lexical_cast<std::string>( item ), __func__,
174 debug() <<
"Data Dependencies for Algorithms:";
176 debug() <<
"\n " << entry.alg->name() <<
" :";
177 for (
const auto*
id : sortedDataObjIDColl( entry.alg->inputDataObjs() ) ) {
178 debug() <<
"\n o INPUT " <<
id->key();
180 for (
const auto*
id : sortedDataObjIDColl( entry.alg->outputDataObjs() ) ) {
181 debug() <<
"\n o OUTPUT " <<
id->key();
190 const auto&
output =
alg.alg->outputDataObjs();
191 if (
output.empty() ) {
continue; }
192 for (
auto id :
output ) {
193 if (
id.key().find(
":" ) != std::string::npos ) {
194 error() <<
" in Alg " << AlgorithmRepr{*
alg.alg} <<
" alternatives are NOT allowed for outputs! id: " <<
id 200 throw GaudiException(
"multiple algorithms declare " +
id.key() +
" as output. This is not allowed", __func__,
207 for (
auto& algEntry : algorithms ) {
208 auto input = sortedDataObjIDColl( algEntry.alg->inputDataObjs() );
211 if (
id.key().find(
":" ) != std::string::npos ) {
212 warning() << AlgorithmRepr{*( algEntry.alg )} <<
" contains alternatives which require resolution...\n";
213 auto tokens = boost::tokenizer<boost::char_separator<char>>{
id.key(), boost::char_separator<char>{
":"}};
216 if ( itok != tokens.end() ) {
217 warning() <<
"found matching output for " << *itok <<
" -- updating info\n";
218 id.updateKey( *itok );
219 warning() <<
"Please update input to not require alternatives, and " 220 "instead properly configure the dataloader" 223 error() <<
"failed to find alternate in global output list" 224 <<
" for id: " <<
id <<
" in Alg " << algEntry.alg <<
endmsg;
227 auto iproducer = producers.
find(
id );
228 if ( iproducer != producers.
end() ) {
229 algEntry.
dependsOn.insert( iproducer->second );
232 error_message <<
"\nUnknown requested input by " << AlgorithmRepr{*( algEntry.alg )} <<
" : " <<
id.key()
234 error_message <<
"You can set the OutputLevel of HiveDataBrokerSvc to DEBUG to get a list of inputs and " 235 "outputs of every algorithm.\n";
256 for (
const auto& req : requested ) {
258 if (
id.key().find(
":" ) != std::string::npos ) {
259 warning() << req.key() <<
" contains alternatives which require resolution...\n";
260 auto tokens = boost::tokenizer<boost::char_separator<char>>{
id.key(), boost::char_separator<char>{
":"}};
263 if ( itok != tokens.end() ) {
264 warning() <<
"found matching output for " << *itok <<
" -- updating info\n";
265 id.updateKey( *itok );
266 warning() <<
"Please update input to not require alternatives, and " 267 "instead properly configure the dataloader" 270 error() <<
"failed to find alternate in global output list" 271 <<
" for id: " <<
id <<
endmsg;
281 for (
auto current = deps.
begin(); current != deps.
end(); ++current ) {
283 [current](
auto& stopper ) {
return ( *current )->alg->name() == stopper; } ) ) {
286 for (
auto* entry : ( *current )->dependsOn ) {
309 error() <<
"requested " << requested <<
" but have matching name with different type: " <<
alg->alg->type()
314 assert( av.size() == 1 );
319 assert(
alg->alg !=
nullptr );
321 [&requested](
auto& stopper ) {
return requested.
name() == stopper; } ) ==
std::end( stoppers ) ) {
328 debug(), result,
",\n ",
329 [](
auto& os,
const Gaudi::Algorithm* a ) -> decltype(
auto ) {
return os << AlgorithmRepr{*a}; } );
Definition of the MsgStream class used to transmit messages.
StatusCode initialize() override
Define general base for Gaudi exception.
StatusCode finalize() override
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
StatusCode start() override
::details::reverse_wrapper< T > reverse(T &&iterable)
std::vector< AlgEntry > m_cfnodes
The IAlgManager is the interface implemented by the Algorithm Factory in the Application Manager to s...
virtual StatusCode createAlgorithm(const std::string &algtype, const std::string &algname, IAlgorithm *&alg, bool managed=false, bool checkIfExists=true)=0
Create an instance of a algorithm type that has been declared beforehand and assigns to it a name.
std::map< DataObjID, AlgEntry * > mapProducers(std::vector< AlgEntry > &algorithms) const
const std::string & type() const
StatusCode finalize() override
StatusCode start() override
std::map< DataObjID, AlgEntry * > m_dependencies
std::string fullKey() const
virtual StatusCode sysInitialize()=0
Initialization method invoked by the framework.
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
StatusCode stop() override
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
std::set< AlgEntry * > dependsOn
Helper class to parse a string of format "type/name".
const std::string & name() const
This class is used for returning status codes from appropriate routines.
Gaudi::Property< std::vector< std::string > > m_producers
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
StatusCode stop() override
std::vector< AlgEntry > m_algorithms
The IAlgorithm is the interface implemented by the Algorithm base class.
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
std::vector< Gaudi::Algorithm * > algorithmsRequiredFor(const DataObjIDColl &requested, const std::vector< std::string > &stoppers={}) const override
MsgStream & msg() const
shortcut for the method msgStream(MSG::INFO)
Base class from which all concrete algorithm classes should be derived.
constexpr static const auto FAILURE
std::vector< AlgEntry > instantiateAndInitializeAlgorithms(const std::vector< std::string > &names) const
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
StatusCode initialize() override
AttribStringParser::Iterator begin(const AttribStringParser &parser)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
const std::string & name() const override
The identifying name of the algorithm object.
std::ostream & operator<<(std::ostream &str, const GaudiAlg::ID &id)
Operator overloading for ostream.
T emplace_back(T... args)