BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
BesVisAlg Class Reference

#include <BesVisAlg.h>

+ Inheritance diagram for BesVisAlg:

Public Member Functions

 BesVisAlg (const std::string &name, ISvcLocator *pSvcLocator)
 
 ~BesVisAlg ()
 
StatusCode initialize ()
 
StatusCode execute ()
 
StatusCode finalize ()
 

Detailed Description

Definition at line 191 of file BesVisAlg.h.

Constructor & Destructor Documentation

◆ BesVisAlg()

BesVisAlg::BesVisAlg ( const std::string & name,
ISvcLocator * pSvcLocator )

Definition at line 20 of file BesVisAlg.cxx.

20 :
21 Algorithm(name, pSvcLocator)
22{
23 // Part 1: Declare the properties
24 declareProperty("TestVec",testVec);
25 declareProperty("OutputShareFile", f_rootOutputFile);
26 declareProperty("InputGeometryFile", f_geoInputFile);
27 declareProperty("DisplayMode", m_mode=0); // offline mode: 0 online mode:1
28 // Part 2: Define some semaphore operate flag
29 // semaphore start_value
30 start_val[0] = 1; // free-space = 1
31 start_val[1] = 0; // output-shore = 0
32
33 // acquire semaphore, decrease resource supply
34 acquire.sem_num = 0;
35 acquire.sem_op = -1;
36 acquire.sem_flg = SEM_UNDO;
37
38 // release semaphore, increase resource supply
39 release.sem_num = 0;
40 release.sem_op = 1;
41 release.sem_flg = SEM_UNDO;
42
43 recdis = NULL;
44 recTrack1 = NULL;
45 mdchit = NULL;
46 tofTrack = NULL;
47 muctrk = NULL;
48
49}
struct sembuf acquire
#define NULL

◆ ~BesVisAlg()

BesVisAlg::~BesVisAlg ( )

Definition at line 52 of file BesVisAlg.cxx.

52 {
53 // Part 1: Get the messaging service, print where you are
54 MsgStream log(msgSvc(), name());
55 log << MSG::INFO << " BesVisAlg ~BesVisAlg()" << endreq;
56
57
58 // Part 2: Delete semaphore
59 //if (semctl(semid, 0, IPC_RMID, 0) == -1)
60 // log << MSG::ERROR << "Delete semaphore" << endreq;
61 //else
62 // log << MSG::INFO << "Delete semaphore" << endreq;
63
64 // Part 3: Delete temp file
65 //if (remove(BUFFER) == -1)
66 // log << MSG::ERROR << "delete -- temp file" << endreq;
67 //else
68 // log << MSG::INFO << "Delete temp file" << endreq;
69
70}
IMessageSvc * msgSvc()

Member Function Documentation

◆ execute()

StatusCode BesVisAlg::execute ( )

Definition at line 180 of file BesVisAlg.cxx.

180 {
181
182 // Part 1: Get the messaging service, print where you are
183 MsgStream log(msgSvc(), name());
184 log << MSG::INFO << "BesVisAlg execute()" << endreq;
185
186 // Part 2: Producer execute
187 const char *msg_sleep = testVec[0].c_str();
188 producer(atoi(msg_sleep));
189
190 return StatusCode::SUCCESS;
191}

◆ finalize()

StatusCode BesVisAlg::finalize ( )

Definition at line 195 of file BesVisAlg.cxx.

195 {
196
197 // Part 1: Get the messaging service, print where you are
198 MsgStream log(msgSvc(), name());
199 log << MSG::INFO << "BesVisAlg finalize()" << endreq;
200
201 // Part 2: Waiting consumer process accessing the data
202 // and then kill it
203 while (1){
204 if (hasRead()) break;
205 else sleep(5);
206 }
207
208 // Part 3: Delete semaphore
209 if (semctl(semid, 0, IPC_RMID, 0) == -1)
210 log << MSG::ERROR << "Delete semaphore" << endreq;
211 else
212 log << MSG::INFO << "Delete semaphore" << endreq;
213
214 int status;
215 pid_t wait_pid;
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: "
219 << status << endreq;
220 if (wait_pid == -1) break;
221 sleep(5);
222 }
223 cout << "finalize" << endl;
224 return StatusCode::SUCCESS;
225}

◆ initialize()

