The Gaudi Framework  v32r2 (46d42edc)
RRWNTupleCnv.cpp
Go to the documentation of this file.
1 #define ALLOW_ALL_TYPES
2 
3 // Compiler include files
6 #include "GaudiKernel/NTuple.h"
7 
8 #include "RRWNTupleCnv.h"
9 #include "TTree.h"
10 
11 // Instantiation of a static factory class used by clients to create
12 // instances of this service
14 
15 // FIXME - leak sanitizers generate a number of warnings here
16 //
17 // clang-format off
18 // Indirect leak of 160 byte(s) in 2 object(s) allocated from:
19 // #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
20 // #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
21 // #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
22 // #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
23 // #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
24 // clang-format on
25 //
26 // These leaks are currently suppressed in Gaudi/job/Gaudi-LSan.supp - remove entry there to reactivate
27 
28 //------------------------------------------------------------------------------
29 StatusCode RootHistCnv::RRWNTupleCnv::book( const std::string& desc, INTuple* nt, TTree*& rtree )
30 //------------------------------------------------------------------------------
31 {
32  MsgStream log( msgSvc(), "RRWNTupleCnv" );
33  // Book the tree
34  rtree = new TTree( desc.c_str(), nt->title().c_str() );
35  // Add the branches
36  for ( const auto& i : nt->items() ) {
37  std::string tag = i->name() + rootVarType( i->type() );
38  // add the branch
39  log << MSG::INFO << "ID " << desc << ": added branch: " << i->name() << " / " << tag << endmsg;
40  rtree->Branch( i->name().c_str(), const_cast<void*>( i->buffer() ), tag.c_str() );
41  }
42  log << MSG::INFO << "Booked TTree with ID:" << desc << " \"" << nt->title() << "\"" << endmsg;
43  return StatusCode::SUCCESS;
44 }
45 
46 //------------------------------------------------------------------------------
48 //------------------------------------------------------------------------------
49 {
50  if ( rtree ) {
51  // Fill the tree;
52  rtree->Fill();
53  // Reset the NTuple
54  nt->reset();
55  return StatusCode::SUCCESS;
56  }
57  MsgStream log( msgSvc(), "RRWNTupleCnv" );
58  log << MSG::ERROR << "Attempt to write invalid N-tuple.";
59  if ( nt ) log << nt->title();
60  log << endmsg;
61  return StatusCode::FAILURE;
62 }
63 
64 //------------------------------------------------------------------------------
65 StatusCode RootHistCnv::RRWNTupleCnv::readData( TTree* /* tree */, INTuple* /* nt */, long /* ievt */ )
66 //------------------------------------------------------------------------------
67 {
68  return StatusCode::FAILURE;
69 }
70 
71 //------------------------------------------------------------------------------
72 StatusCode RootHistCnv::RRWNTupleCnv::load( TTree* /* tree */, INTuple*& /* refpObject */ )
73 //------------------------------------------------------------------------------
74 {
75  return StatusCode::FAILURE;
76 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
GAUDI_API AIDA::IHistogram1D * book(IHistogramSvc *svc, const std::string &path, const Gaudi::Histo1DDef &hist)
helper function to book 1D-histogram
Definition: HistoDef.cpp:87
virtual const std::string & title() const =0
Object title.
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
STL namespace.
#define DECLARE_CONVERTER(x)
Definition: Converter.h:150
Row wise NTuple converter class definition.
Definition: RRWNTupleCnv.h:17
StatusCode load(TTree *tree, INTuple *&refpObject) override
Create the transient representation of an object.
STL class.
NTuple interface class definition.
Definition: INTuple.h:81
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:95
virtual void reset()=0
Reset all entries to their default values.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
StatusCode readData(TTree *rtree, INTuple *pObject, long ievt) override
Read N tuple data.
T c_str(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:86
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
StatusCode writeData(TTree *rtree, INTuple *pObject) override
Write N tuple data.