All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
13 DECLARE_NAMESPACE_CONVERTER_FACTORY(RootHistCnv,RRWNTupleCnv)
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  const INTuple::ItemContainer& itms = nt->items();
23  // Book the tree
24  rtree = new TTree(desc.c_str(),nt->title().c_str());
25  // Add the branches
26  for (size_t length = itms.size(), i = 0; i < length; i++ ) {
27  const char* itm = itms[i]->name().c_str();
28  std::string tag = itm;
29  tag += rootVarType( itms[i]->type() );
30  // add the branch
31  log << MSG::INFO << "ID " << desc << ": added branch: "
32  << itm << " / " << tag << endmsg;
33  rtree->Branch(itm,const_cast<void*>(itms[i]->buffer()),tag.c_str());
34  }
35  log << MSG::INFO << "Booked TTree with ID:" << desc
36  << " \"" << nt->title() << "\"" << endmsg;
37  return StatusCode::SUCCESS;
38 }
39 
40 //------------------------------------------------------------------------------
42 //------------------------------------------------------------------------------
43 {
44  if ( 0 != rtree ) {
45  // Fill the tree;
46  rtree->Fill();
47  // Reset the NTuple
48  nt->reset();
49  return StatusCode::SUCCESS;
50  }
51  MsgStream log(msgSvc(), "RRWNTupleCnv");
52  log << MSG::ERROR << "Attempt to write invalid N-tuple.";
53  if ( nt != 0 ) log << nt->title();
54  log << endmsg;
55  return StatusCode::FAILURE;
56 }
57 
58 //------------------------------------------------------------------------------
60  INTuple* /* nt */,
61  long /* ievt */)
62 //------------------------------------------------------------------------------
63 {
64  return StatusCode::FAILURE;
65 }
66 
67 //------------------------------------------------------------------------------
69  INTuple*& /* refpObject */)
70 //------------------------------------------------------------------------------
71 {
72  return StatusCode::FAILURE;
73 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual StatusCode readData(TTree *rtree, INTuple *pObject, long ievt)
Read N tuple data.
GAUDI_API AIDA::IHistogram1D * book(IHistogramSvc *svc, const std::string &path, const Gaudi::Histo1DDef &hist)
helper function to book 1D-histogram
Definition: HistoDef.cpp:132
tuple itm
Definition: ana.py:57
std::vector< INTupleItem * > ItemContainer
Definition: INTuple.h:86
virtual const std::string & title() const =0
Object title.
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:131
virtual StatusCode writeData(TTree *rtree, INTuple *pObject)
Write N tuple data.
Row wise NTuple converter class definition.
Definition: RRWNTupleCnv.h:18
NTuple interface class definition.
Definition: INTuple.h:80
virtual void reset()=0
Reset all entries to their default values.
string type
Definition: gaudirun.py:126
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual StatusCode load(TTree *tree, INTuple *&refpObject)
Create the transient representation of an object.
#define DECLARE_NAMESPACE_CONVERTER_FACTORY(n, x)
Definition: Converter.h:184
list itms
Definition: ana.py:135
list i
Definition: ana.py:128
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244