1#include "EventModel/Event.h"
2#include "EventModel/EventHeader.h"
3#include "EventModel/EventModel.h"
4#include "RootCnvSvc/Digi/DigiCnv.h"
5#include "RootCnvSvc/EvtHeaderCnv.h"
6#include "RootCnvSvc/Rec/RecTrackCnv.h"
7#include "RootCnvSvc/Trig/TrigCnv.h"
8#include "RootCnvSvc/Trig/TrigDataCnv.h"
9#include "RootEventData/TDigiEvent.h"
10#include "RootEventData/TEvtHeader.h"
11#include "RootEventData/TRecTrackEvent.h"
12#include "RootEventData/TTrigEvent.h"
17Long64_t BesVisAlg::counter = 0;
22 : Algorithm( name, pSvcLocator ) {
24 declareProperty(
"TestVec", testVec );
25 declareProperty(
"OutputShareFile", f_rootOutputFile );
26 declareProperty(
"InputGeometryFile", f_geoInputFile );
27 declareProperty(
"DisplayMode", m_mode = 0 );
41 release.sem_flg = SEM_UNDO;
53 MsgStream log(
msgSvc(), name() );
54 log << MSG::INFO <<
" BesVisAlg ~BesVisAlg()" << endmsg;
73 MsgStream log(
msgSvc(), name() );
74 log << MSG::INFO <<
" BesVisAlg initialize()" << endmsg;
75 StatusCode status = StatusCode::SUCCESS;
80 status = service(
"RootCnvSvc", m_cnvSvc,
false );
81 if ( !status.isSuccess() ) status = service(
"EventCnvSvc", m_cnvSvc,
true );
83 if ( status.isSuccess() ) { log << MSG::INFO <<
"share file writed -- success" << endmsg; }
84 else { log << MSG::ERROR <<
"share file writed -- ERROR!!!!!" << endmsg; }
88 log << MSG::INFO <<
" OutputFile = " << f_rootOutputFile << endmsg;
90 for (
unsigned int i = 0; i < testVec.size(); i++ )
91 { log << MSG::INFO <<
" MyStringVec[" << i <<
"] = " << testVec[i] << endmsg; }
95 log << MSG::ERROR <<
"BesVisAlg process PID: [" << m_pid <<
"]" << endmsg;
97 log << MSG::ERROR <<
"Create and initialize semaphore" << endmsg;
98 if ( ( semid = semget( (
int)m_pid, 2, IPC_CREAT | IPC_EXCL | 0666 ) ) != -1 )
100 arg.array = start_val;
101 log << MSG::ERROR <<
"Semaphore ID:" << semid << endmsg;
103 if ( semctl( semid, 0, SETALL, arg ) == -1 )
105 log << MSG::ERROR <<
"semctl -- parent -- initialization" << endmsg;
109 if ( ( sem_value_F = semctl( semid,
FREE_SPACE, GETVAL, 0 ) ) == -1 )
111 log << MSG::ERROR <<
"semctl -- GETVAL" << endmsg;
115 if ( ( sem_value_O = semctl( semid,
OUTPUT_STORE, GETVAL, 0 ) ) == -1 )
117 log << MSG::ERROR <<
"semctl -- GETVAL" << endmsg;
123 log << MSG::INFO <<
"semget -- parent -- creation" << endmsg;
134 if ( ( c_pid = fork() ) == -1 )
136 log << MSG::ERROR <<
"fork -- consumer" << endmsg;
139 else if ( c_pid == 0 )
142 log << MSG::INFO <<
"Parent fork consumer: ppid = " << getppid() <<
"; pid = " << getpid()
147 sprintf( msg_pid,
"%d", m_pid );
149 const char* msg_sleep = testVec[1].c_str();
151 log << MSG::INFO <<
"msg_pid: " << msg_pid << endmsg;
152 log << MSG::INFO <<
"Consumer sleep time: " << msg_sleep <<
" seconds." << endmsg;
155 execlp(
"besvis.exe",
"besvis.exe",
"-B", msg_pid,
"-e", f_rootOutputFile.c_str(),
"-g",
156 f_geoInputFile.c_str(), (
char*)NULL );
159 log << MSG::ERROR <<
"exec -- consumer" << endmsg;
163 return StatusCode::SUCCESS;
171 MsgStream log(
msgSvc(), name() );
172 log << MSG::INFO <<
"BesVisAlg execute()" << endmsg;
175 const char* msg_sleep = testVec[0].c_str();
176 producer( atoi( msg_sleep ) );
178 return StatusCode::SUCCESS;
186 MsgStream log(
msgSvc(), name() );
187 log << MSG::INFO <<
"BesVisAlg finalize()" << endmsg;
193 if ( hasRead() )
break;
198 if ( semctl( semid, 0, IPC_RMID, 0 ) == -1 )
199 log << MSG::ERROR <<
"Delete semaphore" << endmsg;
200 else log << MSG::INFO <<
"Delete semaphore" << endmsg;
204 cout <<
"wait for besvis terminate" << endl;
205 while ( wait_pid = waitpid( c_pid, &status, 0 ) )
207 log << MSG::INFO <<
"Wait on PID: " << c_pid <<
" returns status of: " << status << endmsg;
208 if ( wait_pid == -1 )
break;
211 cout <<
"finalize" << endl;
212 return StatusCode::SUCCESS;
216StatusCode BesVisAlg::producer(
int p_sleep ) {
218 MsgStream log(
msgSvc(), name() );
219 log << MSG::INFO <<
"Producer work" << endmsg;
220 StatusCode status = StatusCode::SUCCESS;
251 if ( semop( semid, &
acquire, 1 ) == -1 )
253 log << MSG::ERROR <<
"Producer -- decrease -- freeSpace" << endmsg;
314 IOpaqueAddress* pAddress = 0;
316 status = m_pDataProvider->retrieveObject(
"/Event", obj );
317 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
321 status = m_pDataProvider->retrieveObject(
"/Event/Trig", obj );
322 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
325 status = m_pDataProvider->retrieveObject(
"/Event/Trig/TrigData", obj );
326 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
329 status = m_pDataProvider->retrieveObject(
"/Event/EventHeader", obj );
330 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
333 status = m_pDataProvider->retrieveObject(
"/Event/Digi", obj );
334 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
337 status = m_pDataProvider->retrieveObject(
"/Event/Digi/MdcDigiCol", obj );
338 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
341 status = m_pDataProvider->retrieveObject(
"/Event/Digi/TofDigiCol", obj );
342 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
345 status = m_pDataProvider->retrieveObject(
"/Event/Digi/EmcDigiCol", obj );
346 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
349 status = m_pDataProvider->retrieveObject(
"/Event/Digi/MucDigiCol", obj );
350 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
353 status = m_pDataProvider->retrieveObject(
"/Event/Recon", obj );
354 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
357 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecMdcHitCol", obj );
358 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
361 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecMdcTrackCol", obj );
362 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
365 status = m_pDataProvider->retrieveObject(
"/Event/Recon/MdcHOTCol", obj );
366 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
369 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecMdcDedxCol", obj );
370 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
373 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecTofTrackCol", obj );
374 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
378 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecEmcShowerCol", obj );
379 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
382 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecMucTrackCol", obj );
383 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
384 TRecTrackEvent* recEvt = m_cnvSvc->getRecTrackCnv()->getWriteObject();
385 TTrigEvent* trigEvt = m_cnvSvc->getTrigCnv()->getWriteObject();
386 TEvtHeader* evtHeader = m_cnvSvc->getEvtHeaderCnv()->getWriteObject();
387 TDigiEvent* digiEvt = m_cnvSvc->getDigiCnv()->getWriteObject();
399 recdis =
new TDisTrack();
401 recTrack1 =
new TRecMdcTrack[20];
405 std::cout <<
" mdc trk number =" << no << std::endl;
406 if ( no > 20 ) no = 20;
407 for (
int i = 0; i < no; i++ )
413 ( recTrack1 + i )->setTRecMdcTrack( recTrack );
414 recdis->addRecMdcTrack( recTrack1 + i );
423 tofTrack =
new TRecTofTrack[200];
426 std::cout <<
" tof trk number =" << no << std::endl;
427 if ( no > 200 ) no = 200;
428 for (
int i = 0; i < no; i++ )
430 const TRecTofTrack* tofTrack1 = recEvt->
getTofTrack( i );
431 ( tofTrack + i )->setTRecTofTrack( tofTrack1 );
432 recdis->addTofTrack( tofTrack + i );
441 mdchit =
new TRecMdcHit[1000];
444 std::cout <<
" mdc hits number =" << no << std::endl;
445 if ( no > 1000 ) no = 1000;
446 for (
int i = 0; i < no; i++ )
449 ( mdchit + i )->setTRecMdcHit( mdchit1 );
450 recdis->addRecMdcHit( mdchit + i );
458 muctrk =
new TRecMucTrack[20];
462 std::cout <<
" muc trk number =" << no << std::endl;
463 if ( no > 20 ) no = 20;
464 for (
int i = 0; i < no; i++ )
466 const TRecMucTrack* mucTrack1 = recEvt->
getMucTrack( i );
467 ( muctrk + i )->setTRecMucTrack( mucTrack1 );
468 recdis->addMucTrack( muctrk + i );
477 emcshower =
new TRecEmcShower[20];
480 std::cout <<
" emc trk number =" << no << std::endl;
481 if ( no > 20 ) no = 20;
482 for (
int i = 0; i < no; i++ )
484 const TRecEmcShower* rec_emc = recEvt->
getEmcShower( i );
485 ( emcshower + i )->setTRecEmcShower( rec_emc );
486 recdis->addEmcShower( emcshower + i );
489 TFile
file( f_rootOutputFile.c_str(),
"RECREATE" );
490 TTree tree(
"Event",
"Event" );
491 tree.Branch(
"TDisTrack",
"TDisTrack", &recdis, 64000, 1 );
492 tree.Branch(
"TDigiEvent",
"TDigiEvent", &digiEvt, 64000, 1 );
493 tree.Branch(
"TEvtHeader",
"TEvtHeader", &evtHeader, 64000, 1 );
494 tree.Branch(
"TTrigEvent",
"TTrigEvent", &trigEvt, 64000, 1 );
536 if ( semop( semid, &release, 1 ) == -1 )
538 log << MSG::ERROR <<
"Producer -- increase -- storage" << endmsg;
572bool BesVisAlg::hasRead() {
574 MsgStream log(
msgSvc(), name() );
575 log << MSG::INFO <<
"hadRead()" << endmsg;
578 if ( ( sem_value_F = semctl( semid,
FREE_SPACE, GETVAL, 0 ) ) == -1 )
580 log << MSG::ERROR <<
"semctl: GETVAL -- FREE_SPACE" << endmsg;
583 log << MSG::INFO <<
"Semaphore FREE_SPACE has value of " << sem_value_F << endmsg;
585 if ( ( sem_value_O = semctl( semid,
OUTPUT_STORE, GETVAL, 0 ) ) == -1 )
587 log << MSG::ERROR <<
"semctl: GETVAL -- OUTPUT_STORE" << endmsg;
590 log << MSG::INFO <<
"Semaphore OUTPUT_STORE has value of " << sem_value_O << endmsg;
592 if ( ( sem_value_F == 1 ) && ( sem_value_O == 0 ) )
return true;
597StatusCode BesVisAlg::hasWrite() {
598 MsgStream log(
msgSvc(), name() );
599 log << MSG::INFO <<
"hasWrite()" << endmsg;
600 StatusCode status = StatusCode::SUCCESS;
607 if ( !status.isSuccess() )
609 log << MSG::ERROR <<
"getSvc() error!" << endmsg;
610 return StatusCode::SUCCESS;
613 status = collectObjects();
614 if ( !status.isSuccess() )
616 log << MSG::ERROR <<
"collectObjects() error!" << endmsg;
617 return StatusCode::SUCCESS;
640StatusCode BesVisAlg::getSvc() {
641 MsgStream log(
msgSvc(), name() );
642 log << MSG::INFO <<
"getSvc()" << endmsg;
643 StatusCode status = StatusCode::SUCCESS;
646 ItemNames m_itemNames;
647 m_itemNames.push_back(
"/Event#1" );
648 m_itemNames.push_back(
"/Event/EventHeader#1" );
650 m_itemNames.push_back(
"/Event/Digi#1" );
651 m_itemNames.push_back(
"/Event/Digi/MdcDigiCol#1" );
652 m_itemNames.push_back(
"/Event/Digi/TofDigiCol#1" );
653 m_itemNames.push_back(
"/Event/Digi/EmcDigiCol#1" );
654 m_itemNames.push_back(
"/Event/Digi/MucDigiCol#1" );
656 m_itemNames.push_back(
"/Event/Recon#1" );
657 m_itemNames.push_back(
"/Event/Recon/RecMdcHitCol#1" );
658 m_itemNames.push_back(
"/Event/Recon/RecMdcTrackCol#1" );
660 m_itemNames.push_back(
"/Event/Trig#1" );
661 m_itemNames.push_back(
"/Event/Trig/TrigData#1" );
683 clearItems( m_itemList );
684 ItemNames::iterator i;
685 for ( i = m_itemNames.begin(); i != m_itemNames.end(); i++ ) { addItem( m_itemList, *i ); }
687 status = serviceLocator()->service(
"EventDataSvc", m_pDataManager,
true );
688 if ( !status.isSuccess() )
690 log << MSG::FATAL <<
"Unable to locate IDataManagerSvc interface" << endmsg;
694 status = serviceLocator()->service(
"EventDataSvc", m_pDataProvider,
true );
695 if ( !status.isSuccess() )
697 log << MSG::FATAL <<
"Unable to locate IDataProviderSvc interface" << endmsg;
701 status = serviceLocator()->service(
"EventCnvSvc", m_pConversionSvc,
true );
702 if ( !status.isSuccess() )
704 log << MSG::FATAL <<
"Unable to locate IConversionSvc interface" << endmsg;
712StatusCode BesVisAlg::finishSvc() {
713 MsgStream log(
msgSvc(), name() );
714 log << MSG::INFO <<
"finishSvc()" << endmsg;
715 StatusCode status = StatusCode::SUCCESS;
717 status = m_pRootInterface->f_finalize();
718 if ( !status.isSuccess() ) log << MSG::ERROR <<
"f_finalize() error" << endmsg;
720 status = m_pConversionSvc->commitOutput( f_rootOutputFile.c_str(),
true );
721 if ( !status.isSuccess() ) log << MSG::ERROR <<
"commitOutput() error" << endmsg;
723 clearItems( m_itemList );
725 return StatusCode::SUCCESS;
730void BesVisAlg::addItem( Items& itms,
const std::string& descriptor ) {
731 MsgStream log(
msgSvc(), name() );
733 size_t sep = descriptor.rfind(
"#" );
734 std::string obj_path( descriptor, 0, sep );
735 std::string slevel( descriptor, sep + 1, descriptor.length() );
736 if ( slevel ==
"*" ) { level = 9999999; }
737 else { level = atoi( slevel.c_str() ); }
738 size_t idx = obj_path.find(
"/", 1 );
739 while ( idx != std::string::npos )
741 std::string sub_item = obj_path.substr( 0, idx );
742 if ( 0 == findItem( sub_item ) ) { addItem( itms, sub_item +
"#1" ); }
743 idx = obj_path.find(
"/", idx + 1 );
745 DataStoreItem* item =
new DataStoreItem( obj_path, level );
746 log << MSG::DEBUG <<
"Adding OutputStream item " << item->path() <<
" with " << item->depth()
747 <<
" level(s)." << endmsg;
748 itms.push_back( item );
752void BesVisAlg::clearItems( Items& itms ) {
753 for ( Items::iterator i = itms.begin(); i != itms.end(); i++ ) {
delete ( *i ); }
754 itms.erase( itms.begin(), itms.end() );
759DataStoreItem* BesVisAlg::findItem(
const std::string& path ) {
760 for ( Items::const_iterator i = m_itemList.begin(); i != m_itemList.end(); ++i )
762 if ( ( *i )->path() == path )
return ( *i );
768StatusCode BesVisAlg::collectObjects() {
769 MsgStream log(
msgSvc(), name() );
770 StatusCode status = StatusCode::SUCCESS;
775 for ( i = m_itemList.begin(); i != m_itemList.end(); i++ )
778 IOpaqueAddress* pAddress = 0;
779 m_currentItem = ( *i );
781 status = m_pDataProvider->retrieveObject( m_currentItem->path(), obj );
782 if ( status.isSuccess() ) { status = m_pConversionSvc->createRep( obj, pAddress ); }
786 <<
"Cannot write mandatory object(s) (Not found): " << m_currentItem->path()
791 return StatusCode::SUCCESS;
794StatusCode BesVisAlg::write2file() {
795 MsgStream log(
msgSvc(), name() );
796 StatusCode status = StatusCode::SUCCESS;
798 log << MSG::INFO <<
"write2file()" << endmsg;
800 const std::string treename(
"Event" );
810 if ( pTRawEvent == 0 ) { log << MSG::WARNING <<
"Can not get point TDigiEvent" << endmsg; }
812 const std::string rawBranchname(
"TDigiEvent" );
816 m_pRootInterface->f_addOutput( treename, f_rootOutputFile.c_str(), 1, 64000, 1 );
818 if ( pTRawEvent != 0 )
819 m_pRootInterface->f_createBranch( treename, rawBranchname, pTRawEvent->ClassName(),
820 &pTRawEvent, branchnr );
826 if ( pTEvtHeader == 0 ) { log << MSG::WARNING <<
"Can not get point TEvtHeader" << endmsg; }
828 const std::string headerBranchname(
"TEvtHeader" );
830 if ( pTEvtHeader != 0 )
831 m_pRootInterface->f_createBranch( treename, headerBranchname, pTEvtHeader->ClassName(),
832 &pTEvtHeader, branchnr );
838 if ( pTTrigEvent == 0 ) { log << MSG::WARNING <<
"Can not get point TTrigEvent" << endmsg; }
840 const std::string trigBranchname(
"TTrigEvent" );
842 if ( pTTrigEvent != 0 )
843 m_pRootInterface->f_createBranch( treename, trigBranchname, pTTrigEvent->ClassName(),
844 &pTTrigEvent, branchnr );
850 if ( pTRecEvent == 0 ) { log << MSG::WARNING <<
"Can not get point TRecEvent" << endmsg; }
852 const std::string recBranchname(
"TRecEvent" );
854 if ( pTRecEvent != 0 )
855 m_pRootInterface->f_createBranch( treename, recBranchname, pTRecEvent->ClassName(),
856 &pTRecEvent, branchnr );
859 status = m_pRootInterface->f_fillTrees();
860 if ( status.isFailure() ) log << MSG::ERROR <<
"No Root tree was filled" << endmsg;
DECLARE_COMPONENT(BesBdkRc)
sprintf(cut, "kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_" "pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
BesVisAlg(const std::string &name, ISvcLocator *pSvcLocator)
static RootInterface * Instance(const std::string &name)
singleton behaviour
const TObjArray * getTofTrackCol() const
retrieve the whole TObjArray of TofTrack Data
const TRecTofTrack * getTofTrack(Int_t i) const
retrieve a TofTrack From the collection, using the index into the array
const TRecMdcTrack * getRecMdcTrack(Int_t i) const
retrieve a MdcTrack from the collection, using the index into the array
const TObjArray * getEmcShowerCol() const
retrieve the whole TObjArray of EmcShower Data
const TObjArray * getRecMdcTrackCol() const
retrieve the whole TObjArray of RecMdcTrack Data
const TRecEmcShower * getEmcShower(Int_t i) const
retrieve a EmcShower from the collection, using the index into the array */
const TObjArray * getMucTrackCol() const
retrieve the whole TObjArray of MucTrack Data
const TRecMucTrack * getMucTrack(Int_t i) const
retrieve a MucTrack From the collection, using the index into the array
const TRecMdcHit * getRecMdcHit(Int_t i) const
retrieve a RecMdcHit from the collection, using the index into the array
const TObjArray * getRecMdcHitCol() const
retrieve the whole TObjArray of RecMdcHit Data
static TDigiEvent * m_recEvt
Provide access to the ROOT event pointers.
static TTrigEvent * m_trigEvt
Provide access to the ROOT event pointers.
static TRecTrackEvent * m_rectrackEvt
Provide access to the ROOT event pointers.
static TEvtHeader * m_EvtHeader