The Gaudi Framework  master (37c0b60a)
RRWNTupleCnv.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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
14 #include <GaudiKernel/INTupleSvc.h>
15 #include <GaudiKernel/MsgStream.h>
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 // FIXME - leak sanitizers generate a number of warnings here
26 //
27 // clang-format off
28 // Indirect leak of 160 byte(s) in 2 object(s) allocated from:
29 // #0 0x7ff846fbbec8 in operator new[](unsigned long) /afs/cern.ch/cms/CAF/CMSCOMM/COMM_ECAL/dkonst/GCC/build/contrib/gcc-8.2.0/src/gcc/8.2.0/libsanitizer/lsan/lsan_interceptors.cc:231
30 // #1 0x7ff8336e7653 in TBranch::Init(char const*, char const*, int) /mnt/build/jenkins/workspace/lcg_release_tar/BUILDTYPE/Debug/COMPILER/gcc8binutils/LABEL/centos7/build/projects/ROOT-6.18.00/src/ROOT/6.18.00/tree/tree/src/TBranch.cxx:309
31 // #2 0x7ff8336e7039 in TBranch::TBranch(TTree*, char const*, void*, char const*, int, int) /mnt/build/jenkins/workspace/lcg_release_tar/BUILDTYPE/Debug/COMPILER/gcc8binutils/LABEL/centos7/build/projects/ROOT-6.18.00/src/ROOT/6.18.00/tree/tree/src/TBranch.cxx:239
32 // #3 0x7ff833773ceb in TTree::Branch(char const*, void*, char const*, int) /mnt/build/jenkins/workspace/lcg_release_tar/BUILDTYPE/Debug/COMPILER/gcc8binutils/LABEL/centos7/build/projects/ROOT-6.18.00/src/ROOT/6.18.00/tree/tree/src/TTree.cxx:1893
33 // #4 0x7ff831763748 in RootHistCnv::RRWNTupleCnv::book(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, INTuple*, TTree*&) ../RootHistCnv/src/RRWNTupleCnv.cpp:27
34 // clang-format on
35 //
36 // These leaks are currently suppressed in Gaudi/job/Gaudi-LSan.supp - remove entry there to reactivate
37 
38 //------------------------------------------------------------------------------
39 StatusCode RootHistCnv::RRWNTupleCnv::book( const std::string& desc, INTuple* nt, TTree*& rtree )
40 //------------------------------------------------------------------------------
41 {
42  MsgStream log( msgSvc(), "RRWNTupleCnv" );
43  // Book the tree
44  rtree = new TTree( desc.c_str(), nt->title().c_str() );
45  // Add the branches
46  for ( const auto& i : nt->items() ) {
47  std::string tag = i->name() + rootVarType( i->type() );
48  // add the branch
49  log << MSG::INFO << "ID " << desc << ": added branch: " << i->name() << " / " << tag << endmsg;
50  rtree->Branch( i->name().c_str(), const_cast<void*>( i->buffer() ), tag.c_str() );
51  }
52  log << MSG::INFO << "Booked TTree with ID:" << desc << " \"" << nt->title() << "\"" << endmsg;
53  return StatusCode::SUCCESS;
54 }
55 
56 //------------------------------------------------------------------------------
58 //------------------------------------------------------------------------------
59 {
60  if ( rtree ) {
61  // Fill the tree;
62  rtree->Fill();
63  // Reset the NTuple
64  nt->reset();
65  return StatusCode::SUCCESS;
66  }
67  MsgStream log( msgSvc(), "RRWNTupleCnv" );
68  log << MSG::ERROR << "Attempt to write invalid N-tuple.";
69  if ( nt ) log << nt->title();
70  log << endmsg;
71  return StatusCode::FAILURE;
72 }
73 
74 //------------------------------------------------------------------------------
75 StatusCode RootHistCnv::RRWNTupleCnv::readData( TTree* /* tree */, INTuple* /* nt */, long /* ievt */ )
76 //------------------------------------------------------------------------------
77 {
78  return StatusCode::FAILURE;
79 }
80 
81 //------------------------------------------------------------------------------
82 StatusCode RootHistCnv::RRWNTupleCnv::load( TTree* /* tree */, INTuple*& /* refpObject */ )
83 //------------------------------------------------------------------------------
84 {
85  return StatusCode::FAILURE;
86 }
RootHistCnv::RRWNTupleCnv::writeData
StatusCode writeData(TTree *rtree, INTuple *pObject) override
Write N tuple data.
Definition: RRWNTupleCnv.cpp:57
std::string
STL class.
Gaudi.Configuration.log
log
Definition: Configuration.py:28
MSG::INFO
@ INFO
Definition: IMessageSvc.h:25
DECLARE_CONVERTER
#define DECLARE_CONVERTER(x)
Definition: Converter.h:163
RootHistCnv::RRWNTupleCnv::readData
StatusCode readData(TTree *rtree, INTuple *pObject, long ievt) override
Read N tuple data.
Definition: RRWNTupleCnv.cpp:75
AvalancheSchedulerErrorTest.msgSvc
msgSvc
Definition: AvalancheSchedulerErrorTest.py:80
RootHistCnv
Definition: DirectoryCnv.h:27
StatusCode
Definition: StatusCode.h:65
RRWNTupleCnv.h
Gaudi::Histos::book
GAUDI_API AIDA::IHistogram1D * book(IHistogramSvc *svc, const std::string &path, const Gaudi::Histo1DDef &hist)
helper function to book 1D-histogram
Definition: HistoDef.cpp:77
std::string::c_str
T c_str(T... args)
NTuple.h
INTuple
Definition: INTuple.h:91
RootHistCnv::RRWNTupleCnv
Definition: RRWNTupleCnv.h:27
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
MsgStream
Definition: MsgStream.h:33
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
std
STL namespace.
MSG::ERROR
@ ERROR
Definition: IMessageSvc.h:25
INTuple::title
virtual const std::string & title() const =0
Object title.
Converter::msgSvc
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:105
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
INTuple::reset
virtual void reset()=0
Reset all entries to their default values.
RootHistCnv::RRWNTupleCnv::load
StatusCode load(TTree *tree, INTuple *&refpObject) override
Create the transient representation of an object.
Definition: RRWNTupleCnv.cpp:82
INTupleSvc.h
MsgStream.h