Project
Loading...
Searching...
No Matches
NativeAOD.h
Go to the documentation of this file.
1// Copyright 2019-2026 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#ifndef O2_FRAMEWORK_NATIVEAOD_H_
13#define O2_FRAMEWORK_NATIVEAOD_H_
14
15// Glue between DataInputDirector and the ROOT-free AO2D reader (O2::AODNative).
16// No ROOT API is used here: everything goes through RootFile and ByteSource.
17
18#include "AODInputFile.h"
20#include "AODNative/Container.h"
21#include "AODNative/ReadPlan.h"
22#include <future>
23#include <map>
24#include <memory>
25#include <mutex>
26#include <optional>
27#include <string>
28
29namespace o2::framework
30{
31
36 std::shared_ptr<o2::aod::native::ByteSource> source;
38};
39
43{
44 public:
45 NativeAODFileSystem(std::shared_ptr<o2::aod::native::RootFile> file, o2::aod::native::Options options, RootObjectReadingFactory& factory);
46
47 std::string type_name() const override { return "native-aod"; }
48 arrow::Result<arrow::fs::FileInfo> GetFileInfo(const std::string& path) override;
49 std::shared_ptr<RootObjectHandler> GetObjectHandler(arrow::dataset::FileSource source) override;
50 bool CheckSupport(arrow::dataset::FileSource source) override;
51
54 NativeTreeHandle* getTreeHandle(std::string const& path);
66 std::shared_ptr<o2::aod::native::ReadPlan> planFor(std::string const& path);
67 o2::aod::native::RootFile& file() { return *mFile; }
70 std::string const& name() const { return mName; }
71 void setName(std::string name) { mName = std::move(name); }
73 std::vector<o2::aod::native::KeyInfo> keysOf(std::string const& df);
76 void setReadOrder(std::vector<std::string> dfs);
77
78 private:
81 struct Lookahead {
82 std::string df;
83 std::vector<o2::aod::native::KeyInfo> keys;
84 std::vector<std::pair<std::string, o2::aod::native::TreeInfo>> trees;
85 std::shared_ptr<o2::aod::native::ReadPlan> plan;
86 };
87 NativeTreeHandle* findTree(std::string const& df, std::string const& treeName);
89 std::vector<o2::aod::native::KeyInfo> const& directory(std::string const& df);
90 void addToPlan(std::string const& treeName);
92 void adoptLookahead(std::string const& df);
94 void releaseMappedDF(std::string const& df);
95 void startLookahead(std::string const& afterDF, std::vector<std::string> trees);
96
97 std::shared_ptr<o2::aod::native::RootFile> mFile;
98 std::string mName;
100 RootObjectReadingFactory& mObjectFactory;
101 std::mutex mMutex;
102 std::map<std::string, std::vector<o2::aod::native::KeyInfo>> mDirectories;
103 std::map<std::string, std::unique_ptr<NativeTreeHandle>> mTrees;
104 std::shared_ptr<o2::aod::native::ReadBufferPool> mPool;
105 // The plan trees are being added to, and how many bytes it holds.
106 std::shared_ptr<o2::aod::native::ReadPlan> mPlan;
107 uint64_t mPlanBytes = 0;
108 // The plan of each tree of the DF, until planFor() hands it out.
109 std::map<std::string, std::shared_ptr<o2::aod::native::ReadPlan>> mPlanOf;
110 std::string mPlanDF;
111 // The DF whose pages are mapped, released when the next one starts.
112 std::string mMappedDF;
113 std::vector<std::string> mPlanTrees;
114 // Used only by the lookahead task, so that mFile is never shared across threads.
115 std::shared_ptr<o2::aod::native::RootFile> mLookaheadFile;
116 std::vector<std::string> mDataFrames;
117 std::future<std::optional<Lookahead>> mLookahead;
118 std::string mLookaheadDF;
119 // The plan and trees adopted for a DF, until planFor() starts that DF.
120 std::string mAdoptedDF;
121 std::shared_ptr<o2::aod::native::ReadPlan> mAdoptedPlan;
122 std::vector<std::string> mAdoptedTrees;
123};
124
127{
128 public:
133 static std::shared_ptr<NativeAODInputFile> open(std::string const& url, RootObjectReadingFactory& factory, o2::aod::native::Options const& options, std::string const& name = {});
135 static std::shared_ptr<NativeAODInputFile> open(std::unique_ptr<o2::aod::native::ByteSource> source, RootObjectReadingFactory& factory, o2::aod::native::Options const& options, std::string const& name);
137 void setGridInfo(std::string se, double openTime);
138 std::string monitoringDetails() const override;
139
140 std::string name() const override { return mName; }
141 uint64_t size() const override;
142 uint64_t bytesRead() const override;
143 uint64_t readCalls() const override;
144 std::vector<Key> topLevelKeys() override;
145 std::vector<std::string> keysIn(std::string const& dir) override;
146 std::map<std::string, std::string> parentFiles() override { return mParentFiles; }
147 std::map<std::string, std::string> metaData() override { return mMetaData; }
148 std::shared_ptr<VirtualRootFileSystemBase> filesystem() override { return mFilesystem; }
149 void setReadOrder(std::vector<std::string> const& dfs) override { mFilesystem->setReadOrder(dfs); }
150
151 private:
152 NativeAODInputFile() = default;
153 std::string mName;
154 std::string mSE;
155 double mOpenTime = 0;
156 std::shared_ptr<o2::aod::native::RootFile> mFile;
157 std::shared_ptr<NativeAODFileSystem> mFilesystem;
158 std::map<std::string, std::string> mParentFiles;
159 std::map<std::string, std::string> mMetaData;
160};
161
162} // namespace o2::framework
163
164#endif // O2_FRAMEWORK_NATIVEAOD_H_
std::string url
std::vector< std::string > keys
std::vector< o2::aod::native::KeyInfo > keysOf(std::string const &df)
The keys of DF df, read once (or prepared ahead) for all users.
void setName(std::string name)
Definition NativeAOD.h:71
void setReadOrder(std::vector< std::string > dfs)
arrow::Result< arrow::fs::FileInfo > GetFileInfo(const std::string &path) override
std::string type_name() const override
Definition NativeAOD.h:47
std::shared_ptr< o2::aod::native::ReadPlan > planFor(std::string const &path)
Definition NativeAOD.cxx:63
bool CheckSupport(arrow::dataset::FileSource source) override
o2::aod::native::RootFile & file()
Definition NativeAOD.h:67
NativeTreeHandle * getTreeHandle(std::string const &path)
Definition NativeAOD.cxx:53
std::string const & name() const
Definition NativeAOD.h:70
std::shared_ptr< RootObjectHandler > GetObjectHandler(arrow::dataset::FileSource source) override
An AO2D read with the ROOT-free reader.
Definition NativeAOD.h:127
static std::shared_ptr< NativeAODInputFile > open(std::string const &url, RootObjectReadingFactory &factory, o2::aod::native::Options const &options, std::string const &name={})
std::vector< std::string > keysIn(std::string const &dir) override
Names of the keys inside the top-level directory dir, empty if there is none.
std::map< std::string, std::string > metaData() override
Definition NativeAOD.h:147
void setGridInfo(std::string se, double openTime)
The storage element and the seconds the grid lookup and open took, for monitoring.
std::map< std::string, std::string > parentFiles() override
DF_<n> to parent file path. Empty if the file has no parentFiles.
Definition NativeAOD.h:146
uint64_t size() const override
uint64_t readCalls() const override
std::string name() const override
Definition NativeAOD.h:140
std::string monitoringDetails() const override
Extra key=value pairs for the file monitoring metrics, starting with a comma.
void setReadOrder(std::vector< std::string > const &dfs) override
The DF_<n> names in the order they will be read, for readers which read ahead.
Definition NativeAOD.h:149
std::shared_ptr< VirtualRootFileSystemBase > filesystem() override
Definition NativeAOD.h:148
std::vector< Key > topLevelKeys() override
Top-level keys, in the order the file lists them, all cycles.
uint64_t bytesRead() const override
GLuint const GLchar * name
Definition glcorearb.h:781
GLsizei GLsizei GLchar * source
Definition glcorearb.h:798
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::shared_ptr< o2::aod::native::ByteSource > source
Definition NativeAOD.h:36
o2::aod::native::TreeInfo tree
Definition NativeAOD.h:35
o2::aod::native::Options options
Definition NativeAOD.h:37