5#include "datamodel/EventInfoCollection.h"
6#include "datamodel/ExampleClusterCollection.h"
7#include "datamodel/ExampleHitCollection.h"
17 std::cout <<
"start writting collections...\n";
18 auto& info = store.create<EventInfoCollection>(
"info");
19 auto& hits = store.create<ExampleHitCollection>(
"hits");
20 auto& clusters = store.create<ExampleClusterCollection>(
"clusters");
21 auto& hits_subset = store.create<ExampleHitCollection>(
"hits_subset");
22 hits_subset.setSubsetCollection(
true);
30 for (
unsigned i = 0; i < nevents; ++i) {
32 auto item1 = MutableEventInfo();
34 info.push_back(item1);
36 auto& evtMD = store.getEventMetaData();
37 evtMD.setValue(
"UserEventWeight", (
float)100. * i);
38 std::cout <<
" event number: " << i << std::endl;
39 evtMD.setValue(
"UserEventName", std::to_string(i));
41 auto hit1 = ExampleHit(0xbad, 0., 0., 0., 23. + i);
42 auto hit2 = ExampleHit(0xcaffee, 1., 0., 0., 12. + i);
48 auto cluster = MutableExampleCluster();
49 auto clu0 = MutableExampleCluster();
50 auto clu1 = MutableExampleCluster();
53 clu0.energy(hit1.energy());
55 clu1.energy(hit2.energy());
56 cluster.addHits(hit1);
57 cluster.addHits(hit2);
58 cluster.energy(hit1.energy() + hit2.energy());
59 cluster.addClusters(clu0);
60 cluster.addClusters(clu1);
63 hits_subset.push_back(hit1);
64 hits_subset.push_back(hit2);
67 clusters.push_back(clu0);
68 clusters.push_back(clu1);
69 clusters.push_back(cluster);
72 store.clearCollections();
81 reader.openFile(
"associations.root");
84 store.setReader(&reader);
86 const auto nEvents = reader.getEntries();
88 for (
unsigned i = 0; i < nEvents; ++i) {
90 auto& clusters = store.get<ExampleClusterCollection>(
"clusters");
91 if (clusters.isValid()) {
92 for (
const auto& cluster : clusters) {
93 if (cluster.isAvailable()) {
94 for (
const auto& hit : cluster.Hits()) {
95 if (hit.isAvailable()) {
96 throw std::runtime_error(
"Hit is available, although it has not been written");
102 throw std::runtime_error(
"Collection 'clusters' should be present");
106 auto& hits_subset = store.get<ExampleHitCollection>(
"hits_subset");
107 if (hits_subset.isValid()) {
108 if (!hits_subset.isSubsetCollection()) {
109 throw std::runtime_error(
"hits_subset should be a subset collection");
112 if (hits_subset.size() != 2) {
113 throw std::runtime_error(
"subset collection should have original size");
116 for (
const auto& hit : hits_subset) {
117 if (hit.isAvailable()) {
118 throw std::runtime_error(
"Hit is available, although it has not been written");
122 throw std::runtime_error(
"Collection 'hits_subset' should be present");
bool registerForWrite(const std::string &name)