16Long64_t BesVisAlg::counter = 0;
21 Algorithm(name, pSvcLocator)
24 declareProperty(
"TestVec",testVec);
25 declareProperty(
"OutputShareFile", f_rootOutputFile);
26 declareProperty(
"InputGeometryFile", f_geoInputFile);
27 declareProperty(
"DisplayMode", m_mode=0);
54 MsgStream log(
msgSvc(), name());
55 log << MSG::INFO <<
" BesVisAlg ~BesVisAlg()" << endreq;
76 MsgStream log(
msgSvc(), name());
77 log << MSG::INFO <<
" BesVisAlg initialize()" << endreq;
78 StatusCode status = StatusCode::SUCCESS;
83 status = serviceLocator()->service(
"RootCnvSvc", isvc,
false);
84 if ( !status.isSuccess() )
85 status = serviceLocator()->service(
"EventCnvSvc", isvc,
true);
86 if ( status.isSuccess() )
89 if ( status.isSuccess()){
90 log << MSG::INFO <<
"share file writed -- success"
94 log << MSG::ERROR <<
"share file writed -- ERROR!!!!!"
100 log << MSG::INFO <<
" OutputFile = " << f_rootOutputFile << endreq;
102 for (
unsigned int i=0; i<testVec.size(); i++) {
103 log << MSG::INFO <<
" MyStringVec[" << i <<
"] = "
104 << testVec[i] << endreq;
109 log << MSG::ERROR <<
"BesVisAlg process PID: [" << m_pid <<
"]"
112 log << MSG::ERROR <<
"Create and initialize semaphore" << endreq;
113 if ((semid = semget((
int)m_pid, 2, IPC_CREAT | IPC_EXCL | 0666)) != -1){
114 arg.
array = start_val;
115 log << MSG::ERROR <<
"Semaphore ID:" << semid << endreq;
117 if (semctl(semid, 0, SETALL, arg) == -1){
118 log << MSG::ERROR <<
"semctl -- parent -- initialization"
123 if ((sem_value_F = semctl(semid,
FREE_SPACE, GETVAL, 0)) == -1){
124 log << MSG::ERROR <<
"semctl -- GETVAL" << endreq;
128 if ((sem_value_O = semctl(semid,
OUTPUT_STORE, GETVAL, 0)) == -1){
129 log << MSG::ERROR <<
"semctl -- GETVAL" << endreq;
134 log << MSG::INFO <<
"semget -- parent -- creation" << endreq;
145 if ((c_pid = fork()) == -1){
146 log << MSG::ERROR <<
"fork -- consumer" << endreq;
149 else if (c_pid == 0){
151 log << MSG::INFO <<
"Parent fork consumer: ppid = " << getppid()
152 <<
"; pid = " << getpid() << endreq;
158 const char *msg_sleep = testVec[1].c_str();
160 log << MSG::INFO <<
"msg_pid: " << msg_pid << endreq;
161 log << MSG::INFO <<
"Consumer sleep time: " << msg_sleep
162 <<
" seconds." << endreq;
165 execlp(
"besvis.exe",
"besvis.exe",
166 "-B", msg_pid,
"-e", f_rootOutputFile.c_str(),
167 "-g", f_geoInputFile.c_str(), (
char *)
NULL );
170 log << MSG::ERROR <<
"exec -- consumer" << endreq;
175 return StatusCode::SUCCESS;
183 MsgStream log(
msgSvc(), name());
184 log << MSG::INFO <<
"BesVisAlg execute()" << endreq;
187 const char *msg_sleep = testVec[0].c_str();
188 producer(atoi(msg_sleep));
190 return StatusCode::SUCCESS;
198 MsgStream log(
msgSvc(), name());
199 log << MSG::INFO <<
"BesVisAlg finalize()" << endreq;
204 if (hasRead())
break;
209 if (semctl(semid, 0, IPC_RMID, 0) == -1)
210 log << MSG::ERROR <<
"Delete semaphore" << endreq;
212 log << MSG::INFO <<
"Delete semaphore" << endreq;
216 cout <<
"wait for besvis terminate" << endl;
217 while ( wait_pid = waitpid(c_pid, &status, 0) ){
218 log << MSG::INFO <<
"Wait on PID: " << c_pid <<
" returns status of: "
220 if (wait_pid == -1)
break;
223 cout <<
"finalize" << endl;
224 return StatusCode::SUCCESS;
228StatusCode BesVisAlg::producer(
int p_sleep){
230 MsgStream log(
msgSvc(), name());
231 log << MSG::INFO <<
"Producer work" << endreq;
232 StatusCode status = StatusCode::SUCCESS;
263 if (semop(semid, &
acquire, 1) == -1){
264 log << MSG::ERROR <<
"Producer -- decrease -- freeSpace"
326 IOpaqueAddress *pAddress = 0;
328 status = m_pDataProvider->retrieveObject(
"/Event", obj);
329 if ( status.isSuccess() ) {
330 status = m_pConversionSvc->createRep(obj, pAddress);
335 status = m_pDataProvider->retrieveObject(
"/Event/Trig", obj);
336 if ( status.isSuccess() ) {
337 status = m_pConversionSvc->createRep(obj, pAddress);
341 status = m_pDataProvider->retrieveObject(
"/Event/Trig/TrigData", obj);
342 if ( status.isSuccess() ) {
343 status = m_pConversionSvc->createRep(obj, pAddress);
347 status = m_pDataProvider->retrieveObject(
"/Event/EventHeader", obj);
348 if ( status.isSuccess() ) {
349 status = m_pConversionSvc->createRep(obj, pAddress);
353 status = m_pDataProvider->retrieveObject(
"/Event/Digi", obj);
354 if ( status.isSuccess() ) {
355 status = m_pConversionSvc->createRep(obj, pAddress);
359 status = m_pDataProvider->retrieveObject(
"/Event/Digi/MdcDigiCol", obj);
360 if ( status.isSuccess() ) {
361 status = m_pConversionSvc->createRep(obj, pAddress);
365 status = m_pDataProvider->retrieveObject(
"/Event/Digi/TofDigiCol", obj);
366 if ( status.isSuccess() ) {
367 status = m_pConversionSvc->createRep(obj, pAddress);
371 status = m_pDataProvider->retrieveObject(
"/Event/Digi/EmcDigiCol", obj);
372 if ( status.isSuccess() ) {
373 status = m_pConversionSvc->createRep(obj, pAddress);
377 status = m_pDataProvider->retrieveObject(
"/Event/Digi/MucDigiCol", obj);
378 if ( status.isSuccess() ) {
379 status = m_pConversionSvc->createRep(obj, pAddress);
383 status = m_pDataProvider->retrieveObject(
"/Event/Recon", obj);
384 if ( status.isSuccess() ) {
385 status = m_pConversionSvc->createRep(obj, pAddress);
389 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecMdcHitCol", obj);
390 if ( status.isSuccess() ) {
391 status = m_pConversionSvc->createRep(obj, pAddress);
395 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecMdcTrackCol", obj);
396 if ( status.isSuccess() ) {
397 status = m_pConversionSvc->createRep(obj, pAddress);
401 status = m_pDataProvider->retrieveObject(
"/Event/Recon/MdcHOTCol", obj);
402 if ( status.isSuccess() ) {
403 status = m_pConversionSvc->createRep(obj, pAddress);
407 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecMdcDedxCol", obj);
408 if ( status.isSuccess() ) {
409 status = m_pConversionSvc->createRep(obj, pAddress);
413 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecTofTrackCol", obj);
414 if ( status.isSuccess() ) {
415 status = m_pConversionSvc->createRep(obj, pAddress);
420 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecEmcShowerCol", obj);
421 if ( status.isSuccess() ) {
422 status = m_pConversionSvc->createRep(obj, pAddress);
426 status = m_pDataProvider->retrieveObject(
"/Event/Recon/RecMucTrackCol", obj);
427 if ( status.isSuccess() ) {
428 status = m_pConversionSvc->createRep(obj, pAddress);
449 std::cout<<
" mdc trk number ="<<
no <<std::endl;
451 for (
int i=0;i<
no;i++){
456 (recTrack1+i)->setTRecMdcTrack(recTrack);
468 std::cout<<
" tof trk number ="<<
no <<std::endl;
470 for (
int i=0;i<
no;i++){
472 (tofTrack+i)->setTRecTofTrack(tofTrack1);
484 std::cout<<
" mdc hits number ="<<
no <<std::endl;
485 if (
no>1000)
no =1000;
486 for (
int i=0;i<
no;i++){
488 (mdchit+i)->setTRecMdcHit(mdchit1);
500 std::cout<<
" muc trk number ="<<
no <<std::endl;
502 for (
int i=0;i<
no;i++){
504 (muctrk+i)->setTRecMucTrack(mucTrack1);
516 std::cout<<
" emc trk number ="<<
no <<std::endl;
518 for (
int i=0;i<
no;i++){
520 (emcshower+i)->setTRecEmcShower(rec_emc);
525 TFile
file(f_rootOutputFile.c_str(),
"RECREATE");
526 TTree tree(
"Event",
"Event");
527 tree.Branch(
"TDisTrack",
"TDisTrack",&recdis,64000,1);
528 tree.Branch(
"TDigiEvent",
"TDigiEvent", &digiEvt, 64000, 1);
529 tree.Branch(
"TEvtHeader",
"TEvtHeader",&evtHeader,64000,1);
530 tree.Branch(
"TTrigEvent",
"TTrigEvent",&trigEvt,64000,1);
573 if (semop(semid, &release, 1) == -1){
574 log << MSG::ERROR <<
"Producer -- increase -- storage"
609bool BesVisAlg::hasRead(){
611 MsgStream log(
msgSvc(), name());
612 log << MSG::INFO <<
"hadRead()" << endreq;
615 if ((sem_value_F = semctl(semid,
FREE_SPACE, GETVAL, 0)) == -1){
616 log << MSG::ERROR <<
"semctl: GETVAL -- FREE_SPACE"
620 log << MSG::INFO <<
"Semaphore FREE_SPACE has value of " <<
621 sem_value_F << endreq;
623 if ((sem_value_O = semctl(semid,
OUTPUT_STORE, GETVAL, 0)) == -1){
624 log << MSG::ERROR <<
"semctl: GETVAL -- OUTPUT_STORE"
628 log << MSG::INFO <<
"Semaphore OUTPUT_STORE has value of " <<
629 sem_value_O << endreq;
631 if ((sem_value_F == 1) && (sem_value_O == 0))
return true;
637StatusCode BesVisAlg::hasWrite(){
638 MsgStream log(
msgSvc(), name());
639 log << MSG::INFO <<
"hasWrite()" << endreq;
640 StatusCode status = StatusCode::SUCCESS;
647 if ( !status.isSuccess()){
648 log <<MSG::ERROR <<
"getSvc() error!" << endreq;
649 return StatusCode::SUCCESS;
653 status = collectObjects();
654 if ( !status.isSuccess()){
655 log <<MSG::ERROR <<
"collectObjects() error!" << endreq;
656 return StatusCode::SUCCESS;
680StatusCode BesVisAlg::getSvc(){
681 MsgStream log(
msgSvc(), name());
682 log << MSG::INFO <<
"getSvc()" << endreq;
683 StatusCode status = StatusCode::SUCCESS;
686 ItemNames m_itemNames;
687 m_itemNames.push_back(
"/Event#1");
688 m_itemNames.push_back(
"/Event/EventHeader#1");
690 m_itemNames.push_back(
"/Event/Digi#1");
691 m_itemNames.push_back(
"/Event/Digi/MdcDigiCol#1");
692 m_itemNames.push_back(
"/Event/Digi/TofDigiCol#1");
693 m_itemNames.push_back(
"/Event/Digi/EmcDigiCol#1");
694 m_itemNames.push_back(
"/Event/Digi/MucDigiCol#1");
696 m_itemNames.push_back(
"/Event/Recon#1");
697 m_itemNames.push_back(
"/Event/Recon/RecMdcHitCol#1");
698 m_itemNames.push_back(
"/Event/Recon/RecMdcTrackCol#1");
700 m_itemNames.push_back(
"/Event/Trig#1");
701 m_itemNames.push_back(
"/Event/Trig/TrigData#1");
723 clearItems(m_itemList);
724 ItemNames::iterator i;
725 for (i = m_itemNames.begin(); i != m_itemNames.end(); i++){
726 addItem(m_itemList, *i);
729 status = serviceLocator()->service(
"EventDataSvc", m_pDataManager,
true);
730 if ( !status.isSuccess() ) {
731 log << MSG::FATAL <<
"Unable to locate IDataManagerSvc interface"
736 status = serviceLocator()->service(
"EventDataSvc", m_pDataProvider,
true);
737 if ( !status.isSuccess() ) {
738 log << MSG::FATAL <<
"Unable to locate IDataProviderSvc interface"
743 status = serviceLocator()->service(
"EventCnvSvc", m_pConversionSvc,
true);
744 if ( !status.isSuccess() ) {
745 log << MSG::FATAL <<
"Unable to locate IConversionSvc interface"
754StatusCode BesVisAlg::finishSvc(){
755 MsgStream log(
msgSvc(), name());
756 log << MSG::INFO <<
"finishSvc()" << endreq;
757 StatusCode status = StatusCode::SUCCESS;
760 if ( !status.isSuccess())
761 log << MSG::ERROR <<
"f_finalize() error" << endreq;
763 status = m_pConversionSvc->commitOutput(f_rootOutputFile.c_str(),
true);
764 if ( !status.isSuccess())
765 log << MSG::ERROR <<
"commitOutput() error" << endreq;
767 clearItems(m_itemList);
769 return StatusCode::SUCCESS;
774void BesVisAlg::addItem(Items& itms,
const std::string& descriptor) {
775 MsgStream log(
msgSvc(), name());
777 size_t sep = descriptor.rfind(
"#");
778 std::string obj_path (descriptor,0,sep);
779 std::string slevel (descriptor,sep+1,descriptor.length());
780 if ( slevel ==
"*" ) {
784 level = atoi(slevel.c_str());
786 size_t idx = obj_path.find(
"/",1);
787 while (idx != std::string::npos) {
788 std::string sub_item = obj_path.substr(0,idx);
789 if ( 0 == findItem(sub_item) ) {
790 addItem(itms, sub_item+
"#1");
792 idx = obj_path.find(
"/",idx+1);
794 DataStoreItem* item =
new DataStoreItem(obj_path, level);
795 log << MSG::DEBUG <<
"Adding OutputStream item " << item->path()
796 <<
" with " << item->depth()
797 <<
" level(s)." << endreq;
798 itms.push_back( item );
802void BesVisAlg::clearItems(Items& itms) {
803 for ( Items::iterator i = itms.begin(); i != itms.end(); i++ ) {
806 itms.erase(itms.begin(), itms.end());
812BesVisAlg::findItem(
const std::string& path) {
813 for (Items::const_iterator i=m_itemList.begin(); i != m_itemList.end(); ++i) {
814 if ( (*i)->path() == path )
return (*i);
820StatusCode BesVisAlg::collectObjects(){
821 MsgStream log(
msgSvc(), name());
822 StatusCode status = StatusCode::SUCCESS;
827 for ( i = m_itemList.begin(); i != m_itemList.end(); i++ ) {
829 IOpaqueAddress *pAddress = 0;
830 m_currentItem = (*i);
832 status = m_pDataProvider->retrieveObject(m_currentItem->path(), obj);
833 if ( status.isSuccess() ) {
834 status = m_pConversionSvc->createRep(obj, pAddress);
837 log << MSG::WARNING <<
"Cannot write mandatory object(s) (Not found): "
838 << m_currentItem->path() << endreq;
843 return StatusCode::SUCCESS;
846StatusCode BesVisAlg::write2file(){
847 MsgStream log(
msgSvc(), name());
848 StatusCode status = StatusCode::SUCCESS;
850 log << MSG::INFO <<
"write2file()" << endreq;
852 const std::string treename(
"Event");
862 if ( pTRawEvent == 0) {
863 log << MSG::WARNING <<
"Can not get point TDigiEvent" << endreq;
866 const std::string rawBranchname(
"TDigiEvent");
870 m_pRootInterface->
f_addOutput(treename, f_rootOutputFile.c_str(), 1, 64000, 1);
872 if (pTRawEvent != 0) m_pRootInterface->
f_createBranch(treename, rawBranchname,
873 pTRawEvent->ClassName(),
874 &pTRawEvent, branchnr);
880 if ( pTEvtHeader == 0) {
881 log << MSG::WARNING <<
"Can not get point TEvtHeader" << endreq;
884 const std::string headerBranchname(
"TEvtHeader");
886 if (pTEvtHeader != 0) m_pRootInterface->
f_createBranch(treename, headerBranchname,
887 pTEvtHeader->ClassName(),
888 &pTEvtHeader, branchnr);
894 if ( pTTrigEvent == 0) {
895 log << MSG::WARNING <<
"Can not get point TTrigEvent" << endreq;
898 const std::string trigBranchname(
"TTrigEvent");
900 if (pTTrigEvent != 0) m_pRootInterface->
f_createBranch(treename, trigBranchname,
901 pTTrigEvent->ClassName(),
902 &pTTrigEvent, branchnr);
909 if ( pTRecEvent == 0) {
910 log << MSG::WARNING <<
"Can not get point TRecEvent" << endreq;
913 const std::string recBranchname(
"TRecEvent");
915 if (pTRecEvent != 0) m_pRootInterface->
f_createBranch(treename, recBranchname,
916 pTRecEvent->ClassName(),
917 &pTRecEvent, branchnr);
922 if (status.isFailure())
923 log << MSG::ERROR <<
"No Root tree was filled" << endreq;
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)
const InterfaceID IID_IRootCnvSvc
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 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 TRecTrackEvent * m_rectrackEvt
Provide access to the ROOT event pointers.