1#include "BesVisAlg/BesVisAlg.h"
2#include "RootEventData/TRecTrackEvent.h"
3#include "RootEventData/TDigiEvent.h"
4#include "RootEventData/TEvtHeader.h"
5#include "RootEventData/TTrigEvent.h"
6#include "RootCnvSvc/Rec/RecTrackCnv.h"
7#include "RootCnvSvc/Digi/DigiCnv.h"
8#include "RootCnvSvc/EvtHeaderCnv.h"
9#include "RootCnvSvc/Trig/TrigCnv.h"
10#include "RootCnvSvc/Trig/TrigDataCnv.h"
11#include "EventModel/EventHeader.h"
12#include "EventModel/Event.h"
13#include "EventModel/EventModel.h"
16int BesVisAlg::counter = 0;
19 Algorithm(name, pSvcLocator)
22 declareProperty(
"TestVec",testVec);
23 declareProperty(
"OutputShareFile", f_rootOutputFile);
24 declareProperty(
"InputGeometryFile", f_geoInputFile);
25 declareProperty(
"DisplayMode", m_mode=0);
39 release.sem_flg = SEM_UNDO;
52 MsgStream log(
msgSvc(), name());
53 log << MSG::INFO <<
" BesVisAlg ~BesVisAlg()" << endreq;
74 MsgStream log(
msgSvc(), name());
75 log << MSG::INFO <<
" BesVisAlg initialize()" << endreq;
76 StatusCode status = StatusCode::SUCCESS;
81 status = serviceLocator()->service(
"RootCnvSvc", isvc,
false);
82 if ( !status.isSuccess() )
83 status = serviceLocator()->service(
"EventCnvSvc", isvc,
true);
84 if ( status.isSuccess() )
87 if ( status.isSuccess()){
88 log << MSG::INFO <<
"share file writed -- success"
92 log << MSG::ERROR <<
"share file writed -- ERROR!!!!!"
98 log << MSG::INFO <<
" OutputFile = " << f_rootOutputFile << endreq;
100 for (
unsigned int i=0; i<testVec.size(); i++) {
101 log << MSG::INFO <<
" MyStringVec[" << i <<
"] = "
102 << testVec[i] << endreq;
107 log << MSG::ERROR <<
"BesVisAlg process PID: [" << m_pid <<
"]"
110 log << MSG::ERROR <<
"Create and initialize semaphore" << endreq;
111 if ((semid = semget((
int)m_pid, 2, IPC_CREAT | IPC_EXCL | 0666)) != -1){
112 arg.
array = start_val;
113 log << MSG::ERROR <<
"Semaphore ID:" << semid << endreq;
115 if (semctl(semid, 0, SETALL, arg) == -1){
116 log << MSG::ERROR <<
"semctl -- parent -- initialization"
121 if ((sem_value_F = semctl(semid,
FREE_SPACE, GETVAL, 0)) == -1){
122 log << MSG::ERROR <<
"semctl -- GETVAL" << endreq;
126 if ((sem_value_O = semctl(semid,
OUTPUT_STORE, GETVAL, 0)) == -1){
127 log << MSG::ERROR <<
"semctl -- GETVAL" << endreq;
132 log << MSG::INFO <<
"semget -- parent -- creation" << endreq;
143 if ((c_pid = fork()) == -1){
144 log << MSG::ERROR <<
"fork -- consumer" << endreq;
147 else if (c_pid == 0){
149 log << MSG::INFO <<
"Parent fork consumer: ppid = " << getppid()
150 <<
"; pid = " << getpid() << endreq;
154 sprintf(msg_pid,
"%d", m_pid);
156 const char *msg_sleep = testVec[1].c_str();
158 log << MSG::INFO <<
"msg_pid: " << msg_pid << endreq;
159 log << MSG::INFO <<
"Consumer sleep time: " << msg_sleep
160 <<
" seconds." << endreq;
163 execlp(
"besvis.exe",
"besvis.exe",
164 "-B", msg_pid,
"-e", f_rootOutputFile.c_str(),
165 "-g", f_geoInputFile.c_str(), (
char *)NULL );
168 log << MSG::ERROR <<
"exec -- consumer" << endreq;
173 return StatusCode::SUCCESS;
181 MsgStream log(
msgSvc(), name());
182 log << MSG::INFO <<
"BesVisAlg execute()" << endreq;
185 const char *msg_sleep = testVec[0].c_str();
186 producer(atoi(msg_sleep));
188 return StatusCode::SUCCESS;
196 MsgStream log(
msgSvc(), name());
197 log << MSG::INFO <<
"BesVisAlg finalize()" << endreq;
202 if (hasRead())
break;
207 if (semctl(semid, 0, IPC_RMID, 0) == -1)
208 log << MSG::ERROR <<
"Delete semaphore" << endreq;
210 log << MSG::INFO <<
"Delete semaphore" << endreq;
214 cout <<
"wait for besvis terminate" << endl;
215 while ( wait_pid = waitpid(c_pid, &status, 0) ){
216 log << MSG::INFO <<
"Wait on PID: " << c_pid <<
" returns status of: "
218 if (wait_pid == -1)
break;
221 cout <<
"finalize" << endl;
222 return StatusCode::SUCCESS;
226StatusCode BesVisAlg::producer(
int p_sleep){
228 MsgStream log(
msgSvc(), name());
229 log << MSG::INFO <<
"Producer work" << endreq;
230 StatusCode status = StatusCode::SUCCESS;
261 if (semop(semid, &
acquire, 1) == -1){
262 log << MSG::ERROR <<
"Producer -- decrease -- freeSpace"
324 IOpaqueAddress *pAddress = 0;
326 status = m_pDataProvider->retrieveObject(
"/Event", obj);
327 if ( status.isSuccess() ) {
328 status = m_pConversionSvc->createRep(obj, pAddress);
333 status = m_pDataProvider->retrieveObject(
"/Event/Trig", obj);
334 if ( status.isSuccess() ) {
335 status = m_pConversionSvc->createRep(obj, pAddress);
339 status = m_pDataProvider->retrieveObject(
"/Event/Trig/TrigData", obj);
340 if ( status.isSuccess() ) {
341 status = m_pConversionSvc->createRep(obj, pAddress);
345 status = m_pDataProvider->retrieveObject(
"/Event/EventHeader", obj);
346 if ( status.isSuccess() ) {
347 status = m_pConversionSvc->createRep(obj, pAddress);
351 status = m_pDataProvider->retrieveObject(
"/Event/Digi", obj);
352 if ( status.isSuccess() ) {
353 status = m_pConversionSvc->createRep(obj, pAddress);
357 status = m_pDataProvider->retrieveObject(
"/Event/Digi/MdcDigiCol", obj);
358 if ( status.isSuccess() ) {
359 status = m_pConversionSvc->createRep(obj, pAddress);
363 status = m_pDataProvider->retrieveObject(
"/Event/Digi/TofDigiCol", obj);
364 if ( status.isSuccess() ) {
365 status = m_pConversionSvc->createRep(obj, pAddress);
369 status = m_pDataProvider->retrieveObject(
"/Event/Digi/EmcDigiCol", obj);
370 if ( status.isSuccess() ) {
371 status = m_pConversionSvc->createRep(obj, pAddress);
375 status = m_pDataProvider->retrieveObject(
"/Event/Digi/MucDigiCol", obj);
376 if ( status.isSuccess() ) {
377 status = m_pConversionSvc->createRep(obj, pAddress);
381 status = m_pDataProvider->retrieveObject(
"/Event/Recon", obj);
382 if ( status.isSuccess() ) {
383 status = m_pConversionSvc->createRep(obj, pAddress);
387 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecMdcHitCol", obj);
388 if ( status.isSuccess() ) {
389 status = m_pConversionSvc->createRep(obj, pAddress);
393 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecMdcTrackCol", obj);
394 if ( status.isSuccess() ) {
395 status = m_pConversionSvc->createRep(obj, pAddress);
399 status = m_pDataProvider->retrieveObject(
"/Event/Recon/MdcHOTCol", obj);
400 if ( status.isSuccess() ) {
401 status = m_pConversionSvc->createRep(obj, pAddress);
405 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecMdcDedxCol", obj);
406 if ( status.isSuccess() ) {
407 status = m_pConversionSvc->createRep(obj, pAddress);
411 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecTofTrackCol", obj);
412 if ( status.isSuccess() ) {
413 status = m_pConversionSvc->createRep(obj, pAddress);
418 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecEmcShowerCol", obj);
419 if ( status.isSuccess() ) {
420 status = m_pConversionSvc->createRep(obj, pAddress);
424 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecMucTrackCol", obj);
425 if ( status.isSuccess() ) {
426 status = m_pConversionSvc->createRep(obj, pAddress);
447 std::cout<<
" mdc trk number ="<< no <<std::endl;
449 for (
int i=0;i<no;i++){
454 (recTrack1+i)->setTRecMdcTrack(recTrack);
466 std::cout<<
" tof trk number ="<< no <<std::endl;
468 for (
int i=0;i<no;i++){
470 (tofTrack+i)->setTRecTofTrack(tofTrack1);
482 std::cout<<
" mdc hits number ="<< no <<std::endl;
483 if (no>1000) no =1000;
484 for (
int i=0;i<no;i++){
486 (mdchit+i)->setTRecMdcHit(mdchit1);
498 std::cout<<
" muc trk number ="<< no <<std::endl;
500 for (
int i=0;i<no;i++){
502 (muctrk+i)->setTRecMucTrack(mucTrack1);
514 std::cout<<
" emc trk number ="<< no <<std::endl;
516 for (
int i=0;i<no;i++){
518 (emcshower+i)->setTRecEmcShower(rec_emc);
523 TFile file(f_rootOutputFile.c_str(),
"RECREATE");
524 TTree tree(
"Event",
"Event");
525 tree.Branch(
"TDisTrack",
"TDisTrack",&recdis,64000,1);
526 tree.Branch(
"TDigiEvent",
"TDigiEvent", &digiEvt, 64000, 1);
527 tree.Branch(
"TEvtHeader",
"TEvtHeader",&evtHeader,64000,1);
528 tree.Branch(
"TTrigEvent",
"TTrigEvent",&trigEvt,64000,1);
571 if (semop(semid, &release, 1) == -1){
572 log << MSG::ERROR <<
"Producer -- increase -- storage"
607bool BesVisAlg::hasRead(){
609 MsgStream log(
msgSvc(), name());
610 log << MSG::INFO <<
"hadRead()" << endreq;
613 if ((sem_value_F = semctl(semid,
FREE_SPACE, GETVAL, 0)) == -1){
614 log << MSG::ERROR <<
"semctl: GETVAL -- FREE_SPACE"
618 log << MSG::INFO <<
"Semaphore FREE_SPACE has value of " <<
619 sem_value_F << endreq;
621 if ((sem_value_O = semctl(semid,
OUTPUT_STORE, GETVAL, 0)) == -1){
622 log << MSG::ERROR <<
"semctl: GETVAL -- OUTPUT_STORE"
626 log << MSG::INFO <<
"Semaphore OUTPUT_STORE has value of " <<
627 sem_value_O << endreq;
629 if ((sem_value_F == 1) && (sem_value_O == 0))
return true;
635StatusCode BesVisAlg::hasWrite(){
636 MsgStream log(
msgSvc(), name());
637 log << MSG::INFO <<
"hasWrite()" << endreq;
638 StatusCode status = StatusCode::SUCCESS;
645 if ( !status.isSuccess()){
646 log <<MSG::ERROR <<
"getSvc() error!" << endreq;
647 return StatusCode::SUCCESS;
651 status = collectObjects();
652 if ( !status.isSuccess()){
653 log <<MSG::ERROR <<
"collectObjects() error!" << endreq;
654 return StatusCode::SUCCESS;
678StatusCode BesVisAlg::getSvc(){
679 MsgStream log(
msgSvc(), name());
680 log << MSG::INFO <<
"getSvc()" << endreq;
681 StatusCode status = StatusCode::SUCCESS;
684 ItemNames m_itemNames;
685 m_itemNames.push_back(
"/Event#1");
686 m_itemNames.push_back(
"/Event/EventHeader#1");
688 m_itemNames.push_back(
"/Event/Digi#1");
689 m_itemNames.push_back(
"/Event/Digi/MdcDigiCol#1");
690 m_itemNames.push_back(
"/Event/Digi/TofDigiCol#1");
691 m_itemNames.push_back(
"/Event/Digi/EmcDigiCol#1");
692 m_itemNames.push_back(
"/Event/Digi/MucDigiCol#1");
694 m_itemNames.push_back(
"/Event/Recon#1");
695 m_itemNames.push_back(
"/Event/Recon/RecMdcHitCol#1");
696 m_itemNames.push_back(
"/Event/Recon/RecMdcTrackCol#1");
698 m_itemNames.push_back(
"/Event/Trig#1");
699 m_itemNames.push_back(
"/Event/Trig/TrigData#1");
721 clearItems(m_itemList);
722 ItemNames::iterator i;
723 for (i = m_itemNames.begin(); i != m_itemNames.end(); i++){
724 addItem(m_itemList, *i);
727 status = serviceLocator()->service(
"EventDataSvc", m_pDataManager,
true);
728 if ( !status.isSuccess() ) {
729 log << MSG::FATAL <<
"Unable to locate IDataManagerSvc interface"
734 status = serviceLocator()->service(
"EventDataSvc", m_pDataProvider,
true);
735 if ( !status.isSuccess() ) {
736 log << MSG::FATAL <<
"Unable to locate IDataProviderSvc interface"
741 status = serviceLocator()->service(
"EventCnvSvc", m_pConversionSvc,
true);
742 if ( !status.isSuccess() ) {
743 log << MSG::FATAL <<
"Unable to locate IConversionSvc interface"
752StatusCode BesVisAlg::finishSvc(){
753 MsgStream log(
msgSvc(), name());
754 log << MSG::INFO <<
"finishSvc()" << endreq;
755 StatusCode status = StatusCode::SUCCESS;
758 if ( !status.isSuccess())
759 log << MSG::ERROR <<
"f_finalize() error" << endreq;
761 status = m_pConversionSvc->commitOutput(f_rootOutputFile.c_str(),
true);
762 if ( !status.isSuccess())
763 log << MSG::ERROR <<
"commitOutput() error" << endreq;
765 clearItems(m_itemList);
767 return StatusCode::SUCCESS;
772void BesVisAlg::addItem(Items& itms,
const std::string& descriptor) {
773 MsgStream log(
msgSvc(), name());
775 size_t sep = descriptor.rfind(
"#");
776 std::string obj_path (descriptor,0,sep);
777 std::string slevel (descriptor,sep+1,descriptor.length());
778 if ( slevel ==
"*" ) {
782 level = atoi(slevel.c_str());
784 size_t idx = obj_path.find(
"/",1);
785 while (idx != std::string::npos) {
786 std::string sub_item = obj_path.substr(0,idx);
787 if ( 0 == findItem(sub_item) ) {
788 addItem(itms, sub_item+
"#1");
790 idx = obj_path.find(
"/",idx+1);
792 DataStoreItem* item =
new DataStoreItem(obj_path, level);
793 log << MSG::DEBUG <<
"Adding OutputStream item " << item->path()
794 <<
" with " << item->depth()
795 <<
" level(s)." << endreq;
796 itms.push_back( item );
800void BesVisAlg::clearItems(Items& itms) {
801 for ( Items::iterator i = itms.begin(); i != itms.end(); i++ ) {
804 itms.erase(itms.begin(), itms.end());
810BesVisAlg::findItem(
const std::string& path) {
811 for (Items::const_iterator i=m_itemList.begin(); i != m_itemList.end(); ++i) {
812 if ( (*i)->path() == path )
return (*i);
818StatusCode BesVisAlg::collectObjects(){
819 MsgStream log(
msgSvc(), name());
820 StatusCode status = StatusCode::SUCCESS;
825 for ( i = m_itemList.begin(); i != m_itemList.end(); i++ ) {
827 IOpaqueAddress *pAddress = 0;
828 m_currentItem = (*i);
830 status = m_pDataProvider->retrieveObject(m_currentItem->path(), obj);
831 if ( status.isSuccess() ) {
832 status = m_pConversionSvc->createRep(obj, pAddress);
835 log << MSG::WARNING <<
"Cannot write mandatory object(s) (Not found): "
836 << m_currentItem->path() << endreq;
841 return StatusCode::SUCCESS;
844StatusCode BesVisAlg::write2file(){
845 MsgStream log(
msgSvc(), name());
846 StatusCode status = StatusCode::SUCCESS;
848 log << MSG::INFO <<
"write2file()" << endreq;
850 const std::string treename(
"Event");
860 if ( pTRawEvent == 0) {
861 log << MSG::WARNING <<
"Can not get point TDigiEvent" << endreq;
864 const std::string rawBranchname(
"TDigiEvent");
868 m_pRootInterface->
f_addOutput(treename, f_rootOutputFile.c_str(), 1, 64000, 1);
870 if (pTRawEvent != 0) m_pRootInterface->
f_createBranch(treename, rawBranchname,
871 pTRawEvent->ClassName(),
872 &pTRawEvent, branchnr);
878 if ( pTEvtHeader == 0) {
879 log << MSG::WARNING <<
"Can not get point TEvtHeader" << endreq;
882 const std::string headerBranchname(
"TEvtHeader");
884 if (pTEvtHeader != 0) m_pRootInterface->
f_createBranch(treename, headerBranchname,
885 pTEvtHeader->ClassName(),
886 &pTEvtHeader, branchnr);
892 if ( pTTrigEvent == 0) {
893 log << MSG::WARNING <<
"Can not get point TTrigEvent" << endreq;
896 const std::string trigBranchname(
"TTrigEvent");
898 if (pTTrigEvent != 0) m_pRootInterface->
f_createBranch(treename, trigBranchname,
899 pTTrigEvent->ClassName(),
900 &pTTrigEvent, branchnr);
907 if ( pTRecEvent == 0) {
908 log << MSG::WARNING <<
"Can not get point TRecEvent" << endreq;
911 const std::string recBranchname(
"TRecEvent");
913 if (pTRecEvent != 0) m_pRootInterface->
f_createBranch(treename, recBranchname,
914 pTRecEvent->ClassName(),
915 &pTRecEvent, branchnr);
920 if (status.isFailure())
921 log << MSG::ERROR <<
"No Root tree was filled" << endreq;
const InterfaceID IID_IRootCnvSvc
BesVisAlg(const std::string &name, ISvcLocator *pSvcLocator)
static TDigiEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
static TRecTrackEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
RecTrackCnv * getRecTrackCnv()
EvtHeaderCnv * getEvtHeaderCnv()
virtual StatusCode f_createBranch(const std::string &treename, const std::string &branchname, const char *classname, void *addr, int &branchnr)
virtual StatusCode f_finalize()
virtual StatusCode f_fillTrees()
virtual StatusCode f_addOutput(const std::string &treename, const std::string &file, int splitx=1, int bufsize=64000, int compression=1)
static RootInterface * Instance(MsgStream log)
singleton behaviour
void addRecMdcTrack(TRecMdcTrack *Track)
Add a TkrTrack into the Mdc data collection.
void addTofTrack(TRecTofTrack *Track)
void addMucTrack(TRecMucTrack *Track)
Add a MucTrack into the TOF Data collection.
void Clear(Option_t *option="")
void addRecMdcHit(TRecMdcHit *Hit)
Add a Rec Mdc Hit into the Mdc data collection.
void addEmcShower(TRecEmcShower *Track)
Add a TkrTrack into the Emc data collection.
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 TTrigEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
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