1#ifndef PODIO_TESTS_WRITE_FRAME_H
2#define PODIO_TESTS_WRITE_FRAME_H
4#include "datamodel/EventInfoCollection.h"
5#include "datamodel/ExampleClusterCollection.h"
6#include "datamodel/ExampleHitCollection.h"
7#include "datamodel/ExampleMCCollection.h"
8#include "datamodel/ExampleReferencingTypeCollection.h"
9#include "datamodel/ExampleWithARelationCollection.h"
10#include "datamodel/ExampleWithArrayCollection.h"
11#include "datamodel/ExampleWithFixedWidthIntegersCollection.h"
12#include "datamodel/ExampleWithNamespaceCollection.h"
13#include "datamodel/ExampleWithOneRelationCollection.h"
14#include "datamodel/ExampleWithVectorMemberCollection.h"
16#include "extension_model/ContainedTypeCollection.h"
17#include "extension_model/ExternalComponentTypeCollection.h"
18#include "extension_model/ExternalRelationTypeCollection.h"
27static const std::vector<std::string> collsToWrite = {
"mcparticles",
42 "WithNamespaceMember",
43 "WithNamespaceRelation",
44 "WithNamespaceRelationCopy",
49 auto mcps = ExampleMCCollection();
52 auto mcp0 = mcps.create();
53 auto mcp1 = mcps.create();
54 auto mcp2 = mcps.create();
55 auto mcp3 = mcps.create();
56 auto mcp4 = mcps.create();
57 auto mcp5 = mcps.create();
58 auto mcp6 = mcps.create();
59 auto mcp7 = mcps.create();
60 auto mcp8 = mcps.create();
61 auto mcp9 = mcps.create();
64 mcp.adddaughters(mcps[2]);
65 mcp.adddaughters(mcps[3]);
66 mcp.adddaughters(mcps[4]);
67 mcp.adddaughters(mcps[5]);
69 mcp.adddaughters(mcps[2]);
70 mcp.adddaughters(mcps[3]);
71 mcp.adddaughters(mcps[4]);
72 mcp.adddaughters(mcps[5]);
74 mcp.adddaughters(mcps[6]);
75 mcp.adddaughters(mcps[7]);
76 mcp.adddaughters(mcps[8]);
77 mcp.adddaughters(mcps[9]);
79 mcp.adddaughters(mcps[6]);
80 mcp.adddaughters(mcps[7]);
81 mcp.adddaughters(mcps[8]);
82 mcp.adddaughters(mcps[9]);
87 for (
auto mc : mcps) {
88 for (
auto p : mc.daughters()) {
89 int dIndex = p.getObjectID().index;
90 auto d = mcps[dIndex];
99 auto arrays = ExampleWithArrayCollection();
101 std::array<int, 4> arrayTest = {0, 0, 2, 3};
102 std::array<int, 4> arrayTest2 = {4, 4, 2 *
static_cast<int>(i)};
104 a.data.p = arrayTest2;
105 ex2::NamespaceStruct nstruct;
106 nstruct.x =
static_cast<int>(i);
107 std::array<ex2::NamespaceStruct, 4> structArrayTest = {nstruct, nstruct, nstruct, nstruct};
108 auto array = MutableExampleWithArray(a, arrayTest, arrayTest, arrayTest, arrayTest, structArrayTest);
110 array.arrayStruct(a);
111 arrays.push_back(array);
117 auto mcpsRefs = ExampleMCCollection();
118 mcpsRefs.setSubsetCollection();
120 for (
auto p : mcps) {
122 mcpsRefs.push_back(p);
126 for (
auto p : moreMCs) {
127 if (p.id() % 2 == 0) {
128 mcpsRefs.push_back(p);
132 if (mcpsRefs.size() != mcps.size()) {
133 throw std::runtime_error(
134 "The mcParticleRefs collection should now contain as many elements as the mcparticles collection");
141 ExampleHitCollection hits;
143 auto hit1 = ExampleHit(0xbad, 0., 0., 0., 23. + i);
144 auto hit2 = ExampleHit(0xcaffee, 1., 0., 0., 12. + i);
146 hits.push_back(hit1);
147 hits.push_back(hit2);
153 ExampleHitCollection hitRefs;
154 hitRefs.setSubsetCollection();
156 hitRefs.push_back(hits[1]);
157 hitRefs.push_back(hits[0]);
163 ExampleClusterCollection clusters;
165 auto cluster = MutableExampleCluster();
166 auto clu0 = MutableExampleCluster();
167 auto clu1 = MutableExampleCluster();
173 clu0.energy(hit1.energy());
175 clu1.energy(hit2.energy());
176 cluster.addHits(hit1);
177 cluster.addHits(hit2);
178 cluster.energy(hit1.energy() + hit2.energy());
179 cluster.addClusters(clu0);
180 cluster.addClusters(clu1);
182 clusters.push_back(clu0);
183 clusters.push_back(clu1);
184 clusters.push_back(cluster);
190 auto retType = std::tuple<ExampleReferencingTypeCollection, ExampleReferencingTypeCollection>();
191 auto& [refs, refs2] = retType;
193 auto ref = MutableExampleReferencingType();
196 auto ref2 = ExampleReferencingType();
197 refs2.push_back(ref2);
199 ref.addClusters(clusters[2]);
202 auto cyclic = MutableExampleReferencingType();
203 cyclic.addRefs(cyclic);
204 refs.push_back(cyclic);
210 ExampleWithOneRelationCollection oneRels;
212 auto oneRel = MutableExampleWithOneRelation();
213 oneRel.cluster(clusters[2]);
214 oneRels.push_back(oneRel);
217 auto oneRelEmpty = ExampleWithOneRelation();
218 oneRels.push_back(oneRelEmpty);
224 ExampleWithVectorMemberCollection vecs;
226 auto vec = MutableExampleWithVectorMember();
228 vec.addcount(i + 10);
230 auto vec1 = MutableExampleWithVectorMember();
231 vec1.addcount(i + 1);
232 vec1.addcount(i + 11);
233 vecs.push_back(vec1);
239 EventInfoCollection info;
241 auto item1 = MutableEventInfo();
243 info.push_back(item1);
249 auto fixedWidthInts = ExampleWithFixedWidthIntegersCollection();
251 auto maxValues = fixedWidthInts.create();
252 maxValues.fixedI16(std::numeric_limits<std::int16_t>::max());
253 maxValues.fixedU32(std::numeric_limits<std::uint32_t>::max());
254 maxValues.fixedU64(std::numeric_limits<std::uint64_t>::max());
255 auto& maxComp = maxValues.fixedWidthStruct();
256 maxComp.fixedUnsigned16 = std::numeric_limits<std::uint16_t>::max();
257 maxComp.fixedInteger64 = std::numeric_limits<std::int64_t>::max();
258 maxComp.fixedInteger32 = std::numeric_limits<std::int32_t>::max();
260 auto minValues = fixedWidthInts.create();
261 minValues.fixedI16(std::numeric_limits<std::int16_t>::min());
262 minValues.fixedU32(std::numeric_limits<std::uint32_t>::min());
263 minValues.fixedU64(std::numeric_limits<std::uint64_t>::min());
264 auto& minComp = minValues.fixedWidthStruct();
265 minComp.fixedUnsigned16 = std::numeric_limits<std::uint16_t>::min();
266 minComp.fixedInteger64 = std::numeric_limits<std::int64_t>::min();
267 minComp.fixedInteger32 = std::numeric_limits<std::int32_t>::min();
269 auto arbValues = fixedWidthInts.create();
270 arbValues.fixedI16(-12345);
271 arbValues.fixedU32(1234567890);
272 arbValues.fixedU64(1234567890123456789);
273 auto& arbComp = arbValues.fixedWidthStruct();
274 arbComp.fixedUnsigned16 = 12345;
275 arbComp.fixedInteger32 = -1234567890;
276 arbComp.fixedInteger64 = -1234567890123456789ll;
278 return fixedWidthInts;
283 auto& [usrInts, usrDoubles] = retType;
288 for (
auto& iu : usrInts) {
294 usrDoubles.resize(nd);
295 for (
unsigned id = 0;
id < nd; ++id) {
296 usrDoubles[id] = 42.;
303 auto retVal = std::tuple<ex42::ExampleWithNamespaceCollection, ex42::ExampleWithARelationCollection,
304 ex42::ExampleWithARelationCollection>{};
305 auto& [namesps, namesprels, cpytest] = retVal;
307 for (
int j = 0; j < 5; j++) {
308 auto rel = ex42::MutableExampleWithARelation();
310 auto exWithNamesp = ex42::MutableExampleWithNamespace();
311 exWithNamesp.component().x = i;
312 exWithNamesp.component().y = 1000 * i;
313 namesps.push_back(exWithNamesp);
315 rel.ref(exWithNamesp);
316 for (
int k = 0; k < 5; k++) {
317 auto namesp = ex42::MutableExampleWithNamespace();
319 namesp.component().y = k;
320 namesps.push_back(namesp);
324 namesprels.push_back(rel);
326 for (
auto&& namesprel : namesprels) {
327 cpytest.push_back(namesprel.clone());
334 auto coll = extension::ContainedTypeCollection();
336 auto contElem = coll.create();
337 contElem.setAVector({i * 123.f, 0.15f, 3.14f});
343 auto coll = extension::ExternalComponentTypeCollection();
346 auto extCompElem = coll.create();
347 extension::ExtComponent extComp{};
348 extComp.aStruct.data.x = 42 * i;
349 extComp.nspStruct = ex2::NamespaceStruct{i, 2 * i};
350 extCompElem.setAComponent(extComp);
351 SimpleStruct simpleS{};
352 simpleS.p = {i, i - 2, i + 4, i * 8};
353 extCompElem.setAStruct(simpleS);
359 const ExampleClusterCollection& clusters) {
360 auto coll = extension::ExternalRelationTypeCollection();
362 auto elem0 = coll.create();
363 elem0.setWeight(i * 100.f);
364 elem0.setSingleHit(hits[0]);
366 auto elem1 = coll.create();
367 elem1.addToClusters(clusters[1]);
368 elem1.addToClusters(clusters[0]);
370 auto elem2 = coll.create();
371 for (
int j = 0; j < 3; j++) {
372 auto s = SimpleStruct();
374 elem2.addToSomeStructs(s);
390 ExampleMCCollection moreMCs{};
391 for (
const auto&& mc : mcps) {
392 moreMCs.push_back(mc.clone());
394 auto& otherMCs = frame.put(std::move(moreMCs),
"moreMCs");
403 frame.put(std::move(refs),
"refs");
404 frame.put(std::move(refs2),
"refs2");
409 frame.put(std::move(usrInts),
"userInts");
410 frame.put(std::move(usrDoubles),
"userDoubles");
413 frame.put(std::move(namesps),
"WithNamespaceMember");
414 frame.put(std::move(namespsrels),
"WithNamespaceRelation");
415 frame.put(std::move(cpytest),
"WithNamespaceRelationCopy");
418 frame.putParameter(
"anInt", 42 + iFrame);
419 frame.putParameter(
"UserEventWeight", 100.f * iFrame);
420 frame.putParameter(
"UserEventName",
" event_number_" + std::to_string(iFrame));
421 frame.putParameter(
"SomeVectorData", {1, 2, 3, 4});
422 frame.putParameter(
"SomeVectorData", {
"just",
"some",
"strings"});
423 frame.putParameter(
"SomeVectorData", {iFrame * 1.1, iFrame * 2.2});
424 frame.putParameter(
"SomeValue",
"string value");
425 frame.putParameter(
"SomeValue", 42);
428 frame.put(ExampleClusterCollection(),
"emptyCollection");
430 auto emptySubsetColl = ExampleHitCollection();
431 emptySubsetColl.setSubsetCollection();
432 frame.put(std::move(emptySubsetColl),
"emptySubsetColl");
441template <
typename WriterT>
443 WriterT writer(filename);
445 for (
int i = 0; i < 10; ++i) {
447 writer.writeFrame(frame,
"events", collsToWrite);
450 for (
int i = 100; i < 110; ++i) {
452 writer.writeFrame(frame,
"other_events");
const CollT & put(CollT &&coll, const std::string &name)
void resize(size_t count)
auto createExtensionExternalRelationCollection(int i, const ExampleHitCollection &hits, const ExampleClusterCollection &clusters)
auto createUserDataCollections(int i)
auto createHitRefCollection(const ExampleHitCollection &hits)
auto createArrayCollection(int i)
auto createInfoCollection(int i)
auto createVectorMemberCollection(int i)
podio::Frame makeFrame(int iFrame)
auto createFixedWidthCollection()
auto createClusterCollection(const ExampleHitCollection &hits)
auto createMCRefCollection(const ExampleMCCollection &mcps, const ExampleMCCollection &moreMCs)
auto createHitCollection(int i)
auto createMCCollection()
auto createOneRelCollection(const ExampleClusterCollection &clusters)
auto createExtensionExternalComponentCollection(int i)
auto createReferencingCollections(const ExampleClusterCollection &clusters)
void write_frames(const std::string &filename)
auto createNamespaceRelationCollection(int i)
auto createExtensionContainedCollection(int i)