BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Event/GeneratorObject/include/DataModel/ElementLink.h
Go to the documentation of this file.
1#ifndef DATAMODEL_ELEMENTLINK_H
2#define DATAMODEL_ELEMENTLINK_H
3
4#ifndef DATAMODEL_TOOLS_GENERATEINDEXINGPOLICY_H
5# include "DataModel/tools/GenerateIndexingPolicy.h"
6#endif
7
8#ifndef DATAMODEL_TOOLS_DATAPROXYSTORAGE_H
9# include "DataModel/tools/DataProxyStorage.h"
10#endif
11
12#ifndef __EXCEPTION__
13# include <exception>
14#endif
15
16/** @class ElementLink
17 * @brief a persistable pointer to an element of a STORABLE (data object)
18 *
19 * @param STORABLE host object type (e,g. vector<Elem>, NOT Elem),
20 * @param StoragePolicy STORABLE management policy (defaults to DataProxyStorage)
21 * @param IndexingPolicy policy to find the element in the host STORABLE \n
22 * IndexingPolicy is generated automatically for STL sequences
23 * (e.g. vector, DataList etc). For other types of containers
24 * (e.g. maps), the container author must define the container type
25 * using the macros in tools/DeclareIndexingPolicies.h \n
26 * Advanced developers may have to define an ad-hoc indexing policy
27 * (e.g. GenParticleIndexing in GeneratorObjects/McEventIndexingPolicy.h)
28 *
29 * @author ATLAS Collaboration
30 * $Id: ElementLink.h,v 1.3 2003/06/04 16:01:22 calaf Exp $
31 **/
32
33class IProxyDict;
34
35template <typename STORABLE, class StoragePolicy = DataProxyStorage<STORABLE>,
36 class IndexingPolicy = typename SG::GenerateIndexingPolicy<STORABLE>::type>
37class ElementLink : public StoragePolicy, public IndexingPolicy {
38private:
39 typedef typename IndexingPolicy::pointer pointer;
40
41public:
42 // typedef typename StoragePolicy::ID_type ID_type;
43 typedef typename std::string ID_type;
44 // typedef typename StoragePolicy::const_reference BaseConstReference;
45 typedef const STORABLE& BaseConstReference;
46 typedef typename IndexingPolicy::index_type index_type;
47 typedef typename IndexingPolicy::ElementParameter ElementParameter;
48 typedef typename IndexingPolicy::ElementConstReference ElementConstReference;
49 typedef typename IndexingPolicy::ElementConstPointer ElementConstPointer;
50 typedef typename IndexingPolicy::ElementPointer ElementPointer;
51
52 // CONSTRUCTORS
53 /// default
54 ElementLink( IProxyDict* sg = StoragePolicy::defaultDataSource() )
55 : StoragePolicy( sg ), IndexingPolicy(), m_element( 0 ) {}
56
57 /// o(1) version: provide storable key and element index
59 IProxyDict* sg = StoragePolicy::defaultDataSource() )
60 : StoragePolicy( dataID, sg ), IndexingPolicy( elemID ), m_element( 0 ) {}
61 /// o(1) version: provide storable key, element index AND element ptr
62 /// USE CAREFULLY: no coherency checks, we just trust you!
64 : StoragePolicy( dataID, 0 ), IndexingPolicy( elemID ), m_element( pEl ) {}
65 /// o(1) version: provide index (identifier) of owned object
66 /// and a pointer to the storable
67 ///@throws std::invalid_argument when the element is not found
69 IProxyDict* sg = StoragePolicy::defaultDataSource() )
70 : StoragePolicy( data, sg ), IndexingPolicy( elemID ), m_element( 0 ) {}
71 // up to o(n) version: using a ref to the storable and to the element
72 //! this will trigger a linear search for sequence
73 // storables such as vectors and lists!
74 // notice that the element argument is a pointer. This is to remove
75 // an ambiguity with the previous constructor when the storable is a
76 // container of integers (or more in general of types convertible to
77 // index type. This constructor will throw when the pointer is NULL
78 // or when the element is not found
79 // NOT YET ElementLink(BaseConstReference data, ElementConstReference element,
80 // NOT YET DataSource* sg=StoragePolicy::defaultDataSource());
81 // throw (std::invalid_argument)
82
83 /// \name Modifiers, use to make an ElementLink persistable
84 //@{
85 /// set link to point to given index: FAST
87 /// set link to point to given element: O(n) for sequences!
89 /// set link storable to data object pointed by data
90 void setStorableObject( BaseConstReference data ) { StoragePolicy::setData( data ); }
91 //@}
92
93 /// \name Accessors
94 //@{
95 /// @throws std::runtime_error when the element is not found
97
98 ElementConstPointer operator->() const { return cptr(); }
99 operator ElementConstPointer() const { return cptr(); }
101
102 bool isValid() const { return ( 0 != cptr() ); }
103 bool operator!() const { return !isValid(); }
104 //@}
105
106private:
107 /// cache element we are linking - mutable for cptr
108 mutable ElementPointer m_element;
109};
110
111// inserters and extractors
112
113template <class OS, typename STORABLE, class DLB, class IDX>
115
116template <class IS, typename STORABLE, class DLB, class IDX>
118
119#include "DataModel/ElementLink.icc"
120
121#ifndef DATAMODEL_TOOLS_PLAINPTRSTORAGE_H
122# include "DataModel/tools/PlainPtrStorage.h"
123#endif
124
125/// @class PlainPtrElementLink
126/// @brief helper struct to be used as type generator
127/// e.g. PlainPtrElementLink<vector<int> >::type
128template <typename STORABLE,
129 class IndexingPolicy = typename SG::GenerateIndexingPolicy<STORABLE>::type>
133#endif /*ELEMENTLINK_H*/
TTree * data
boost::detail::if_true<(isSTLSequence)>::template then< ForwardIndexingPolicy< CONTAINER >, typenameDefaultIndexingPolicy< CONTAINER >::type >::type type