The Gaudi Framework  master (9e5914fb)
Loading...
Searching...
No Matches
RRWNTupleCnv.cpp
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#define ALLOW_ALL_TYPES
12
13// Compiler include files
16#include <GaudiKernel/NTuple.h>
17
18#include "RRWNTupleCnv.h"
19#include <TTree.h>
20
21// Instantiation of a static factory class used by clients to create
22// instances of this service
24
25//------------------------------------------------------------------------------
26StatusCode RootHistCnv::RRWNTupleCnv::book( const std::string& desc, INTuple* nt, TTree*& rtree )
27//------------------------------------------------------------------------------
28{
29 MsgStream log( msgSvc(), "RRWNTupleCnv" );
30 // Book the tree
31 rtree = new TTree( desc.c_str(), nt->title().c_str() );
32 // Add the branches
33 for ( const auto& i : nt->items() ) {
34 std::string tag = i->name() + rootVarType( i->type() );
35 // add the branch
36 log << MSG::INFO << "ID " << desc << ": added branch: " << i->name() << " / " << tag << endmsg;
37 rtree->Branch( i->name().c_str(), const_cast<void*>( i->buffer() ), tag.c_str() );
38 }
39 log << MSG::INFO << "Booked TTree with ID:" << desc << " \"" << nt->title() << "\"" << endmsg;
41}
42
43//------------------------------------------------------------------------------
45//------------------------------------------------------------------------------
46{
47 if ( rtree ) {
48 // Fill the tree;
49 rtree->Fill();
50 // Reset the NTuple
51 nt->reset();
53 }
54 MsgStream log( msgSvc(), "RRWNTupleCnv" );
55 log << MSG::ERROR << "Attempt to write invalid N-tuple.";
56 if ( nt ) log << nt->title();
57 log << endmsg;
59}
60
61//------------------------------------------------------------------------------
62StatusCode RootHistCnv::RRWNTupleCnv::readData( TTree* /* tree */, INTuple* /* nt */, long /* ievt */ )
63//------------------------------------------------------------------------------
64{
66}
67
68//------------------------------------------------------------------------------
69StatusCode RootHistCnv::RRWNTupleCnv::load( TTree* /* tree */, INTuple*& /* refpObject */ )
70//------------------------------------------------------------------------------
71{
73}
#define DECLARE_CONVERTER(x)
Definition Converter.h:142
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
NTuple interface class definition.
Definition INTuple.h:86
virtual void reset()=0
Reset all entries to their default values.
virtual const std::string & title() const =0
Object title.
Definition of the MsgStream class used to transmit messages.
Definition MsgStream.h:29
virtual std::string rootVarType(int)
Return ROOT type info:
Row wise NTuple converter class definition.
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.
RRWNTupleCnv(ISvcLocator *svc)
Standard constructor.
StatusCode writeData(TTree *rtree, INTuple *pObject) override
Write N tuple data.
StatusCode load(TTree *tree, INTuple *&refpObject) override
Create the transient representation of an object.
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
@ ERROR
Definition IMessageSvc.h:22
@ INFO
Definition IMessageSvc.h:22
STL namespace.