Project
Loading...
Searching...
No Matches
GeneratorHybrid.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_EVENTGEN_GENERATORHYBRID_H_
15#define ALICEO2_EVENTGEN_GENERATORHYBRID_H_
16
31#include <TRandom3.h>
33#include "FairGenerator.h"
34#include <DetectorsBase/Stack.h>
35#include <SimConfig/SimConfig.h>
36#include <rapidjson/document.h>
37#include <rapidjson/error/en.h>
38#include <rapidjson/istreamwrapper.h>
39#include <rapidjson/writer.h>
40#include "TBufferJSON.h"
41
42#include <tbb/concurrent_queue.h>
43#include <tbb/task_arena.h>
44#include <iostream>
45#include <thread>
46#include <atomic>
47
48namespace o2
49{
50namespace eventgen
51{
52
54{
55
56 public:
59
60 // Singleton access method
61 static GeneratorHybrid& Instance(const std::string& inputgens = "");
62
63 Bool_t Init() override;
64 Bool_t generateEvent() override;
65 Bool_t importParticles() override;
66 void updateHeader(o2::dataformats::MCEventHeader* eventHeader) override;
67 void stop() override; // end-of-stream hook that joins the TBB task pool
68
69 Bool_t parseJSON(const std::string& path);
70 Bool_t confSetter(const auto& gen);
71 template <typename T>
72 std::string jsonValueToString(const T& value);
73 std::vector<std::shared_ptr<o2::eventgen::Generator>> const& getGenerators() { return gens; }
74
75 private:
76 GeneratorHybrid(const std::string& inputgens);
78 o2::eventgen::Generator* currentgen = nullptr;
79 std::vector<std::shared_ptr<o2::eventgen::Generator>> gens;
80 const std::vector<std::string> generatorNames = {"evtpool", "boxgen", "external", "hepmc", "pythia8", "pythia8pp", "pythia8hi", "pythia8hf", "pythia8powheg"};
81 std::vector<std::string> mInputGens;
82 std::vector<std::string> mGens;
83 std::vector<std::string> mConfigs;
84 std::vector<std::string> mConfsPythia8;
85
86 std::vector<bool> mGenIsInitialized;
87
88 // Parameters configurations
89 std::vector<std::unique_ptr<o2::eventgen::BoxGenConfig>> mBoxGenConfigs;
90 std::vector<std::unique_ptr<o2::eventgen::Pythia8GenConfig>> mPythia8GenConfigs;
91 std::vector<std::unique_ptr<o2::eventgen::O2KineGenConfig>> mO2KineGenConfigs;
92 std::vector<o2::eventgen::EventPoolGenConfig> mEventPoolConfigs;
93 std::vector<std::unique_ptr<o2::eventgen::ExternalGenConfig>> mExternalGenConfigs;
94 std::vector<std::unique_ptr<o2::eventgen::FileOrCmdGenConfig>> mFileOrCmdGenConfigs;
95 std::vector<std::unique_ptr<o2::eventgen::HepMCGenConfig>> mHepMCGenConfigs;
96
97 bool mRandomize = false;
98 std::vector<int> mFractions;
99 std::vector<float> mRngFractions;
100 int mseqCounter = 0;
101 int mCurrentFraction = 0;
102 int mIndex = 0;
103 int mEventCounter = 0;
104 int mTasksStarted = 0;
105
106 // Cocktail mode
107 bool mCocktailMode = false;
108 std::vector<std::vector<int>> mGroups;
109
110 // Trigger configuration
111 std::vector<ETriggerMode_t> mTriggerModes; // trigger mode for each generator
112 std::vector<std::vector<std::string>> mTriggerMacros; // trigger macros for each generator (multiple triggers for each generator possible)
113 std::vector<std::vector<std::string>> mTriggerFuncs; // trigger functions for each generator (multiple triggers for each generator possible)
114
115 // Create a task arena with a specified number of threads
116 std::thread mTBBTaskPoolRunner;
117 tbb::concurrent_bounded_queue<int> mInputTaskQueue;
118 std::vector<tbb::concurrent_bounded_queue<int>> mResultQueue;
119 tbb::task_arena mTaskArena;
120 std::atomic<bool> mStopFlag;
121 bool mIsInitialized = false;
122
123 // Hyperloop flag
124 const bool mIsHyperloop = Generator::isHyperloop();
125
126 o2::dataformats::MCEventHeader mMCEventHeader; // to capture event headers
127 int mHeaderGeneratorIndex = -1; // index of the generator that updated the header in current event
128
129 enum class GenMode {
130 kSeq,
131 kParallel
132 };
133
134 // hybrid gen operation mode - should be either 'sequential' or 'parallel'
135 // parallel means that we have clones of the same generator collaborating on event generation
136 // sequential means that events will be produced in the order given by fractions; async processing is still happening
137 GenMode mGenerationMode = GenMode::kSeq;
138};
139
140} // namespace eventgen
141} // namespace o2
142
143#endif
Definition of the Stack class.
default_random_engine gen(dev())
GeneratorHybrid(const GeneratorHybrid &)=delete
Bool_t parseJSON(const std::string &path)
std::string jsonValueToString(const T &value)
void updateHeader(o2::dataformats::MCEventHeader *eventHeader) override
static GeneratorHybrid & Instance(const std::string &inputgens="")
Bool_t confSetter(const auto &gen)
std::vector< std::shared_ptr< o2::eventgen::Generator > > const & getGenerators()
GeneratorHybrid & operator=(const GeneratorHybrid &)=delete
static bool isHyperloop()
Definition Generator.cxx:49
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...