9#include "TBufferFile.h"
11#include "GaudiKernel/SmartIF.h"
12#include "GaudiKernel/IProperty.h"
13#include "GaudiKernel/Bootstrap.h"
14#include "GaudiKernel/IAppMgrUI.h"
23 Algorithm(name, pSvcLocator)
25 m_itemNames.push_back(
"/Event");
26 m_itemNames.push_back(
"/Event/EventHeader");
28 m_itemNames.push_back(
"/Event/Digi");
29 m_itemNames.push_back(
"/Event/Digi/MdcDigiCol");
30 m_itemNames.push_back(
"/Event/Digi/TofDigiCol");
31 m_itemNames.push_back(
"/Event/Digi/EmcDigiCol");
32 m_itemNames.push_back(
"/Event/Digi/MucDigiCol");
34 m_itemNames.push_back(
"/Event/Hlt");
35 m_itemNames.push_back(
"/Event/Hlt/HltRawCol");
36 m_itemNames.push_back(
"/Event/Hlt/HltInf");
39 m_itemNames.push_back(
"/Event/Recon");
41 m_itemNames.push_back(
"/Event/Recon/RecMdcTrackCol");
43 m_itemNames.push_back(
"/Event/Recon/RecMdcDedxCol");
45 m_itemNames.push_back(
"/Event/Recon/RecMdcKalTrackCol");
47 m_itemNames.push_back(
"/Event/Recon/RecEsTimeCol");
48 m_itemNames.push_back(
"/Event/Recon/RecExtTrackCol");
51 m_itemNames.push_back(
"/Event/Recon/RecTofTrackCol");
54 m_itemNames.push_back(
"/Event/Recon/RecEmcHitCol");
55 m_itemNames.push_back(
"/Event/Recon/RecEmcClusterCol");
56 m_itemNames.push_back(
"/Event/Recon/RecEmcShowerCol");
58 m_itemNames.push_back(
"/Event/Recon/RecMucTrackCol");
59 m_itemNames.push_back(
"/Event/Recon/EvtRecEvent");
60 m_itemNames.push_back(
"/Event/Recon/EvtRecTrackCol");
64 declareProperty(
"digiRootOutputFile",m_dofileName =
"event.rec");
65 declareProperty(
"ItemList",m_itemNames);
66 declareProperty(
"RunMode", m_mode = 2);
72 MsgStream log(
msgSvc(), name());
73 log << MSG::INFO <<
" EventWriter ~EventWriter()" << endreq;
83 MsgStream log(
msgSvc(), name());
84 log << MSG::INFO <<
" EventWriter initialize()" << endreq;
93 StatusCode status = serviceLocator()->service(
"RootCnvSvc", isvc,
false);
95 if ( !status.isSuccess() ) status = serviceLocator()->service(
"EventCnvSvc", isvc,
true);
97 if ( status.isSuccess() ) {
104 status = serviceLocator()->service(
"EventCnvSvc", m_pConversionSvc,
true);
105 if ( !status.isSuccess() ) {
106 log << MSG::FATAL <<
"Unable to locate IConversionSvc interface"
112 status = serviceLocator()->service(
"EventDataSvc", m_pDataProvider,
true);
113 if ( !status.isSuccess() ) {
114 log << MSG::FATAL <<
"Unable to locate IDataProviderSvc interface"
122 m_single_outputFiles =
new TFile(m_dofileName.c_str(),
"RECREATE");
123 if(m_single_outputFiles->IsZombie()||(!m_single_outputFiles->IsWritable())){
124 std::cout<<
"EventWriter ERROR::Can't not open file"<<m_dofileName.c_str()<<std::endl;
128 m_single_outputTrees =
new TTree(
"Event",
"Event");
129 m_jobInfoTree =
new TTree(
"JobInfoTree",
"Job info");
132 else if ( m_mode == 3 ) {
133 status = DistBoss::GetPropertyValue<std::string>(
"DistBoss",
"ServerName", m_svrName);
136 m_bufsize = 512*1024;
137 m_cbuf =
new char[m_bufsize];
142 log << MSG::FATAL <<
"Unvalid RunMode @ initialize(): " << m_mode << endreq;
147 if ( !status.isSuccess() ) {
148 log << MSG::FATAL <<
"can not getSvc" << endreq;
153 return StatusCode::SUCCESS;
158StatusCode EventWriter::getSvc(){
159 MsgStream log(
msgSvc(), name());
160 log << MSG::INFO <<
"getSvc()" << endreq;
161 StatusCode status = StatusCode::SUCCESS;
162 if(m_itemNames.empty()) {
163 log << MSG::ERROR <<
"no ItemList from the jobOption" << endreq;
164 return StatusCode::FAILURE;
167 clearItems(m_itemList);
168 ItemNames::iterator i;
169 for (i = m_itemNames.begin(); i != m_itemNames.end(); i++){
170 addItem(m_itemList, *i);
179 MsgStream log(
msgSvc(), name());
180 log << MSG::INFO <<
"EventWriter execute()" << endreq;
187 if(m_common.
m_dstEvt) m_single_outputTrees->Branch(
"TDstEvent",
"TDstEvent",&m_common.
m_dstEvt,3200000,1);
188 if(m_common.
m_recEvt) m_single_outputTrees->Branch(
"TDigiEvent",
"TDigiEvent",&m_common.
m_recEvt,3200000,1);
189 if(m_common.
m_EvtHeader) m_single_outputTrees->Branch(
"TEvtHeader",
"TEvtHeader",&m_common.
m_EvtHeader,3200000,1);
190 if(m_common.
m_hltEvt) m_single_outputTrees->Branch(
"THltEvent",
"THltEvent",&m_common.
m_hltEvt,3200000,1);
191 if(m_common.
m_mcEvt) m_single_outputTrees->Branch(
"TMcEvent",
"TMcEvent",&m_common.
m_mcEvt,3200000,1);
192 if(m_common.
m_trigEvt) m_single_outputTrees->Branch(
"TTrigEvent",
"TTrigEvent",&m_common.
m_trigEvt,3200000,1);
193 m_jobInfoTree->Branch(
"JobInfo",&jobInfo);
197 if(m_single_outputFiles->IsZombie()||(!m_single_outputFiles->IsOpen())){
198 std::cout<<
"EventWriter ERROR::The ROOT File:"<<m_dofileName.c_str()<<
"status is false"<<std::endl;
201 int nb = m_single_outputTrees->Fill();
204 log << MSG::FATAL <<
"Error in fill tree (EventWriter) "<<m_single_outputTrees->GetName() <<
" with "<<nb<<
" bytes" <<endreq;
208 m_single_outputFiles = m_single_outputTrees->GetCurrentFile();
210 else if ( m_mode == 3 ) {
221 TBufferFile m_TBuffer(TBufferFile::kWrite, m_bufsize-12, m_cbuf+4,
false);
222 m_TBuffer.WriteObject(m_TFullEvt);
223 if ( m_TBuffer.Buffer() != (m_cbuf+4) ) {
224 m_bufsize = m_TBuffer.Length() + 12;
225 m_cbuf =
new char[m_bufsize];
226 memcpy(m_cbuf+4, m_TBuffer.Buffer(), m_TBuffer.Length());
227 m_TBuffer.SetBit(TBuffer::kIsOwner);
230 m_writer->
writeEvent( (
void*)m_cbuf, m_TBuffer.Length()+4 );
237 return StatusCode::SUCCESS;
240void EventWriter::addItem(Items& itms,
const std::string& descriptor) {
241 MsgStream log(
msgSvc(), name());
243 size_t sep = descriptor.rfind(
"#");
244 std::string obj_path (descriptor,0,sep);
245 std::string slevel (descriptor,sep+1,descriptor.length());
246 if ( slevel ==
"*" ) {
250 level = atoi(slevel.c_str());
252 size_t idx = obj_path.find(
"/",1);
253 while (idx != std::string::npos) {
254 std::string sub_item = obj_path.substr(0,idx);
255 if ( 0 == findItem(sub_item) ) {
256 addItem(itms, sub_item+
"#1");
258 idx = obj_path.find(
"/",idx+1);
260 DataStoreItem* item =
new DataStoreItem(obj_path, level);
261 log << MSG::DEBUG <<
"Adding OutputStream item " << item->path()
262 <<
" with " << item->depth()
263 <<
" level(s)." << endreq;
264 itms.push_back( item );
268void EventWriter::clearItems(Items& itms) {
269 for ( Items::iterator i = itms.begin(); i != itms.end(); i++ ) {
272 itms.erase(itms.begin(), itms.end());
276EventWriter::findItem(
const std::string& path) {
277 for (Items::const_iterator i=m_itemList.begin(); i != m_itemList.end(); ++i) {
278 if ( (*i)->path() == path )
return (*i);
285StatusCode EventWriter::collectObjects(){
286 MsgStream log(
msgSvc(), name());
287 StatusCode status = StatusCode::SUCCESS;
293 for ( i = m_itemList.begin(); i != m_itemList.end(); i++ ) {
295 IOpaqueAddress *pAddress = 0;
296 m_currentItem = (*i);
298 status = m_pDataProvider->retrieveObject(m_currentItem->path(), obj);
299 if ( status.isSuccess() ) {
300 status = m_pConversionSvc->createRep(obj, pAddress);
306 log << MSG::ERROR <<
"Cannot write mandatory object(s) (Not found): "
307 << m_currentItem->path() << endreq;
322 MsgStream log(
msgSvc(), name());
324 std::cout<<
"11111111111111111111111111"<<std::endl;
327 m_bossVer = getenv(
"BES_RELEASE");
328 log << MSG::INFO <<
"fill boss version: "<<m_bossVer << endreq;
330 string tmpJobOptions = getJobOptions();
331 m_jobOptions.push_back( tmpJobOptions );
333 if(m_decayOptions.size()==0)
334 m_decayOptions = getDecayOptions();
340 m_jobInfoTree->Fill();
342 st = m_single_outputFiles->Write();
345 log << MSG::FATAL <<
"can not write to the file "<<m_dofileName.c_str()<<endreq;
348 m_single_outputFiles->Close();
350 delete m_single_outputFiles;
362 log << MSG::INFO <<
"EventWriter finalize()" << endreq;
363 return StatusCode::SUCCESS;
370std::string EventWriter::getJobOptions()
372 MsgStream log(
msgSvc(), name());
373 IInterface* iface = Gaudi::createApplicationMgr();
375 SmartIF<IProperty> propMgr ( iface );
377 propMgr->getProperty(
"JobOptionsPath", path);
378 log << MSG::INFO <<
"JobOptions file for current job: " <<path << endreq;
379 ifstream fin(path.c_str());
382 while(getline(fin,tempString))
384 if( tempString.size()>0 && tempString.find(
"//")>tempString.size() )
386 jobOptions += tempString;
390 log << MSG::INFO <<
"JobOptions: " << endreq
391 << jobOptions << endreq;
395std::string EventWriter::getDecayOptions()
397 MsgStream log(
msgSvc(), name());
398 ISvcLocator* svcLocator = Gaudi::svcLocator();
402 StatusCode status = svcLocator->service(
"DataInfoSvc",tmpInfoSvc);
403 if (status.isSuccess()) {
404 log << MSG::INFO <<
"get the DataInfoSvc" << endreq;
405 jobInfoSvc=
dynamic_cast<DataInfoSvc *
>(tmpInfoSvc);
407 log << MSG::INFO <<
"get decay options" << endreq
408 << decayOptions << endreq;
410 log << MSG::WARNING <<
"could not get the DataInfoSvc. Ignore it." << endreq;
PthrWriterBufPool< DimRpcWriter, 4 > NetDataWriter
const InterfaceID IID_IRootCnvSvc
EventWriter(const std::string &name, ISvcLocator *pSvcLocator)
int writeEvent(void *pevt, int size)
void setHltEvent(THltEvent *obj)
void setTrigEvent(TTrigEvent *obj)
void setDigiEvent(TDigiEvent *obj)
void setEvtRecObject(TEvtRecObject *obj)
void setMcEvent(TMcEvent *obj)
void setRecTrackEvent(TRecTrackEvent *obj)
void setDstEvent(TDstEvent *obj)
void setEvtHeader(TEvtHeader *obj)
void setBossVer(string ver)
void setDecayOptions(string opt)
void setJobOptions(vector< string > opt)
static TEvtRecObject * m_evtRecObject
static TEvtHeader * m_EvtHeader
static TDigiEvent * m_recEvt
Provide access to the ROOT event pointers.
static TTrigEvent * m_trigEvt
Provide access to the ROOT event pointers.
static THltEvent * m_hltEvt
Provide access to the ROOT event pointers.
static TMcEvent * m_mcEvt
Provide access to the ROOT event pointers.
static TRecTrackEvent * m_rectrackEvt
Provide access to the ROOT event pointers.
static TDstEvent * m_dstEvt
Provide access to the ROOT event pointers.