BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
RootFileWriter.cxx
Go to the documentation of this file.
2#include "TFile.h"
3#include "TTree.h"
4#include "TBufferFile.h"
8#include <stdlib.h>
9
11 : m_fname( fname),
12 m_firstRound( true ),
13 m_stat(0)
14{
15 m_file = new TFile(fname.c_str(), "RECREATE");
16 m_tree = new TTree("Event","Event");
17 m_jtree = new TTree("JobInfoTree", "Job info");
18 m_evt = new TBossFullEvent;
19 m_jobInfo = new TJobInfo;
20}
21
23{
24 if ( m_file->IsOpen() ) {
25 this->close();
26 }
27
28 delete m_file;
29 //delete m_tree;
30 //delete m_jtree;
31 delete m_evt;
32 delete m_jobInfo;
33}
34
35int RootFileWriter::writeEvent(void* pevt, int size)
36{
37 if ( size == 4 ) {
38 m_stat = *((int*)pevt);
39 if ( m_stat == DistBossCode::StatusFinalize ) {
40 throw ReachEndOfFileList();
41 }
42 else {
43 throw RawExMessage("[RootFileWriter] Get an invalid DistBossCode!");
44 }
45 }
46
47 TBufferFile buffer(TBuffer::kRead, size, ((char*)pevt+4), kFALSE);
48 TBossFullEvent * evt = (TBossFullEvent*)buffer.ReadObject(TBossFullEvent::Class());
49
50 m_evt->copy(evt);
51
52 /*
53 static int ii = 0;
54 std::cout << "Total: " << ++ii << " Run: " << m_evt->m_EvtHeader->getRunId()
55 << " Evt: " << m_evt->m_EvtHeader->getEventId() << std::endl;
56 */
57
58 if ( m_firstRound ) {
59 if (m_evt->m_EvtHeader) m_tree->Branch("TEvtHeader","TEvtHeader",&m_evt->m_EvtHeader,3200000,1);
60 if (m_evt->m_digiEvt) m_tree->Branch("TDigiEvent","TDigiEvent",&m_evt->m_digiEvt,3200000,1);
61 if (m_evt->m_dstEvt) m_tree->Branch("TDstEvent", "TDstEvent", &m_evt->m_dstEvt, 3200000, 1);
62 if (m_evt->m_mcEvt) m_tree->Branch("TMcEvent","TMcEvent",&m_evt->m_mcEvt,3200000,1);
63 if (m_evt->m_trigEvt) m_tree->Branch("TTrigEvent","TTrigEvent",&m_evt->m_trigEvt,3200000,1);
64 if (m_evt->m_hltEvt) m_tree->Branch("THltEvent","THltEvent",&m_evt->m_hltEvt,3200000,1);
65 if (m_evt->m_rectrackEvt) m_tree->Branch("TRecEvent", "TRecTrackEvent", &m_evt->m_rectrackEvt, 3200000, 1);
66 if (m_evt->m_evtRecObject) m_tree->Branch("TEvtRecObject", "TEvtRecObject", &m_evt->m_evtRecObject, 3200000, 1);
67
68 m_jtree->Branch("JobInfo",&m_jobInfo);
69
70 m_firstRound = false;
71 }
72
73 if ( m_file->IsZombie() || (!m_file->IsOpen()) ) {
74 std::cout<<"ROOT File: " << m_fname << " bad status in RootFileWriter" << std::endl;
75 exit(1);
76 }
77
78 int nb = m_tree->Fill();
79 if ( nb == -1 ) {
80 std::cerr << "RootFileWriter: error in fill tree " << m_tree->GetName() << std::endl;
81 exit(1);
82 }
83
84 delete evt;
85
86 m_evt->reset();
87 m_file = m_tree->GetCurrentFile();
88
89 return nb;
90}
91
93{
94 m_jobInfo->setBossVer( getenv("BES_RELEASE") );
95 m_jobInfo->addJobOptions( this->getJobOptions() );
96 m_jobInfo->setDecayOptions( this->getDecayOptions() );
97 m_jtree->Fill();
98
99 m_file->Write();
100 m_file->Close();
101
102 m_stat = 1;
103
104 return 0;
105}
106
108{
109 return m_stat;
110}
111
112std::string RootFileWriter::getJobOptions()
113{
114 string opts("JobOptions Place Holder\n");
115 return opts;
116}
117
118std::string RootFileWriter::getDecayOptions()
119{
120 string opts("DecayOptions Place Holder\n");
121 return opts;
122}
int writeEvent(void *pevt, int size)
virtual ~RootFileWriter()
RootFileWriter(WriterArgType &fname)
const std::string WriterArgType
TRecTrackEvent * m_rectrackEvt
THltEvent * m_hltEvt
TDstEvent * m_dstEvt
TEvtRecObject * m_evtRecObject
TDigiEvent * m_digiEvt
TTrigEvent * m_trigEvt
TMcEvent * m_mcEvt
void copy(TBossFullEvent *obj)
TEvtHeader * m_EvtHeader
void setBossVer(string ver)
Definition TJobInfo.h:21
void setDecayOptions(string opt)
Definition TJobInfo.h:24
void addJobOptions(string opt)
Definition TJobInfo.h:22