The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
RCWNTupleCnv.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
13// Include files
14#include "RNTupleCnv.h"
17
18#include <filesystem>
19#include <map>
20#include <memory>
21#include <mutex>
22#include <set>
23#include <string>
24#include <vector>
25
26#include <TFile.h>
27#include <TTree.h>
28
29namespace RootHistCnv {
30
36
37 class RCWNTupleCnv : public RNTupleCnv {
38 public:
40 static const CLID& classID() { return CLID_ColumnWiseTuple; }
43
44 StatusCode initialize() override;
45 StatusCode finalize() override;
47 StatusCode updateRep( IOpaqueAddress* pAddr, DataObject* pObj ) override;
48
50 struct Layout {
51 struct Item {
52 std::string name;
53 std::string block;
54 std::string leaflist;
55 long bufPos{ 0 };
56 long bufLen{ 0 };
57 long rangeLower{ 0 };
58 long rangeUpper{ -1 };
59 long indexPos{ -1 };
60 long unitBytes{ 0 };
61 long maxUnits{ 0 };
62 };
63 std::vector<Item> items;
64 long rowBytes{ 0 };
65 };
66
67 protected:
69 StatusCode load( TTree* tree, INTuple*& refpObject ) override;
71 StatusCode book( const std::string& desc, INTuple* pObject, TTree*& tree ) override;
73 StatusCode writeData( TTree* rtree, INTuple* pObject ) override;
75 StatusCode readData( TTree* rtree, INTuple* pObject, long ievt ) override;
76
77 private:
78 struct Buffered {
79 std::string desc;
81 std::unique_ptr<Gaudi::NTuple::DiskBuffer::Writer> writer;
82 };
83
84 Layout analyse( const INTuple& nt );
85 StatusCode createTree( const std::string& desc, INTuple* nt, const Layout& layout, TTree*& rtree );
86 StatusCode bookBuffered( const std::string& desc, INTuple* nt, Layout layout );
89 StatusCode bufferDirectory( std::filesystem::path& dir );
90 void releaseBufferDir();
92 bool replayed( INTuple* nt );
93
94 std::mutex m_mutex;
95 std::map<INTuple*, Buffered> m_buffered;
96 std::set<INTuple*> m_replayed;
97 std::filesystem::path m_bufferDir;
98 unsigned m_nextBufferId{ 0 };
99 bool m_bookDirect{ false };
100
102 bool m_diskBuffer{ false };
105 std::size_t m_diskBufferBlockSize{ 0 };
106 };
107} // namespace RootHistCnv
unsigned int CLID
Class ID definition.
Definition ClassID.h:16
A DataObject is the base class of any identifiable object on any data store.
Definition DataObject.h:37
NTuple interface class definition.
Definition INTuple.h:86
Opaque address interface definition.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
StatusCode load(TTree *tree, INTuple *&refpObject) override
Create the transient representation of an object.
StatusCode book(const std::string &desc, INTuple *pObject, TTree *&tree) override
Book the N tuple.
StatusCode readData(TTree *rtree, INTuple *pObject, long ievt) override
Read N tuple data.
StatusCode finalize() override
std::size_t m_diskBufferBlockSize
Buffered * buffered(INTuple *nt)
StatusCode createTree(const std::string &desc, INTuple *nt, const Layout &layout, TTree *&rtree)
std::map< INTuple *, Buffered > m_buffered
StatusCode writeBuffered(Buffered &b, INTuple *nt)
std::mutex m_mutex
guards m_buffered, m_replayed and m_bufferDir
StatusCode initialize() override
StatusCode replay(IOpaqueAddress *pAddr, INTuple *nt, Buffered &b)
RCWNTupleCnv(ISvcLocator *svc)
Standard constructor.
std::filesystem::path m_bufferDir
bool m_diskBuffer
NTupleSvc.DiskBuffer* of the service owning this stream, read once in initialize().
static const CLID & classID()
Inquire class type.
std::string m_diskBufferDirectory
std::set< INTuple * > m_replayed
tuples whose tree has been built; cannot be written again
StatusCode writeData(TTree *rtree, INTuple *pObject) override
Write N tuple data.
StatusCode bufferDirectory(std::filesystem::path &dir)
bool replayed(INTuple *nt)
StatusCode bookBuffered(const std::string &desc, INTuple *nt, Layout layout)
Layout analyse(const INTuple &nt)
bool m_bookDirect
force the columnar path in book()
StatusCode updateRep(IOpaqueAddress *pAddr, DataObject *pObj) override
Write the TTree; for a disk-buffered tuple, first build it from the buffer file.
RNTupleCnv(ISvcLocator *svc, const CLID &clid)
Standard constructor.
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
std::unique_ptr< Gaudi::NTuple::DiskBuffer::Writer > writer
std::string leaflist
ROOT leaf list, e.g. "x[n][3]/F".
long unitBytes
bytes per unit of the index
std::string name
variable name (leaf name)
long indexPos
position in items() of the counting item, -1 if fixed size
How the items of a tuple map onto the staging buffer and the TTree branches.