Project
Loading...
Searching...
No Matches
O2PrimaryServerDevice.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 O2_DEVICES_PRIMSERVDEVICE_H_
15#define O2_DEVICES_PRIMSERVDEVICE_H_
16
17#include <fairmq/Device.h>
18#include <DetectorsBase/Stack.h>
20#include <SimConfig/SimConfig.h>
23#include <TRandom3.h>
24#include <atomic>
25#include <map>
26#include <memory>
27#include <string>
28#include <thread>
29#include <unordered_map>
30#include "PrimaryServerState.h"
31
32namespace o2
33{
34namespace devices
35{
36
38{
39 public:
42
45
46 protected:
47 void initGenerator();
48
49 // function generating one event
50 void generateEvent(/*bool changeState = false*/);
51
52 // launches a thread that listens for status/config/shutdown requests from outside asynchronously
53 void launchInfoThread();
54
55 void InitTask() final;
56
57 // function for intermediate/on-the-fly reinitializations
58 bool ReInit(o2::conf::SimReconfigData const& reconfig);
59
60 // method reacting to requests to get the simulation configuration
61 bool HandleConfigRequest(fair::mq::Channel& channel);
62
63 bool ConditionalRun() override;
64
65 void PostRun() override;
66
67 bool HandleRequest(fair::mq::MessagePtr& request, int /*index*/, fair::mq::Channel& channel);
68
69 void stateTransition(O2PrimaryServerState to, const char* message);
70
72
73 private:
74 o2::conf::SimConfig mSimConfig = o2::conf::SimConfig::Instance(); // local sim config object
75 o2::eventgen::PrimaryGenerator* mPrimGen = nullptr; // the current primary generator
77 o2::data::Stack* mStack = nullptr; // the stack which is filled (pointer since constructor to be called only init method)
78 int mChunkGranularity = 500; // how many primaries to send to a worker
79 int mPartCounter = 0;
80 bool mNeedNewEvent = true;
81 int mMaxEvents = 2;
82 ULong_t mInitialSeed = 0;
83 bool mUseFixedChunkSeed = false;
84 ULong_t mFixedChunkSeed = 0;
85 int mPipeToDriver = -1; // handle for direct piper to driver (to communicate meta info)
86 int mEventCounter = 0;
87
88 std::thread mGeneratorThread;
89 // or to generate events
90 std::thread mControlThread;
91
92 // Keeps various generators instantiated in memory
93 // useful when running simulation as a service (when generators
94 // change between batches). Also takes care of resource management of Primary generators via unique ptr
95 // TODO: some care needs to be taken (or the user warned) that the caching is based on generator name
96 // and that parameter-based reconfiguration is not yet implemented (for which we would need to hash all
97 // configuration parameters as well)
98 std::map<std::string, std::unique_ptr<o2::eventgen::PrimaryGenerator>> mPrimGeneratorCache;
99
100 std::atomic<O2PrimaryServerState> mState{O2PrimaryServerState::Initializing};
101 std::atomic<int> mWaitingControlInput{0};
102 std::atomic<bool> mInfoThreadStopped{false};
103
104 bool mAsService = false;
105
106 // a dedicate (on-the-fly channel) for control messages
107 fair::mq::Channel mControlChannel;
108
109 // some information specific to use case when we have a collision context
110 o2::steer::DigitizationContext* mCollissionContext = nullptr;
111 std::unordered_map<int, int> mEventID_to_CollID;
112 std::string mEmbeddIntoPrefix;
113
114 TRandom3 mSeedGenerator;
115};
116
117} // namespace devices
118} // namespace o2
119
120#endif
Definition of the Stack class.
static SimConfig & Instance()
Definition SimConfig.h:112
bool ReInit(o2::conf::SimReconfigData const &reconfig)
void stateTransition(O2PrimaryServerState to, const char *message)
~O2PrimaryServerDevice() final
Default destructor.
bool HandleConfigRequest(fair::mq::Channel &channel)
bool HandleRequest(fair::mq::MessagePtr &request, int, fair::mq::Channel &channel)
GLuint GLsizei const GLchar * message
Definition glcorearb.h:2517
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
O2PrimaryServerState
enum to represent state of the O2Sim event/primary server
TODO: Make this a base class of SimConfigData?
Definition SimConfig.h:205