21 #include "GaudiKernel/ISvcLocator.h"
23 #include "AthLinks/ElementLink.h"
24 #include "GaudiKernel/AlgTool.h"
25 #include "GaudiKernel/Chrono.h"
26 #include "GaudiKernel/ToolVisitor.h"
27 #include "GaudiKernel/ConcurrencyFlags.h"
36 inline void renounceInputs([[maybe_unused]]
const std::unordered_set<std::string> &
outputs, std::vector< const DataObjID *> &output_ids, AlgTool *a_tool) {
37 for (
const DataObjID *a_data_id : output_ids ) {
38 a_tool->renounceInput( *a_data_id );
41 inline void collectOutputs(std::unordered_set<std::string> &
outputs, std::vector< const DataObjID *> &output_ids,
const AlgTool *a_tool) {
42 for (
const DataObjID &a_data_id : a_tool->outputDataObjs() ) {
43 if (
outputs.insert( a_data_id.key() ).second) {
44 output_ids.push_back( &a_data_id );
48 template <
typename Callable,
typename = std::enable_if_t<std::is_invocable_r_v<
void, Callable, IAlgTool*>>>
49 inline void visitTools(IAlgTool &a_tool_interface, Callable &func) {
50 const AlgTool *alg_tool =
dynamic_cast<AlgTool *
>(&a_tool_interface);
52 func(&a_tool_interface);
53 std::vector<IAlgTool *> &non_const_tools
ATLAS_THREAD_SAFE =
const_cast< std::vector<IAlgTool *> &
>( alg_tool->tools() );
54 ToolVisitor::visit( non_const_tools, func);
61 m_chronoSvc(
"ChronoStatSvc",
name),
62 m_runSkimmingFirst(false)
85 if( m_skimmingTools.retrieve().isFailure() ) {
87 return StatusCode::FAILURE;
89 ATH_MSG_INFO(
"The following skimming tools will be applied....");
93 if( m_thinningTools.retrieve().isFailure() ) {
95 return StatusCode::FAILURE;
97 ATH_MSG_INFO(
"The following thinning tools will be applied");
101 if( m_augmentationTools.retrieve().isFailure() ) {
103 return StatusCode::FAILURE;
105 ATH_MSG_INFO(
"The following augmentation tools will be applied....");
109 if (m_doChronoStat) {
114 if (m_runSkimmingFirst) {
115 ATH_MSG_INFO(
"Skimming will be run before augmentation. Make sure your skimming does not depend on variables calculated in the augmentation step!");
118 std::unordered_set<std::string>
outputs;
119 std::vector<const DataObjID *> output_ids;
120 auto output_collector = [&
outputs, &output_ids](IAlgTool *a_tool_interface) {
121 const AlgTool *alg_tool =
dynamic_cast<AlgTool *
>(a_tool_interface);
123 collectOutputs(
outputs,output_ids, alg_tool);
126 auto renounce_and_collect_outputs = [&
outputs, &output_ids](IAlgTool *a_tool_interface) {
127 AlgTool *alg_tool =
dynamic_cast<AlgTool *
>(a_tool_interface);
129 renounceInputs(
outputs,output_ids, alg_tool);
130 collectOutputs(
outputs,output_ids, alg_tool);
133 auto renouncer = [&
outputs, &output_ids](IAlgTool *a_tool_interface) {
134 AlgTool *alg_tool =
dynamic_cast<AlgTool *
>(a_tool_interface);
136 renounceInputs(
outputs,output_ids, alg_tool);
142 if (m_runSkimmingFirst) {
143 for (ToolHandle<ISkimmingTool> &a_tool_handle : m_skimmingTools ) {
144 visitTools(*a_tool_handle, output_collector);
146 for (ToolHandle<IAugmentationTool> &a_tool_handle : m_augmentationTools ) {
147 visitTools(*a_tool_handle, renounce_and_collect_outputs);
151 for (ToolHandle<IAugmentationTool> &a_tool_handle : m_augmentationTools ) {
152 visitTools(*a_tool_handle, output_collector);
154 for (ToolHandle<ISkimmingTool> &a_tool_handle : m_skimmingTools ) {
155 visitTools(*a_tool_handle, renounce_and_collect_outputs);
158 for (ToolHandle<IThinningTool> &a_tool_handle : m_thinningTools ) {
159 visitTools(*a_tool_handle, renouncer);
163 return StatusCode::SUCCESS;
170 IChronoSvc* cSvc=m_chronoSvc.get();
172 Chrono chrono( cSvc ,
name() );
184 if (!m_runSkimmingFirst) {
187 while (augmentationTool != endOfAugmentationTools) {
189 if ( (**augmentationTool).addBranches().isFailure() ) {
191 return StatusCode::FAILURE;
202 bool acceptEvent(
true);
209 if (!((**skimmingTool).eventPassesFilter())) {
211 ATH_MSG_DEBUG(
"This event failed the " << (**skimmingTool).name() <<
" filter. Therefore it will not be recorded.");
218 if (acceptEvent) ++m_acceptCntr;
221 setFilterPassed(acceptEvent);
224 if (!acceptEvent)
return StatusCode::SUCCESS;
227 if (m_runSkimmingFirst) {
230 while (augmentationTool != endOfAugmentationTools) {
232 if ( (**augmentationTool).addBranches().isFailure() ) {
234 return StatusCode::FAILURE;
247 while (thinningTool != endOfThinningTools) {
249 if ( (**thinningTool).doThinning().isFailure() ) {
251 return StatusCode::FAILURE;
257 return StatusCode::SUCCESS;
265 ATH_MSG_INFO(
"============================================================================");
266 ATH_MSG_INFO(
"|| SUMMARY OF THE DERIVATION FRAMEWORK KERNEL WITH NAME " <<
name() <<
" || ");
267 ATH_MSG_INFO(
"============================================================================");
268 ATH_MSG_INFO(
"============================================================================");
271 ATH_MSG_INFO(
"============================================================================");
273 return StatusCode::SUCCESS;