28 void popRenounced(
const std::vector<std::string> &renounce,
29 std::vector<Gaudi::DataHandle *> &new_input_handles) {
30 for (
const std::string &a_key : renounce) {
31 if (new_input_handles.back()->objKey() == a_key ) {
32 new_input_handles.pop_back();
54 size_t dotPosition =
varname.find(
'.');
55 containerName =
varname.substr(0, dotPosition);
56 methodName =
varname.substr(dotPosition + 1);
59 std::pair<RootUtils::TSMethodCall, TVirtualCollectionProxy *>
62 std::cout <<
"DEBUG SGxAODProxyLoader search for " << method_name <<
" in type " <<
info.name() << std::endl;
64 TClass *containerClass = TClass::GetClass(
info);
65 if (!containerClass) {
70 if (!containerClass) {
71 std::stringstream
msg;
72 msg <<
"No dictionary for " <<
info.name() << std::endl;
73 throw std::runtime_error(
msg.str());
76 TClass *elementClass=
nullptr;
77 TVirtualCollectionProxy *collection_proxy=
nullptr;
78 if( strcmp(containerClass->GetName(),
"SG::AuxElementStandaloneData")==0 ) {
79 elementClass=containerClass;
82 collection_proxy = containerClass->GetCollectionProxy();
83 elementClass = (collection_proxy ? collection_proxy->GetValueClass() :
nullptr);
85 std::stringstream
msg;
86 msg <<
"No collection proxy or element class for " <<
info.name() << std::endl;
87 throw std::runtime_error(
msg.str());
91 method_call.
setProto (elementClass, method_name,
"",
92 ROOT::kConversionMatch);
93 if (!method_call.
call() || !method_call.
call()->IsValid()) {
94 std::stringstream
msg;
95 msg <<
"No valid method " << method_name <<
" for " <<
info.name() << std::endl;
96 throw std::runtime_error(
msg.str());
100 std::cout <<
"DEBUG SGxAODProxyLoader got method " <<
" . " << method_name <<
" : "
101 << method_call.
call()->GetMethod()->GetReturnTypeNormalizedName ()
102 <<
" proto=" << method_call.
call()->GetProto()
103 <<
" signature=" << method_call.
call()->GetMethod()->GetSignature ()
104 <<
" proto=" << method_call.
call()->GetMethod()->GetPrototype()
107 return std::make_pair( method_call, collection_proxy);
111 template <
class T_Aux>
116 const std::string &method_name)
const
120 std::stringstream
msg;
121 msg <<
"Failed to get " <<
key.key();
122 throw std::runtime_error(
msg.str());
125 return std::unique_ptr<IAccessor>();
138 const std::string &
varname)
const
142 std::string container_name;
143 std::string method_name;
145 ReadHandleMap::const_iterator key_iter =
m_readKeys.find(container_name);
147 std::stringstream
msg;
148 msg <<
"No read handle key for " << container_name;
149 throw std::runtime_error(
msg.str());
152 ReadDecorHandleMap::const_iterator decor_key_iter =
m_decorKeys.end();
155 if (method_id != SG::null_auxid) {
159 std::unique_ptr<IAccessor>
accessor;
161 if (
m_verbose) { std::cout <<
"DEBUG SGxAODProxyLoader::computeClassForVarname is Vector: " <<
varname << std::endl; }
169 if (
m_verbose) { std::cout <<
"DEBUG SGxAODProxyLoader::computeClassForVarname is element: " <<
varname << std::endl; }
177 if (
m_verbose) { std::cout <<
"DEBUG SGxAODProxyLoader::computeClassForVarname try to create plain type accessor for " <<
varname << std::endl; }
185 std::cout <<
"DEBUG SGxAODProxyLoader use accessor "
186 <<
typeid(*accessorPlainPtr).name() <<
" for " <<
varname
189 accessor_iter->second.set(std::move(
accessor));
190 return *(accessor_iter->second);
194 const EventContext& ctx = Gaudi::Hive::currentContext();
199 template <
typename T>
201 for (
auto elm :
vec) {
202 std::cout <<
" " << elm;
209 #ifdef DEBUG_VARIABLE_LOADING
210 std::cout <<
"DEBUG SGxAODProxyLoader::dump " <<
varname <<
val << std::endl;
218 const EventContext& ctx = Gaudi::Hive::currentContext();
224 const EventContext& ctx = Gaudi::Hive::currentContext();
230 const EventContext& ctx = Gaudi::Hive::currentContext();
236 const EventContext& ctx = Gaudi::Hive::currentContext();
241 const std::vector<std::string> &var_names,
242 const std::vector<std::string> &renounce,
243 const std::vector<const DataObjID *> &input_data_in,
244 const std::vector<const DataObjID *> &output_data_in,
245 std::vector<Gaudi::DataHandle *> &new_input_handles,
246 std::vector<Gaudi::DataHandle *> &new_output_handles)
248 (void) new_output_handles;
250 for (
const std::string &
var_name : var_names) {
252 std::string container_name;
253 std::string method_name;
256 std::cout <<
"DEBUG SGxAODProxyLoader::updateDataDependencies var " <<
var_name <<
" -> " << container_name <<
" . " << method_name
257 <<
" i:" << input_data_in.size() <<
" o:" << output_data_in.size()
260 const DataObjID *container_data_id=
nullptr;
261 const DataObjID *method_data_id=
nullptr;
270 auto set_ids = [&method_data_id,&container_data_id,&
var_name,&container_name,
verbose](
const DataObjID *obj_data_id) ->
bool {
271 std::string_view handle_key(obj_data_id->key());
272 std::string::size_type
pos=obj_data_id->key().find(
'+');
273 pos = (
pos==std::string::npos ? 0 :
pos+1);
274 handle_key=handle_key.substr(
pos,handle_key.size()-
pos);
275 if (
verbose && (handle_key == container_name || handle_key ==
var_name)) {
277 std::cout <<
"DEBUG SGxAODProxyLoader::updateDataDependencies " << handle_key <<
" matches " <<
var_name <<
" ? "
278 << (handle_key ==
var_name ?
" method " :
"")
279 << (handle_key == container_name ?
" container " :
"")
280 <<
"-> " << (base_info ? base_info->
typeinfo().name() :
"")
284 method_data_id = obj_data_id;
285 if (container_data_id)
return true;
287 else if (handle_key == container_name ) {
288 container_data_id = obj_data_id;
289 if (method_data_id)
return true;
294 for( std::vector<const DataObjID *>::const_iterator elm_iter = output_data_in.begin(); elm_iter != output_data_in.end() && !set_ids(*elm_iter); ++elm_iter) {}
295 if (!method_data_id) {
296 for( std::vector<const DataObjID *>::const_iterator elm_iter = input_data_in.begin(); elm_iter != input_data_in.end() && !set_ids(*elm_iter); ++elm_iter) {}
298 if (method_data_id) {
299 if (!container_data_id) {
300 container_data_id=method_data_id;
304 if (
m_verbose && method_data_id && method_data_id != container_data_id) {
305 std::cout <<
"DEBUG SGxAODProxyLoader method_clid " << method_data_id->clid() << std::endl;
308 std::cout <<
"DEBUG SGxAODProxyLoader container_clid " << container_data_id->clid() << std::endl;
312 if (container_data_id) {
315 if (have_container_read_key && !method_data_id)
continue;
317 auto clid = container_data_id->clid();
321 std::stringstream
msg;
322 msg <<
"Missing type information about container " << container_name <<
".";
323 if (container_data_id) {
324 msg <<
" It seems that inheritance information is missing for " << container_data_id->className() <<
"."
325 <<
" Only container which inherit from SG::AuxVectorBase or data inheriting from SG::AuxElement "
326 <<
" are supported by the SGxAODProxyLoader loader.";
329 msg <<
" This problem may occur if the container is read from the input"
330 <<
" file and not accessed anywhere in the job via read handles. ";
332 throw std::runtime_error(
msg.str());
336 std::cout <<
"DEBUG SGxAODProxyLoader " << container_name <<
" -> " << base_info->
typeinfo().name() << std::endl;
339 std::cout <<
"DEBUG SGxAODProxyLoader " << container_name <<
" base: " << a_base_info->
typeinfo().name() << std::endl;
348 if (!have_container_read_key) {
349 read_key = std::make_any<SG::ReadHandleKey<SG::AuxVectorBase> >(container_name);
351 if (method_data_id) {
352 decor_key = std::make_any<SG::ReadDecorHandleKey<SG::AuxVectorBase> >(
var_name);
356 if (!have_container_read_key) {
357 read_key = std::make_any<SG::ReadHandleKey<SG::AuxElement> >(container_name);
359 if (method_data_id) {
360 decor_key = std::make_any<SG::ReadDecorHandleKey<SG::AuxElement> >(
var_name);
364 if (method_data_id && method_data_id != container_data_id && method_data_id->clid() != container_data_id->clid()) {
365 std::stringstream
msg;
366 msg <<
"Did not expect a \"method\" handle for the plain type " <<
var_name;
367 throw std::logic_error(
msg.str());
370 if (registered_key) {
371 popRenounced(renounce, new_input_handles);
376 if (!have_container_read_key) {
377 if (!read_key.has_value()) {
378 std::stringstream
msg;
379 msg <<
"Container " << container_name <<
" is of unsupported type " << base_info->
typeinfo().name()
380 <<
" expected a type derived from SG::AuxVectorBase or SG::AuxElement";
381 throw std::runtime_error(
msg.str());
383 std::pair<ReadHandleMap::iterator, bool> ret =
m_readKeys.insert(std::make_pair(container_name, std::move(read_key)));
387 std::stringstream
msg;
388 msg <<
"Failed to add read handle key for " << container_name;
389 throw std::runtime_error(
msg.str());
397 popRenounced(renounce, new_input_handles);
401 if (method_data_id) {
402 if (!decor_key.has_value()) {
403 std::stringstream
msg;
404 msg <<
"Container " << container_name <<
" is of unsupported type " << base_info->
typeinfo().name()
405 <<
" expected a type derived from SG::AuxVectorBase or SG::AuxElement";
406 throw std::runtime_error(
msg.str());
408 std::pair<ReadDecorHandleMap::iterator, bool> ret =
m_decorKeys.insert(std::make_pair(
var_name,std::move(decor_key)));
412 std::stringstream
msg;
413 msg <<
"Failed to add read decor handle key for " <<
var_name;
414 throw std::runtime_error(
msg.str());
422 popRenounced(renounce, new_input_handles);