Helper class to gather all declared data IDs and propagate them to components which declare data dependencies dynamically.
More...
#include <DynamicDataHelper.h>
|
void | gatherDataHandlesAndDynamicConsumers (const std::string &parent_name, Gaudi::Algorithm *theAlgorithm) |
| Gather the input and output data declared by the given algorithm, its child algorithms and their tools. More...
|
|
StatusCode | addExtraDependencies (IClassIDSvc &clid_svc, std::vector< std::string > &undeclared_output_data, MsgStream &out) |
| Add extra output data which is not declared by any of the gathered components. More...
|
|
void | updateDataNeeds (unsigned int max_pass, MsgStream &out) |
| Update the data dependencies of all components which dynamically declare tehm. More...
|
|
|
bool | updateDataNeeds (const std::vector< const DataObjID * > &input_data_in, const std::vector< const DataObjID * > &output_data_in, std::vector< const DataObjID * > &input_data_out, std::vector< const DataObjID * > &output_data_out, MsgStream &out) |
| Update the data dependencies of all components once. More...
|
|
Helper class to gather all declared data IDs and propagate them to components which declare data dependencies dynamically.
Definition at line 25 of file DynamicDataHelper.h.
◆ addExtraDependencies()
StatusCode Ath::DynamicDataHelper::addExtraDependencies |
( |
IClassIDSvc & |
clid_svc, |
|
|
std::vector< std::string > & |
undeclared_output_data, |
|
|
MsgStream & |
out |
|
) |
| |
Add extra output data which is not declared by any of the gathered components.
- Parameters
-
clid_svc | the ClassIDSvc needed to translate the type name into a CLID. |
undeclared_output_data | strings which are composed of the type and variable name separated by "/". |
out | the message output stream used for error messages. |
Definition at line 26 of file DynamicDataHelper.cxx.
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;
◆ gatherDataHandlesAndDynamicConsumers()
void Ath::DynamicDataHelper::gatherDataHandlesAndDynamicConsumers |
( |
const std::string & |
parent_name, |
|
|
Gaudi::Algorithm * |
theAlgorithm |
|
) |
| |
Gather the input and output data declared by the given algorithm, its child algorithms and their tools.
- Parameters
-
parent_name | the name of the parent component used in messsages |
theAlgorithm | the top algorithm to start the collection Additionally also all components are collected which dynamically declare their data dependencies. |
Definition at line 65 of file DynamicDataHelper.cxx.
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);
◆ updateDataNeeds() [1/2]
bool Ath::DynamicDataHelper::updateDataNeeds |
( |
const std::vector< const DataObjID * > & |
input_data_in, |
|
|
const std::vector< const DataObjID * > & |
output_data_in, |
|
|
std::vector< const DataObjID * > & |
input_data_out, |
|
|
std::vector< const DataObjID * > & |
output_data_out, |
|
|
MsgStream & |
out |
|
) |
| |
|
protected |
Update the data dependencies of all components once.
- Parameters
-
input_data_in | IDs of all declared input data |
output_data_in | IDs of all declared output data |
input_data_out | IDs of newly declared input data in this iteration |
output_data_out | IDs of newly declared input data in this iteration |
- Returns
- true if new input or output data was declared.
Definition at line 121 of file DynamicDataHelper.cxx.
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;
◆ updateDataNeeds() [2/2]
void Ath::DynamicDataHelper::updateDataNeeds |
( |
unsigned int |
max_pass, |
|
|
MsgStream & |
out |
|
) |
| |
Update the data dependencies of all components which dynamically declare tehm.
- Parameters
-
max_pass | maximum number of iterations |
out | the message stream of the parent component The update happens iteratively until non of the components declares new output data, but at most max_pass times. |
Definition at line 100 of file DynamicDataHelper.cxx.
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;
◆ m_dynDataConsumer
std::unordered_map< IDynamicDataConsumer *,std::vector<Gaudi::Algorithm *> > Ath::DynamicDataHelper::m_dynDataConsumer |
|
protected |
◆ m_extraOutputIDs
std::vector<DataObjID> Ath::DynamicDataHelper::m_extraOutputIDs |
|
protected |
◆ m_inputHandles
◆ m_outputHandles
The documentation for this class was generated from the following files: