72 LOG(info) <<
"Setting up the simulation ...";
73 simptr = std::move(std::unique_ptr<FairRunSim>(o2sim_init(
true)));
74 FairSystemInfo sysinfo;
79 TVirtualMC::GetMC()->ProcessRun(0);
81 LOG(info) <<
"MEM-STAMP END OF SIM INIT" << sysinfo.GetCurrentMemory() / (1024. * 1024) <<
" "
82 << sysinfo.GetMaxMemory() <<
" MB\n";
89 std::stringstream
str;
90 str <<
"[W" << workerID <<
"]";
91 auto workerStr =
str.str();
93 int timeoutinMS = 2000;
99 fair::mq::MessagePtr reply(statuschannel.NewSimpleMessage(
i));
100 auto sendcode = statuschannel.Send(request, timeoutinMS);
102 LOG(info) << workerStr <<
" Waiting for status answer ";
103 auto code = statuschannel.Receive(reply, timeoutinMS);
105 int state(*((
int*)(reply->GetData())));
107 LOG(info) << workerStr <<
" SERVER IS SERVING";
110 LOG(info) << workerStr <<
" SERVER IS STILL INITIALIZING";
114 LOG(info) << workerStr <<
" SERVER IS WAITING FOR EVENT";
118 LOG(info) << workerStr <<
" SERVER IS IDLE";
121 LOG(info) << workerStr <<
" SERVER STATE UNKNOWN OR STOPPED";
124 LOG(error) << workerStr <<
" STATUS REQUEST UNSUCCESSFUL";
131bool O2SimDevice::Kernel(
int workerID, fair::mq::Channel& requestchannel, fair::mq::Channel& dataoutchannel, fair::mq::Channel* statuschannel)
134 bool reproducibleSim =
true;
135 if (getenv(
"O2_DISABLE_REPRODUCIBLE_SIM")) {
136 reproducibleSim =
false;
143 auto eventselection = getenv(
"O2SIM_RESTRICT_EVENTPART");
144 int focus_on_event = -1;
145 int focus_on_part = -1;
146 if (eventselection) {
148 std::pair<std::string, std::string> parts;
149 size_t pos =
str.find(
':');
150 if (
pos != std::string::npos) {
151 parts.first =
str.substr(0,
pos);
152 parts.second =
str.substr(
pos + 1);
157 focus_on_event = std::atoi(p.first.c_str());
158 focus_on_part = std::atoi(p.second.c_str());
161 fair::mq::MessagePtr request(requestchannel.NewSimpleMessage(
PrimaryChunkRequest{workerID, -1, counter++}));
162 fair::mq::Parts reply;
167 auto workerStr = [workerID]() {
168 std::stringstream
str;
169 str <<
"[W" << workerID <<
"]";
173 doLogInfo(workerID,
"Requesting work chunk");
174 int timeoutinMS = 2000;
175 auto sendcode = requestchannel.Send(request, timeoutinMS);
177 doLogInfo(workerID,
"Waiting for answer");
180 auto code = requestchannel.Receive(reply);
182 doLogInfo(workerID,
"Primary chunk received");
183 auto rawmessage = std::move(reply.At(0));
185 if (!
header.payload_attached) {
195 auto payload = std::move(reply.At(1));
202 if (chunk->mParticles.size() == 0 && chunk->mSubEventInfo.eventID == -1) {
203 doLogInfo(workerID,
"No particles in reply : quitting kernel");
209 auto info = chunk->mSubEventInfo;
210 LOG(info) << workerStr() <<
" Processing " << chunk->mParticles.size() <<
" primary particles "
211 <<
"for event " << info.eventID <<
"/" << info.maxEvents <<
" "
212 <<
"part " << info.part <<
"/" << info.nparts;
214 if (eventselection ==
nullptr || (focus_on_event == info.eventID && focus_on_part == info.part)) {
219 LOG(info) << workerStr() <<
" This chunk will be skipped";
224 if (reproducibleSim) {
225 LOG(info) << workerStr() <<
" Setting seed for this sub-event to " << chunk->mSubEventInfo.seed;
226 gRandom->SetSeed(chunk->mSubEventInfo.seed);
232 if (strcmp(conf.getMCEngine().c_str(),
"TGeant4") == 0 || strcmp(conf.getMCEngine().c_str(),
"O2TrivialMCEngine") == 0) {
235 mVMC->ProcessEvent();
242 FairSystemInfo sysinfo;
243 LOG(info) << workerStr() <<
" TIME-STAMP " << mTimer.RealTime() <<
"\t";
245 LOG(info) << workerStr() <<
" MEM-STAMP " << sysinfo.GetCurrentMemory() / (1024. * 1024) <<
" "
246 << sysinfo.GetMaxMemory() <<
" MB\n";
252 LOG(info) << workerStr() <<
" No primary answer received from server (within timeout). Return code " << code;
255 LOG(info) << workerStr() <<
" Requesting work from server not possible. Return code " << sendcode;