Skip to content

Commit ca37ec5

Browse files
committed
Codify some of the implicitly assumed conventions
1 parent ac26a12 commit ca37ec5

File tree

4 files changed

+54
-10
lines changed

4 files changed

+54
-10
lines changed

include/podio/Frame.h

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "podio/CollectionBase.h"
55
#include "podio/CollectionBufferFactory.h"
66
#include "podio/CollectionIDTable.h"
7+
#include "podio/FrameCategories.h" // mainly for convenience
78
#include "podio/GenericParameters.h"
89
#include "podio/ICollectionProvider.h"
910
#include "podio/SchemaEvolution.h"

include/podio/FrameCategories.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef PODIO_FRAMECATEGORIES_H
2+
#define PODIO_FRAMECATEGORIES_H
3+
4+
#include <string>
5+
6+
namespace podio {
7+
8+
/**
9+
* Create a parameterName that encodes the collection name and the parameter
10+
* Name into one string.
11+
*
12+
* This codifies a convention that was decided on to store collection level
13+
* parameters. These are parameters / metadata that are valid for all
14+
* collections of a given name in a file, e.g. CellID encoding strings. These
15+
* parameters are usually stored in a dedicated metadata Frame inside a file,
16+
* see the predefined category names in the Cateogry namespace.
17+
*
18+
* @param collName the name of the collection
19+
* @param paramName the name of the parameter
20+
*
21+
* @returns A single key string that combines the collection and parameter name
22+
*/
23+
inline std::string collMetadataParamName(const std::string& collName, const std::string& paramName) {
24+
return collName + "__" + paramName;
25+
}
26+
27+
/**
28+
* This namespace mimics an enum (at least in its usage) and simply defines
29+
* either commonly used category names, or category names that form a
30+
* convention.
31+
*/
32+
namespace Category {
33+
/// The event category
34+
constexpr const auto Event = "events";
35+
/// The run category
36+
constexpr const auto Run = "runs";
37+
/// The metadata cateogry that is used to store a single Frame that holds data
38+
/// that is valid for a whole file, e.g. collection level parameters
39+
constexpr const auto Metadata = "metadata";
40+
} // namespace Category
41+
} // namespace podio
42+
43+
#endif

tests/read_frame.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,22 @@ int read_frames(const std::string& filename, bool assertBuildVersion = true) {
7777
return 1;
7878
}
7979

80-
if (reader.getEntries("events") != 10) {
80+
if (reader.getEntries(podio::Category::Event) != 10) {
8181
std::cerr << "Could not read back the number of events correctly. "
82-
<< "(expected:" << 10 << ", actual: " << reader.getEntries("events") << ")" << std::endl;
82+
<< "(expected:" << 10 << ", actual: " << reader.getEntries(podio::Category::Event) << ")" << std::endl;
8383
return 1;
8484
}
8585

86-
if (reader.getEntries("events") != reader.getEntries("other_events")) {
86+
if (reader.getEntries(podio::Category::Event) != reader.getEntries("other_events")) {
8787
std::cerr << "Could not read back the number of events correctly. "
8888
<< "(expected:" << 10 << ", actual: " << reader.getEntries("other_events") << ")" << std::endl;
8989
return 1;
9090
}
9191

9292
// Read the frames in a different order than when writing them here to make
9393
// sure that the writing/reading order does not impose any usage requirements
94-
for (size_t i = 0; i < reader.getEntries("events"); ++i) {
95-
auto frame = podio::Frame(reader.readNextEntry("events"));
94+
for (size_t i = 0; i < reader.getEntries(podio::Category::Event); ++i) {
95+
auto frame = podio::Frame(reader.readNextEntry(podio::Category::Event));
9696
if (reader.currentFileVersion() > podio::version::Version{0, 16, 2}) {
9797
if (frame.get("emptySubsetColl") == nullptr) {
9898
std::cerr << "Could not retrieve an empty subset collection" << std::endl;
@@ -114,7 +114,7 @@ int read_frames(const std::string& filename, bool assertBuildVersion = true) {
114114
}
115115
}
116116

117-
if (reader.readNextEntry("events")) {
117+
if (reader.readNextEntry(podio::Category::Event)) {
118118
std::cerr << "Trying to read more frame data than is present should return a nullptr" << std::endl;
119119
return 1;
120120
}
@@ -127,10 +127,10 @@ int read_frames(const std::string& filename, bool assertBuildVersion = true) {
127127

128128
// Reading specific (jumping to) entry
129129
{
130-
auto frame = podio::Frame(reader.readEntry("events", 4));
130+
auto frame = podio::Frame(reader.readEntry(podio::Category::Event, 4));
131131
processEvent(frame, 4, reader.currentFileVersion());
132132
// Reading the next entry after jump, continues from after the jump
133-
auto nextFrame = podio::Frame(reader.readNextEntry("events"));
133+
auto nextFrame = podio::Frame(reader.readNextEntry(podio::Category::Event));
134134
processEvent(nextFrame, 5, reader.currentFileVersion());
135135

136136
auto otherFrame = podio::Frame(reader.readEntry("other_events", 4));
@@ -147,7 +147,7 @@ int read_frames(const std::string& filename, bool assertBuildVersion = true) {
147147
}
148148

149149
// Trying to read a Frame that is not present returns a nullptr
150-
if (reader.readEntry("events", 10)) {
150+
if (reader.readEntry(podio::Category::Event, 10)) {
151151
std::cerr << "Trying to read a specific entry that does not exist should return a nullptr" << std::endl;
152152
return 1;
153153
}

tests/write_frame.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ void write_frames(const std::string& filename) {
424424

425425
for (int i = 0; i < 10; ++i) {
426426
auto frame = makeFrame(i);
427-
writer.writeFrame(frame, "events", collsToWrite);
427+
writer.writeFrame(frame, podio::Category::Event, collsToWrite);
428428
}
429429

430430
for (int i = 100; i < 110; ++i) {

0 commit comments

Comments
 (0)