/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/DistBoss/RootFile/RootFile-00-00-05/src/RootFileWriter.cxx

Go to the documentation of this file.
00001 #include "RootFile/RootFileWriter.h"
00002 #include "TFile.h"
00003 #include "TTree.h"
00004 #include "TBufferFile.h"
00005 #include "RootEventData/TJobInfo.h"
00006 #include "IRawFile/RawFileExceptions.h"
00007 #include "DistBossUtil/DistBossCode.h"
00008 #include <stdlib.h>
00009 
00010 RootFileWriter::RootFileWriter(WriterArgType& fname)
00011    : m_fname( fname),
00012      m_firstRound( true ),
00013      m_stat(0)
00014 {
00015    m_file = new TFile(fname.c_str(), "RECREATE");
00016    m_tree = new TTree("Event","Event");
00017    m_jtree = new TTree("JobInfoTree", "Job info");
00018    m_evt  = new TBossFullEvent;
00019    m_jobInfo = new TJobInfo;
00020 }
00021 
00022 RootFileWriter::~RootFileWriter()
00023 {
00024    if ( m_file->IsOpen() ) {
00025       this->close();
00026    }
00027 
00028    delete m_file;
00029    //delete m_tree;
00030    //delete m_jtree;
00031    delete m_evt;
00032    delete m_jobInfo;
00033 }
00034 
00035 int RootFileWriter::writeEvent(void* pevt, int size)
00036 {
00037    if ( size == 4 ) {
00038       m_stat = *((int*)pevt);
00039       if ( m_stat == DistBossCode::StatusFinalize ) {
00040          throw ReachEndOfFileList();
00041       }
00042       else {
00043          throw RawExMessage("[RootFileWriter] Get an invalid DistBossCode!");
00044       }
00045    }
00046 
00047    TBufferFile buffer(TBuffer::kRead, size, ((char*)pevt+4), kFALSE);
00048    TBossFullEvent * evt = (TBossFullEvent*)buffer.ReadObject(TBossFullEvent::Class());
00049 
00050    m_evt->copy(evt);
00051 
00052    /*
00053    static int ii = 0;
00054    std::cout << "Total: " << ++ii << "   Run: " << m_evt->m_EvtHeader->getRunId()
00055              << "  Evt: " << m_evt->m_EvtHeader->getEventId() << std::endl;
00056              */
00057 
00058    if ( m_firstRound ) {
00059       if (m_evt->m_EvtHeader) m_tree->Branch("TEvtHeader","TEvtHeader",&m_evt->m_EvtHeader,3200000,1);
00060       if (m_evt->m_digiEvt) m_tree->Branch("TDigiEvent","TDigiEvent",&m_evt->m_digiEvt,3200000,1);
00061       if (m_evt->m_dstEvt) m_tree->Branch("TDstEvent", "TDstEvent", &m_evt->m_dstEvt, 3200000, 1);
00062       if (m_evt->m_mcEvt) m_tree->Branch("TMcEvent","TMcEvent",&m_evt->m_mcEvt,3200000,1);
00063       if (m_evt->m_trigEvt) m_tree->Branch("TTrigEvent","TTrigEvent",&m_evt->m_trigEvt,3200000,1);
00064       if (m_evt->m_hltEvt) m_tree->Branch("THltEvent","THltEvent",&m_evt->m_hltEvt,3200000,1);
00065       if (m_evt->m_rectrackEvt) m_tree->Branch("TRecEvent", "TRecTrackEvent", &m_evt->m_rectrackEvt, 3200000, 1);
00066       if (m_evt->m_evtRecObject) m_tree->Branch("TEvtRecObject", "TEvtRecObject", &m_evt->m_evtRecObject, 3200000, 1);
00067 
00068       m_jtree->Branch("JobInfo",&m_jobInfo);
00069 
00070       m_firstRound = false;
00071    }
00072 
00073    if ( m_file->IsZombie() || (!m_file->IsOpen()) ) {
00074       std::cout<<"ROOT File: " << m_fname << " bad status in RootFileWriter" << std::endl;
00075       exit(1);
00076    }
00077 
00078    int nb = m_tree->Fill();
00079    if ( nb == -1 ) {
00080       std::cerr << "RootFileWriter: error in fill tree " << m_tree->GetName() << std::endl;
00081       exit(1);
00082    }
00083 
00084    delete evt;
00085 
00086    m_evt->reset();
00087    m_file = m_tree->GetCurrentFile();
00088 
00089    return nb;
00090 }
00091 
00092 int RootFileWriter::close()
00093 {
00094    m_jobInfo->setBossVer( getenv("BES_RELEASE") );
00095    m_jobInfo->addJobOptions( this->getJobOptions() );
00096    m_jobInfo->setDecayOptions( this->getDecayOptions() );
00097    m_jtree->Fill();
00098 
00099    m_file->Write();
00100    m_file->Close();
00101 
00102    m_stat = 1;
00103 
00104    return 0;
00105 }
00106 
00107 int RootFileWriter::stat()
00108 {
00109    return m_stat;
00110 }
00111 
00112 std::string RootFileWriter::getJobOptions()
00113 {
00114    string opts("JobOptions Place Holder\n");
00115    return opts;
00116 }
00117 
00118 std::string RootFileWriter::getDecayOptions()
00119 {
00120    string opts("DecayOptions Place Holder\n");
00121    return opts;
00122 }

Generated on Tue Nov 29 22:58:02 2016 for BOSS_7.0.2 by  doxygen 1.4.7