From ab22856a051be48a4f92f62561d5429f9db18c77 Mon Sep 17 00:00:00 2001 From: Frank Winklmeier <frank.winklmeier@cern.ch> Date: Mon, 24 Jan 2022 12:03:17 +0100 Subject: [PATCH] TrigDecisionTool: use ConstDataVector in FeatureCollect classes Instead of using `const_cast` to push a `const` pointer into a `DataVector` use `ConstDataVector`, which exists exactly for this use-case. --- .../TrigDecisionTool/FeatureCollectAthena.h | 22 +++++++++---------- .../FeatureCollectStandalone.h | 12 +++++----- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/FeatureCollectAthena.h b/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/FeatureCollectAthena.h index 8d614ad5d9fa..535af19c639e 100644 --- a/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/FeatureCollectAthena.h +++ b/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/FeatureCollectAthena.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ #ifndef XAOD_ANALYSIS // Full Athena only @@ -26,6 +26,8 @@ #include "boost/shared_ptr.hpp" #include "boost/lexical_cast.hpp" +#include "AthContainers/ConstDataVector.h" + #include "TrigNavigation/NavigationCore.h" #include "TrigNavigation/NavigationCore.icc" #include "TrigDecisionTool/Conditions.h" @@ -104,20 +106,16 @@ namespace Trig { const TrigPassBits* bits(0); if ( condition == TrigDefs::Physics ) {// only passing objects - bits = getBits(source->size(), te, label , navigation); + bits = getBits(source->size(), te, label , navigation); } if ( bits ) { // the actual filtering - T* destination = new T(); - destination->clear(SG::VIEW_ELEMENTS); - // std::string name = "TDT_temporary_"+label+"_"+boost::lexical_cast<std::string>( (void*) destination); - //navigation->getAccessProxy()->record(destination, name); + auto destination = new ConstDataVector<T>(SG::VIEW_ELEMENTS); - - for(const typename T::base_value_type *obj : *source) { - if ( HLT::isPassing(bits, obj, source) ) // if bits are missing or obj is realy marked as passing - destination->push_back(const_cast<typename T::value_type>(obj)); - } - return destination; + for(const typename T::base_value_type *obj : *source) { + if ( HLT::isPassing(bits, obj, source) ) // if bits are missing or obj is realy marked as passing + destination->push_back(obj); + } + return destination->asDataVector(); } // else return source; diff --git a/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/FeatureCollectStandalone.h b/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/FeatureCollectStandalone.h index a1da0f1c7821..4f23640c26ee 100644 --- a/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/FeatureCollectStandalone.h +++ b/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/FeatureCollectStandalone.h @@ -43,6 +43,7 @@ #include "AsgMessaging/Check.h" #include "AsgTools/EventStoreType.h" +#include "AthContainers/ConstDataVector.h" #include "TrigNavStructure/TypedHolder.h" @@ -107,16 +108,15 @@ namespace Trig { std::cerr << "WARNING: bits size and owned size" << std::endl; return original; } - STORED* f = new STORED; - f->clear(SG::VIEW_ELEMENTS); + auto f = new ConstDataVector<STORED>(SG::VIEW_ELEMENTS); for(auto obj : *original){ - if(HLT::isPassing(bits,obj,original.get())){ - f->push_back(const_cast<typename STORED::value_type>(obj)); - } + if(HLT::isPassing(bits,obj,original.get())){ + f->push_back(obj); + } } //manage the memory - std::shared_ptr<const STORED> filtered(f); + std::shared_ptr<const STORED> filtered(f->asDataVector()); return filtered; } -- GitLab