The Gaudi Framework  v29r0 (ff2e7097)
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 //------------------------------------------------------------------------------
16 StatusCode RootHistCnv::RRWNTupleCnv::book( const std::string& desc, INTuple* nt, TTree*& rtree )
17 //------------------------------------------------------------------------------
18 {
19  MsgStream log( msgSvc(), "RRWNTupleCnv" );
20  // Book the tree
21  rtree = new TTree( desc.c_str(), nt->title().c_str() );
22  // Add the branches
23  for ( const auto& i : nt->items() ) {
24  std::string tag = i->name() + rootVarType( i->type() );
25  // add the branch
26  log << MSG::INFO << "ID " << desc << ": added branch: " << i->name() << " / " << tag << endmsg;
27  rtree->Branch( i->name().c_str(), const_cast<void*>( i->buffer() ), tag.c_str() );
28  }
29  log << MSG::INFO << "Booked TTree with ID:" << desc << " \"" << nt->title() << "\"" << endmsg;
30  return StatusCode::SUCCESS;
31 }
32 
33 //------------------------------------------------------------------------------
35 //------------------------------------------------------------------------------
36 {
37  if ( rtree ) {
38  // Fill the tree;
39  rtree->Fill();
40  // Reset the NTuple
41  nt->reset();
42  return StatusCode::SUCCESS;
43  }
44  MsgStream log( msgSvc(), "RRWNTupleCnv" );
45  log << MSG::ERROR << "Attempt to write invalid N-tuple.";
46  if ( nt ) log << nt->title();
47  log << endmsg;
48  return StatusCode::FAILURE;
49 }
50 
51 //------------------------------------------------------------------------------
52 StatusCode RootHistCnv::RRWNTupleCnv::readData( TTree* /* tree */, INTuple* /* nt */, long /* ievt */ )
53 //------------------------------------------------------------------------------
54 {
55  return StatusCode::FAILURE;
56 }
57 
58 //------------------------------------------------------------------------------
59 StatusCode RootHistCnv::RRWNTupleCnv::load( TTree* /* tree */, INTuple*& /* refpObject */ )
60 //------------------------------------------------------------------------------
61 {
62  return StatusCode::FAILURE;
63 }
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:105
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:103
STL namespace.
Row wise NTuple converter class definition.
Definition: RRWNTupleCnv.h:18
StatusCode load(TTree *tree, INTuple *&refpObject) override
Create the transient representation of an object.
STL class.
NTuple interface class definition.
Definition: INTuple.h:82
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:28
StatusCode readData(TTree *rtree, INTuple *pObject, long ievt) override
Read N tuple data.
#define DECLARE_NAMESPACE_CONVERTER_FACTORY(n, x)
Definition: Converter.h:177
T c_str(T...args)
virtual const std::string & title() const =0
Object title.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode writeData(TTree *rtree, INTuple *pObject) override
Write N tuple data.