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"
15#include "GaudiKernel/SmartIF.h"
16#include "GaudiKernel/IJobOptionsSvc.h"
18#include "GaudiKernel/Bootstrap.h"
19#include "GaudiKernel/ISvcLocator.h"
20#include "CLHEP/Vector/ThreeVector.h"
21#include "CLHEP/Vector/LorentzVector.h"
22#include "CLHEP/Vector/TwoVector.h"
23using CLHEP::Hep3Vector;
24using CLHEP::Hep2Vector;
25using CLHEP::HepLorentzVector;
26#include "CLHEP/Geometry/Point3D.h"
27#ifndef ENABLE_BACKWARDS_COMPATIBILITY
30#include "CLHEP/Matrix/SymMatrix.h"
49 Algorithm(name, pSvcLocator) {
51 declareProperty(
"OutputDstFile", m_outputFile);
56 MsgStream log(
msgSvc(), name());
58 log << MSG::INFO <<
"in initialize()" << endmsg;
60 Gaudi::svcLocator()->service(
"TagFilterSvc", m_tagFilterSvc);
63 std::cout<<
"init DstReformAlg, m_dstDataType: "<< m_dstDataType <<std::endl;
65 return StatusCode::SUCCESS;
79 if( (dstDataType==4) && (tagData0==3) )
81 cmap[tagData0+tagData1].push_back(m_evtNum);
84 cmap[tagData0].push_back(m_evtNum);
87 if (m_dstDataType==1) {
88 evtmap[m_evtNum].push_back(tagData0);
89 evtmap[m_evtNum].push_back(tagData1);
90 evtmap[m_evtNum].push_back(tagData2);
91 evtmap[m_evtNum].push_back(tagData3);
92 evtmap[m_evtNum].push_back(tagData4);
93 }
else if (m_dstDataType==2) {
98 evtmap[m_evtNum].push_back(tagData1);
99 evtmap[m_evtNum].push_back(tagData2);
100 evtmap[m_evtNum].push_back(tagData3);
101 evtmap[m_evtNum].push_back(tagData4);
102 evtmap[m_evtNum].push_back(tagData5);
103 evtmap[m_evtNum].push_back(tagData6);
104 evtmap[m_evtNum].push_back(tagData7);
105 evtmap[m_evtNum].push_back(tagData8);
106 }
else if ( (m_dstDataType==3) || (m_dstDataType==4) ) {
112 evtmap[m_evtNum].push_back(tagData1);
113 evtmap[m_evtNum].push_back(tagData2);
114 evtmap[m_evtNum].push_back(tagData3);
115 evtmap[m_evtNum].push_back(tagData4);
116 evtmap[m_evtNum].push_back(tagData5);
117 evtmap[m_evtNum].push_back(tagData6);
118 evtmap[m_evtNum].push_back(tagData7);
119 evtmap[m_evtNum].push_back(tagData8);
120 evtmap[m_evtNum].push_back(tagData9);
129 MsgStream log(
msgSvc(), name());
132 SmartIF<IJobOptionsSvc> iSvc(Gaudi::svcLocator()->service(
"JobOptionsSvc"));
133 if ( iSvc.isValid() ) {
134 const std::vector<const Property*>* ps = iSvc->getProperties(
"EventCnvSvc");
135 std::vector<const Property*>::const_iterator it, end = ps->end();
136 for ( it = ps->begin(); it != end; ++it ) {
137 if ( (*it)->name() ==
"digiRootInputFile" ) {
138 std::string flist=(*it)->toString();
139 std::string::size_type p1 = flist.find(
'"') + 1;
140 std::string::size_type p2 = flist.find(
'"', p1);
141 fn = flist.substr(p1, p2-p1);
142 std::cout<<
"input dst file name: "<<fn<<std::endl;
146 TFile*
f1 = TFile::Open(fn.c_str(),
"READ");
147 TFile* f2 = TFile::Open(m_outputFile.c_str(),
"RECREATE");
148 TTree* t1 = (TTree*)
f1->Get(
"Event");
150 log << MSG::INFO <<
"in finalize()" << endmsg;
151 TTree* jt1 = (TTree*)(
f1->Get(
"JobInfoTree"));
152 TTree* jt2 = jt1->CloneTree();
153 TTree* t0 =
new TTree(
"Metadata",
"");
154 Int_t mode = -1, begin = 0, end = 0;
155 t0->Branch(
"mode", &mode,
"mode/I");
156 t0->Branch(
"begin", &begin,
"begin/I");
157 t0->Branch(
"end", &end,
"end/I");
159 for ( std::map<
int, std::vector<long int> >::iterator it = cmap.begin(); it != cmap.end(); ++it ) {
162 end += (it->second).size();
163 std::cout<<
"mode: "<<mode<<
" begin: "<<begin<<
" end: "<<end<<std::endl;
167 TTree* t2 = t1->CloneTree(0);
168 Int_t nEvents = t1->GetEntries();
169 std::cout<<
"Total nEvents: "<<nEvents<<std::endl;
170 Int_t origEntry=0, currEntry=0;
171 UInt_t tagData0, tagData1, tagData2, tagData3, tagData4;
172 UInt_t tagData5, tagData6, tagData7, tagData8;
173 TTree* t3 =
new TTree(
"Entries",
"");
174 t3->Branch(
"origEntry", &origEntry,
"origEntry/I");
175 t3->Branch(
"currEntry", &currEntry,
"currEntry/I");
176 t3->Branch(
"tagData0", &tagData0,
"tagData0/i");
177 t3->Branch(
"tagData1", &tagData1,
"tagData1/i");
178 t3->Branch(
"tagData2", &tagData2,
"tagData2/i");
179 t3->Branch(
"tagData3", &tagData3,
"tagData3/i");
180 t3->Branch(
"tagData4", &tagData4,
"tagData4/i");
181 if (m_dstDataType==2) {
182 t3->Branch(
"tagData5", &tagData5,
"tagData5/i");
183 t3->Branch(
"tagData6", &tagData6,
"tagData6/i");
184 t3->Branch(
"tagData7", &tagData7,
"tagData7/i");
186 if ( (m_dstDataType==3) || (m_dstDataType==4) ) {
187 t3->Branch(
"tagData5", &tagData5,
"tagData5/i");
188 t3->Branch(
"tagData6", &tagData6,
"tagData6/i");
189 t3->Branch(
"tagData7", &tagData7,
"tagData7/i");
190 t3->Branch(
"tagData8", &tagData8,
"tagData8/i");
193 for ( std::map<
int, std::vector<long int> >::iterator it = cmap.begin(); it != cmap.end(); ++it ) {
194 int nNt = it->second.size();
195 std::cout <<
"Writing " << nNt <<
"\t events with " << it->first <<
" TagData0..." << std::endl;
196 for (
int i = 0; i < nNt; ++i ) {
197 origEntry=(it->second)[i];
198 t1->GetEntry(origEntry);
199 tagData0=(evtmap[origEntry])[0];
200 tagData1=(evtmap[origEntry])[1];
201 tagData2=(evtmap[origEntry])[2];
202 tagData3=(evtmap[origEntry])[3];
203 tagData4=(evtmap[origEntry])[4];
204 if (m_dstDataType==2) {
205 tagData5=(evtmap[origEntry])[5];
206 tagData6=(evtmap[origEntry])[6];
207 tagData7=(evtmap[origEntry])[7];
209 if ( (m_dstDataType==3) || (m_dstDataType==4) ) {
210 tagData5=(evtmap[origEntry])[5];
211 tagData6=(evtmap[origEntry])[6];
212 tagData7=(evtmap[origEntry])[7];
213 tagData8=(evtmap[origEntry])[8];
219 (it->second).clear();
224 return StatusCode::SUCCESS;
virtual unsigned int getTagData1()=0
virtual unsigned int getTagData2()=0
virtual int getDstDataType()=0
virtual unsigned int getTagData8()=0
virtual unsigned int getTagData9()=0
virtual unsigned int getTagData6()=0
virtual unsigned int getTagData4()=0
virtual unsigned int getTagData5()=0
virtual unsigned int getTagData7()=0
virtual unsigned int getTagData3()=0
virtual unsigned int getTagData0()=0