The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
NTupleSvc.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 // Framework include files
14 #include <GaudiKernel/DataSvc.h>
16 #include <GaudiKernel/INTupleSvc.h>
17 
18 // STL include files
19 #include <map>
20 
32 class NTupleSvc : public extends<DataSvc, INTupleSvc, IDataSourceMgr> {
33 protected:
34  struct Connection final {
37  Connection( const Connection& c ) : service( c.service ) {}
38  };
39  typedef std::vector<std::string> DBaseEntries;
40  typedef std::pair<std::string, std::string> Prop;
41 
42 public:
44  StatusCode initialize() override;
46  StatusCode reinitialize() override;
48  StatusCode finalize() override;
50  IConversionSvc* getDataLoader( IRegistry* pReg ) override;
51 
53  NTuple::Directory* createDirectory( DataObject* pParent, const std::string& title ) override;
55  NTuple::Directory* createDirectory( DataObject* pParent, long id ) override;
57  NTuple::Directory* createDirectory( const std::string& dirPath, long id ) override;
59  NTuple::Directory* createDirectory( const std::string& dirPath, const std::string& title ) override;
61  NTuple::Directory* createDirectory( const std::string& fullPath ) override;
62 
64  StatusCode create( const CLID& typ, const std::string& title, NTuple::Tuple*& refpTuple ) override;
66  NTuple::Tuple* book( const std::string& fullPath, const CLID& type, const std::string& title ) override;
68  NTuple::Tuple* book( const std::string& dirPath, const std::string& relPath, const CLID& type,
69  const std::string& title ) override;
71  NTuple::Tuple* book( const std::string& dirPath, long id, const CLID& type, const std::string& title ) override;
73  NTuple::Tuple* book( DataObject* pParent, const std::string& relPath, const CLID& type,
74  const std::string& title ) override;
76  NTuple::Tuple* book( DataObject* pParent, long id, const CLID& type, const std::string& title ) override;
78  NTuple::Tuple* access( const std::string& fullPath, const std::string& filename ) override;
80  StatusCode save( const std::string& fullPath ) override;
82  StatusCode save( NTuple::Tuple* tuple ) override;
84  StatusCode save( DataObject* pParent, const std::string& relPath ) override;
86  StatusCode writeRecord( NTuple::Tuple* tuple ) override;
88  StatusCode writeRecord( const std::string& fullPath ) override;
90  StatusCode writeRecord( DataObject* pParent, const std::string& relPath ) override;
92  StatusCode readRecord( NTuple::Tuple* tuple ) override;
94  StatusCode readRecord( const std::string& fullPath ) override;
96  StatusCode readRecord( DataObject* pParent, const std::string& relPath ) override;
97 
99  bool isConnected( const std::string& identifier ) const override;
100 
102  StatusCode connect( const std::string& ident ) override;
104  StatusCode connect( const std::string& ident, std::string& logname ) override;
106  StatusCode disconnect( const std::string& nam ) override;
108  StatusCode disconnectAll() override;
109 
111  NTupleSvc( const std::string& name, ISvcLocator* svc );
112 
113 protected:
115  StatusCode createService( const std::string& nam, const std::string& typ, const std::vector<Prop>& props,
116  IConversionSvc*& pSvc );
118  void releaseConnection( Connection& c );
120  StatusCode attachTuple( const std::string& filename, const std::string& logname, const char typ, const long t );
123 
124  Gaudi::Property<DBaseEntries> m_input{ this, "Input", {}, "input streams" };
125  Gaudi::Property<DBaseEntries> m_output{ this, "Output", {}, "output streams" };
126 
127  Gaudi::Property<int> m_basketsize{ this, "BasketSize", 32000, "BasketSize" }; // ROOT default
129  std::map<std::string, Connection> m_connections;
130 };
NTupleSvc
Definition: NTupleSvc.h:32
NTupleSvc::m_connections
std::map< std::string, Connection > m_connections
Container of connection points.
Definition: NTupleSvc.h:129
NTupleSvc::createDirectory
NTuple::Directory * createDirectory(DataObject *pParent, const std::string &title) override
Create Ntuple directory and register it with the data store.
Definition: NTupleSvc.cpp:400
NTupleSvc::attachTuple
StatusCode attachTuple(const std::string &filename, const std::string &logname, const char typ, const long t)
Attach output/input file.
Definition: NTupleSvc.cpp:433
NTupleSvc::writeRecord
StatusCode writeRecord(NTuple::Tuple *tuple) override
Write single record to N tuple.
Definition: NTupleSvc.cpp:527
NTuple::Directory
Small class representing an N tuple directory in the transient store.
Definition: NTuple.h:906
NTupleSvc::updateDirectories
StatusCode updateDirectories()
Update directory data.
Definition: NTupleSvc.cpp:105
NTupleSvc::Connection::service
IConversionSvc * service
Definition: NTupleSvc.h:35
gaudirun.s
string s
Definition: gaudirun.py:346
check_ParticleID.props
props
Definition: check_ParticleID.py:21
ISvcLocator
Definition: ISvcLocator.h:42
NTupleSvc::Prop
std::pair< std::string, std::string > Prop
Definition: NTupleSvc.h:40
NTupleSvc::reinitialize
StatusCode reinitialize() override
DataSvc overrides: reinitialize service.
Definition: NTupleSvc.cpp:86
NTupleSvc::book
NTuple::Tuple * book(const std::string &fullPath, const CLID &type, const std::string &title) override
Book Ntuple and register it with the data store.
Definition: NTupleSvc.cpp:327
NTupleSvc::DBaseEntries
std::vector< std::string > DBaseEntries
Definition: NTupleSvc.h:39
NTupleSvc::m_output
Gaudi::Property< DBaseEntries > m_output
Definition: NTupleSvc.h:125
gaudirun.c
c
Definition: gaudirun.py:525
IRegistry
Definition: IRegistry.h:29
NTupleSvc::Connection::Connection
Connection(const Connection &c)
Definition: NTupleSvc.h:37
bug_34121.t
t
Definition: bug_34121.py:31
IDataSourceMgr.h
NTupleSvc::connect
StatusCode connect(const std::string &ident) override
Add file to list I/O list.
Definition: NTupleSvc.cpp:187
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:333
StatusCode
Definition: StatusCode.h:64
NTupleSvc::finalize
StatusCode finalize() override
DataSvc overrides: stop the service.
Definition: NTupleSvc.cpp:179
NTupleSvc::access
NTuple::Tuple * access(const std::string &fullPath, const std::string &filename) override
Access N tuple on disk.
Definition: NTupleSvc.cpp:491
NTupleSvc::m_input
Gaudi::Property< DBaseEntries > m_input
Definition: NTupleSvc.h:124
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:16
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:19
NTupleSvc::create
StatusCode create(const CLID &typ, const std::string &title, NTuple::Tuple *&refpTuple) override
Create requested N tuple (Hide constructor)
Definition: NTupleSvc.cpp:308
NTupleSvc::Connection
Definition: NTupleSvc.h:34
NTupleSvc::releaseConnection
void releaseConnection(Connection &c)
Finalize single service.
Definition: NTupleSvc.cpp:155
NTupleSvc::disconnect
StatusCode disconnect(const std::string &nam) override
Close open connection.
Definition: NTupleSvc.cpp:163
gaudirun.type
type
Definition: gaudirun.py:160
NTupleSvc::isConnected
bool isConnected(const std::string &identifier) const override
Check if a datasource is connected.
Definition: NTupleSvc.cpp:89
NTupleSvc::createService
StatusCode createService(const std::string &nam, const std::string &typ, const std::vector< Prop > &props, IConversionSvc *&pSvc)
Create conversion service.
Definition: NTupleSvc.cpp:255
NTuple::Tuple
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:380
NTupleSvc::disconnectAll
StatusCode disconnectAll() override
Close all open connections.
Definition: NTupleSvc.cpp:172
DataObject
Definition: DataObject.h:37
GaudiConfig2.semantics.ident
ident
Definition: semantics.py:203
NTupleSvc::Connection::Connection
Connection(IConversionSvc *s)
Definition: NTupleSvc.h:36
NTupleSvc::NTupleSvc
NTupleSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: NTupleSvc.cpp:61
NTupleSvc::initialize
StatusCode initialize() override
DataSvc overrides: Initialize the service.
Definition: NTupleSvc.cpp:67
NTupleSvc::readRecord
StatusCode readRecord(NTuple::Tuple *tuple) override
Read single record from N tuple.
Definition: NTupleSvc.cpp:567
NTupleSvc::getDataLoader
IConversionSvc * getDataLoader(IRegistry *pReg) override
DataSvc overrides: Retrieve data loader.
Definition: NTupleSvc.cpp:95
graphanalysis.filename
filename
Definition: graphanalysis.py:130
DataSvc.h
Gaudi::Property< DBaseEntries >
INTupleSvc.h
NTupleSvc::save
StatusCode save(const std::string &fullPath) override
Save N tuple to disk. Must be called in order to close the ntuple file properly.
Definition: NTupleSvc.cpp:494
NTupleSvc::m_basketsize
Gaudi::Property< int > m_basketsize
Definition: NTupleSvc.h:127
IConversionSvc
Definition: IConversionSvc.h:43