StatusCode BesVisAlg::initialize ( )

Definition at line 73 of file BesVisAlg.cxx.

73 {
74
75 // Part 1: Get the messaging service, print where you are
76 MsgStream log(msgSvc(), name());
77 log << MSG::INFO << " BesVisAlg initialize()" << endreq;
78 StatusCode status = StatusCode::SUCCESS;
79
80 // Part 2: Print out the property values
81//############################################################
82 IService* isvc = 0;
83 status = serviceLocator()->service("RootCnvSvc", isvc, false);
84 if ( !status.isSuccess() )
85 status = serviceLocator()->service("EventCnvSvc", isvc, true);
86 if ( status.isSuccess() )
87 status = isvc->queryInterface(IID_IRootCnvSvc, (void**)&m_cnvSvc);
88 status = hasWrite();
89 if ( status.isSuccess()){
90 log << MSG::INFO << "share file writed -- success"
91 << endreq;
92 }
93 else {
94 log << MSG::ERROR << "share file writed -- ERROR!!!!!"
95 << endreq;
96 }
97//############################################################
98
99 // Part 2: Print out the property values
100 log << MSG::INFO << " OutputFile = " << f_rootOutputFile << endreq;
101
102 for (unsigned int i=0; i<testVec.size(); i++) {
103 log << MSG::INFO << " MyStringVec[" << i << "] = "
104 << testVec[i] << endreq;
105 }
106
107 // Part 3: Initialize semphore
108 m_pid = getpid();
109 log << MSG::ERROR << "BesVisAlg process PID: [" << m_pid << "]"
110 << endreq;
111
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;
116
117 if (semctl(semid, 0, SETALL, arg) == -1){
118 log << MSG::ERROR << "semctl -- parent -- initialization"
119 << endreq;
120 exit(1);
121 }
122
123 if ((sem_value_F = semctl(semid, FREE_SPACE, GETVAL, 0)) == -1){
124 log << MSG::ERROR << "semctl -- GETVAL" << endreq;
125 exit(1);
126 }
127
128 if ((sem_value_O = semctl(semid, OUTPUT_STORE, GETVAL, 0)) == -1){
129 log << MSG::ERROR << "semctl -- GETVAL" << endreq;
130 exit(1);
131 }
132 }
133 else {
134 log << MSG::INFO << "semget -- parent -- creation" << endreq;
135 exit(2);
136 }
137 //******************************
138 // Debug information
139 //*******************************
140 //log << MSG::INFO << "semaphore ID: " << semid << endreq;
141 //log << MSG::ERROR << "set init sem_value_FREE-SPACE: " << sem_value_F << endreq;
142 //log << MSG::ERROR << "set init sem_value_OUTPUT-STORE: " << sem_value_O << endreq;
143
144 // Part 4: fork consumer process
145 if ((c_pid = fork()) == -1){
146 log << MSG::ERROR << "fork -- consumer" << endreq;
147 exit(5);
148 }
149 else if (c_pid == 0){
150 // enter consumer logic
151 log << MSG::INFO << "Parent fork consumer: ppid = " << getppid()
152 << "; pid = " << getpid() << endreq;
153
154 // convert msg to char[] and transfer them to child process
155 char msg_pid[25];
156 sprintf(msg_pid, "%d", m_pid);
157
158 const char *msg_sleep = testVec[1].c_str();
159
160 log << MSG::INFO << "msg_pid: " << msg_pid << endreq;
161 log << MSG::INFO << "Consumer sleep time: " << msg_sleep
162 << " seconds." << endreq;
163
164 //execute besvis.exe
165 execlp("besvis.exe", "besvis.exe",
166 "-B", msg_pid, "-e", f_rootOutputFile.c_str(),
167 "-g", f_geoInputFile.c_str(), (char *)NULL );
168
169 //execlp("./a.out", "consumer", msg_pid, "5", (char *)NULL);
170 log << MSG::ERROR << "exec -- consumer" << endreq;
171 exit(6);
172 }
173
174
175 return StatusCode::SUCCESS;
176}
@ FREE_SPACE
Definition BesVisAlg.h:146
@ OUTPUT_STORE
Definition BesVisAlg.h:146
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
ushort * array
Definition BesVisAlg.h:143

The documentation for this class was generated from the following files: