16#include "../macro/o2sim.C"
17#include "TVirtualMC.h"
18#include <fairmq/Message.h>
19#include <fairmq/Parts.h>
20#include <fairlogger/Logger.h>
31 LOG(info) <<
"[W" << workerID <<
"] " <<
message;
43 LOG(info) <<
"Shutting down O2SimDevice";
44 LOG(info) <<
"TIME-STAMP " << mTimer.RealTime() <<
"\t";
54 initSim(GetChannels().at(
"o2sim-primserv-info").at(0), mSimRun);
57 mVMC = TVirtualMC::GetMC();
74 LOG(info) <<
"Setting up the simulation ...";
75 simptr = std::move(std::unique_ptr<FairRunSim>(o2sim_init(
true)));
81 TVirtualMC::GetMC()->ProcessRun(0);
83 LOG(info) <<
"MEM-STAMP END OF SIM INIT" << sysinfo.
GetCurrentMemory() / (1024. * 1024) <<
" "
91 std::stringstream
str;
92 str <<
"[W" << workerID <<
"]";
93 auto workerStr =
str.str();
95 int timeoutinMS = 2000;
101 fair::mq::MessagePtr reply(statuschannel.NewSimpleMessage(
i));
102 auto sendcode = statuschannel.Send(request, timeoutinMS);
104 LOG(info) << workerStr <<
" Waiting for status answer ";
105 auto code = statuschannel.Receive(reply, timeoutinMS);
107 int state(*((
int*)(reply->GetData())));
109 LOG(info) << workerStr <<
" SERVER IS SERVING";
112 LOG(info) << workerStr <<
" SERVER IS STILL INITIALIZING";
116 LOG(info) << workerStr <<
" SERVER IS WAITING FOR EVENT";
120 LOG(info) << workerStr <<
" SERVER IS IDLE";
123 LOG(info) << workerStr <<
" SERVER STATE UNKNOWN OR STOPPED";
126 LOG(
error) << workerStr <<
" STATUS REQUEST UNSUCCESSFUL";
133bool O2SimDevice::Kernel(
int workerID, fair::mq::Channel& requestchannel, fair::mq::Channel& dataoutchannel, fair::mq::Channel* statuschannel)
135 bool reproducibleSim =
true;
136 if (getenv(
"O2_DISABLE_REPRODUCIBLE_SIM")) {
137 reproducibleSim =
false;
143 auto workerStr = [workerID]() {
144 std::stringstream
str;
145 str <<
"[W" << workerID <<
"]";
149 auto fetched =
fetchChunk(workerID, requestchannel);
157 auto& chunk = fetched.chunk;
159 auto info = chunk->mSubEventInfo;
160 LOG(info) << workerStr() <<
" Processing " << chunk->mParticles.size() <<
" primary particles "
161 <<
"for event " << info.eventID <<
"/" << info.maxEvents <<
" "
162 <<
"part " << info.part <<
"/" << info.nparts;
170 LOG(info) << workerStr() <<
" This chunk will be skipped";
175 if (reproducibleSim) {
176 LOG(info) << workerStr() <<
" Setting seed for this sub-event to " << chunk->mSubEventInfo.seed;
183 if (strcmp(conf.getMCEngine().c_str(),
"TGeant4") == 0 || strcmp(conf.getMCEngine().c_str(),
"O2TrivialMCEngine") == 0) {
186 mVMC->ProcessEvent();
194 LOG(info) << workerStr() <<
" TIME-STAMP " << mTimer.RealTime() <<
"\t";
196 LOG(info) << workerStr() <<
" MEM-STAMP " << sysinfo.
GetCurrentMemory() / (1024. * 1024) <<
" "
203 static std::atomic<int>
counter{0};
204 fair::mq::MessagePtr request(requestchannel.NewSimpleMessage(
PrimaryChunkRequest{workerID, -1, counter++}));
205 fair::mq::Parts reply;
207 auto workerStr = [workerID]() {
208 std::stringstream
str;
209 str <<
"[W" << workerID <<
"]";
213 doLogInfo(workerID,
"Requesting work chunk");
214 int timeoutinMS = 2000;
215 auto sendcode = requestchannel.Send(request, timeoutinMS);
217 LOG(info) << workerStr() <<
" Requesting work from server not possible. Return code " << sendcode;
220 doLogInfo(workerID,
"Waiting for answer");
222 auto code = requestchannel.Receive(reply);
224 LOG(info) << workerStr() <<
" No primary answer received from server (within timeout). Return code " << code;
227 doLogInfo(workerID,
"Primary chunk received");
228 auto rawmessage = std::move(reply.At(0));
230 if (!
header.payload_attached) {
240 auto payload = std::move(reply.At(1));
246 if (chunk->mParticles.size() == 0 && chunk->mSubEventInfo.eventID == -1) {
247 doLogInfo(workerID,
"No particles in reply : quitting kernel");
255 return Kernel(-1, GetChannels().at(
"primary-get").at(0), GetChannels().at(
"simdata").at(0));
Definition of the Stack class.
std::vector< std::string > header
GPUTPCCFCheckPadBaseline Kernel
char error[CURL_ERROR_SIZE]
void doLogInfo(int workerID, std::string const &message)
size_t GetCurrentMemory()
A TMessage reading from a buffer it does not own.
static VMCSeederService const & instance()
static SimConfig & Instance()
static bool initSim(fair::mq::Channel &channel, std::unique_ptr< FairRunSim > &simptr)
bool Kernel(int workerID, fair::mq::Channel &requestchannel, fair::mq::Channel &dataoutchannel, fair::mq::Channel *statuschannel=nullptr)
~O2SimDevice() final
Default destructor.
static FetchedChunk fetchChunk(int workerID, fair::mq::Channel &requestchannel)
requests one chunk of primaries from the server on the given channel
bool isWorkAvailable(fair::mq::Channel &statuschannel, int workerID=-1)
void InitTask() final
Overloads the InitTask() method of fair::mq::Device.
@ EndOfWork
the server sent the end-of-work marker
@ Work
a chunk to transport
@ Stop
the request could not be sent, or the server has nothing more to give; stop asking
@ Retry
nothing yet (server busy or no answer); ask again
bool ConditionalRun() final
Overloads the ConditionalRun() method of fair::mq::Device.
static bool isSelectedSubEvent(int eventID, int part)
whether a sub-event passes the O2SIM_RESTRICT_EVENTPART ("event:part") selection, a debugging aid
void setSimDataChannel(fair::mq::Channel *channel)
void setPrimaries(std::vector< TParticle > const &p)
void setSubEventInfo(o2::data::SubEventInfo *i)
static ShmManager & Instance()
GLuint GLsizei const GLchar * message
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
bool querySimConfig(fair::mq::Channel &channel)
constexpr const char * PrimStateToString[5]
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"