Skip to content

Commit a7b2795

Browse files
committed
WIP DPL Analysis: centralised CCDB support in analysis
Thanks to the newly added binary view columns we can finally support proper CCDB integration in analysis. In order to do so, the user needs to create a TIMESTAMPED table, i.e. a table which is an extension of another one where the timestamps for each rows are provided. The extra columns of such timestamped table will be CCDB columns where the iterator of each provides access for one specified CCDB object.
1 parent a47072d commit a7b2795

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

Framework/Core/include/Framework/ASoA.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,43 @@ consteval static std::string_view namespace_prefix()
23602360
}; \
23612361
[[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_ { _Label_, _Name_::hash, o2::framework::expressions::selectArrowType<_Type_>() }
23622362

2363+
#define DECLARE_SOA_CCDB_COLUMN_FULL(_Name_, _Label_, _Getter_, _ConcreteType_, _CCDBQuery_) \
2364+
struct _Name_ : o2::soa::Column<std::span<std::byte>, _Name_> { \
2365+
static constexpr const char* mLabel = _Label_; \
2366+
static constexpr const char* query = _CCDBQuery_; \
2367+
static constexpr const uint32_t hash = crc32(namespace_prefix<_Name_>(), std::string_view{#_Getter_}); \
2368+
using base = o2::soa::Column<std::span<std::byte>, _Name_>; \
2369+
using type = std::span<std::byte>; \
2370+
using column_t = _Name_; \
2371+
_Name_(arrow::ChunkedArray const* column) \
2372+
: o2::soa::Column<std::span<std::byte>, _Name_>(o2::soa::ColumnIterator<std::span<std::byte>>(column)) \
2373+
{ \
2374+
} \
2375+
\
2376+
_Name_() = default; \
2377+
_Name_(_Name_ const& other) = default; \
2378+
_Name_& operator=(_Name_ const& other) = default; \
2379+
\
2380+
decltype(auto) _Getter_() const \
2381+
{ \
2382+
static std::byte* payload = nullptr; \
2383+
static _ConcreteType_* deserialised = nullptr; \
2384+
auto span = *mColumnIterator; \
2385+
if (payload != (std::byte*)span.data()) { \
2386+
payload = (std::byte*)span.data(); \
2387+
TBufferFile f(TBufferFile::EMode::kRead, span.size(), (char*)span.data(), kFALSE); \
2388+
deserialised = (_ConcreteType_*)f.ReadObjectAny(TClass::GetClass(#_ConcreteType_)); \
2389+
} \
2390+
return *deserialised; \
2391+
} \
2392+
\
2393+
decltype(auto) \
2394+
get() const \
2395+
{ \
2396+
return _Getter_(); \
2397+
} \
2398+
};
2399+
23632400
#define DECLARE_SOA_COLUMN(_Name_, _Getter_, _Type_) \
23642401
DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, "f" #_Name_)
23652402

@@ -3235,6 +3272,32 @@ consteval auto getIndexTargets()
32353272
using metadata = _Name_##Metadata; \
32363273
};
32373274

3275+
// Declare were each row is associated to a timestamp column of an _TimestampSource_
3276+
// table.
3277+
//
3278+
// The columns of this table have to be CCDB_COLUMNS so that for each timestamp, we get a row
3279+
// which points to the specified CCDB objectes described by those columns.
3280+
#define DECLARE_SOA_TIMESTAMPED_TABLE_FULL(_Name_, _Label_, _TimestampSource_, _TimestampColumn_, _Origin_, _Version_, _Desc_, ...) \
3281+
O2HASH(_Desc_ "/" #_Version_); \
3282+
template <typename O> \
3283+
using _Name_##TimestampFrom = soa::Table<o2::aod::Hash<_Label_ ""_h>, o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, O>; \
3284+
using _Name_##Timestamp = _Name_##TimestampFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3285+
template <typename O = o2::aod::Hash<_Origin_ ""_h>> \
3286+
struct _Name_##TimestampMetadataFrom : TableMetadata<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, __VA_ARGS__> { \
3287+
using timestamp_table_t = _TimestampSource_; \
3288+
using extension_table_t = _Name_##TimestampFrom<O>; \
3289+
using ccdb_pack_t = framework::pack<__VA_ARGS__>; \
3290+
/*static constexpr auto timestampColumn = _TimestampColumn_;*/ \
3291+
}; \
3292+
using _Name_##TimestampMetadata = _Name_##TimestampMetadataFrom<o2::aod::Hash<_Origin_ ""_h>>; \
3293+
template <> \
3294+
struct MetadataTrait<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>> { \
3295+
using metadata = _Name_##TimestampMetadata; \
3296+
}; \
3297+
template <typename O> \
3298+
using _Name_##From = o2::soa::JoinFull<o2::aod::Hash<_Desc_ "/" #_Version_ ""_h>, _TimestampSource_, _Name_##TimestampFrom<O>>; \
3299+
using _Name_ = _Name_##From<o2::aod::Hash<_Origin_ ""_h>>;
3300+
32383301
#define DECLARE_SOA_INDEX_TABLE(_Name_, _Key_, _Description_, ...) \
32393302
DECLARE_SOA_INDEX_TABLE_FULL(_Name_, _Key_, "IDX", 0, _Description_, false, __VA_ARGS__)
32403303

Framework/TestWorkflows/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ o2_add_dpl_workflow(analysis-histograms
4141
SOURCES src/o2TestHistograms.cxx
4242
COMPONENT_NAME TestWorkflows)
4343

44+
o2_add_dpl_workflow(analysis-ccdb
45+
SOURCES src/o2TestAnalysisCCDB.cxx
46+
PUBLIC_LINK_LIBRARIES O2::DataFormatsTOF
47+
COMPONENT_NAME TestWorkflows)
48+
4449
o2_add_dpl_workflow(two-timers
4550
SOURCES src/o2TwoTimers.cxx
4651
COMPONENT_NAME TestWorkflows)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
///
12+
/// \brief FullTracks is a join of Tracks, TracksCov, and TracksExtra.
13+
/// \author
14+
/// \since
15+
16+
#include "Framework/runDataProcessing.h"
17+
#include "Framework/AnalysisTask.h"
18+
#include "Framework/AnalysisDataModel.h"
19+
#include "DataFormatsTOF/CalibLHCphaseTOF.h"
20+
#include <iostream>
21+
22+
#include <TH2F.h>
23+
24+
using namespace o2;
25+
using namespace o2::framework;
26+
using namespace o2::framework::expressions;
27+
28+
namespace o2::aod
29+
{
30+
namespace tofcalib
31+
{
32+
DECLARE_SOA_CCDB_COLUMN_FULL(LHCphase, "LHCphase", lhcPhase, o2::dataformats::CalibLHCphaseTOF, "TOF/LHCphase"); //!
33+
} // namespace tofcalib
34+
35+
DECLARE_SOA_TIMESTAMPED_TABLE_FULL(TOFCalibrationObjects, "TOFCalibrationObject", aod::Timestamps, o2::aod::timestamp::Timestamp, "AOD", 1, "TOFCALIB", //!
36+
tofcalib::LHCphase);
37+
} // namespace o2::aod
38+
39+
struct SimpleCCDBConsumer {
40+
void process(o2::aod::TOFCalibrationObjects const& ccdbObjectsForAllTimestamps)
41+
{
42+
LOGP(info, "Looking at all the LHCphases associated to the timestamps");
43+
for (auto& object : ccdbObjectsForAllTimestamps) {
44+
std::cout << object.lhcPhase().getStartValidity() << " " << object.lhcPhase().getEndValidity() << std::endl;
45+
}
46+
}
47+
};
48+
49+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
50+
{
51+
return WorkflowSpec{
52+
adaptAnalysisTask<SimpleCCDBConsumer>(cfgc, TaskName{"simple-ccdb-fetcher"}),
53+
};
54+
}

0 commit comments

Comments
 (0)