BOSS 8.0.0
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 187 of file BesVisAlg.h.

Constructor & Destructor Documentation

◆ BesVisAlg()

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

Definition at line 21 of file BesVisAlg.cxx.

22 : Algorithm( name, pSvcLocator ) {
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}
struct sembuf acquire

Referenced by BesVisAlg().

◆ ~BesVisAlg()

BesVisAlg::~BesVisAlg ( )

Definition at line 51 of file BesVisAlg.cxx.

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

Member Function Documentation

◆ execute()

StatusCode BesVisAlg::execute ( )

Definition at line 168 of file BesVisAlg.cxx.

168 {
169
170 // Part 1: Get the messaging service, print where you are
171 MsgStream log( msgSvc(), name() );
172 log << MSG::INFO << "BesVisAlg execute()" << endmsg;
173
174 // Part 2: Producer execute
175 const char* msg_sleep = testVec[0].c_str();
176 producer( atoi( msg_sleep ) );
177
178 return StatusCode::SUCCESS;
179}

◆ finalize()

StatusCode BesVisAlg::finalize ( )

Definition at line 183 of file BesVisAlg.cxx.

183 {
184
185 // Part 1: Get the messaging service, print where you are
186 MsgStream log( msgSvc(), name() );
187 log << MSG::INFO << "BesVisAlg finalize()" << endmsg;
188
189 // Part 2: Waiting consumer process accessing the data
190 // and then kill it
191 while ( 1 )
192 {
193 if ( hasRead() ) break;
194 else sleep( 5 );
195 }
196
197 // Part 3: Delete semaphore
198 if ( semctl( semid, 0, IPC_RMID, 0 ) == -1 )
199 log << MSG::ERROR << "Delete semaphore" << endmsg;
200 else log << MSG::INFO << "Delete semaphore" << endmsg;
201
202 int status;
203 pid_t wait_pid;
204 cout << "wait for besvis terminate" << endl;
205 while ( wait_pid = waitpid( c_pid, &status, 0 ) )
206 {
207 log << MSG::INFO << "Wait on PID: " << c_pid << " returns status of: " << status << endmsg;
208 if ( wait_pid == -1 ) break;
209 sleep( 5 );
210 }
211 cout << "finalize" << endl;
212 return StatusCode::SUCCESS;
213}

◆ initialize()

StatusCode BesVisAlg::initialize ( )

Definition at line 70 of file BesVisAlg.cxx.

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

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