2#include "DataInfoSvc/IDataInfoSvc.h"
4#include "GaudiKernel/Bootstrap.h"
5#include "GaudiKernel/IAppMgrUI.h"
6#include "GaudiKernel/IProperty.h"
7#include "GaudiKernel/SmartIF.h"
16 : Algorithm( name, pSvcLocator ) {
17 m_itemNames.push_back(
"/Event" );
18 m_itemNames.push_back(
"/Event/EventHeader" );
19 m_itemNames.push_back(
"/Event/Navigator" );
21 m_itemNames.push_back(
"/Event/Digi" );
22 m_itemNames.push_back(
"/Event/Digi/MdcDigiCol" );
23 m_itemNames.push_back(
"/Event/Digi/TofDigiCol" );
24 m_itemNames.push_back(
"/Event/Digi/EmcDigiCol" );
25 m_itemNames.push_back(
"/Event/Digi/MucDigiCol" );
27 m_itemNames.push_back(
"/Event/Hlt" );
28 m_itemNames.push_back(
"/Event/Hlt/HltRawCol" );
29 m_itemNames.push_back(
"/Event/Hlt/HltInf" );
32 m_itemNames.push_back(
"/Event/Recon" );
34 m_itemNames.push_back(
"/Event/Recon/RecMdcTrackCol" );
36 m_itemNames.push_back(
"/Event/Recon/RecMdcDedxCol" );
38 m_itemNames.push_back(
"/Event/Recon/RecMdcKalTrackCol" );
40 m_itemNames.push_back(
"/Event/Recon/RecEsTimeCol" );
41 m_itemNames.push_back(
"/Event/Recon/RecExtTrackCol" );
44 m_itemNames.push_back(
"/Event/Recon/RecTofTrackCol" );
47 m_itemNames.push_back(
"/Event/Recon/RecEmcHitCol" );
48 m_itemNames.push_back(
"/Event/Recon/RecEmcClusterCol" );
49 m_itemNames.push_back(
"/Event/Recon/RecEmcShowerCol" );
51 m_itemNames.push_back(
"/Event/Recon/RecMucTrackCol" );
52 m_itemNames.push_back(
"/Event/Recon/EvtRecEvent" );
53 m_itemNames.push_back(
"/Event/Recon/EvtRecTrackCol" );
57 declareProperty(
"digiRootOutputFile", m_dofileName =
"event.rec" );
58 declareProperty(
"ItemList", m_itemNames );
59 declareProperty(
"RunMode", m_mode = 2 );
65 MsgStream log(
msgSvc(), name() );
66 log << MSG::INFO <<
" EventWriter ~EventWriter()" << endmsg;
73 MsgStream log(
msgSvc(), name() );
74 log << MSG::INFO <<
" EventWriter initialize()" << endmsg;
76 StatusCode status = serviceLocator()->service(
"RootCnvSvc", m_cnvSvc,
false );
78 if ( !status.isSuccess() )
79 status = serviceLocator()->service(
"EventCnvSvc", m_cnvSvc,
true );
81 status = serviceLocator()->service(
"EventCnvSvc", m_pConversionSvc,
true );
82 if ( !status.isSuccess() )
84 log << MSG::FATAL <<
"Unable to locate IConversionSvc interface" << endmsg;
88 status = serviceLocator()->service(
"EventDataSvc", m_pDataProvider,
true );
89 if ( !status.isSuccess() )
91 log << MSG::FATAL <<
"Unable to locate IDataProviderSvc interface" << endmsg;
97 m_single_outputFiles =
new TFile( m_dofileName.c_str(),
"RECREATE" );
98 if ( m_single_outputFiles->IsZombie() || ( !m_single_outputFiles->IsWritable() ) )
100 std::cout <<
"EventWriter ERROR::Can't not open file" << m_dofileName.c_str()
105 m_single_outputTrees =
new TTree(
"Event",
"Event" );
106 m_jobInfoTree =
new TTree(
"JobInfoTree",
"Job info" );
109 else if ( m_mode == 3 )
111 log << MSG::FATAL <<
"The DistBossMode has been abandoned!" << endmsg;
112 return StatusCode::FAILURE;
116 log << MSG::FATAL <<
"Unvalid RunMode @ initialize(): " << m_mode << endmsg;
121 if ( !status.isSuccess() )
123 log << MSG::FATAL <<
"can not getSvc" << endmsg;
128 return StatusCode::SUCCESS;
133StatusCode EventWriter::getSvc() {
134 MsgStream log(
msgSvc(), name() );
135 log << MSG::INFO <<
"getSvc()" << endmsg;
136 StatusCode status = StatusCode::SUCCESS;
137 if ( m_itemNames.empty() )
139 log << MSG::ERROR <<
"no ItemList from the jobOption" << endmsg;
140 return StatusCode::FAILURE;
143 clearItems( m_itemList );
144 ItemNames::iterator i;
145 for ( i = m_itemNames.begin(); i != m_itemNames.end(); i++ ) { addItem( m_itemList, *i ); }
152 MsgStream log(
msgSvc(), name() );
153 log << MSG::INFO <<
"EventWriter execute()" << endmsg;
154 collectObjects().ignore();
160 if ( m_common.m_rectrackEvt )
161 m_single_outputTrees->Branch(
"TRecEvent",
"TRecTrackEvent", &m_common.m_rectrackEvt,
163 if ( m_common.m_evtRecObject )
164 m_single_outputTrees->Branch(
"TEvtRecObject",
"TEvtRecObject",
165 &m_common.m_evtRecObject, 3200000, 1 );
166 if ( m_common.m_dstEvt )
167 m_single_outputTrees->Branch(
"TDstEvent",
"TDstEvent", &m_common.m_dstEvt, 3200000,
169 if ( m_common.m_recEvt )
170 m_single_outputTrees->Branch(
"TDigiEvent",
"TDigiEvent", &m_common.m_recEvt, 3200000,
172 if ( m_common.m_EvtHeader )
173 m_single_outputTrees->Branch(
"TEvtHeader",
"TEvtHeader", &m_common.m_EvtHeader,
175 if ( m_common.m_EvtNavigator )
176 m_single_outputTrees->Branch(
"TEvtNavigator",
"TEvtNavigator",
177 &m_common.m_EvtNavigator, 3200000, 1 );
178 if ( m_common.m_hltEvt )
179 m_single_outputTrees->Branch(
"THltEvent",
"THltEvent", &m_common.m_hltEvt, 3200000,
181 if ( m_common.m_mcEvt )
182 m_single_outputTrees->Branch(
"TMcEvent",
"TMcEvent", &m_common.m_mcEvt, 3200000, 1 );
183 if ( m_common.m_trigEvt )
184 m_single_outputTrees->Branch(
"TTrigEvent",
"TTrigEvent", &m_common.m_trigEvt, 3200000,
186 m_jobInfoTree->Branch(
"JobInfo", &jobInfo );
190 if ( m_single_outputFiles->IsZombie() || ( !m_single_outputFiles->IsOpen() ) )
192 std::cout <<
"EventWriter ERROR::The ROOT File:" << m_dofileName.c_str()
193 <<
"status is false" << std::endl;
196 int nb = m_single_outputTrees->Fill();
199 log << MSG::FATAL <<
"Error in fill tree (EventWriter) "
200 << m_single_outputTrees->GetName() <<
" with " << nb <<
" bytes" << endmsg;
204 m_single_outputFiles = m_single_outputTrees->GetCurrentFile();
206 else if ( m_mode == 3 )
208 log << MSG::FATAL <<
"The DistBossMode has been abandoned!" << endmsg;
209 return StatusCode::FAILURE;
214 return StatusCode::SUCCESS;
217void EventWriter::addItem( Items& itms,
const std::string& descriptor ) {
218 MsgStream log(
msgSvc(), name() );
220 size_t sep = descriptor.rfind(
"#" );
221 std::string obj_path( descriptor, 0, sep );
222 std::string slevel( descriptor, sep + 1, descriptor.length() );
223 if ( slevel ==
"*" ) { level = 9999999; }
224 else { level = atoi( slevel.c_str() ); }
225 size_t idx = obj_path.find(
"/", 1 );
226 while ( idx != std::string::npos )
228 std::string sub_item = obj_path.substr( 0, idx );
229 if ( 0 == findItem( sub_item ) ) { addItem( itms, sub_item +
"#1" ); }
230 idx = obj_path.find(
"/", idx + 1 );
232 DataStoreItem* item =
new DataStoreItem( obj_path, level );
233 log << MSG::DEBUG <<
"Adding OutputStream item " << item->path() <<
" with " << item->depth()
234 <<
" level(s)." << endmsg;
235 itms.push_back( item );
239void EventWriter::clearItems( Items& itms ) {
240 for ( Items::iterator i = itms.begin(); i != itms.end(); i++ ) {
delete ( *i ); }
241 itms.erase( itms.begin(), itms.end() );
244DataStoreItem* EventWriter::findItem(
const std::string& path ) {
245 for ( Items::const_iterator i = m_itemList.begin(); i != m_itemList.end(); ++i )
247 if ( ( *i )->path() == path )
return ( *i );
252StatusCode EventWriter::collectObjects() {
253 MsgStream log(
msgSvc(), name() );
254 StatusCode status = StatusCode::SUCCESS;
260 for ( i = m_itemList.begin(); i != m_itemList.end(); i++ )
263 IOpaqueAddress* pAddress = 0;
264 m_currentItem = ( *i );
266 status = m_pDataProvider->retrieveObject( m_currentItem->path(), obj );
267 if ( status.isSuccess() )
269 status = m_pConversionSvc->createRep( obj, pAddress );
277 <<
"Cannot write mandatory object(s) (Not found): " << m_currentItem->path()
290 MsgStream log(
msgSvc(), name() );
292 std::cout <<
"11111111111111111111111111" << std::endl;
296 m_bossVer = getenv(
"BES_RELEASE" );
297 log << MSG::INFO <<
"fill boss version: " << m_bossVer << endmsg;
299 string tmpJobOptions = getJobOptions();
300 m_jobOptions.push_back( tmpJobOptions );
302 if ( m_decayOptions.size() == 0 ) m_decayOptions = getDecayOptions();
304 jobInfo->setBossVer( m_bossVer );
305 jobInfo->setJobOptions( m_jobOptions );
306 jobInfo->setDecayOptions( m_decayOptions );
308 m_jobInfoTree->Fill();
310 st = m_single_outputFiles->Write();
313 log << MSG::FATAL <<
"can not write to the file " << m_dofileName.c_str() << endmsg;
316 m_single_outputFiles->Close();
318 delete m_single_outputFiles;
324 log << MSG::FATAL <<
"The DistBossMode has been abandoned!" << endmsg;
325 return StatusCode::FAILURE;
328 log << MSG::INFO <<
"EventWriter finalize()" << endmsg;
329 return StatusCode::SUCCESS;
335std::string EventWriter::getJobOptions() {
336 MsgStream log(
msgSvc(), name() );
337 IInterface* iface = Gaudi::createApplicationMgr();
338 SmartIF<IProperty> propMgr( iface );
340 propMgr->getProperty(
"JobOptionsPath", path ).ignore();
341 log << MSG::INFO <<
"JobOptions file for current job: " << path << endmsg;
342 ifstream fin( path.c_str() );
345 while ( getline( fin, tempString ) )
347 if ( tempString.size() > 0 && tempString.find(
"//" ) > tempString.size() )
349 jobOptions += tempString;
353 log << MSG::INFO <<
"JobOptions: " << endmsg << jobOptions << endmsg;
357std::string EventWriter::getDecayOptions() {
358 MsgStream log(
msgSvc(), name() );
359 ISvcLocator* svcLocator = Gaudi::svcLocator();
360 IDataInfoSvc* jobInfoSvc;
362 StatusCode status = svcLocator->service(
"DataInfoSvc", jobInfoSvc );
363 if ( status.isSuccess() )
365 log << MSG::INFO <<
"get the DataInfoSvc" << endmsg;
367 log << MSG::INFO <<
"get decay options" << endmsg << decayOptions << endmsg;
369 else { log << MSG::WARNING <<
"could not get the DataInfoSvc. Ignore it." << endmsg; }
DECLARE_COMPONENT(BesBdkRc)
EventWriter(const std::string &name, ISvcLocator *pSvcLocator)
virtual string getDecayOptions()=0