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");
27 m_itemNames.push_back(
"/Event/Navigator");
29 m_itemNames.push_back(
"/Event/Digi");
30 m_itemNames.push_back(
"/Event/Digi/MdcDigiCol");
31 m_itemNames.push_back(
"/Event/Digi/TofDigiCol");
32 m_itemNames.push_back(
"/Event/Digi/EmcDigiCol");
33 m_itemNames.push_back(
"/Event/Digi/MucDigiCol");
35 m_itemNames.push_back(
"/Event/Hlt");
36 m_itemNames.push_back(
"/Event/Hlt/HltRawCol");
37 m_itemNames.push_back(
"/Event/Hlt/HltInf");
40 m_itemNames.push_back(
"/Event/Recon");
42 m_itemNames.push_back(
"/Event/Recon/RecMdcTrackCol");
44 m_itemNames.push_back(
"/Event/Recon/RecMdcDedxCol");
46 m_itemNames.push_back(
"/Event/Recon/RecMdcKalTrackCol");
48 m_itemNames.push_back(
"/Event/Recon/RecEsTimeCol");
49 m_itemNames.push_back(
"/Event/Recon/RecExtTrackCol");
52 m_itemNames.push_back(
"/Event/Recon/RecTofTrackCol");
55 m_itemNames.push_back(
"/Event/Recon/RecEmcHitCol");
56 m_itemNames.push_back(
"/Event/Recon/RecEmcClusterCol");
57 m_itemNames.push_back(
"/Event/Recon/RecEmcShowerCol");
59 m_itemNames.push_back(
"/Event/Recon/RecMucTrackCol");
60 m_itemNames.push_back(
"/Event/Recon/EvtRecEvent");
61 m_itemNames.push_back(
"/Event/Recon/EvtRecTrackCol");
65 declareProperty(
"digiRootOutputFile",m_dofileName =
"event.rec");
66 declareProperty(
"ItemList",m_itemNames);
67 declareProperty(
"RunMode", m_mode = 2);
73 MsgStream log(
msgSvc(), name());
74 log << MSG::INFO <<
" EventWriter ~EventWriter()" << endreq;
84 MsgStream log(
msgSvc(), name());
85 log << MSG::INFO <<
" EventWriter initialize()" << endreq;
94 StatusCode status = serviceLocator()->service(
"RootCnvSvc", isvc,
false);
96 if ( !status.isSuccess() ) status = serviceLocator()->service(
"EventCnvSvc", isvc,
true);
98 if ( status.isSuccess() ) {
105 status = serviceLocator()->service(
"EventCnvSvc", m_pConversionSvc,
true);
106 if ( !status.isSuccess() ) {
107 log << MSG::FATAL <<
"Unable to locate IConversionSvc interface"
113 status = serviceLocator()->service(
"EventDataSvc", m_pDataProvider,
true);
114 if ( !status.isSuccess() ) {
115 log << MSG::FATAL <<
"Unable to locate IDataProviderSvc interface"
123 m_single_outputFiles =
new TFile(m_dofileName.c_str(),
"RECREATE");
124 if(m_single_outputFiles->IsZombie()||(!m_single_outputFiles->IsWritable())){
125 std::cout<<
"EventWriter ERROR::Can't not open file"<<m_dofileName.c_str()<<std::endl;
129 m_single_outputTrees =
new TTree(
"Event",
"Event");
130 m_jobInfoTree =
new TTree(
"JobInfoTree",
"Job info");
133 else if ( m_mode == 3 ) {
134 status = DistBoss::GetPropertyValue<std::string>(
"DistBoss",
"ServerName", m_svrName);
137 m_bufsize = 512*1024;
138 m_cbuf =
new char[m_bufsize];
143 log << MSG::FATAL <<
"Unvalid RunMode @ initialize(): " << m_mode << endreq;
148 if ( !status.isSuccess() ) {
149 log << MSG::FATAL <<
"can not getSvc" << endreq;
154 return StatusCode::SUCCESS;
159StatusCode EventWriter::getSvc(){
160 MsgStream log(
msgSvc(), name());
161 log << MSG::INFO <<
"getSvc()" << endreq;
162 StatusCode status = StatusCode::SUCCESS;
163 if(m_itemNames.empty()) {
164 log << MSG::ERROR <<
"no ItemList from the jobOption" << endreq;
165 return StatusCode::FAILURE;
168 clearItems(m_itemList);
169 ItemNames::iterator i;
170 for (i = m_itemNames.begin(); i != m_itemNames.end(); i++){
171 addItem(m_itemList, *i);
180 MsgStream log(
msgSvc(), name());
181 log << MSG::INFO <<
"EventWriter execute()" << endreq;
188 if(m_common.
m_dstEvt) m_single_outputTrees->Branch(
"TDstEvent",
"TDstEvent",&m_common.
m_dstEvt,3200000,1);
189 if(m_common.
m_recEvt) m_single_outputTrees->Branch(
"TDigiEvent",
"TDigiEvent",&m_common.
m_recEvt,3200000,1);
190 if(m_common.
m_EvtHeader) m_single_outputTrees->Branch(
"TEvtHeader",
"TEvtHeader",&m_common.
m_EvtHeader,3200000,1);
192 if(m_common.
m_hltEvt) m_single_outputTrees->Branch(
"THltEvent",
"THltEvent",&m_common.
m_hltEvt,3200000,1);
193 if(m_common.
m_mcEvt) m_single_outputTrees->Branch(
"TMcEvent",
"TMcEvent",&m_common.
m_mcEvt,3200000,1);
194 if(m_common.
m_trigEvt) m_single_outputTrees->Branch(
"TTrigEvent",
"TTrigEvent",&m_common.
m_trigEvt,3200000,1);
195 m_jobInfoTree->Branch(
"JobInfo",&jobInfo);
199 if(m_single_outputFiles->IsZombie()||(!m_single_outputFiles->IsOpen())){
200 std::cout<<
"EventWriter ERROR::The ROOT File:"<<m_dofileName.c_str()<<
"status is false"<<std::endl;
203 int nb = m_single_outputTrees->Fill();
206 log << MSG::FATAL <<
"Error in fill tree (EventWriter) "<<m_single_outputTrees->GetName() <<
" with "<<nb<<
" bytes" <<endreq;
210 m_single_outputFiles = m_single_outputTrees->GetCurrentFile();
212 else if ( m_mode == 3 ) {
223 TBufferFile m_TBuffer(TBufferFile::kWrite, m_bufsize-12, m_cbuf+4,
false);
224 m_TBuffer.WriteObject(m_TFullEvt);
225 if ( m_TBuffer.Buffer() != (m_cbuf+4) ) {
226 m_bufsize = m_TBuffer.Length() + 12;
227 m_cbuf =
new char[m_bufsize];
228 memcpy(m_cbuf+4, m_TBuffer.Buffer(), m_TBuffer.Length());
229 m_TBuffer.SetBit(TBuffer::kIsOwner);
232 m_writer->
writeEvent( (
void*)m_cbuf, m_TBuffer.Length()+4 );
239 return StatusCode::SUCCESS;
242void EventWriter::addItem(Items& itms,
const std::string& descriptor) {
243 MsgStream log(
msgSvc(), name());
245 size_t sep = descriptor.rfind(
"#");
246 std::string obj_path (descriptor,0,sep);
247 std::string slevel (descriptor,sep+1,descriptor.length());
248 if ( slevel ==
"*" ) {
252 level = atoi(slevel.c_str());
254 size_t idx = obj_path.find(
"/",1);
255 while (idx != std::string::npos) {
256 std::string sub_item = obj_path.substr(0,idx);
257 if ( 0 == findItem(sub_item) ) {
258 addItem(itms, sub_item+
"#1");
260 idx = obj_path.find(
"/",idx+1);
262 DataStoreItem* item =
new DataStoreItem(obj_path, level);
263 log << MSG::DEBUG <<
"Adding OutputStream item " << item->path()
264 <<
" with " << item->depth()
265 <<
" level(s)." << endreq;
266 itms.push_back( item );
270void EventWriter::clearItems(Items& itms) {
271 for ( Items::iterator i = itms.begin(); i != itms.end(); i++ ) {
274 itms.erase(itms.begin(), itms.end());
278EventWriter::findItem(
const std::string& path) {
279 for (Items::const_iterator i=m_itemList.begin(); i != m_itemList.end(); ++i) {
280 if ( (*i)->path() == path )
return (*i);
287StatusCode EventWriter::collectObjects(){
288 MsgStream log(
msgSvc(), name());
289 StatusCode status = StatusCode::SUCCESS;
295 for ( i = m_itemList.begin(); i != m_itemList.end(); i++ ) {
297 IOpaqueAddress *pAddress = 0;
298 m_currentItem = (*i);
300 status = m_pDataProvider->retrieveObject(m_currentItem->path(), obj);
301 if ( status.isSuccess() ) {
302 status = m_pConversionSvc->createRep(obj, pAddress);
308 log << MSG::ERROR <<
"Cannot write mandatory object(s) (Not found): "
309 << m_currentItem->path() << endreq;
324 MsgStream log(
msgSvc(), name());
326 std::cout<<
"11111111111111111111111111"<<std::endl;
329 m_bossVer = getenv(
"BES_RELEASE");
330 log << MSG::INFO <<
"fill boss version: "<<m_bossVer << endreq;
332 string tmpJobOptions = getJobOptions();
333 m_jobOptions.push_back( tmpJobOptions );
335 if(m_decayOptions.size()==0)
336 m_decayOptions = getDecayOptions();
342 m_jobInfoTree->Fill();
344 st = m_single_outputFiles->Write();
347 log << MSG::FATAL <<
"can not write to the file "<<m_dofileName.c_str()<<endreq;
350 m_single_outputFiles->Close();
352 delete m_single_outputFiles;
364 log << MSG::INFO <<
"EventWriter finalize()" << endreq;
365 return StatusCode::SUCCESS;
372std::string EventWriter::getJobOptions()
374 MsgStream log(
msgSvc(), name());
375 IInterface* iface = Gaudi::createApplicationMgr();
377 SmartIF<IProperty> propMgr ( iface );
379 propMgr->getProperty(
"JobOptionsPath", path);
380 log << MSG::INFO <<
"JobOptions file for current job: " <<path << endreq;
381 ifstream fin(path.c_str());
384 while(getline(fin,tempString))
386 if( tempString.size()>0 && tempString.find(
"//")>tempString.size() )
388 jobOptions += tempString;
392 log << MSG::INFO <<
"JobOptions: " << endreq
393 << jobOptions << endreq;
397std::string EventWriter::getDecayOptions()
399 MsgStream log(
msgSvc(), name());
400 ISvcLocator* svcLocator = Gaudi::svcLocator();
404 StatusCode status = svcLocator->service(
"DataInfoSvc",tmpInfoSvc);
405 if (status.isSuccess()) {
406 log << MSG::INFO <<
"get the DataInfoSvc" << endreq;
407 jobInfoSvc=
dynamic_cast<DataInfoSvc *
>(tmpInfoSvc);
409 log << MSG::INFO <<
"get decay options" << endreq
410 << decayOptions << endreq;
412 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 TEvtNavigator * m_EvtNavigator
static TRecTrackEvent * m_rectrackEvt
Provide access to the ROOT event pointers.
static TDstEvent * m_dstEvt
Provide access to the ROOT event pointers.