Project
Loading...
Searching...
No Matches
O2SimDevice.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
14#ifndef ALICEO2_DEVICES_SIMDEVICE_H_
15#define ALICEO2_DEVICES_SIMDEVICE_H_
16
17#include <memory>
18#include <string>
19#include <fairmq/Device.h>
20#include <FairRunSim.h>
21#include <TStopwatch.h>
22#include "PrimaryServerState.h"
24
25class TVirtualMC;
26
27namespace o2::steer
28{
29class O2MCApplication;
30}
31
32// a helper for logging with worker index prefixed
33void doLogInfo(int workerID, std::string const& message);
34
35namespace o2
36{
37namespace devices
38{
39
40// device representing a simulation worker
41class O2SimDevice final : public fair::mq::Device
42{
43 public:
44 O2SimDevice() = default;
45 O2SimDevice(o2::steer::O2MCApplication* vmcapp, TVirtualMC* vmc) : mVMCApp{vmcapp}, mVMC{vmc} {}
46
48 ~O2SimDevice() final;
49
52 void InitTask() final;
53
54 public:
55 void lateInit();
56
57 // initializes the simulation classes; queries the configuration on a given channel
58 static bool initSim(fair::mq::Channel& channel, std::unique_ptr<FairRunSim>& simptr);
59
60 bool isWorkAvailable(fair::mq::Channel& statuschannel, int workerID = -1);
61
62 bool Kernel(int workerID, fair::mq::Channel& requestchannel, fair::mq::Channel& dataoutchannel, fair::mq::Channel* statuschannel = nullptr);
63
65 enum class ChunkStatus {
66 Work,
67 Retry,
68 EndOfWork,
69 Stop
70 };
71 struct FetchedChunk {
73 std::unique_ptr<o2::data::PrimaryChunk> chunk;
74 };
75
77 static FetchedChunk fetchChunk(int workerID, fair::mq::Channel& requestchannel);
78
79 protected:
81 bool ConditionalRun() final;
82
83 void PostRun() final;
84
85 private:
86 TStopwatch mTimer;
87 o2::steer::O2MCApplication* mVMCApp = nullptr;
88 TVirtualMC* mVMC = nullptr;
89 std::unique_ptr<FairRunSim> mSimRun;
90};
91
92} // namespace devices
93} // namespace o2
94
95#endif
void doLogInfo(int workerID, std::string const &message)
#define protected
static bool initSim(fair::mq::Channel &channel, std::unique_ptr< FairRunSim > &simptr)
~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
O2SimDevice(o2::steer::O2MCApplication *vmcapp, TVirtualMC *vmc)
Definition O2SimDevice.h:45
bool isWorkAvailable(fair::mq::Channel &statuschannel, int workerID=-1)
void InitTask() final
Overloads the InitTask() method of fair::mq::Device.
ChunkStatus
outcome of asking the primary server for work
Definition O2SimDevice.h:65
@ EndOfWork
the server sent the end-of-work marker
@ 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.
GLuint GLsizei const GLchar * message
Definition glcorearb.h:2517
Definition ASoA.h:45
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::unique_ptr< o2::data::PrimaryChunk > chunk
set for ChunkStatus::Work
Definition O2SimDevice.h:73