6 #include "GaudiKernel/AlgTool.h"
7 #include "GaudiKernel/IClassIDSvc.h"
15 void insertHandles(
DataObjIDPtrColl &handle_set,
const std::vector<Gaudi::DataHandle*> &new_handles) {
16 for(
const Gaudi::DataHandle*handle : new_handles) {
17 handle_set.insert( &handle->fullKey() );
27 std::stringstream
error;
29 out <<
MSG::FATAL <<
"Logic erroor. Already added some extra output data IDs. This method can only be called once." <<
endmsg;
30 return StatusCode::FAILURE;
33 for(
const std::string &type_and_name : undeclared_output_data) {
34 std::string::size_type
pos = type_and_name.find(
'/');
35 if (
pos == std::string::npos) {
36 error <<
" " << type_and_name;
39 std::string_view type_name(type_and_name.data(),
pos);
40 std::string_view
var_name(&(type_and_name.data()[
pos+1]), type_and_name.size()-
pos-1);
42 if (clid_svc.getIDOfTypeName(std::string(type_name), clid).isFailure() ) {
45 error <<
" no clid: " << type_name;
55 if (!
error.str().empty()) {
57 return StatusCode::FAILURE;
62 return StatusCode::SUCCESS;
67 auto algorithm_visitor =
68 [
this](Gaudi::Algorithm *an_alg) {
70 if (a_dyn_data_consumer) {
71 std::vector<Gaudi::Algorithm *> &alg_list =
m_dynDataConsumer[a_dyn_data_consumer];
72 if (
std::find(alg_list.begin(),alg_list.end(),an_alg)==alg_list.end()) {
73 alg_list.push_back(an_alg);
80 =
const_cast< std::vector<IAlgTool *> &
>(
const_cast<const Gaudi::Algorithm *
>(an_alg)->
tools());
82 auto tool_visitor = [
this, an_alg](IAlgTool *alg_tool) {
84 if (a_dyn_data_consumer) {
85 std::vector<Gaudi::Algorithm *> &alg_list =
m_dynDataConsumer[a_dyn_data_consumer];
86 if (
std::find(alg_list.begin(),alg_list.end(),an_alg)==alg_list.end()) {
87 alg_list.push_back(an_alg);
90 if (
auto* tool_impl =
dynamic_cast<AlgTool*
>( alg_tool ); tool_impl) {
95 xGaudi::ToolVisitor::visit(
tools,tool_visitor);
97 xGaudi::AlgorithmVisitor::visit({theAlgorithm},algorithm_visitor);
103 std::vector<const DataObjID *> all_input_data;
104 std::vector<const DataObjID *> all_output_data;
108 std::vector<const DataObjID *> new_input_data;
109 std::vector<const DataObjID *> new_output_data;
110 unsigned int pass_i=max_pass;
111 unsigned last_out_size=new_output_data.size();
112 for (; --pass_i>0 &&
updateDataNeeds(all_input_data, all_output_data, new_input_data, new_output_data,
out); ) {
113 if (last_out_size == new_output_data.size() )
break;
114 last_out_size=new_output_data.size();
116 if (last_out_size != new_output_data.size()) {
117 out << MSG::WARNING <<
"Not iterating any further, although after " << max_pass <<
" iterations there are still algorithms which updated their data needs. " <<
endmsg;
122 const std::vector<const DataObjID *> &output_data_in,
123 std::vector<const DataObjID *> &input_data_out,
124 std::vector<const DataObjID *> &output_data_out,
129 for (
const DataObjID *
id : input_data_in) {
134 for (
const DataObjID *
id : output_data_in) {
140 std::vector<Gaudi::DataHandle *> tmp_new_input_handles;
141 std::vector<Gaudi::DataHandle *> tmp_new_output_handles;
142 bool ret = dyn_data_consumer.first->updateDataNeeds(input_data_in, output_data_in, tmp_new_input_handles, tmp_new_output_handles);
145 for (
const Gaudi::Algorithm *parent_alg : dyn_data_consumer.second) {
146 out <<
" " << parent_alg->name();
148 out <<
" i:" << tmp_new_input_handles.size()
149 <<
" o:" << tmp_new_output_handles.size()
155 if (Gaudi::Algorithm *
const an_alg =
dynamic_cast<Gaudi::Algorithm *
const>(dyn_data_consumer.first); an_alg) {
159 for (
const Gaudi::DataHandle *handle : an_alg->inputHandles()) {
160 out <<
" " << handle->fullKey();
164 else if (AlgTool *alg_tool =
dynamic_cast<AlgTool *
const>(dyn_data_consumer.first); alg_tool) {
168 for (
const Gaudi::DataHandle *handle : alg_tool->inputHandles()) {
169 out <<
" " << handle->fullKey();
174 out << MSG::WARNING <<
"Unknown dynamic data consumer type " <<
typeid(dyn_data_consumer.first).
name() <<
endmsg;
178 for (Gaudi::Algorithm *parent_alg : dyn_data_consumer.second) {
179 input_data_out.reserve(input_data_out.size()+tmp_new_input_handles.size());
180 for (Gaudi::DataHandle *a_handle : tmp_new_input_handles) {
182 input_data_out.push_back(&(a_handle->fullKey()));
184 << a_handle->fullKey().className() <<
" / " << a_handle->objKey() <<
endmsg;
186 output_data_out.reserve(output_data_out.size()+tmp_new_output_handles.size());
187 for (Gaudi::DataHandle *a_handle : tmp_new_output_handles) {
189 output_data_out.push_back(&(a_handle->fullKey()));
191 << a_handle->fullKey().className() <<
" / " << a_handle->objKey() <<
endmsg;