Skip to content

Commit e4d2e4c

Browse files
committed
introduce string helpers for TableRef
1 parent 05c8840 commit e4d2e4c

File tree

10 files changed

+56
-31
lines changed

10 files changed

+56
-31
lines changed

Detectors/AOD/include/AODProducerWorkflow/AODProducerHelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ auto createTableCursor(framework::ProcessingContext& pc)
5353
framework::Produces<T> c;
5454
c.resetCursor(pc.outputs()
5555
.make<framework::TableBuilder>(framework::OutputForTable<T>::ref()));
56-
c.setLabel(o2::aod::Hash<T::ref.label_hash>::str);
56+
c.setLabel(aod::label<T::ref>());
5757
return c;
5858
}
5959
} // namespace o2::aodhelpers

Detectors/AOD/src/StandaloneAODProducer.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void fillMCollisionTable(o2::steer::MCKinematicsReader const& mcreader)
9494

9595
TFile outfile("aod.root", "UPDATE");
9696
{
97-
TableToTree t2t(mccoltable, &outfile, o2::aod::Hash<o2::aod::McCollisions::ref.label_hash>::str);
97+
TableToTree t2t(mccoltable, &outfile, aod::description_str(aod::signature<o2::aod::McCollisions::ref>()).data());
9898
t2t.addAllBranches();
9999
t2t.process();
100100
}
@@ -200,12 +200,12 @@ void fillCollisionAndTrackTable()
200200
f.Close();
201201
TFile outfile("aod.root", "RECREATE");
202202
{
203-
TableToTree t2t(colltable, &outfile, o2::aod::Hash<o2::aod::Collisions::ref.label_hash>::str);
203+
TableToTree t2t(colltable, &outfile, aod::description_str(aod::signature<o2::aod::Collisions::ref>()).data());
204204
t2t.addAllBranches();
205205
t2t.process();
206206
}
207207
{
208-
TableToTree t2t(tracktable, &outfile, "Tracks" /* aod::MetadataTrait<o2::aod::Tracks>::metadata::tableLabel() */);
208+
TableToTree t2t(tracktable, &outfile, aod::description_str(aod::signature<o2::aod::StoredTracks::ref>()).data());
209209
t2t.addAllBranches();
210210
t2t.process();
211211
}

Framework/Core/include/Framework/ASoA.h

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,31 @@ static inline constexpr header::DataDescription description(const char* const st
318318
return {out};
319319
}
320320

321+
// Helpers to get strings from TableRef
322+
template <soa::TableRef R>
323+
consteval const char* label()
324+
{
325+
return o2::aod::Hash<R.label_hash>::str;
326+
}
327+
328+
template <soa::TableRef R>
329+
consteval const char* origin_str()
330+
{
331+
return o2::aod::Hash<R.origin_hash>::str;
332+
}
333+
334+
template <soa::TableRef R>
335+
consteval header::DataOrigin origin()
336+
{
337+
return o2::aod::Hash<R.desc_hash>::origin;
338+
}
339+
340+
template <soa::TableRef R>
341+
consteval const char* signature()
342+
{
343+
return o2::aod::Hash<R.desc_hash>::str;
344+
}
345+
321346
/// hash identification concepts
322347
template <typename T>
323348
concept is_aod_hash = requires(T t) { t.hash; t.str; };
@@ -329,7 +354,7 @@ concept is_origin_hash = is_aod_hash<T> && requires(T t) { t.origin; };
329354
template <soa::TableRef R>
330355
static constexpr auto sourceSpec()
331356
{
332-
return fmt::format("{}/{}/{}/{}", o2::aod::Hash<R.label_hash>::str, o2::aod::Hash<R.origin_hash>::str, description(o2::aod::Hash<R.desc_hash>::str), R.version);
357+
return fmt::format("{}/{}/{}/{}", label<R>(), origin_str<R>(), description_str(signature<R>()), R.version);
333358
}
334359
} // namespace o2::aod
335360

