BOSS 7.0.2
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 ()
 
 BesVisAlg (const std::string &name, ISvcLocator *pSvcLocator)
 
 ~BesVisAlg ()
 
StatusCode initialize ()
 
StatusCode execute ()
 
StatusCode finalize ()
 

Detailed Description

Constructor & Destructor Documentation

◆ BesVisAlg() [1/2]

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

Definition at line 18 of file BesVisAlg.cxx.

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

◆ ~BesVisAlg() [1/2]

BesVisAlg::~BesVisAlg ( )

Definition at line 50 of file BesVisAlg.cxx.

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

◆ BesVisAlg() [2/2]

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

◆ ~BesVisAlg() [2/2]

BesVisAlg::~BesVisAlg ( )

Member Function Documentation

◆ execute() [1/2]

StatusCode BesVisAlg::execute ( )

Definition at line 178 of file BesVisAlg.cxx.

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

◆ execute() [2/2]

StatusCode BesVisAlg::execute ( )

◆ finalize() [1/2]

StatusCode BesVisAlg::finalize ( )

Definition at line 193 of file BesVisAlg.cxx.

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

◆ finalize() [2/2]

StatusCode BesVisAlg::finalize ( )

◆ initialize() [1/2]

StatusCode BesVisAlg::initialize ( )

Definition at line 71 of file BesVisAlg.cxx.

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

◆ initialize() [2/2]

StatusCode BesVisAlg::initialize ( )

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