1#ifndef PODIO_TESTS_WRITE_TEST_H
2#define PODIO_TESTS_WRITE_TEST_H
5#include "datamodel/EventInfoCollection.h"
6#include "datamodel/ExampleClusterCollection.h"
7#include "datamodel/ExampleHitCollection.h"
8#include "datamodel/ExampleMCCollection.h"
9#include "datamodel/ExampleReferencingTypeCollection.h"
10#include "datamodel/ExampleWithARelationCollection.h"
11#include "datamodel/ExampleWithArrayCollection.h"
12#include "datamodel/ExampleWithComponentCollection.h"
13#include "datamodel/ExampleWithFixedWidthIntegersCollection.h"
14#include "datamodel/ExampleWithNamespaceCollection.h"
15#include "datamodel/ExampleWithOneRelationCollection.h"
16#include "datamodel/ExampleWithVectorMemberCollection.h"
27template <
class WriterT>
29 std::cout <<
"start processing" << std::endl;
31 auto& info = store.
create<EventInfoCollection>(
"info");
32 auto& mcps = store.
create<ExampleMCCollection>(
"mcparticles");
33 auto& moreMCs = store.
create<ExampleMCCollection>(
"moreMCs");
34 auto& mcpsRefs = store.
create<ExampleMCCollection>(
"mcParticleRefs");
35 mcpsRefs.setSubsetCollection();
36 auto& hits = store.
create<ExampleHitCollection>(
"hits");
37 auto& hitRefs = store.
create<ExampleHitCollection>(
"hitRefs");
38 hitRefs.setSubsetCollection();
39 auto& clusters = store.
create<ExampleClusterCollection>(
"clusters");
40 auto& refs = store.
create<ExampleReferencingTypeCollection>(
"refs");
41 auto& refs2 = store.
create<ExampleReferencingTypeCollection>(
"refs2");
42 auto& comps = store.
create<ExampleWithComponentCollection>(
"Component");
43 auto& oneRels = store.
create<ExampleWithOneRelationCollection>(
"OneRelation");
44 auto& vecs = store.
create<ExampleWithVectorMemberCollection>(
"WithVectorMember");
45 auto& namesps = store.
create<ex42::ExampleWithNamespaceCollection>(
"WithNamespaceMember");
46 auto& namesprels = store.
create<ex42::ExampleWithARelationCollection>(
"WithNamespaceRelation");
47 auto& cpytest = store.
create<ex42::ExampleWithARelationCollection>(
"WithNamespaceRelationCopy");
48 auto& arrays = store.
create<ExampleWithArrayCollection>(
"arrays");
49 auto& fixedWidthInts = store.
create<ExampleWithFixedWidthIntegersCollection>(
"fixedWidthInts");
53 writer.registerForWrite(
"info");
54 writer.registerForWrite(
"mcparticles");
55 writer.registerForWrite(
"moreMCs");
56 writer.registerForWrite(
"mcParticleRefs");
57 writer.registerForWrite(
"hits");
58 writer.registerForWrite(
"hitRefs");
59 writer.registerForWrite(
"clusters");
60 writer.registerForWrite(
"refs");
61 writer.registerForWrite(
"refs2");
62 writer.registerForWrite(
"Component");
63 writer.registerForWrite(
"OneRelation");
64 writer.registerForWrite(
"WithVectorMember");
65 writer.registerForWrite(
"WithNamespaceMember");
66 writer.registerForWrite(
"WithNamespaceRelation");
67 writer.registerForWrite(
"WithNamespaceRelationCopy");
68 writer.registerForWrite(
"arrays");
69 writer.registerForWrite(
"fixedWidthInts");
70 writer.registerForWrite(
"userInts");
71 writer.registerForWrite(
"userDoubles");
73 unsigned nevents = 2000;
75 for (
unsigned i = 0; i < nevents; ++i) {
77 std::cout <<
"processing event " << i << std::endl;
80 auto item1 = MutableEventInfo();
82 info.push_back(item1);
85 evtMD.
setValue(
"UserEventWeight", (
float)100. * i);
87 ss <<
" event_number_" << i;
88 evtMD.setValue(
"UserEventName", ss.str());
89 evtMD.setValue(
"SomeVectorData", {1, 2, 3, 4});
90 evtMD.setValue(
"SomeVectorData", {i * 1.1, i * 2.2});
93 colMD.
setValue(
"CellIDEncodingString",
"system:8,barrel:3,layer:6,slice:5,x:-16,y:-16");
95 auto hit1 = ExampleHit(0xbad, 0., 0., 0., 23. + i);
96 auto hit2 = ExampleHit(0xcaffee, 1., 0., 0., 12. + i);
101 hitRefs.push_back(hit2);
102 hitRefs.push_back(hit1);
105 auto mcp0 = ExampleMC();
106 auto mcp1 = ExampleMC();
107 auto mcp2 = ExampleMC();
108 auto mcp3 = ExampleMC();
109 auto mcp4 = ExampleMC();
110 auto mcp5 = ExampleMC();
111 auto mcp6 = ExampleMC();
112 auto mcp7 = ExampleMC();
113 auto mcp8 = ExampleMC();
114 auto mcp9 = ExampleMC();
116 mcps.push_back(mcp0);
117 mcps.push_back(mcp1);
118 mcps.push_back(mcp2);
119 mcps.push_back(mcp3);
120 mcps.push_back(mcp4);
121 mcps.push_back(mcp5);
122 mcps.push_back(mcp6);
123 mcps.push_back(mcp7);
124 mcps.push_back(mcp8);
125 mcps.push_back(mcp9);
128 mcp.adddaughters(mcps[2]);
129 mcp.adddaughters(mcps[3]);
130 mcp.adddaughters(mcps[4]);
131 mcp.adddaughters(mcps[5]);
133 mcp.adddaughters(mcps[2]);
134 mcp.adddaughters(mcps[3]);
135 mcp.adddaughters(mcps[4]);
136 mcp.adddaughters(mcps[5]);
138 mcp.adddaughters(mcps[6]);
139 mcp.adddaughters(mcps[7]);
140 mcp.adddaughters(mcps[8]);
141 mcp.adddaughters(mcps[9]);
143 mcp.adddaughters(mcps[6]);
144 mcp.adddaughters(mcps[7]);
145 mcp.adddaughters(mcps[8]);
146 mcp.adddaughters(mcps[9]);
151 for (
auto mc : mcps) {
152 for (
auto p : mc.daughters()) {
153 int dIndex = p.getObjectID().index;
154 auto d = mcps[dIndex];
159 for (
auto p : mcps) {
160 std::cout <<
" particle " << p.getObjectID().index <<
" has daughters: ";
161 for (
auto it = p.daughters_begin(), end = p.daughters_end(); it != end; ++it) {
162 std::cout <<
" " << it->getObjectID().index;
164 std::cout <<
" and parents: ";
165 for (
auto it = p.parents_begin(), end = p.parents_end(); it != end; ++it) {
166 std::cout <<
" " << it->getObjectID().index;
168 std::cout << std::endl;
172 std::cout <<
"The const particle still has the same relations: daughters: ";
173 for (
auto it = constP.daughters_begin(); it != constP.daughters_end(); ++it) {
174 std::cout <<
" " << it->getObjectID().index;
176 std::cout <<
" and parents: ";
177 for (
auto it = constP.parents_begin(); it != constP.parents_end(); ++it) {
178 std::cout <<
" " << it->getObjectID().index;
186 for (
const auto&& mc : mcps) {
187 moreMCs.push_back(mc.clone());
191 for (
auto p : mcps) {
193 mcpsRefs.push_back(p);
197 for (
auto p : moreMCs) {
198 if (p.id() % 2 == 0) {
199 mcpsRefs.push_back(p);
203 if (mcpsRefs.size() != mcps.size()) {
204 throw std::runtime_error(
205 "The mcParticleRefs collection should now contain as many elements as the mcparticles collection");
209 auto cluster = MutableExampleCluster();
210 auto clu0 = MutableExampleCluster();
211 auto clu1 = MutableExampleCluster();
214 clu0.energy(hit1.energy());
216 clu1.energy(hit2.energy());
217 cluster.addHits(hit1);
218 cluster.addHits(hit2);
219 cluster.energy(hit1.energy() + hit2.energy());
220 cluster.addClusters(clu0);
221 cluster.addClusters(clu1);
223 clusters.push_back(clu0);
224 clusters.push_back(clu1);
225 clusters.push_back(cluster);
227 auto ref = MutableExampleReferencingType();
230 auto ref2 = ExampleReferencingType();
231 refs2.push_back(ref2);
233 ref.addClusters(cluster);
236 auto comp = MutableExampleWithComponent();
237 comp.component().data.x = 0;
238 comp.component().data.y = 1;
239 comp.component().data.z = i;
240 comps.push_back(comp);
242 auto cyclic = MutableExampleReferencingType();
243 cyclic.addRefs(cyclic);
244 refs.push_back(cyclic);
246 auto oneRel = MutableExampleWithOneRelation();
247 oneRel.cluster(cluster);
248 oneRels.push_back(oneRel);
251 auto oneRelEmpty = ExampleWithOneRelation();
252 oneRels.push_back(oneRelEmpty);
254 auto vec = MutableExampleWithVectorMember();
256 vec.addcount(i + 10);
258 auto vec1 = MutableExampleWithVectorMember();
259 vec1.addcount(i + 1);
260 vec1.addcount(i + 11);
261 vecs.push_back(vec1);
263 for (
int j = 0; j < 5; j++) {
264 auto rel = ex42::MutableExampleWithARelation();
266 auto exWithNamesp = ex42::MutableExampleWithNamespace();
267 exWithNamesp.component().x = i;
268 exWithNamesp.component().y = 1000 * i;
269 namesps.push_back(exWithNamesp);
271 rel.ref(exWithNamesp);
272 for (
int k = 0; k < 5; k++) {
273 auto namesp = ex42::MutableExampleWithNamespace();
275 namesp.component().y = k;
276 namesps.push_back(namesp);
280 namesprels.push_back(rel);
282 for (
auto&& namesprel : namesprels) {
283 cpytest.push_back(namesprel.clone());
286 std::array<int, 4> arrayTest = {0, 0, 2, 3};
287 std::array<int, 4> arrayTest2 = {4, 4, 2 *
static_cast<int>(i)};
289 a.data.p = arrayTest2;
290 ex2::NamespaceStruct nstruct;
291 nstruct.x =
static_cast<int>(i);
292 std::array<ex2::NamespaceStruct, 4> structArrayTest = {nstruct, nstruct, nstruct, nstruct};
293 auto array = MutableExampleWithArray(a, arrayTest, arrayTest, arrayTest, arrayTest, structArrayTest);
295 array.arrayStruct(a);
296 arrays.push_back(array);
298 auto maxValues = fixedWidthInts.create();
299 maxValues.fixedI16(std::numeric_limits<std::int16_t>::max());
300 maxValues.fixedU32(std::numeric_limits<std::uint32_t>::max());
301 maxValues.fixedU64(std::numeric_limits<std::uint64_t>::max());
302 auto& maxComp = maxValues.fixedWidthStruct();
303 maxComp.fixedUnsigned16 = std::numeric_limits<std::uint16_t>::max();
304 maxComp.fixedInteger64 = std::numeric_limits<std::int64_t>::max();
305 maxComp.fixedInteger32 = std::numeric_limits<std::int32_t>::max();
307 auto minValues = fixedWidthInts.create();
308 minValues.fixedI16(std::numeric_limits<std::int16_t>::min());
309 minValues.fixedU32(std::numeric_limits<std::uint32_t>::min());
310 minValues.fixedU64(std::numeric_limits<std::uint64_t>::min());
311 auto& minComp = minValues.fixedWidthStruct();
312 minComp.fixedUnsigned16 = std::numeric_limits<std::uint16_t>::min();
313 minComp.fixedInteger64 = std::numeric_limits<std::int64_t>::min();
314 minComp.fixedInteger32 = std::numeric_limits<std::int32_t>::min();
316 auto arbValues = fixedWidthInts.create();
317 arbValues.fixedI16(-12345);
318 arbValues.fixedU32(1234567890);
319 arbValues.fixedU64(1234567890123456789);
320 auto& arbComp = arbValues.fixedWidthStruct();
321 arbComp.fixedUnsigned16 = 12345;
322 arbComp.fixedInteger32 = -1234567890;
323 arbComp.fixedInteger64 = -1234567890123456789ll;
326 auto& uivec = usrInts;
329 for (
auto& iu : uivec) {
335 for (
unsigned id = 0;
id < nd; ++id) {
336 usrDoubles[id] = 42.;
GenericParameters & getEventMetaData() override
return the event meta data for the current event
void clearCollections()
empties collections.
T & create(const std::string &name)
create a new collection
GenericParameters & getCollectionMetaData(int colID) override
return the collection meta data for the given colID
void setValue(const std::string &key, T value)
Store (a copy of) the passed value under the given key.
void resize(size_t count)
void write(podio::EventStore &store, WriterT &writer)