00001
00002 #ifndef TRIGGER_DECISION_TOOL_FeatureCollectStandalone_H
00003 #define TRIGGER_DECISION_TOOL_FeatureCollectStandalone_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 "TrigDecisionTool/Conditions.h"
00025 #include "TrigDecisionTool/TDTUtilities.h"
00026
00027 #include "TrigDecisionTool/Feature.h"
00028
00029 #include "TrigSteeringEvent/TrigPassBits.h"
00030 #include "TrigSteeringEvent/TrigPassBitsCollection.h"
00031
00032 #include "TrigSteeringEvent/TrigRoiDescriptor.h"
00033 #include "TrigRoiConversion/RoiSerialise.h"
00034 #include "xAODTrigger/RoiDescriptorStore.h"
00035
00036 #include "TrigDecisionTool/TypelessFeature.h"
00037 #include "TrigDecisionTool/EventPtrDef.h"
00038
00039 #include "TrigNavStructure/TrigNavStructure.h"
00040
00041 #include "AsgTools/AsgToolsConf.h"
00042 #include "AsgTools/Check.h"
00043
00044 #include "TrigNavStructure/TypedHolder.h"
00045
00046 namespace HLT{
00047 class TrigNavStructure;
00048 }
00049
00050
00051
00052 namespace Trig {
00053
00058 namespace FeatureAccessImpl{
00059
00060 HLT::TriggerElement::FeatureAccessHelper getTypelessBits(const HLT::TriggerElement* te, const HLT::TrigNavStructure* navigation);
00061
00062 void typelessCollect(const HLT::TriggerElement* te, HLT::class_id_type clid, std::vector<Trig::TypelessFeature>& data, const std::string& label, unsigned int condition, HLT::TrigNavStructure* navigation);
00063
00064
00065 template<typename REQUESTED,typename STORED, typename CONTAINER>
00066 std::vector<Trig::Feature<REQUESTED> > typedGet(const std::vector<TypelessFeature>& features, HLT::TrigNavStructure* navigation, EventPtr_t store,const std::string& container_name = ClassID_traits<CONTAINER>::typeName());
00067
00068
00070
00071
00072 template<typename STORED, typename REQUESTED>
00073 void insert_element(std::vector<Trig::Feature<REQUESTED> >&, Trig::TypelessFeature&, const STORED*);
00074
00075 template<typename REQUESTED>
00076 void insert_element(std::vector<Trig::Feature<REQUESTED> >& result, Trig::TypelessFeature& feature, const REQUESTED* element){
00077 result.push_back(Trig::Feature<REQUESTED>(feature,element));
00078 }
00079
00080
00081 template<typename STORED>
00082 void insert_flatten_if(std::vector<Trig::Feature<STORED> >& result, const Trig::TypelessFeature& feature, const std::shared_ptr<const STORED>& newfeature){
00083 result.push_back(Trig::Feature<STORED>(feature,newfeature));
00084 }
00085
00086 template<typename REQUESTED, typename STORED>
00087 void insert_flatten_if(std::vector<Trig::Feature<REQUESTED> >& result, const Trig::TypelessFeature& feature, const std::shared_ptr<const STORED>& newfeature){
00088 for(auto element : *newfeature){
00089 result.push_back(Trig::Feature<REQUESTED>(feature,element));
00090 }
00091 }
00092
00093
00094 template<typename STORED>
00095 std::shared_ptr<const STORED> filter_if(boost::mpl::bool_<true> is_same, std::shared_ptr<const STORED>& original,const TrigPassBits* bits){
00096 (void)is_same;
00097
00098
00099 if(original->size() != bits->size()){
00100 std::cerr << "WARNING: bits size and owned size" << std::endl;
00101 return original;
00102 }
00103 STORED* f = new STORED;
00104 f->clear(SG::VIEW_ELEMENTS);
00105
00106 for(auto obj : *original){
00107 if(HLT::isPassing(bits,obj,original.get())){
00108 f->push_back(const_cast<typename STORED::value_type>(obj));
00109 }
00110 }
00111
00112 std::shared_ptr<const STORED> filtered(f);
00113 return filtered;
00114 }
00115
00116 template<typename STORED>
00117 std::shared_ptr<const STORED> filter_if(boost::mpl::bool_<false> , std::shared_ptr<const STORED>& original,const TrigPassBits* ){
00118
00119 return original;
00120 }
00121
00122 template<typename REQUESTED,typename STORED, typename CONTAINER>
00123 std::vector<Trig::Feature<REQUESTED> > typedGet(const std::vector<TypelessFeature>& features, HLT::TrigNavStructure* navigation, EventPtr_t store, const std::string& container_name) {
00124 std::vector<Trig::Feature<REQUESTED> > typedvec;
00125
00126 for(auto feature : features){
00127 auto typelessholder = navigation->getHolder(feature.accessHelper());
00128 if(!typelessholder){
00129 std::cerr << "ERROR, holder not present" << std::endl;
00130 }
00131 HLT::TypedHolder<STORED,CONTAINER> typedholder(*typelessholder,store,container_name);
00132 const STORED* dest = 0;
00133
00134 StatusCode sc = typedholder.get(dest,feature.accessHelper().getIndex());
00135 if(sc.isFailure()){
00136 std::cerr << "TrigDecisionTool WARNING: Feature access failed for feature: " << feature.accessHelper() << std::endl;
00137 continue;
00138 }
00139
00140 if(boost::is_same<STORED,CONTAINER>::value){
00141
00142 std::shared_ptr<const STORED> owned(dest);
00143
00144 auto passbitsFeatureAccessHelper = FeatureAccessImpl::getTypelessBits(feature.te(),navigation);
00145 if(passbitsFeatureAccessHelper.valid()){
00146 #ifndef __CLING__
00147 auto passbitsHolder = navigation->getHolder(passbitsFeatureAccessHelper);
00148 HLT::TypedHolder<TrigPassBits,TrigPassBitsCollection> typedBits(*passbitsHolder,store);
00149 const TrigPassBits* bits = 0;
00150 if(typedBits.get(bits,passbitsFeatureAccessHelper.getIndex()).isFailure()){
00151 std::cerr << "WARNING: couldn't get passbits from Holder" << std::endl;
00152 }
00153 owned = filter_if(boost::is_same<STORED,CONTAINER>(),owned,bits);
00154 #endif
00155 }
00156
00157
00158 insert_flatten_if(typedvec,feature,owned);
00159 }
00160 else{
00161 if(boost::is_same<STORED,TrigRoiDescriptor>::value){
00162 std::shared_ptr<const STORED> owned(dest);
00163
00164 insert_flatten_if(typedvec,feature,owned);
00165 }
00166 else{
00167
00168 insert_element(typedvec,feature,dest);
00169 }
00170 }
00171 }
00172 return typedvec;
00173 }
00174 }
00175
00176 }
00177
00178
00179 namespace HLT{
00180 template<>
00181 class TypedHolder<TrigRoiDescriptor,TrigRoiDescriptorCollection> : public TypelessHolder, public asg::AsgMessaging {
00182 public:
00183 TypedHolder(const BaseHolder& baseholder, EventPtr store, const std::string& container_name = "")
00184 : TypelessHolder(baseholder.typeClid(),baseholder.label(),baseholder.subTypeIndex()),
00185 asg::AsgMessaging("TypedHolder"),
00186 m_store(store){
00187 (void)container_name;
00188 };
00189
00190 StatusCode get(const TrigRoiDescriptor*& destination, HLT::TriggerElement::ObjectIndex idx){
00191
00192 std::string key = HLTNavDetails::formatSGkey("HLT","xAOD::RoiDescriptorStore",this->label());
00193 const xAOD::RoiDescriptorStore* roistore = 0;
00194 ASG_CHECK(m_store->retrieve(roistore,key));
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 std::vector<const IRoiDescriptor*> rois;
00206 RoiUtil::deserialise( roistore->serialised(), rois );
00207 if((idx.objectsEnd() - idx.objectsBegin())!=1){
00208 ATH_MSG_ERROR("accessing RoI holder with key: is not single element: ");
00209 return StatusCode::FAILURE;
00210 }
00211
00212 if(rois.size() < idx.objectsBegin()){
00213 ATH_MSG_ERROR("deserialized roi collection too small");
00214 return StatusCode::FAILURE;
00215 };
00216 for (unsigned int index = 0; index < rois.size(); ++index){
00217 if(index == idx.objectsBegin()){
00218 destination = dynamic_cast<const TrigRoiDescriptor*>(rois.at(index));
00219 }
00220 else{
00221 delete rois.at(index);
00222 }
00223 }
00224 return StatusCode::SUCCESS;
00225 }
00226 private:
00227 EventPtr m_store;
00228 };
00229 }
00230
00231
00232
00233 #endif
00234
00235