forked from AIDASoft/podio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExampleReferencingTypeCollection.h
141 lines (106 loc) · 4.61 KB
/
ExampleReferencingTypeCollection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//AUTOMATICALLY GENERATED - DO NOT EDIT
#ifndef ExampleReferencingTypeCollection_H
#define ExampleReferencingTypeCollection_H
#include <string>
#include <vector>
#include <deque>
#include <array>
#include <algorithm>
// podio specific includes
#include "podio/ICollectionProvider.h"
#include "podio/CollectionBase.h"
#include "podio/CollectionIDTable.h"
// datamodel specific includes
#include "ExampleReferencingTypeData.h"
#include "ExampleReferencingType.h"
#include "ExampleReferencingTypeObj.h"
typedef std::vector<ExampleReferencingTypeData> ExampleReferencingTypeDataContainer;
typedef std::deque<ExampleReferencingTypeObj*> ExampleReferencingTypeObjPointerContainer;
class ExampleReferencingTypeCollectionIterator {
public:
ExampleReferencingTypeCollectionIterator(int index, const ExampleReferencingTypeObjPointerContainer* collection) : m_index(index), m_object(nullptr), m_collection(collection) {}
bool operator!=(const ExampleReferencingTypeCollectionIterator& x) const {
return m_index != x.m_index; //TODO: may not be complete
}
const ExampleReferencingType operator*() const;
const ExampleReferencingType* operator->() const;
const ExampleReferencingTypeCollectionIterator& operator++() const;
private:
mutable int m_index;
mutable ExampleReferencingType m_object;
const ExampleReferencingTypeObjPointerContainer* m_collection;
};
/**
A Collection is identified by an ID.
*/
class ExampleReferencingTypeCollection : public podio::CollectionBase {
public:
typedef const ExampleReferencingTypeCollectionIterator const_iterator;
ExampleReferencingTypeCollection();
// ExampleReferencingTypeCollection(const ExampleReferencingTypeCollection& ) = delete; // deletion doesn't work w/ ROOT IO ! :-(
// ExampleReferencingTypeCollection(ExampleReferencingTypeVector* data, int collectionID);
~ExampleReferencingTypeCollection();
void clear();
/// Append a new object to the collection, and return this object.
ExampleReferencingType create();
/// Append a new object to the collection, and return this object.
/// Initialized with the parameters given
template<typename... Args>
ExampleReferencingType create(Args&&... args);
int size() const;
/// Returns the const object of given index
const ExampleReferencingType operator[](unsigned int index) const;
/// Returns the object of a given index
ExampleReferencingType operator[](unsigned int index);
/// Returns the const object of given index
const ExampleReferencingType at(unsigned int index) const;
/// Returns the object of given index
ExampleReferencingType at(unsigned int index);
/// Append object to the collection
void push_back(ConstExampleReferencingType object);
void prepareForWrite();
void prepareAfterRead();
void setBuffer(void* address);
bool setReferences(const podio::ICollectionProvider* collectionProvider);
podio::CollRefCollection* referenceCollections() { return &m_refCollections;};
void setID(unsigned ID){
m_collectionID = ID;
std::for_each(m_entries.begin(),m_entries.end(),
[ID](ExampleReferencingTypeObj* obj){obj->id = {obj->id.index,static_cast<int>(ID)}; }
);
};
bool isValid() const {
return m_isValid;
}
// support for the iterator protocol
const const_iterator begin() const {
return const_iterator(0, &m_entries);
}
const const_iterator end() const {
return const_iterator(m_entries.size(), &m_entries);
}
/// returns the address of the pointer to the data buffer
void* getBufferAddress() { return (void*)&m_data;};
/// returns the pointer to the data buffer
std::vector<ExampleReferencingTypeData>* _getBuffer() { return m_data;};
private:
bool m_isValid;
int m_collectionID;
ExampleReferencingTypeObjPointerContainer m_entries;
// members to handle 1-to-N-relations
std::vector<::ConstExampleCluster>* m_rel_Clusters; ///< Relation buffer for read / write
std::vector<std::vector<::ConstExampleCluster>*> m_rel_Clusters_tmp; ///< Relation buffer for internal book-keeping
std::vector<::ConstExampleReferencingType>* m_rel_Refs; ///< Relation buffer for read / write
std::vector<std::vector<::ConstExampleReferencingType>*> m_rel_Refs_tmp; ///< Relation buffer for internal book-keeping
// members to handle streaming
podio::CollRefCollection m_refCollections;
ExampleReferencingTypeDataContainer* m_data;
};
template<typename... Args>
ExampleReferencingType ExampleReferencingTypeCollection::create(Args&&... args){
int size = m_entries.size();
auto obj = new ExampleReferencingTypeObj({size,m_collectionID},{args...});
m_entries.push_back(obj);
return ExampleReferencingType(obj);
}
#endif