00001
00002
00003 #ifndef ATHLINKS_ELEMENTLINK_H
00004 #define ATHLINKS_ELEMENTLINK_H
00005
00006
00007 extern "C" {
00008 # include <stdint.h>
00009 }
00010 #include <string>
00011
00012
00013 #include "AthLinks/ElementLinkBase.h"
00014 #include "AthLinks/tools/selection_ns.h"
00015 #include "AthLinks/tools/TypeTools.h"
00016
00017
00018 ENTER_ROOT_SELECTION_NS
00019 template< typename STORABLE >
00020 class ElementLink;
00021 EXIT_ROOT_SELECTION_NS
00022 namespace xAOD {
00023 class TVirtualEvent;
00024 }
00025
00038 template< typename STORABLE >
00039 class ElementLink : public ElementLinkBase {
00040
00041 public:
00044
00046 typedef std::string ID_type;
00048 typedef uint32_t sgkey_t;
00049
00051 typedef const STORABLE& BaseConstReference;
00053 typedef const STORABLE* BaseConstPointer;
00054
00056 typedef size_t index_type;
00057
00059 typedef typename STORABLE::value_type value_type;
00061 typedef typename STORABLE::const_iterator const_iterator;
00062
00064 typedef typename TypeTools::Copy< value_type >::type ElementType;
00066 typedef typename TypeTools::Copy< value_type >::const_reference
00067 ElementConstReference;
00069 typedef typename TypeTools::Copy< value_type >::const_pointer
00070 ElementConstPointer;
00071
00073
00076
00078 ElementLink();
00080 ElementLink( xAOD::TVirtualEvent* event );
00081
00083 ElementLink( const ID_type& key, index_type index,
00084 xAOD::TVirtualEvent* event = 0 );
00086 ElementLink( sgkey_t id, index_type index,
00087 xAOD::TVirtualEvent* event = 0 );
00088
00092 ElementLink( const ID_type& key, index_type index, ElementType element,
00093 xAOD::TVirtualEvent* event = 0 );
00097 ElementLink( sgkey_t id, index_type index, ElementType element,
00098 xAOD::TVirtualEvent* event = 0 );
00099
00101 ElementLink( BaseConstReference container, index_type index,
00102 xAOD::TVirtualEvent* event = 0 );
00104 ElementLink( ElementType element, BaseConstReference container,
00105 xAOD::TVirtualEvent* event = 0 );
00106
00108 ElementLink( const ElementLink& parent );
00109
00111
00113 ElementLink& operator=( const ElementLink& rhs );
00114
00117
00119 bool toIndexedElement( BaseConstReference container, index_type index );
00121 bool toContainedElement( BaseConstReference container, ElementType element );
00122
00124 bool setElement( ElementType element );
00126 bool setStorableObject( BaseConstReference data, bool replace = false );
00127
00129 void resetWithKeyAndIndex( const ID_type& key, index_type index,
00130 xAOD::TVirtualEvent* event = 0 );
00132 void resetWithKeyAndIndex( sgkey_t id, index_type index,
00133 xAOD::TVirtualEvent* event = 0 );
00135 void reset();
00136
00138
00141
00143 BaseConstPointer getStorableObjectPointer() const;
00145 BaseConstReference getStorableObjectRef() const;
00146
00148 index_type index() const { return persIndex(); }
00149
00151 const ID_type& dataID() const;
00153 sgkey_t key() const { return persKey(); }
00154
00156 ElementConstReference operator*() const;
00157
00159 ElementConstPointer operator->() const { return cptr(); }
00161 operator ElementConstPointer () const { return cptr(); }
00163 ElementConstPointer cptr() const;
00164
00166 bool isValid() const;
00168 bool operator!() const { return ! isValid(); }
00169
00171 ElementType cachedElement() const { return m_element; }
00173 bool hasCachedElement() const { return m_elementCached; }
00174
00176
00178 xAOD::TVirtualEvent* source() const { return m_event; }
00179
00181 bool toPersistent() { return true; }
00182
00183 private:
00185 virtual bool toTransient();
00187 void findIdentifier();
00189 void findIndex();
00190
00192 mutable BaseConstPointer m_container;
00194 mutable ElementType m_element;
00196 mutable bool m_elementCached;
00198 xAOD::TVirtualEvent* m_event;
00199
00201 typedef typename
00202 ROOT_SELECTION_NS::ElementLink< STORABLE >::self DictSel;
00203
00204 };
00205
00206
00207
00208
00209
00210 ENTER_ROOT_SELECTION_NS
00211 template< typename STORABLE >
00212 class ElementLink
00213 #if ROOT_VERSION_CODE >= ROOT_VERSION( 6, 0, 2 )
00214 : public SelectNoInstance
00215 #endif
00216 {
00217
00218 public:
00220 typedef ElementLink< STORABLE > self;
00221
00222 #if ROOT_VERSION_CODE < ROOT_VERSION( 5, 99, 0 )
00223
00225 ROOT_SELECTION_NS::NO_SELF_AUTOSELECT dummy;
00226
00228 ROOT_SELECTION_NS::TRANSIENT m_container;
00229 ROOT_SELECTION_NS::TRANSIENT m_element;
00230 ROOT_SELECTION_NS::TRANSIENT m_elementCached;
00231 ROOT_SELECTION_NS::TRANSIENT m_event;
00232
00233 #else
00234
00236 ROOT_SELECTION_NS::MemberAttributes< kTransient > m_container;
00237 ROOT_SELECTION_NS::MemberAttributes< kTransient > m_element;
00238 ROOT_SELECTION_NS::MemberAttributes< kTransient > m_elementCached;
00239 ROOT_SELECTION_NS::MemberAttributes< kTransient > m_event;
00240
00241 #endif // ROOT_VERSION
00242
00243 };
00244 EXIT_ROOT_SELECTION_NS
00245
00246
00247 #ifndef __GCCXML__
00248 # include "ElementLink.icc"
00249 #endif // __GCCXML__
00250
00251 #endif // ATHLINKS_ELEMENTLINK_H