#include <EventWriter.h>
Public Member Functions | |
EventWriter (const std::string &name, ISvcLocator *pSvcLocator) | |
EventWriter (const std::string &name, ISvcLocator *pSvcLocator) | |
StatusCode | execute () |
StatusCode | execute () |
StatusCode | finalize () |
StatusCode | finalize () |
StatusCode | initialize () |
StatusCode | initialize () |
~EventWriter () | |
~EventWriter () | |
Private Types | |
typedef std::vector< std::string > | ItemNames |
typedef std::vector< std::string > | ItemNames |
typedef std::vector< DataStoreItem * > | Items |
typedef std::vector< DataStoreItem * > | Items |
Private Member Functions | |
void | addItem (Items &itms, const std::string &descriptor) |
void | addItem (Items &itms, const std::string &descriptor) |
void | clearItems (Items &items) |
void | clearItems (Items &items) |
StatusCode | collectObjects () |
StatusCode | collectObjects () |
DataStoreItem * | findItem (const std::string &path) |
DataStoreItem * | findItem (const std::string &path) |
virtual std::string | getDecayOptions () |
virtual std::string | getDecayOptions () |
virtual std::string | getJobOptions () |
virtual std::string | getJobOptions () |
StatusCode | getSvc () |
StatusCode | getSvc () |
Private Attributes | |
TJobInfo * | jobInfo |
TJobInfo * | jobInfo |
std::string | m_bossVer |
int | m_bufsize |
char * | m_cbuf |
char * | m_cbuf |
RootCnvSvc * | m_cnvSvc |
RootCnvSvc * | m_cnvSvc |
commonData | m_common |
DataStoreItem * | m_currentItem |
DataStoreItem * | m_currentItem |
std::string | m_decayOptions |
TDigiEvent * | m_digiEvt |
TDigiEvent * | m_digiEvt |
string | m_dofileName |
string | m_dofileName_1 |
TEvtHeader * | m_evtHd |
TEvtHeader * | m_evtHd |
THltEvent * | m_hltEvt |
THltEvent * | m_hltEvt |
Items | m_itemList |
ItemNames | m_itemNames |
TTree * | m_jobInfoTree |
TTree * | m_jobInfoTree |
std::vector< std::string > | m_jobOptions |
std::vector< std::string > | m_jobOptions |
TMcEvent * | m_mcEvt |
TMcEvent * | m_mcEvt |
int | m_mode |
IDataStoreAgent * | m_pAgent |
IDataStoreAgent * | m_pAgent |
IConversionSvc * | m_pConversionSvc |
IConversionSvc * | m_pConversionSvc |
IDataManagerSvc * | m_pDataManager |
IDataManagerSvc * | m_pDataManager |
IDataProviderSvc * | m_pDataProvider |
IDataProviderSvc * | m_pDataProvider |
RootInterface * | m_pRootInterface |
RootInterface * | m_pRootInterface |
TFile * | m_single_outputFiles |
TFile * | m_single_outputFiles |
TTree * | m_single_outputTrees |
TTree * | m_single_outputTrees |
std::string | m_svrName |
TBossFullEvent * | m_TFullEvt |
TBossFullEvent * | m_TFullEvt |
TRecTrackEvent * | m_trkEvt |
TRecTrackEvent * | m_trkEvt |
NetDataWriter * | m_writer |
NetDataWriter * | m_writer |
int | st |
|
|
|
|
|
|
|
|
|
00022 : 00023 Algorithm(name, pSvcLocator) 00024 { 00025 m_itemNames.push_back("/Event"); 00026 m_itemNames.push_back("/Event/EventHeader"); 00027 00028 m_itemNames.push_back("/Event/Digi"); 00029 m_itemNames.push_back("/Event/Digi/MdcDigiCol"); 00030 m_itemNames.push_back("/Event/Digi/TofDigiCol"); 00031 m_itemNames.push_back("/Event/Digi/EmcDigiCol"); 00032 m_itemNames.push_back("/Event/Digi/MucDigiCol"); 00033 00034 m_itemNames.push_back("/Event/Hlt"); 00035 m_itemNames.push_back("/Event/Hlt/HltRawCol"); 00036 m_itemNames.push_back("/Event/Hlt/HltInf"); 00037 //m_itemNames.push_back("/Event/Hlt/DstHltInf"); 00038 00039 m_itemNames.push_back("/Event/Recon"); 00040 // m_itemNames.push_back("/Event/Recon/RecMdcHitCol"); 00041 m_itemNames.push_back("/Event/Recon/RecMdcTrackCol"); 00042 // m_itemNames.push_back("/Event/Recon/MdcHOTCol"); 00043 m_itemNames.push_back("/Event/Recon/RecMdcDedxCol"); 00044 // m_itemNames.push_back("/Event/Recon/RecMdcDedxHitCol"); 00045 m_itemNames.push_back("/Event/Recon/RecMdcKalTrackCol"); 00046 // m_itemNames.push_back("/Event/Recon/RecMdcKalHelixSegCol"); 00047 m_itemNames.push_back("/Event/Recon/RecEsTimeCol"); 00048 m_itemNames.push_back("/Event/Recon/RecExtTrackCol"); 00049 // m_itemNames.push_back("/Event/Recon/RecBTofHitCol"); 00050 // m_itemNames.push_back("/Event/Recon/RecETofHitCol"); 00051 m_itemNames.push_back("/Event/Recon/RecTofTrackCol"); 00052 // m_itemNames.push_back("/Event/Recon/RecBTofCalHitCol"); 00053 // m_itemNames.push_back("/Event/Recon/RecETofCalHitCol"); 00054 m_itemNames.push_back("/Event/Recon/RecEmcHitCol"); 00055 m_itemNames.push_back("/Event/Recon/RecEmcClusterCol"); 00056 m_itemNames.push_back("/Event/Recon/RecEmcShowerCol"); 00057 // m_itemNames.push_back("/Event/Recon/MucRecHitCol"); 00058 m_itemNames.push_back("/Event/Recon/RecMucTrackCol"); 00059 m_itemNames.push_back("/Event/Recon/EvtRecEvent"); 00060 m_itemNames.push_back("/Event/Recon/EvtRecTrackCol"); 00061 // m_itemNames.push_back("/Event/Recon/EvtRecVertexCol"); 00062 00063 // Part 1: Declare the properties 00064 declareProperty("digiRootOutputFile",m_dofileName = "event.rec"); 00065 declareProperty("ItemList",m_itemNames); 00066 declareProperty("RunMode", m_mode = 2); 00067 }
|
|
00070 { 00071 // Part 1: Get the messaging service, print where you are 00072 MsgStream log(msgSvc(), name()); 00073 log << MSG::INFO << " EventWriter ~EventWriter()" << endreq; 00074 00075 00076 00077 }
|
|
|
|
|
|
|
|
00241 { 00242 MsgStream log(msgSvc(), name()); 00243 int level = 0; 00244 size_t sep = descriptor.rfind("#"); 00245 std::string obj_path (descriptor,0,sep); 00246 std::string slevel (descriptor,sep+1,descriptor.length()); 00247 if ( slevel == "*" ) { 00248 level = 9999999; 00249 } 00250 else { 00251 level = atoi(slevel.c_str()); 00252 } 00253 size_t idx = obj_path.find("/",1); 00254 while (idx != std::string::npos) { 00255 std::string sub_item = obj_path.substr(0,idx); 00256 if ( 0 == findItem(sub_item) ) { 00257 addItem(itms, sub_item+"#1"); 00258 } 00259 idx = obj_path.find("/",idx+1); 00260 } 00261 DataStoreItem* item = new DataStoreItem(obj_path, level); 00262 log << MSG::DEBUG << "Adding OutputStream item " << item->path() 00263 << " with " << item->depth() 00264 << " level(s)." << endreq; 00265 itms.push_back( item ); 00266 }
|
|
|
|
00269 { 00270 for ( Items::iterator i = itms.begin(); i != itms.end(); i++ ) { 00271 delete (*i); 00272 } 00273 itms.erase(itms.begin(), itms.end()); 00274 }
|
|
|
|
00286 { 00287 MsgStream log(msgSvc(), name()); 00288 StatusCode status = StatusCode::SUCCESS; 00289 Items::iterator i; 00290 00291 // Traverse the tree and collect the requested objects 00292 // status = m_pConversionSvc->connectOutput(f_rootOutputFile.c_str(), "recreate"); 00293 00294 for ( i = m_itemList.begin(); i != m_itemList.end(); i++ ) { 00295 DataObject* obj = 0; 00296 IOpaqueAddress *pAddress = 0; 00297 m_currentItem = (*i); 00298 00299 status = m_pDataProvider->retrieveObject(m_currentItem->path(), obj); 00300 if ( status.isSuccess() ) { 00301 status = m_pConversionSvc->createRep(obj, pAddress); 00302 //IRegistry *pReg = obj->registry(); 00303 //pReg->setAddress(pAddress); 00304 //status = m_pConversionSvc->fillRepRefs(pReg->address(), *i); 00305 } 00306 else { 00307 log << MSG::ERROR << "Cannot write mandatory object(s) (Not found): " 00308 << m_currentItem->path() << endreq; 00309 } 00310 } 00311 00312 00313 return status; 00314 }
|
|
|
|
00176 { 00177 00178 // Part 1: Get the messaging service, print where you are 00179 MsgStream log(msgSvc(), name()); 00180 log << MSG::INFO << "EventWriter execute()" << endreq; 00181 collectObjects(); 00182 00183 if ( m_mode == 2 ) { //OfflineMode 00184 if(st!=1){ 00185 if(m_common.m_rectrackEvt) m_single_outputTrees->Branch("TRecEvent","TRecTrackEvent",&m_common.m_rectrackEvt,3200000,1); 00186 m_single_outputTrees->Branch("TEvtRecObject","TEvtRecObject",&m_common.m_evtRecObject,3200000,1); 00187 if(m_common.m_dstEvt) m_single_outputTrees->Branch("TDstEvent","TDstEvent",&m_common.m_dstEvt,3200000,1); 00188 m_single_outputTrees->Branch("TDigiEvent","TDigiEvent",&m_common.m_recEvt,3200000,1); 00189 m_single_outputTrees->Branch("TEvtHeader","TEvtHeader",&m_common.m_EvtHeader,3200000,1); 00190 m_single_outputTrees->Branch("THltEvent","THltEvent",&m_common.m_hltEvt,3200000,1); 00191 m_single_outputTrees->Branch("TMcEvent","TMcEvent",&m_common.m_mcEvt,3200000,1); 00192 m_single_outputTrees->Branch("TTrigEvent","TTrigEvent",&m_common.m_trigEvt,3200000,1); 00193 m_jobInfoTree->Branch("JobInfo",&jobInfo); 00194 st=1; 00195 } 00196 00197 if(m_single_outputFiles->IsZombie()||(!m_single_outputFiles->IsOpen())){ 00198 std::cout<<"EventWriter ERROR::The ROOT File:"<<m_dofileName.c_str()<<"status is false"<<std::endl; 00199 exit(1); 00200 } 00201 00202 int nb = m_single_outputTrees->Fill(); 00203 if(nb==-1) 00204 { 00205 log << MSG::FATAL << "Error in fill tree (EventWriter) "<<m_single_outputTrees->GetName() << " with "<<nb<<" bytes" <<endreq; 00206 exit(1); 00207 } 00208 00209 m_single_outputFiles = m_single_outputTrees->GetCurrentFile(); 00210 } 00211 else if ( m_mode == 3 ) { //DistBossMode 00212 m_TFullEvt->setEvtHeader(m_common.m_EvtHeader); 00213 m_TFullEvt->setDigiEvent(m_common.m_recEvt); //TDigiEvent 00214 m_TFullEvt->setDstEvent(m_common.m_dstEvt); 00215 m_TFullEvt->setMcEvent(m_common.m_mcEvt); 00216 m_TFullEvt->setTrigEvent(m_common.m_trigEvt); 00217 m_TFullEvt->setHltEvent(m_common.m_hltEvt); 00218 m_TFullEvt->setRecTrackEvent(m_common.m_rectrackEvt); 00219 m_TFullEvt->setEvtRecObject(m_common.m_evtRecObject); 00220 00221 // Might it be able to optimize within higher version of ROOT? 00222 TBuffer m_TBuffer(TBuffer::kWrite, m_bufsize-12, m_cbuf+4, false); 00223 m_TBuffer.WriteObject(m_TFullEvt); 00224 if ( m_TBuffer.Buffer() != (m_cbuf+4) ) { 00225 m_bufsize = m_TBuffer.Length() + 12; 00226 m_cbuf = new char[m_bufsize]; 00227 memcpy(m_cbuf+4, m_TBuffer.Buffer(), m_TBuffer.Length()); 00228 m_TBuffer.SetBit(TBuffer::kIsOwner); 00229 } 00230 *((int*)m_cbuf) = m_common.m_EvtHeader->getEventId(); 00231 m_writer->writeEvent( (void*)m_cbuf, m_TBuffer.Length()+4 ); 00232 00233 m_TFullEvt->reset(); 00234 } 00235 00236 m_common.clear(); 00237 00238 return StatusCode::SUCCESS; 00239 }
|
|
|
|
00320 { 00321 00322 // Part 1: Get the messaging service, print where you are 00323 MsgStream log(msgSvc(), name()); 00324 int st =1; 00325 std::cout<<"11111111111111111111111111"<<std::endl; 00326 00327 if ( m_mode == 2 ) { //OfflineMode 00328 m_bossVer = getenv("BES_RELEASE"); 00329 log << MSG::INFO << "fill boss version: "<<m_bossVer << endreq; 00330 00331 string tmpJobOptions = getJobOptions(); 00332 m_jobOptions.push_back( tmpJobOptions ); 00333 00334 if(m_decayOptions.size()==0) 00335 m_decayOptions = getDecayOptions(); 00336 00337 jobInfo->setBossVer(m_bossVer); 00338 jobInfo->setJobOptions(m_jobOptions); 00339 jobInfo->setDecayOptions(m_decayOptions); 00340 00341 m_jobInfoTree->Fill(); 00342 00343 st = m_single_outputFiles->Write(); 00344 if(st==0) 00345 { 00346 log << MSG::FATAL <<"can not write to the file "<<m_dofileName.c_str()<<endreq; 00347 exit(1); 00348 } 00349 m_single_outputFiles->Close(); 00350 00351 delete m_single_outputFiles; 00352 delete jobInfo; 00353 } 00354 00355 if ( m_mode == 3 ) { //DistBossMode 00356 int code = DistBossCode::StatusFinalize; 00357 m_writer->writeEvent((void*)&code, 4); 00358 delete m_writer; 00359 delete m_TFullEvt; 00360 delete [] m_cbuf; 00361 } 00362 00363 log << MSG::INFO << "EventWriter finalize()" << endreq; 00364 return StatusCode::SUCCESS; 00365 }
|
|
|
|
00277 { 00278 for (Items::const_iterator i=m_itemList.begin(); i != m_itemList.end(); ++i) { 00279 if ( (*i)->path() == path ) return (*i); 00280 } 00281 return 0; 00282 }
|
|
|
|
00396 { 00397 MsgStream log(msgSvc(), name()); 00398 ISvcLocator* svcLocator = Gaudi::svcLocator(); 00399 IDataInfoSvc *tmpInfoSvc; 00400 DataInfoSvc* jobInfoSvc; 00401 string decayOptions; 00402 StatusCode status = svcLocator->service("DataInfoSvc",tmpInfoSvc); 00403 if (status.isSuccess()) { 00404 log << MSG::INFO << "get the DataInfoSvc" << endreq; 00405 jobInfoSvc=dynamic_cast<DataInfoSvc *>(tmpInfoSvc); 00406 decayOptions = jobInfoSvc->getDecayOptions(); 00407 log << MSG::INFO << "get decay options" << endreq 00408 << decayOptions << endreq; 00409 }else { 00410 log << MSG::WARNING << "could not get the DataInfoSvc. Ignore it." << endreq; 00411 } 00412 return decayOptions; 00413 }
|
|
|
|
00372 { 00373 MsgStream log(msgSvc(), name()); 00374 IInterface* iface = Gaudi::createApplicationMgr(); 00375 SmartIF<IProperty> propMgr ( IID_IProperty, iface ); 00376 std::string path; 00377 propMgr->getProperty( "JobOptionsPath", path); 00378 log << MSG::INFO << "JobOptions file for current job: " <<path << endreq; 00379 ifstream fin(path.c_str()); 00380 string jobOptions; 00381 string tempString; 00382 while(getline(fin,tempString)) 00383 { 00384 if( tempString.size()>0 && tempString.find("//")>tempString.size() ) 00385 { 00386 jobOptions += tempString; 00387 jobOptions += "\n"; 00388 } 00389 } 00390 log << MSG::INFO << "JobOptions: " << endreq 00391 << jobOptions << endreq; 00392 return jobOptions; 00393 }
|
|
|
|
00158 { 00159 MsgStream log(msgSvc(), name()); 00160 log << MSG::INFO << "getSvc()" << endreq; 00161 StatusCode status = StatusCode::SUCCESS; 00162 if(m_itemNames.empty()) { 00163 log << MSG::ERROR << "no ItemList from the jobOption" << endreq; 00164 return StatusCode::FAILURE; 00165 } 00166 // ItemNames m_itemNames; 00167 clearItems(m_itemList); 00168 ItemNames::iterator i; 00169 for (i = m_itemNames.begin(); i != m_itemNames.end(); i++){ 00170 addItem(m_itemList, *i); 00171 } 00172 return status; 00173 }
|
|
|
|
00080 { 00081 00082 // Part 1: Get the messaging service, print where you are 00083 MsgStream log(msgSvc(), name()); 00084 log << MSG::INFO << " EventWriter initialize()" << endreq; 00085 00086 00087 // StatusCode status = Converter::initialize(); 00088 00089 // if ( status.isSuccess() ) { 00090 00091 IService* isvc = 0; 00092 00093 StatusCode status = serviceLocator()->service("RootCnvSvc", isvc, false); 00094 00095 if ( !status.isSuccess() ) status = serviceLocator()->service("EventCnvSvc", isvc, true); 00096 00097 if ( status.isSuccess() ) { 00098 00099 status = isvc->queryInterface(IID_IRootCnvSvc, (void**)&m_cnvSvc); 00100 00101 } 00102 00103 00104 status = serviceLocator()->service("EventCnvSvc", m_pConversionSvc, true); 00105 if ( !status.isSuccess() ) { 00106 log << MSG::FATAL << "Unable to locate IConversionSvc interface" 00107 << endreq; 00108 return status; 00109 } 00110 00111 00112 status = serviceLocator()->service("EventDataSvc", m_pDataProvider, true); 00113 if ( !status.isSuccess() ) { 00114 log << MSG::FATAL << "Unable to locate IDataProviderSvc interface" 00115 << endreq; 00116 return status; 00117 } 00118 00119 // } 00120 00121 if ( m_mode == 2 ) { //OfflineMode 00122 m_single_outputFiles = new TFile(m_dofileName.c_str(), "RECREATE"); 00123 if(m_single_outputFiles->IsZombie()||(!m_single_outputFiles->IsWritable())){ 00124 std::cout<<"EventWriter ERROR::Can't not open file"<<m_dofileName.c_str()<<std::endl; 00125 exit(1); 00126 } 00127 00128 m_single_outputTrees = new TTree("Event","Event"); 00129 m_jobInfoTree = new TTree("JobInfoTree","Job info"); 00130 jobInfo = new TJobInfo; 00131 } 00132 else if ( m_mode == 3 ) { //DistBossMode 00133 status = DistBoss::GetPropertyValue<std::string>("DistBoss", "ServerName", m_svrName); 00134 m_TFullEvt = new TBossFullEvent; 00135 m_writer = new NetDataWriter(m_svrName+'/'+name()); 00136 m_bufsize = 512*1024; 00137 m_cbuf = new char[m_bufsize]; 00138 int code = DistBossCode::ClientReady; 00139 m_writer->writeEvent((void*)&code, 4); 00140 } 00141 else { 00142 log << MSG::FATAL << "Unvalid RunMode @ initialize(): " << m_mode << endreq; 00143 exit(1); 00144 } 00145 00146 status = getSvc(); 00147 if ( !status.isSuccess() ) { 00148 log << MSG::FATAL << "can not getSvc" << endreq; 00149 return status; 00150 } 00151 st=0; 00152 00153 return StatusCode::SUCCESS; 00154 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|