@@ -1233,7 +1258,7 @@ concept is_index_table = framework::specialization_of_template<o2::soa::IndexTab
12331258
template <soa::is_table T>
12341259
static constexpr std::string getLabelForTable()
12351260
{
1236-
return std::string{o2::aod::Hash<std::decay_t<T>::originals[0].label_hash>::str};
1261+
return std::string{aod::label<std::decay_t<T>::originals[0]>()};
12371262
}
12381263

12391264
template <soa::is_table T>
@@ -1269,7 +1294,7 @@ static constexpr auto hasColumnForKey(framework::pack<C...>, std::string const&
12691294
template <TableRef ref>
12701295
static constexpr std::pair<bool, std::string> hasKey(std::string const& key)
12711296
{
1272-
return {hasColumnForKey(typename aod::MetadataTrait<o2::aod::Hash<ref.desc_hash>>::metadata::columns{}, key), o2::aod::Hash<ref.label_hash>::str};
1297+
return {hasColumnForKey(typename aod::MetadataTrait<o2::aod::Hash<ref.desc_hash>>::metadata::columns{}, key), aod::label<ref>()};
12731298
}
12741299

12751300
template <typename... C>

Framework/Core/include/Framework/AnalysisDataModel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,13 +1621,13 @@ using TrackedV0 = TrackedV0s::iterator;
16211621
using Tracked3Bodys = Tracked3Bodys;
16221622
using Tracked3body = Tracked3Bodys::iterator;
16231623

1624-
namespace origin
1624+
namespace origins
16251625
{
16261626
DECLARE_SOA_COLUMN(DataframeID, dataframeID, uint64_t); //! Data frame ID (what is usually found in directory name in the AO2D.root, i.e. DF_XXX)
16271627
} // namespace origin
16281628

16291629
DECLARE_SOA_TABLE(Origins, "AOD", "ORIGIN", //! Table which contains the IDs of all dataframes merged into this dataframe
1630-
o2::soa::Index<>, origin::DataframeID);
1630+
o2::soa::Index<>, origins::DataframeID);
16311631

16321632
using Origin = Origins::iterator;
16331633

Framework/Core/include/Framework/AnalysisHelpers.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,44 +32,44 @@ template <TableRef R>
3232
constexpr auto tableRef2InputSpec()
3333
{
3434
return framework::InputSpec{
35-
o2::aod::Hash<R.label_hash>::str,
36-
o2::aod::Hash<R.origin_hash>::origin,
37-
o2::aod::description(o2::aod::Hash<R.desc_hash>::str),
35+
o2::aod::label<R>(),
36+
o2::aod::origin<R>(),
37+
o2::aod::description(o2::aod::signature<R>()),
3838
R.version};
3939
}
4040

4141
template <TableRef R>
4242
constexpr auto tableRef2OutputSpec()
4343
{
4444
return framework::OutputSpec{
45-
framework::OutputLabel{o2::aod::Hash<R.label_hash>::str},
46-
o2::aod::Hash<R.origin_hash>::origin,
47-
o2::aod::description(o2::aod::Hash<R.desc_hash>::str),
45+
framework::OutputLabel{o2::aod::label<R>()},
46+
o2::aod::origin<R>(),
47+
o2::aod::description(o2::aod::signature<R>()),
4848
R.version};
4949
}
5050

5151
template <TableRef R>
5252
constexpr auto tableRef2Output()
5353
{
5454
return framework::Output{
55-
o2::aod::Hash<R.origin_hash>::origin,
56-
o2::aod::description(o2::aod::Hash<R.desc_hash>::str),
55+
o2::aod::origin<R>(),
56+
o2::aod::description(o2::aod::signature<R>()),
5757
R.version};
5858
}
5959

6060
template <TableRef R>
6161
constexpr auto tableRef2OutputRef()
6262
{
6363
return framework::OutputRef{
64-
o2::aod::Hash<R.label_hash>::str,
64+
o2::aod::label<R>(),
6565
R.version};
6666
}
6767

