00001
00002 #ifndef TRIGGER_DECISION_TOOL_FeatureContainer_H
00003 #define TRIGGER_DECISION_TOOL_FeatureContainer_H
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "boost/foreach.hpp"
00020 #include "boost/type_traits/is_same.hpp"
00021 #include "boost/type_traits/is_base_of.hpp"
00022
00023 #include "TrigDecisionTool/Combination.h"
00024 #include "TrigDecisionTool/Conditions.h"
00025 #include "TrigDecisionTool/Feature.h"
00026 #include "TrigDecisionTool/FeatureCollectStandalone.h"
00027 #include "TrigDecisionTool/TypelessFeature.h"
00028
00029 #include "TrigSteeringEvent/TrigPassFlags.h"
00030
00031 #include "TrigNavStructure/TrigNavStructure.h"
00032
00033
00034
00035 #include <vector>
00036 #include <map>
00037
00038 namespace Trig {
00039
00040
00041
00042 class FeatureContainer
00043 {
00044 public:
00045
00046 typedef std::vector<Combination>::const_iterator combination_const_iterator;
00047
00049 FeatureContainer(const CacheGlobalMemory* cgm = 0): m_combinations_unique(true), m_cgm(cgm) {}
00050
00059 template<class T> const std::vector<Trig::Feature<T> > get(const std::string& label = "", unsigned int condition = TrigDefs::Physics,
00060 const std::string& teName = "") const;
00061
00062
00063 std::vector<Trig::Feature<xAOD::IParticle> > getIParticle(HLT::class_id_type clid, const std::string& container_name, const std::string& label = "", unsigned int condition = TrigDefs::Physics, const std::string & teName = "" ) const{
00064 auto features = typelessGet(clid,label,condition,teName);
00065 return FeatureAccessImpl::typedGet<xAOD::IParticle,xAOD::IParticleContainer,xAOD::IParticleContainer>(features,
00066 navigation(),
00067 m_cgm->store(),
00068 container_name);
00069 }
00070
00071 template<typename CONTAINER> using ELEMENT_OF = typename CONTAINER::base_value_type;
00072
00073 template<typename CONTAINER>
00074 std::vector<Feature<ELEMENT_OF<CONTAINER> > > elementFeature(const std::string& label = "", unsigned int condition = TrigDefs::Physics, const std::string& teName = "") const{
00075 auto features = typelessGet(ClassID_traits<ELEMENT_OF<CONTAINER> >::ID(),label,condition,teName);
00076 return FeatureAccessImpl::typedGet<ELEMENT_OF<CONTAINER>,ELEMENT_OF<CONTAINER>,CONTAINER>(features,navigation(),m_cgm->store());
00077 }
00078
00079 template<typename CONTAINER>
00080 std::vector<Feature<CONTAINER> > containerFeature(const std::string& label = "", unsigned int condition = TrigDefs::Physics, const std::string& teName = "") const{
00081 auto features = typelessGet(ClassID_traits<CONTAINER>::ID(),label,condition,teName);
00082 return FeatureAccessImpl::typedGet<CONTAINER,CONTAINER,CONTAINER>(features,navigation(),m_cgm->store());
00083 }
00084
00085 template<typename CONTAINER>
00086 std::vector<Feature<ELEMENT_OF<CONTAINER> > > flattenedContainerFeature(const std::string& label = "", unsigned int condition = TrigDefs::Physics, const std::string& teName = "") const{
00087 auto features = typelessGet(ClassID_traits<CONTAINER>::ID(),label,condition,teName);
00088 return FeatureAccessImpl::typedGet<ELEMENT_OF<CONTAINER>,CONTAINER,CONTAINER>(features,navigation(),m_cgm->store());
00089 }
00090
00091
00096 const std::vector<Trig::TypelessFeature> typelessGet(HLT::class_id_type clid, const std::string& label = "", unsigned int condition = TrigDefs::Physics, const std::string& teName = "") const;
00097
00098
00105 #if defined(ASGTOOL_ATHENA) && !defined(XAOD_ANALYSIS)
00106 template<class T> TrigPassFlags getFlags(const Trig::Feature<T> & f, const std::string & flagsLabel = "") const;
00107 #endif
00108
00112 const std::vector<Trig::Combination>& getCombinations() const;
00113
00114
00118 bool addWithChecking(const Combination& newComb);
00119 void append(const FeatureContainer& other);
00120
00121 private:
00122 const Trig::CacheGlobalMemory* cgm() const { return m_cgm; }
00123
00124 HLT::TrigNavStructure* navigation() const;
00125
00126
00127 mutable std::vector<Trig::Combination> m_combinations;
00128 std::vector<Trig::Combination> m_nonunique_combinations;
00129 mutable bool m_combinations_unique;
00130 const Trig::CacheGlobalMemory* m_cgm;
00131
00132
00133
00134
00135
00136
00137
00138
00139 class ordering_by_objects_attached2 {
00140 public:
00141 template<class T>
00142 bool operator()(Feature<T> a, Feature<T> b);
00143 bool weakOrder(const HLT::TriggerElement* te_a, const HLT::TriggerElement* te_b, void* obj_a, void* obj_b);
00144 };
00145
00146 };
00147
00148 }
00149
00150
00151 template<class T>
00152 bool
00153 Trig::FeatureContainer::ordering_by_objects_attached2::operator()(Feature<T> a, Feature<T> b) {
00154 bool ret = weakOrder(a.te(), b.te(), (void*) a.cptr(), (void*) b.cptr());
00155
00156 return ret;
00157 }
00158
00159 template<class T> const std::vector<Trig::Feature<T> >
00160 Trig::FeatureContainer::get(const std::string& label, unsigned int condition, const std::string& teName) const
00161 {
00162 if ( condition != TrigDefs::Physics && condition != TrigDefs::alsoDeactivateTEs ) {
00163 throw std::runtime_error("Only two flags can be supplied to features");
00164 }
00165
00166
00167 getCombinations();
00168
00169
00170
00171 std::set<Trig::Feature<T>, Trig::FeatureContainer::ordering_by_objects_attached2 > uniqnessHelper;
00172
00173
00174 BOOST_FOREACH(const Trig::Combination& comb, m_combinations ) {
00175
00176
00177 if (condition == TrigDefs::Physics) {
00178 if (!comb.active()) continue;
00179 }
00180 std::vector<Trig::Feature<T> > features = comb.get<T>(label, condition, teName);
00181
00182
00183
00184
00185 BOOST_REVERSE_FOREACH(const Trig::Feature<T>& f, features) {
00186
00187 uniqnessHelper.insert(f);
00188
00189 }
00190 }
00191
00192
00193
00194 return std::vector<Trig::Feature<T> >(uniqnessHelper.begin(), uniqnessHelper.end());
00195
00196 }
00197
00198
00199
00206 #if defined(ASGTOOL_ATHENA) && !defined(XAOD_ANALYSIS)
00207 template<class T> TrigPassFlags
00208 Trig::FeatureContainer::getFlags(const Trig::Feature<T> & f, const std::string & flagsLabel) const {
00209
00210 TrigPassFlags pf;
00211
00212
00213 const TrigPassFlags* flags(0);
00214 const HLT::TriggerElement* sourceTE(0);
00215 std::string sourceLabel;
00216
00217 auto fullnavi = dynamic_cast<HLT::NavigationCore*>(navigation());
00218
00219 bool success = fullnavi->getRecentFeature(f.te(), flags, flagsLabel, sourceTE, sourceLabel);
00220
00221 if(!success || !flags)
00222 return pf;
00223
00224
00225 return FeatureAccessImpl::getFlags(f, flags, fullnavi);
00226
00227 }
00228 #endif
00229
00230 #endif