BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TagWriterAlg.cxx
Go to the documentation of this file.
1#include "GaudiKernel/AlgFactory.h"
2#include "GaudiKernel/Bootstrap.h"
3#include "GaudiKernel/IDataProviderSvc.h"
4#include "GaudiKernel/ISvcLocator.h"
5#include "GaudiKernel/MsgStream.h"
6#include "GaudiKernel/PropertyMgr.h"
7#include "GaudiKernel/SmartDataPtr.h"
8
9#include "EventModel/Event.h"
10#include "EventModel/EventModel.h"
11
12#include "EventModel/EventHeader.h"
13#include "EvtRecEvent/EvtRecEvent.h"
14#include "EvtRecEvent/EvtRecTrack.h"
15
16#include "CLHEP/Geometry/Point3D.h"
17#include "CLHEP/Vector/LorentzVector.h"
18#include "CLHEP/Vector/ThreeVector.h"
19#include "CLHEP/Vector/TwoVector.h"
20#include "GaudiKernel/Bootstrap.h"
21#include "GaudiKernel/IHistogramSvc.h"
22#include "GaudiKernel/INTupleSvc.h"
23#include "GaudiKernel/NTuple.h"
24
26
27#include "GaudiKernel/IJobOptionsSvc.h"
28#include "GaudiKernel/SmartIF.h"
29#include "RootCnvSvc/RootInterface.h"
30
31#include "TMath.h"
32#include <vector>
33
34/////////////////////////////////////////////////////////////////////////////
36TagWriterAlg::TagWriterAlg( const std::string& name, ISvcLocator* pSvcLocator )
37 : Algorithm( name, pSvcLocator ) {
38
39 // declareProperty("InputTagFile", m_inputTagFile);
40 declareProperty( "OutputTagFile", m_outputTagFile );
41 // declareProperty("FilterTotalCharged", m_filterTotalCharged=2);
42}
43
44// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
46 MsgStream log( msgSvc(), name() );
47
48 log << MSG::INFO << "in initialize()" << endmsg;
49
50 SmartIF<IJobOptionsSvc> iSvc( serviceLocator()->service( "JobOptionsSvc" ) );
51 if ( iSvc.isValid() )
52 {
53 std::string dll; // sub so name
54 const std::vector<const Property*>* ps = 0;
55 if ( iSvc->getProperties( "RootCnvSvc" ) != 0 ) ps = iSvc->getProperties( "RootCnvSvc" );
56 if ( iSvc->getProperties( "EventCnvSvc" ) != 0 ) ps = iSvc->getProperties( "EventCnvSvc" );
57 if ( iSvc->getProperties( "WriteDst" ) != 0 ) ps = iSvc->getProperties( "WriteDst" );
58
59 if ( ps != 0 )
60 {
61 for ( int i = 0; i < ps->size(); i++ )
62 {
63 if ( ( *ps )[i]->name() == "digiRootOutputFile" )
64
65 {
66 m_dstOutput = ( *ps )[i]->toString();
67 std::cout << "read from JobOptionSvc, dstOutput: " << m_dstOutput << std::endl;
68 }
69 }
70 }
71 }
72
73 m_rootInterface = RootInterface::Instance( name() );
74 log << MSG::INFO << "RootInteface TotalFileNum: " << m_rootInterface->getTotalFileNum()
75 << endmsg;
76 std::cout << "getTotalFileNum: " << m_rootInterface->getTotalFileNum() << std::endl;
77
78 if ( m_rootInterface->getTotalFileNum() > 0 )
79 {
80 if ( m_rootInterface->getTotalFileNum() != m_outputTagFile.size() )
81 {
82 std::cout << "the input file num != output file number, please check your jobOptions"
83 << std::endl;
84 exit( -1 );
85 }
86 }
87
88 m_entry = -1;
89 m_entry_in_alg = -1;
90 m_dstFile = "";
91 m_fileNum = -1;
92 return StatusCode::SUCCESS;
93}
94
95// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
97
98 MsgStream log( msgSvc(), name() );
99 log << MSG::INFO << "in execute()" << endmsg;
100
101 // Write Tag during reconstruction
102 if ( m_dstOutput != "" )
103 {
104 if ( m_entry == -1 )
105 {
106 std::cout << "TagWriterAlg: write tag during reconstruction" << std::endl;
107 m_dstFile = m_dstOutput;
108 std::cout << "dst file: " << m_dstFile << std::endl;
109 openOutputTagFile( m_outputTagFile[0] );
110 m_oFileTree->Fill();
111 }
112 }
113 else // Write Tag after reconstruction
114 {
115 if ( m_dstFile != m_rootInterface->getCurrentFileName() )
116 {
117 std::cout << "TagWriterAlg, current file: " << m_rootInterface->getCurrentFileName()
118 << std::endl;
119 m_fileNum++;
120 m_dstFile = m_rootInterface->getCurrentFileName();
121
122 m_entry = -1;
123 if ( m_fileNum > 0 )
124 {
125 m_oFile->Write();
126 delete m_oTree;
127 delete m_oFileTree;
128 delete m_oFile;
129 }
130
131 log << MSG::INFO << "open ROOT output TAG file: " << m_outputTagFile[m_fileNum]
132 << endmsg;
133 openOutputTagFile( m_outputTagFile[m_fileNum] );
134 m_oFileTree->Fill();
135 }
136 }
137
138 m_entry++;
139 getTagInfo();
140 log << MSG::INFO << "writing TAG information to ROOT TAG file" << endmsg;
141 m_oTree->Fill();
142
143 m_entry_in_alg++;
144 return StatusCode::SUCCESS;
145}
146
147// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
149 MsgStream log( msgSvc(), name() );
150 log << MSG::INFO << "reading event data from DST" << endmsg;
151
152 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
153 if ( !eventHeader )
154 {
155 log << MSG::FATAL << "Could not find EventHeader." << endmsg;
156 return StatusCode::FAILURE;
157 }
158
159 m_runNo = eventHeader->runNumber();
160 m_eventId = eventHeader->eventNumber();
161 log << MSG::DEBUG << "run, evtnum = " << m_runNo << " , " << m_eventId << endmsg;
162
163 SmartDataPtr<EvtRecEvent> evtRecEvent( eventSvc(), EventModel::EvtRec::EvtRecEvent );
164 if ( !evtRecEvent )
165 {
166 log << MSG::FATAL << "Could not find EvtRecEvent." << endmsg;
167 return StatusCode::FAILURE;
168 }
169 log << MSG::DEBUG << "ncharg, nneu, tottks = " << evtRecEvent->totalCharged() << " , "
170 << evtRecEvent->totalNeutral() << " , " << evtRecEvent->totalTracks() << endmsg;
171 m_totalCharged = evtRecEvent->totalCharged();
172 m_totalNeutral = evtRecEvent->totalNeutral();
173 m_totalTrks = evtRecEvent->totalTracks();
174 return StatusCode::SUCCESS;
175}
176
177// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
179
180 MsgStream log( msgSvc(), name() );
181
182 m_oFile->Write();
183
184 log << MSG::INFO << "in finalize()" << endmsg;
185 return StatusCode::SUCCESS;
186}
187
188// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
189void TagWriterAlg::openOutputTagFile( std::string ofile ) {
190 m_oFile = new TFile( ofile.c_str(), "RECREATE", "ROOT file for TAG" );
191 m_oTree = new TTree( "Tag", "Tags for DST file" );
192 m_oTree->Branch( "entry", &m_entry, "entry/I" );
193 m_oTree->Branch( "runNo", &m_runNo, "runNo/I" );
194 m_oTree->Branch( "eventId", &m_eventId, "eventId/I" );
195 m_oTree->Branch( "totalCharged", &m_totalCharged, "totalCharged/I" );
196 m_oTree->Branch( "totalNeutral", &m_totalNeutral, "totalNeutral/I" );
197 m_oTree->Branch( "totalTrks", &m_totalTrks, "totalTrks/I" );
198 m_oFileTree = new TTree( "File", "DST file names" );
199 m_oFileTree->Branch( "fileName", &m_dstFile );
200}
201
202// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
203/*bool TagWriterAlg::eventFilter()
204{
205 std::cout<<"m_entry in eventFilter: "<<m_entry<<std::endl;
206
207 //set your filter criteria here
208 if(m_r_totalCharged==m_filterTotalCharged)
209 return true;
210 else
211 return false;
212}*/
DECLARE_COMPONENT(BesBdkRc)
IMessageSvc * msgSvc()
static RootInterface * Instance(const std::string &name)
singleton behaviour
TagWriterAlg(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode finalize()
StatusCode execute()
void openOutputTagFile(std::string file)
StatusCode initialize()
StatusCode getTagInfo()