RRWNTupleCnv.cpp
Go to the documentation of this file.
1 #define ALLOW_ALL_TYPES
2 
3 // Compiler include files
5 #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,
17  INTuple* nt,
18  TTree*& rtree)
19 //------------------------------------------------------------------------------
20 {
21  MsgStream log(msgSvc(), "RRWNTupleCnv");
22  // Book the tree
23  rtree = new TTree(desc.c_str(),nt->title().c_str());
24  // Add the branches
25  for (const auto& i : nt->items() ) {
26  std::string tag = i->name() + rootVarType( i->type() );
27  // add the branch
28  log << MSG::INFO << "ID " << desc << ": added branch: "
29  << i->name() << " / " << tag << endmsg;
30  rtree->Branch(i->name().c_str(),const_cast<void*>(i->buffer()),tag.c_str());
31  }
32  log << MSG::INFO << "Booked TTree with ID:" << desc
33  << " \"" << nt->title() << "\"" << endmsg;
34  return StatusCode::SUCCESS;
35 }
36 
37 //------------------------------------------------------------------------------
39 //------------------------------------------------------------------------------
40 {
41  if ( rtree ) {
42  // Fill the tree;
43  rtree->Fill();
44  // Reset the NTuple
45  nt->reset();
46  return StatusCode::SUCCESS;
47  }
48  MsgStream log(msgSvc(), "RRWNTupleCnv");
49  log << MSG::ERROR << "Attempt to write invalid N-tuple.";
50  if ( nt ) log << nt->title();
51  log << endmsg;
52  return StatusCode::FAILURE;
53 }
54 
55 //------------------------------------------------------------------------------
57  INTuple* /* nt */,
58  long /* ievt */)
59 //------------------------------------------------------------------------------
60 {
61  return StatusCode::FAILURE;
62 }
63 
64 //------------------------------------------------------------------------------
66  INTuple*& /* refpObject */)
67 //------------------------------------------------------------------------------
68 {
69  return StatusCode::FAILURE;
70 }
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:124
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:129
STL namespace.
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:79
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:26
StatusCode readData(TTree *rtree, INTuple *pObject, long ievt) override
Read N tuple data.
#define DECLARE_NAMESPACE_CONVERTER_FACTORY(n, x)
Definition: Converter.h:184
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:244
StatusCode writeData(TTree *rtree, INTuple *pObject) override
Write N tuple data.