00001
00002 #ifndef TRIGNAVSTRUCTURE_TYPEDHOLDER_H
00003 #define TRIGNAVSTRUCTURE_TYPEDHOLDER_H
00004
00005 #include <memory>
00006 #include <stdexcept>
00007 #include <type_traits>
00008 #include <boost/type_traits/is_same.hpp>
00009
00010 #include "TrigNavStructure/TypelessHolder.h"
00011 #include "TrigNavStructure/TriggerElement.h"
00012 #include "TrigNavStructure/TypelessHolder.h"
00013
00014 #include "AthContainers/OwnershipPolicy.h"
00015
00016 #ifdef ASGTOOL_STANDALONE //guarded b/c athena includes its own
00017 #include "xAODCore/ClassID_traits.h"
00018 #endif
00019
00020 #include "AsgTools/AsgToolsConf.h"
00021 #ifdef ASGTOOL_STANDALONE
00022 #include "AsgTools/SgTEvent.h"
00023 typedef asg::SgTEvent* EventPtr;
00024 #endif //ASGTOOL_STANDALONE
00025
00026 #ifdef ASGTOOL_ATHENA
00027 #include "StoreGate/StoreGateSvc.h"
00028 typedef StoreGateSvc* EventPtr;
00029 #endif //ASGTOOL_ATHENA
00030
00031 #include "AsgTools/AsgMessaging.h"
00032
00033
00034
00035 class TrigRoiDescriptor;
00036 class TrigRoiDescriptorCollection;
00037
00038 namespace HLTNavDetails{
00042 std::string formatSGkey(const std::string& prefix, const std::string& containername, const std::string& label);
00043 }
00044
00045 namespace HLT{
00046
00047
00048 template<typename FEATURE, typename CONTAINER> class TypedHolder;
00049
00050
00054 template<>
00055 class TypedHolder<TrigRoiDescriptor,TrigRoiDescriptorCollection>;
00056
00060 template<typename FEATURE, typename CONTAINER>
00061 class TypedHolder : public TypelessHolder, public asg::AsgMessaging {
00062 public:
00066 template<typename T,bool value> using StatusCode_if = typename std::enable_if<boost::is_same<T,CONTAINER>::value == value,StatusCode>::type;
00067
00072 TypedHolder(const BaseHolder& baseholder, EventPtr store, const std::string& container_name = ClassID_traits<CONTAINER>::typeName())
00073 : TypelessHolder(baseholder.typeClid(),baseholder.label(),baseholder.subTypeIndex()),
00074 asg::AsgMessaging("TypedHolder"),
00075 m_store(store),
00076 m_cont(0) {
00077
00078
00079 m_key = HLTNavDetails::formatSGkey("HLT",container_name,this->label());
00080 }
00081
00085 TypedHolder(const TypelessHolder& typeless, EventPtr store, const std::string& container_name = ClassID_traits<CONTAINER>::typeName())
00086 : TypelessHolder(typeless),
00087 asg::AsgMessaging("TypedHolder"),
00088 m_store(store),
00089 m_cont(0) {
00090
00091
00092 m_key = HLTNavDetails::formatSGkey("HLT",container_name,this->label());
00093 }
00094
00098 std::string key(){return m_key;}
00099
00105 template<typename T> StatusCode_if<T,true> get(const T*& destination, HLT::TriggerElement::ObjectIndex idx){
00106 if(syncWithStore().isFailure()){
00107 ATH_MSG_ERROR("accessing holder with key: " << key() << " sync with store failed ");
00108 return StatusCode::FAILURE;
00109 }
00110 if(m_cont->size() < idx.objectsEnd()){
00111 ATH_MSG_ERROR("accessing holder with key: " << key() << " index past range " << "idx range is: " << idx.objectsBegin() << ":" << idx.objectsEnd() << " container size: " << m_cont->size());
00112 return StatusCode::FAILURE;
00113 };
00114
00115
00116 if(destination){
00117
00118 return StatusCode::FAILURE;
00119 }
00120
00121 CONTAINER* nonConstDestination = new CONTAINER(SG::VIEW_ELEMENTS);
00122
00123
00124 CONTAINER* src = const_cast<CONTAINER*>(m_cont);
00125 typename CONTAINER::iterator beg = src->begin();
00126 typename CONTAINER::iterator end = src->begin();
00127
00128 std::advance(beg, idx.objectsBegin());
00129 std::advance(end, idx.objectsEnd());
00130 nonConstDestination->insert(nonConstDestination->end(), beg, end);
00131
00132
00133 destination = nonConstDestination;
00134 return StatusCode::SUCCESS;
00135 }
00136
00141 template<typename T> StatusCode_if<T,false> get(const T*& destination, HLT::TriggerElement::ObjectIndex idx){
00142 if((idx.objectsEnd() - idx.objectsBegin())!=1){
00143
00144 return StatusCode::FAILURE;
00145 }
00146 if(syncWithStore().isFailure()){
00147
00148 return StatusCode::FAILURE;
00149 }
00150 if(m_cont->size() < idx.objectsBegin()){
00151
00152 return StatusCode::FAILURE;
00153 };
00154
00155
00156 destination = m_cont->at(idx.objectsBegin());
00157 return StatusCode::SUCCESS;
00158 }
00159
00160 private:
00161
00165 StatusCode syncWithStore(){
00166 if(m_cont) return StatusCode::SUCCESS;
00167
00168 StatusCode sc = m_store->retrieve(m_cont,key());
00169
00170
00171 if(sc.isFailure()) return StatusCode::FAILURE;
00172 if(!m_cont) return StatusCode::FAILURE;
00173
00174 return StatusCode::SUCCESS;
00175 }
00176
00177 TypedHolder(){;}
00178 EventPtr m_store;
00179 const CONTAINER* m_cont;
00180 std::string m_key;
00181 };
00182
00183 }
00184
00185 #endif