00001
00002 #ifndef TRIGGER_DECISION_TOOL_Feature_H
00003 #define TRIGGER_DECISION_TOOL_Feature_H
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <string>
00018 #include <set>
00019 #include "boost/foreach.hpp"
00020 #include "boost/type_traits/is_same.hpp"
00021 #include "boost/shared_ptr.hpp"
00022 #include "boost/lexical_cast.hpp"
00023
00024 #include "AsgTools/MsgStream.h"
00025
00026 #include "TrigNavStructure/TriggerElement.h"
00027 #include "xAODTrigger/EmTauRoI.h"
00028 #include "xAODTrigger/EmTauRoIContainer.h"
00029
00030 #include "xAODTrigger/MuonRoI.h"
00031 #include "xAODTrigger/MuonRoIContainer.h"
00032
00033 #include "xAODTrigger/JetRoI.h"
00034 #include "xAODTrigger/JetRoIContainer.h"
00035
00036 #include "TrigDecisionTool/TypelessFeature.h"
00037
00038 #if defined(ASGTOOL_ATHENA) && !defined(XAOD_ANALYSIS)
00039 #include "TrigStorageDefinitions/EDM_TypeInfo.h"
00040 #endif
00041
00042
00043
00044
00045
00046
00047
00048 #if defined(ASGTOOL_ATHENA) && !defined(XAOD_ANALYSIS)
00049 class Muon_ROI;
00050 class EmTau_ROI;
00051 class Jet_ROI;
00052 #endif
00053
00054 #include "xAODBase/IParticle.h"
00055
00056 namespace Trig {
00074 template<typename T> struct is_storable_type{
00075 #if defined(ASGTOOL_ATHENA) && !defined(XAOD_ANALYSIS)
00076 static const bool value =
00077 !(
00078 boost::is_same<T,Muon_ROI>::value ||
00079 boost::is_same<T,EmTau_ROI>::value ||
00080 boost::is_same<T,Jet_ROI>::value ||
00081 boost::is_same<T,xAOD::EmTauRoI>::value ||
00082 boost::is_same<T,xAOD::MuonRoI>::value ||
00083 boost::is_same<T,xAOD::JetRoI>::value ||
00084 boost::is_same<T,xAOD::IParticle>::value
00085 );
00086 #else
00087 static const bool value = false;
00088 #endif
00089 };
00090
00091 template<typename T,bool> struct link_or_not;
00092
00093
00094 #if defined(ASGTOOL_ATHENA) && !defined(XAOD_ANALYSIS)
00095 template<typename T> struct link_or_not<T,true>{
00096 static const bool known = IsKnownFeature<T>::value;
00097 typedef typename Features2Container<T>::type container_type;
00098 typedef typename Features2LinkHelper<T,container_type>::type type;
00099 };
00100 #endif
00101
00102 struct ElementLink_is_not_available_for_non_storable_types{};
00103
00104 template<typename T> struct link_or_not<T,false>{
00105 typedef ElementLink_is_not_available_for_non_storable_types type;
00106 };
00107
00108 template<class T>
00109 class Feature {
00110 public:
00114 typedef T ValueType;
00115 typedef T* PointerType;
00116
00117 #ifndef __GCCXML__
00118 typedef typename link_or_not<T,is_storable_type<T>::value >::type link_type;
00119 #endif
00120
00121 Feature()
00122 : m_feature((const T*)0), m_te(0), m_label(""), m_owned(false) { }
00123
00124 Feature(const TypelessFeature& feat, const T* const feature)
00125 : m_feature(feature), m_te(feat.te()),
00126 m_label(feat.label()), m_owned(false) { }
00127
00128 Feature(const TypelessFeature& feat, const std::shared_ptr<const T>& feature)
00129 : m_owning_feature(feature),
00130 m_feature(m_owning_feature.get()),
00131 m_te(feat.te()), m_label(feat.label()), m_owned(true) { }
00132
00136 #ifndef __GCCXML__
00137 Feature(const T* feature, const HLT::TriggerElement* te, const std::string& label = "", const bool own = false, const link_type link = link_type())
00138 : m_feature(feature), m_te(te), m_label(label), m_owned(own), m_link(link) {
00139
00140
00141 }
00142 #endif
00143
00147 ~Feature() {
00148 }
00149
00153 operator const T*() const { return cptr(); }
00154
00158 const T* cptr() const { return m_feature; }
00159
00163 operator const HLT::TriggerElement*() const { return m_te; }
00164
00168 const HLT::TriggerElement* te() const { return m_te; }
00169
00173 operator const std::string() const { return m_label; }
00174
00178 const std::string& label() const { return m_label; }
00179
00183 bool empty() const { return (!m_te || !m_feature); }
00184
00185 bool owned() const { return m_owned; }
00186
00187 #ifndef __GCCXML__
00188 link_type link() const {return m_link;}
00189 #endif
00190
00191 private:
00192 std::shared_ptr<const T> m_owning_feature;
00193 const T* m_feature;
00194 const HLT::TriggerElement* m_te;
00195 std::string m_label;
00196 bool m_owned;
00197 #ifndef __GCCXML__
00198 link_type m_link;
00199 #endif
00200 };
00201
00202
00206 template<class T>
00207 bool sameObject(const Feature<T>& a, const Feature<T>& b) {
00208 return a.cptr() == b.cptr();
00209 }
00210
00211 }
00212
00213 template<class T>
00214 MsgStream& operator<< ( MsgStream& m, const Trig::Feature<T>& d ) {
00215 m << "TE id: " << d.te()->getId() << "obj ptr: " << d.cptr()
00216 << " obj type: " << ClassID_traits<T>::typeName() << " label: " << d.label();
00217 return m;
00218 }
00219 #endif