19 #ifdef XAOD_STANDALONE
20 #include <TInterpreter.h>
24 #include <GaudiKernel/AlgTool.h>
26 #include <GaudiKernel/IToolSvc.h>
27 #include "Gaudi/Interfaces/IOptionsSvc.h"
39 AnaToolShare (
const ToolHandle<interfaceType_t>& val_th,
40 std::shared_ptr<void> val_cleanup,
41 std::vector<std::function<
StatusCode ()>>&& extraInit)
42 : m_th (val_th), m_extraInit (std::move (extraInit)), m_cleanup (std::move (val_cleanup))
44 assert (!m_th.empty());
52 assert (!m_th.empty());
58 AnaToolShareList& AnaToolShareList ::
67 std::shared_ptr<AnaToolShare> AnaToolShareList ::
68 getShare (
const std::string&
name)
const
71 auto iter = m_shared.find (
name);
72 if (iter == m_shared.end())
73 return std::shared_ptr<AnaToolShare> ();
74 return iter->second.lock();
79 std::shared_ptr<AnaToolShare> AnaToolShareList ::
80 setShare (
const std::string&
name,
81 std::unique_ptr<AnaToolShare> val_share)
84 std::shared_ptr<AnaToolShare>
result = getShare (
name);
87 result.reset (val_share.release ());
95 makeShare (
const std::string&
name,
96 const AsgToolConfig&
config,
97 std::vector<std::function<
StatusCode ()>>&& extraInit,
98 std::shared_ptr<AnaToolShare>&
result)
101 using namespace msgToolHandle;
103 auto& share = m_shared[
name];
104 auto res_result = share.lock();
105 if (res_result !=
nullptr)
108 return StatusCode::SUCCESS;
110 ToolHandle<interfaceType_t>
th;
111 std::shared_ptr<void> cleanup;
112 for (
auto&
init : extraInit)
115 ANA_MSG_DEBUG (
"made shared tool with " << extraInit.size() <<
" inits for TH: " <<
th);
116 res_result.reset (
new AnaToolShare (
th, cleanup, std::move (extraInit)));
117 #ifndef XAOD_STANDALONE
123 assert (share.lock() ==
nullptr);
126 return StatusCode::SUCCESS;
135 #ifdef XAOD_STANDALONE
142 const std::string&
name,
145 using namespace msgToolHandle;
147 std::regex typeExpr (
"[A-Za-z_][A-Za-z0-9_]*(::[A-Za-z_][A-Za-z0-9_]*)*");
148 if (!std::regex_match (
type, typeExpr))
151 return StatusCode::FAILURE;
153 std::regex nameExpr (
"[A-Za-z_][A-Za-z0-9_]*((\\.|::)[A-Za-z_][A-Za-z0-9_]*)*(@[0-9]+)?");
154 if (!std::regex_match (
name, nameExpr))
157 return StatusCode::FAILURE;
163 for (
const char *
typeName : {
"asg::AsgTool",
type.c_str()})
165 TClass* toolClass = TClass::GetClass (
typeName);
168 return StatusCode::FAILURE;
173 tool = (AsgTool*) (gInterpreter->Calc((
"dynamic_cast<asg::AsgTool*>(new " +
type +
" (\"" +
name +
"\"))").c_str()));
177 ANA_MSG_ERROR (
"make sure you created a dictionary for your tool");
178 return StatusCode::FAILURE;
183 return StatusCode::SUCCESS;
196 if(
svc.retrieve().isFailure() )
return StatusCode::FAILURE;
199 for (
auto& prop :
svc->items())
201 if (std::get<0>(prop).substr (0, toolName.size()) == toolName &&
202 std::get<0>(prop)[toolName.size()] ==
'.')
203 out = StatusCode::SUCCESS;
205 svc.release().ignore();
214 joSvc->set( toolName +
"." + propertyName, propertyValue );
215 if(joSvc.release().isFailure())
return StatusCode::FAILURE;
216 return StatusCode::SUCCESS;
224 std::string theToolName = toolName; std::string thePropertyName=propertyName;
225 std::string::size_type dotLocation = thePropertyName.find_last_of(
'.');
226 if(dotLocation != std::string::npos) {
227 theToolName = toolName +
"." + thePropertyName.substr(0,dotLocation);
228 thePropertyName = thePropertyName.substr(dotLocation+1,thePropertyName.length()-dotLocation);
230 joSvc->pop( theToolName +
"." + thePropertyName );
231 if(joSvc.release().isFailure())
return StatusCode::FAILURE;
232 return StatusCode::SUCCESS;
236 toolSvc.retrieve().ignore();
237 auto tools = toolSvc->getTools();
242 toolSvc.release().ignore();
247 using Gaudi::PluginService::Details::Registry;
249 if(reg.getInfo(
type).library==
"unknown")
return StatusCode::FAILURE;
250 return StatusCode::SUCCESS;
254 using namespace msgToolHandle;
259 if(fromTool == toTool)
return StatusCode::SUCCESS;
262 auto fromProps = joSvc->items(
std::regex (
"^" + fromTool));
263 for(
auto& prop : fromProps) {
264 std::get<0>(prop).replace (0, fromTool.size(), toTool);
265 joSvc->set( std::get<0>(prop) , std::get<1>(prop) );
267 if(joSvc.release().isFailure())
return StatusCode::FAILURE;
268 return StatusCode::SUCCESS;
273 using namespace msgToolHandle;
276 decltype(
auto) fromProps = joSvc->items(
std::regex (
"^" + toolName));
277 for(
const auto& prop : fromProps) {
278 if (std::get<0>(prop) == toolName)
280 config.setTypeAndName (std::get<1>(prop));
283 config.setPropertyFromString (std::get<0>(prop).substr (toolName.size()+1) , std::get<1>(prop));
287 return StatusCode::SUCCESS;