RRWNTupleCnv.cpp
Go to the documentation of this file.00001
00002 #define ROOTHISTCNV_RRWNTUPLECNV_CPP
00003
00004 #define ALLOW_ALL_TYPES
00005
00006
00007 #include "GaudiKernel/CnvFactory.h"
00008 #include "GaudiKernel/MsgStream.h"
00009 #include "GaudiKernel/NTuple.h"
00010 #include "GaudiKernel/INTupleSvc.h"
00011
00012 #include "RRWNTupleCnv.h"
00013 #include "TTree.h"
00014
00015
00016
00017 DECLARE_NAMESPACE_CONVERTER_FACTORY(RootHistCnv,RRWNTupleCnv)
00018
00019
00020 StatusCode RootHistCnv::RRWNTupleCnv::book(const std::string& desc,
00021 INTuple* nt,
00022 TTree*& rtree)
00023
00024 {
00025 MsgStream log(msgSvc(), "RRWNTupleCnv");
00026 const INTuple::ItemContainer& itms = nt->items();
00027
00028 rtree = new TTree(desc.c_str(),nt->title().c_str());
00029
00030 for (size_t length = itms.size(), i = 0; i < length; i++ ) {
00031 const char* itm = itms[i]->name().c_str();
00032 std::string tag = itm;
00033 tag += rootVarType( itms[i]->type() );
00034
00035 log << MSG::INFO << "ID " << desc << ": added branch: "
00036 << itm << " / " << tag << endmsg;
00037 rtree->Branch(itm,const_cast<void*>(itms[i]->buffer()),tag.c_str());
00038 }
00039 log << MSG::INFO << "Booked TTree with ID:" << desc
00040 << " \"" << nt->title() << "\"" << endmsg;
00041 return StatusCode::SUCCESS;
00042 }
00043
00044
00045 StatusCode RootHistCnv::RRWNTupleCnv::writeData(TTree* rtree, INTuple* nt)
00046
00047 {
00048 if ( 0 != rtree ) {
00049
00050 rtree->Fill();
00051
00052 nt->reset();
00053 return StatusCode::SUCCESS;
00054 }
00055 MsgStream log(msgSvc(), "RRWNTupleCnv");
00056 log << MSG::ERROR << "Attempt to write invalid N-tuple.";
00057 if ( nt != 0 ) log << nt->title();
00058 log << endmsg;
00059 return StatusCode::FAILURE;
00060 }
00061
00062
00063 StatusCode RootHistCnv::RRWNTupleCnv::readData(TTree* ,
00064 INTuple* ,
00065 long )
00066
00067 {
00068 return StatusCode::FAILURE;
00069 }
00070
00071
00072 StatusCode RootHistCnv::RRWNTupleCnv::load(TTree* ,
00073 INTuple*& )
00074
00075 {
00076 return StatusCode::FAILURE;
00077 }