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