12 #include "GaudiKernel/MsgStream.h"
13 #include "GaudiKernel/GenericAddress.h"
14 #include "GaudiKernel/Algorithm.h"
15 #include "GaudiKernel/IAlgManager.h"
16 #include "GaudiKernel/IClassIDSvc.h"
31 #include "boost/range.hpp"
36 base_class(
name, pSvcLocator),
37 m_clidSvc(
"ClassIDSvc",
name),
38 m_RCUSvc(
"Athena::RCUSvc",
name),
58 const std::string::size_type p_sep = overwrite.find(
"->");
59 if (p_sep == std::string::npos) {
60 ATH_MSG_ERROR(
"Unexpected format in TypeKeyOverwriteMaps: " << overwrite);
61 return(StatusCode::FAILURE);
64 const std::pair<std::string, std::string>
entry(overwrite.substr(p_sep + 2), overwrite.substr(0, p_sep));
66 <<
" -> " <<
entry.first);
67 const std::string::size_type p_oldSep =
entry.first.find(
'#');
68 if (p_oldSep == std::string::npos) {
69 ATH_MSG_ERROR(
"Unexpected format in TypeKeyOverwriteMaps: " << overwrite);
70 return(StatusCode::FAILURE);
73 std::string clidStr =
entry.first.substr(0, p_oldSep);
74 std::set<CLID> symClids;
75 for (std::string::size_type p_clidSep = clidStr.rfind(
','); p_clidSep != std::string::npos; clidStr.resize(p_clidSep), p_clidSep = clidStr.rfind(
',')) {
76 symClids.insert(
getClid(clidStr.substr(p_clidSep + 1)));
78 std::string keyStr =
entry.first.substr(p_oldSep + 1);
79 std::set<std::string> aliases;
80 for (std::string::size_type p_keySep = keyStr.rfind(
','); p_keySep != std::string::npos; keyStr.resize(p_keySep), p_keySep = keyStr.rfind(
',')) {
81 aliases.insert(keyStr.substr(p_keySep + 1));
84 for (
CLID clid : symClids) {
85 oldTad.setTransientID(clid);
87 oldTad.setAlias(aliases);
89 const std::string::size_type p_newSep =
entry.second.find(
'#');
90 if (p_newSep == std::string::npos) {
91 ATH_MSG_ERROR(
"Unexpected format in TypeKeyOverwriteMaps: " << overwrite);
92 return(StatusCode::FAILURE);
95 ATH_MSG_INFO(
"TypeKeyOverwriteMaps for: " << newTad.clID()
96 <<
"#" << newTad.name()
97 <<
" -> " << oldTad.clID()
98 <<
"#" << oldTad.name());
105 return(StatusCode::SUCCESS);
117 if (toadd.empty())
return;
121 auto newmap = std::make_unique<InputRenameMap_t> (*
u);
122 for (
const auto&
p : toadd)
124 u.update (std::move (newmap));
130 StatusCode AddressRemappingSvc::initInputRenames()
138 std::string::size_type pos1 =
remap.find(
'#');
139 std::string::size_type pos2 =
remap.find(
"->");
140 if (pos1 == std::string::npos || pos2 == std::string::npos || pos2 < pos1)
146 std::string cname =
remap.substr (0, pos1);
147 std::string from =
remap.substr (pos1+1, pos2-pos1-1);
148 std::string
to =
remap.substr (pos2+2, std::string::npos);
150 if (clid == CLID_NULL) {
172 return StatusCode::SUCCESS;
182 return(StatusCode::SUCCESS);
197 const std::vector<SG::TransientAddress>* oldTads =
nullptr;
198 const std::vector<SG::TransientAddress>* newTads =
nullptr;
204 return StatusCode::SUCCESS;
216 if (!
status.isSuccess()) {
220 for (std::vector<SG::TransientAddress>::const_iterator oldIter = oldTads->begin(),
221 newIter = newTads->begin(), oldIterEnd = oldTads->end();
222 oldIter != oldIterEnd; ++oldIter, ++newIter) {
224 tads.push_back(tadd);
225 m_proxyDict->stringToKey(oldIter->name(), oldIter->clID());
226 m_proxyDict->stringToKey(newIter->name(), newIter->clID());
228 return(StatusCode::SUCCESS);
245 return StatusCode::SUCCESS;
248 std::vector<SG::TransientAddress> oldTadsCleaned =
m_oldTads;
249 std::vector<SG::TransientAddress> newTadsCleaned =
m_newTads;
253 if (!
status.isSuccess()) {
258 newIter = newTadsCleaned.begin(), oldIterEnd = oldTadsCleaned.end();
259 oldIter != oldIterEnd; ++oldIter, ++newIter)
261 CLID goodCLID = newIter->clID();
263 std::set<CLID> clidToKeep (clidvec.begin(), clidvec.end());
268 clidToKeep.erase(goodCLID);
273 dataProxy =
m_proxyDict->proxy(goodCLID, newIter->name());
275 clidToKeep.erase(goodCLID);
279 ATH_MSG_DEBUG(
"Remapping " << oldIter->clID() <<
"#" << oldIter->name() <<
" to base-class CLID: " << goodCLID <<
"#" << newIter->name());
285 ATH_MSG_INFO(
"Skipping remapping of " << oldIter->clID() <<
"#" << oldIter->name() <<
" because no suitable remapping found");
291 for(
auto tIter = clidToKeep.begin(); tIter != clidToKeep.end(); ++tIter) {
292 if(goodCLID == *tIter)
continue;
296 if(oldIter->clID()!=tadd->
clID()) {
299 tads.push_back(tadd);
300 m_proxyDict->stringToKey(oldIter->name(), oldIter->clID());
301 m_proxyDict->stringToKey(newIter->name(), newIter->clID());
309 return StatusCode::SUCCESS;
315 const EventContext& ctx)
321 const EventContext& )
const
323 const std::vector<SG::TransientAddress>* oldTads =
nullptr;
324 const std::vector<SG::TransientAddress>* newTads =
nullptr;
336 for (std::vector<SG::TransientAddress>::const_iterator oldIter = oldTads->begin(),
337 newIter = newTads->begin(), oldIterEnd = oldTads->end();
338 oldIter != oldIterEnd; ++oldIter, ++newIter) {
339 if (oldIter->transientID(tad->
clID())
340 && (oldIter->name() == tad->
name() || oldIter->alias().find(tad->
name()) != oldIter->alias().end())) {
341 ATH_MSG_DEBUG(
"Overwrite for: " << tad->
clID() <<
"#" << tad->
name() <<
" -> " << newIter->clID() <<
"#" << newIter->name());
343 if (dataProxy == 0) {
344 ATH_MSG_WARNING(
"Cannot get proxy for: " << newIter->clID() <<
"#" << newIter->name());
345 return(StatusCode::FAILURE);
347 GenericAddress* newGadd = 0;
350 ATH_MSG_WARNING(
"Cannot get GenericAddress for: " << newIter->clID() <<
"#" << newIter->name());
351 return(StatusCode::FAILURE);
353 GenericAddress* oldGadd =
new GenericAddress(newGadd->svcType(), tad->
clID(), *newGadd->par(), tad->
name(), *newGadd->ipar());
355 return(StatusCode::SUCCESS);
358 return(StatusCode::FAILURE);
374 if (
r->empty() &&
m_deletes.empty())
return StatusCode::SUCCESS;
391 if (
it !=
r->end()) {
392 const std::string& name_renamed =
it->second.m_key;
395 auto tad_new = std::make_unique<SG::TransientAddress>
396 (tad_clid, name_renamed,
399 if (clid == tad_clid)
continue;
400 tad_new->setTransientID (clid);
402 if (
r->find(from_key) ==
r->end()) {
408 size_t namelen = tad->
name().size();
410 for (
const std::string&
a : tad->
alias()) {
411 std::string a_renamed =
a;
414 auto it_a =
r->find (from_key);
415 if (it_a !=
r->end()) {
416 a_renamed = it_a->second.m_key;
419 if (strncmp (a_renamed.c_str(), tad->
name().c_str(), namelen) == 0 &&
420 a_renamed[namelen] ==
'.')
422 a_renamed = name_renamed + a_renamed.substr (namelen, std::string::npos);
425 newAliases.insert (a_renamed);
427 tad_new->setAlias (newAliases);
432 tad = tad_new.release();
440 auto tad_new = std::make_unique<SG::TransientAddress>
441 (tad->
clID(), tad->
name() +
"_DELETED",
445 for (
const std::string&
a : tad->
alias()) {
446 tad_new->setAlias (
a +
"_DELETED");
450 tad = tad_new.release();
458 for (
const std::string&
a : aset) {
460 auto it_a =
r->find (from_key);
461 if (it_a !=
r->end()) {
462 const std::string&
s = it_a->second.m_key;
475 return StatusCode::SUCCESS;
508 for (IAlgorithm* ialg :
algs) {
509 if (Gaudi::Algorithm*
alg =
dynamic_cast<Gaudi::Algorithm*
> (ialg)) {
512 if (
alg->name() ==
"SGInputLoader")
continue;
515 if (
alg->type() ==
"AthViews::ViewDataVerifier" )
continue;
517 for (
const DataObjID& dobj :
alg->outputDataObjs()) {
518 static const std::string pref =
"StoreGateSvc+";
519 if (dobj.key().rfind(pref, 0) != std::string::npos) {
520 std::string
key = dobj.key().substr (pref.size());
527 if (dobj.fullKey().find (
"xAOD") != std::string::npos ||
528 dobj.fullKey().find (
"cinfo") != std::string::npos)
546 for (
auto p : boost::make_iterator_range (
m_deletes.equal_range (
key))) {
547 CLID clid =
p.second;