Skip to content

ToolHandle: add TaggedBool parameter to control retrieval

A very common situation in ATLAS is the conditional retrieval of Tools based on one or more global flags. The forced auto-retrieval of Tools has made the explicit disabling of unwanted tools necessary, requiring lots and lots of extra lines of code in intialize of components. eg:

MyAlg::initialize() {
  ....
   if ((m_MCflag || m_feelingLucky) && m_mcTool.isEnabled()) {
      ATH_CHECK(m_mcTool.retrieve());
   } else {
      m_mcTool.disable();
   }
  ....
}

(the ATH_CHECK macro checks the StatusCode of the function, and in case of failure prints an error message and does an immediate return with that sc.)

This MR would reduce all this boilerplate to

   ATH_CHECK( m_mcTool.retrieve( DisableTool{m_MCFlag || m_feelingLucky} ) );

Some notes: the original ToolHandle::retrieve() method is marked const, even though it's not. I think it would make sense to make this one const too, but then we would have to make m_enabled mutable. I think this is reasonable, as it's not grossly changing the internal state of the ToolHandle, but just changing an attribute. I don't expect this to ever be called in a concurrent way since retrieval is done in initialize, but we could always make m_enabled atomic.

Also, I'm not sure if we should put the TaggedBool DisableTool into the ToolHandle namespace or not. If we do so, then we would have:

   ATH_CHECK( m_mcTool.retrieve( ToolHandle::DisableTool{m_MCFlag} ) );

which to me looks clunky.

If this is acceptable, I'll add a test to the GaudiExamples.

Merge request reports