PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
write_ascii.cpp File Reference
#include "datamodel/EventInfoCollection.h"
#include "datamodel/ExampleClusterCollection.h"
#include "datamodel/ExampleHitCollection.h"
#include "datamodel/ExampleMCCollection.h"
#include "datamodel/ExampleReferencingTypeCollection.h"
#include "datamodel/ExampleWithARelationCollection.h"
#include "datamodel/ExampleWithComponentCollection.h"
#include "datamodel/ExampleWithNamespaceCollection.h"
#include "datamodel/ExampleWithOneRelationCollection.h"
#include "datamodel/ExampleWithVectorMemberCollection.h"
#include <iostream>
#include <vector>
#include "podio/ASCIIWriter.h"
#include "podio/EventStore.h"

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( )

Definition at line 21 of file write_ascii.cpp.

21 {
22
23 std::cout << "start processing" << std::endl;
24
25 auto store = podio::EventStore();
26 auto writer = podio::ASCIIWriter("example.txt", &store);
27
28 auto& info = store.create<EventInfoCollection>("info");
29 auto& mcps = store.create<ExampleMCCollection>("mcparticles");
30 auto& hits = store.create<ExampleHitCollection>("hits");
31 auto& clusters = store.create<ExampleClusterCollection>("clusters");
32 auto& refs = store.create<ExampleReferencingTypeCollection>("refs");
33 auto& refs2 = store.create<ExampleReferencingTypeCollection>("refs2");
34 auto& comps = store.create<ExampleWithComponentCollection>("Component");
35 auto& oneRels = store.create<ExampleWithOneRelationCollection>("OneRelation");
36 auto& vecs = store.create<ExampleWithVectorMemberCollection>("WithVectorMember");
37 auto& namesps = store.create<ex42::ExampleWithNamespaceCollection>("WithNamespaceMember");
38 auto& namesprels = store.create<ex42::ExampleWithARelationCollection>("WithNamespaceRelation");
39 writer.registerForWrite<EventInfoCollection>("info");
40 writer.registerForWrite<ExampleMCCollection>("mcparticles");
41 writer.registerForWrite<ExampleHitCollection>("hits");
42 writer.registerForWrite<ExampleClusterCollection>("clusters");
43 writer.registerForWrite<ExampleReferencingTypeCollection>("refs");
44 writer.registerForWrite<ExampleReferencingTypeCollection>("refs2");
45 writer.registerForWrite<ExampleWithComponentCollection>("Component");
46 writer.registerForWrite<ExampleWithOneRelationCollection>("OneRelation");
47 writer.registerForWrite<ExampleWithVectorMemberCollection>("WithVectorMember");
48 writer.registerForWrite<ex42::ExampleWithNamespaceCollection>("WithNamespaceMember");
49 writer.registerForWrite<ex42::ExampleWithARelationCollection>("WithNamespaceRelation");
50
51 unsigned nevents = 1; // 2000;
52
53 for (unsigned i = 0; i < nevents; ++i) {
54 if (i % 1000 == 0) {
55 std::cout << "processing event " << i << std::endl;
56 }
57
58 auto item1 = MutableEventInfo();
59 item1.Number(i);
60 info.push_back(item1);
61 auto hit1 = ExampleHit(0xbad, 0., 0., 0., 23. + i);
62 auto hit2 = ExampleHit(0xcaffee, 1., 0., 0., 12. + i);
63
64 hits.push_back(hit1);
65 hits.push_back(hit2);
66
67 // ---- add some MC particles ----
68 auto mcp0 = ExampleMC();
69 auto mcp1 = ExampleMC();
70 auto mcp2 = ExampleMC();
71 auto mcp3 = ExampleMC();
72 auto mcp4 = ExampleMC();
73 auto mcp5 = ExampleMC();
74 auto mcp6 = ExampleMC();
75 auto mcp7 = ExampleMC();
76 auto mcp8 = ExampleMC();
77 auto mcp9 = ExampleMC();
78
79 mcps.push_back(mcp0);
80 mcps.push_back(mcp1);
81 mcps.push_back(mcp2);
82 mcps.push_back(mcp3);
83 mcps.push_back(mcp4);
84 mcps.push_back(mcp5);
85 mcps.push_back(mcp6);
86 mcps.push_back(mcp7);
87 mcps.push_back(mcp8);
88 mcps.push_back(mcp9);
89
90 // --- add some daughter relations
91
92 auto p = mcps[0];
93 p.adddaughters(mcps[2]);
94 p.adddaughters(mcps[3]);
95 p.adddaughters(mcps[4]);
96 p.adddaughters(mcps[5]);
97 p = mcps[1];
98 p.adddaughters(mcps[2]);
99 p.adddaughters(mcps[3]);
100 p.adddaughters(mcps[4]);
101 p.adddaughters(mcps[5]);
102 p = mcps[2];
103 p.adddaughters(mcps[6]);
104 p.adddaughters(mcps[7]);
105 p.adddaughters(mcps[8]);
106 p.adddaughters(mcps[9]);
107 p = mcps[3];
108 p.adddaughters(mcps[6]);
109 p.adddaughters(mcps[7]);
110 p.adddaughters(mcps[8]);
111 p.adddaughters(mcps[9]);
112
113 //--- now fix the parent relations
114 for (unsigned j = 0, N = mcps.size(); j < N; ++j) {
115 p = mcps[j];
116 for (auto it = p.daughters_begin(), end = p.daughters_end(); it != end; ++it) {
117 int dIndex = it->getObjectID().index;
118 auto d = mcps[dIndex];
119 d.addparents(p);
120 }
121 }
122 //-------- print relations for debugging:
123 for (auto _p : mcps) {
124 std::cout << " particle " << _p.getObjectID().index << " has daughters: ";
125 for (auto it = _p.daughters_begin(), end = _p.daughters_end(); it != end; ++it) {
126 std::cout << " " << it->getObjectID().index;
127 }
128 std::cout << " and parents: ";
129 for (auto it = _p.parents_begin(), end = _p.parents_end(); it != end; ++it) {
130 std::cout << " " << it->getObjectID().index;
131 }
132 std::cout << std::endl;
133 }
134 //-------------------------------
135
136 auto cluster = MutableExampleCluster();
137 auto clu0 = MutableExampleCluster();
138 auto clu1 = MutableExampleCluster();
139
140 clu0.addHits(hit1);
141 clu0.energy(hit1.energy());
142 clu1.addHits(hit2);
143 clu1.energy(hit2.energy());
144 cluster.addHits(hit1);
145 cluster.addHits(hit2);
146 cluster.energy(hit1.energy() + hit2.energy());
147 cluster.addClusters(clu0);
148 cluster.addClusters(clu1);
149
150 clusters.push_back(clu0);
151 clusters.push_back(clu1);
152 clusters.push_back(cluster);
153
154 auto ref = MutableExampleReferencingType();
155 refs.push_back(ref);
156
157 auto ref2 = ExampleReferencingType();
158 refs2.push_back(ref2);
159
160 ref.addClusters(cluster);
161 ref.addRefs(ref2);
162
163 auto comp = MutableExampleWithComponent();
164 comp.component().data.x = 0;
165 comp.component().data.y = 1;
166 comp.component().data.z = i;
167 comps.push_back(comp);
168
169 auto cyclic = MutableExampleReferencingType();
170 cyclic.addRefs(cyclic);
171 refs.push_back(cyclic);
172
173 auto oneRel = MutableExampleWithOneRelation();
174 oneRel.cluster(cluster);
175 oneRels.push_back(oneRel);
176
177 // write non-filled relation
178 auto oneRelEmpty = ExampleWithOneRelation();
179 oneRels.push_back(oneRelEmpty);
180
181 auto vec = MutableExampleWithVectorMember();
182 vec.addcount(23);
183 vec.addcount(24);
184 vecs.push_back(vec);
185
186 auto namesp = ex42::MutableExampleWithNamespace();
187 namesp.component().x = 1;
188 namesp.component().y = i;
189 namesps.push_back(namesp);
190
191 auto rel = ex42::MutableExampleWithARelation();
192 rel.ref(namesp);
193 namesprels.push_back(rel);
194
195 writer.writeEvent();
196 store.clearCollections();
197 }
198
199 writer.finish();
200}