6868
template <TableRef R>
6969
constexpr auto tableRef2ConfigParamSpec()
7070
{
7171
return o2::framework::ConfigParamSpec{
72-
std::string{"input:"} + o2::aod::Hash<R.label_hash>::str,
72+
std::string{"input:"} + o2::aod::label<R>(),
7373
framework::VariantType::String,
7474
aod::sourceSpec<R>(),
7575
{"\"\""}};
@@ -163,12 +163,12 @@ struct OutputForTable {
163163

164164
static OutputSpec const spec()
165165
{
166-
return OutputSpec{OutputLabel{o2::aod::Hash<T::ref.label_hash>::str}, o2::aod::Hash<T::ref.origin_hash>::origin, o2::aod::description(o2::aod::Hash<T::ref.desc_hash>::str), T::ref.version};
166+
return OutputSpec{OutputLabel{aod::label<T::ref>()}, o2::aod::origin<T::ref>(), o2::aod::description(o2::aod::signature<T::ref>()), T::ref.version};
167167
}
168168

169169
static OutputRef ref()
170170
{
171-
return OutputRef{o2::aod::Hash<T::ref.label_hash>::str, T::ref.version};
171+
return OutputRef{aod::label<T::ref>(), T::ref.version};
172172
}
173173
};
174174

@@ -440,7 +440,7 @@ struct Builds : decltype(transformBase<T>()) {
440440
template <typename Key, typename... Cs>
441441
auto build(framework::pack<Cs...>, std::vector<std::shared_ptr<arrow::Table>>&& tables)
442442
{
443-
this->table = std::make_shared<T>(IP::template indexBuilder<Key, metadata::sources.size(), metadata::sources>(o2::aod::Hash<T::ref.label_hash>::str, std::forward<std::vector<std::shared_ptr<arrow::Table>>>(tables), framework::pack<Cs...>{}));
443+
this->table = std::make_shared<T>(IP::template indexBuilder<Key, metadata::sources.size(), metadata::sources>(o2::aod::label<T::ref>(), std::forward<std::vector<std::shared_ptr<arrow::Table>>>(tables), framework::pack<Cs...>{}));
444444
return (this->table != nullptr);
445445
}
446446
};

Framework/Core/include/Framework/AnalysisManagers.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ struct OutputManager<Produces<T>> {
253253
}
254254
static bool finalize(ProcessingContext&, Produces<T>& what)
255255
{
256-
what.setLabel(o2::aod::Hash<Produces<T>::persistent_table_t::ref.label_hash>::str);
256+
what.setLabel(o2::aod::label<Produces<T>::persistent_table_t::ref>());
257257
what.release();
258258
return true;
259259
}
@@ -335,7 +335,7 @@ template <size_t N, std::array<soa::TableRef, N> refs>
335335
static inline auto extractOriginals(ProcessingContext& pc)
336336
{
337337
return [&]<size_t... Is>(std::index_sequence<Is...>) -> std::vector<std::shared_ptr<arrow::Table>> {
338-
return {pc.inputs().get<TableConsumer>(o2::aod::Hash<refs[Is].label_hash>::str)->asArrowTable()...};
338+
return {pc.inputs().get<TableConsumer>(o2::aod::label<refs[Is]>())->asArrowTable()...};
339339
}(std::make_index_sequence<refs.size()>());
340340
}
341341

@@ -353,10 +353,10 @@ struct OutputManager<Spawns<T>> {
353353
auto originalTable = soa::ArrowHelpers::joinTables(extractOriginals<metadata::sources.size(), metadata::sources>(pc));
354354
if (originalTable->schema()->fields().empty() == true) {
355355
using base_table_t = typename Spawns<T>::base_table_t::table_t;
356-
originalTable = makeEmptyTable<base_table_t>(o2::aod::Hash<metadata::extension_table_t::ref.label_hash>::str);
356+
originalTable = makeEmptyTable<base_table_t>(o2::aod::label<metadata::extension_table_t::ref>());
357357
}
358358

359-
what.extension = std::make_shared<typename Spawns<T>::extension_t>(o2::framework::spawner<o2::aod::Hash<metadata::extension_table_t::ref.desc_hash>>(originalTable, o2::aod::Hash<metadata::extension_table_t::ref.label_hash>::str));
359+
what.extension = std::make_shared<typename Spawns<T>::extension_t>(o2::framework::spawner<o2::aod::Hash<metadata::extension_table_t::ref.desc_hash>>(originalTable, o2::aod::label<metadata::extension_table_t::ref>()));
360360
what.table = std::make_shared<typename T::table_t>(soa::ArrowHelpers::joinTables({what.extension->asArrowTable(), originalTable}));
361361
return true;
362362
}

Framework/Core/include/Framework/AnalysisTask.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ struct AnalysisDataProcessorBuilder {
137137
auto inputSources = getInputMetadata<metadata>();
138138
inputMetadata.insert(inputMetadata.end(), inputSources.begin(), inputSources.end());
139139
}
140-
DataSpecUtils::updateInputList(inputs, InputSpec{o2::aod::Hash<R.label_hash>::str, o2::aod::Hash<R.origin_hash>::origin, aod::description(o2::aod::Hash<R.desc_hash>::str), aod::version(o2::aod::Hash<R.desc_hash>::str), Lifetime::Timeframe, inputMetadata});
140+
DataSpecUtils::updateInputList(inputs, InputSpec{o2::aod::label<R>(), o2::aod::origin<R>(), aod::description(o2::aod::signature<R>()), R.version, Lifetime::Timeframe, inputMetadata});
141141
}
142142

143143
template <typename R, typename C, typename... Args>
@@ -185,7 +185,7 @@ struct AnalysisDataProcessorBuilder {
185185
template <soa::TableRef R>
186186
static auto extractTableFromRecord(InputRecord& record)
187187
{
188-
auto table = record.get<TableConsumer>(o2::aod::Hash<R.label_hash>::str)->asArrowTable();
188+
auto table = record.get<TableConsumer>(o2::aod::label<R>())->asArrowTable();
189189
if (table->num_rows() == 0) {
190190
table = makeEmptyTable<R>();
191191
}

Framework/Core/include/Framework/TableBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ auto makeEmptyTable()
871871
{
872872
TableBuilder b;
873873
[[maybe_unused]] auto writer = b.cursor(typename aod::MetadataTrait<aod::Hash<R.desc_hash>>::metadata::columns{});
874-
b.setLabel(aod::Hash<R.label_hash>::str);
874+
b.setLabel(aod::label<R>());
875875
return b.finalize();
876876
}
877877

Framework/Core/src/AODReaderHelpers.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ template <size_t N, std::array<soa::TableRef, N> refs>
8181
static inline auto extractOriginals(ProcessingContext& pc)
8282
{
8383
return [&]<size_t... Is>(std::index_sequence<Is...>) -> std::vector<std::shared_ptr<arrow::Table>> {
84-
return {pc.inputs().get<TableConsumer>(o2::aod::Hash<refs[Is].label_hash>::str)->asArrowTable()...};
84+
return {pc.inputs().get<TableConsumer>(o2::aod::label<refs[Is]>())->asArrowTable()...};
8585
}(std::make_index_sequence<refs.size()>());
8686
}
8787

Framework/Core/src/verifyAODFile.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using namespace o2::soa;
2323
template <typename T>
2424
void verifyTable(TFile* infile, const char* branchName)
2525
{
26-
std::cout << "Table: " << o2::aod::Hash<T::ref.label_hash>::str << std::endl;
26+
std::cout << "Table: " << o2::aod::label<T::ref>() << std::endl;
2727
std::unique_ptr<TTreeReader> reader = std::make_unique<TTreeReader>(branchName, infile);
2828
TableBuilder builder;
2929
RootTableBuilderHelpers::convertASoA<T>(builder, *reader);

0 commit comments

Comments
 (0)