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
68 Bool_t parseJSON(const std::string& path);
69 Bool_t confSetter(const auto& gen);
70 template <typename T>
71 std::string jsonValueToString(const T& value);
72 std::vector<std::shared_ptr<o2::eventgen::Generator>> const& getGenerators() { return gens; }
73
74 private:
75 GeneratorHybrid(const std::string& inputgens);
77 o2::eventgen::Generator* currentgen = nullptr;
78 std::vector<std::shared_ptr<o2::eventgen::Generator>> gens;
79 const std::vector<std::string> generatorNames = {"extkinO2", "evtpool", "boxgen", "external", "hepmc", "pythia8", "pythia8pp", "pythia8hi", "pythia8hf", "pythia8powheg"};
80 std::vector<std::string> mInputGens;
81 std::vector<std::string> mGens;
82 std::vector<std::string> mConfigs;
83 std::vector<std::string> mConfsPythia8;
84
85 std::vector<bool> mGenIsInitialized;
86
87 // Parameters configurations
88 std::vector<std::unique_ptr<o2::eventgen::BoxGenConfig>> mBoxGenConfigs;
89 std::vector<std::unique_ptr<o2::eventgen::Pythia8GenConfig>> mPythia8GenConfigs;
90 std::vector<std::unique_ptr<o2::eventgen::O2KineGenConfig>> mO2KineGenConfigs;
91 std::vector<o2::eventgen::EventPoolGenConfig> mEventPoolConfigs;
92 std::vector<std::unique_ptr<o2::eventgen::ExternalGenConfig>> mExternalGenConfigs;
93 std::vector<std::unique_ptr<o2::eventgen::FileOrCmdGenConfig>> mFileOrCmdGenConfigs;
94 std::vector<std::unique_ptr<o2::eventgen::HepMCGenConfig>> mHepMCGenConfigs;
95
96 bool mRandomize = false;
97 std::vector<int> mFractions;
98 std::vector<float> mRngFractions;
99 int mseqCounter = 0;
100 int mCurrentFraction = 0;
101 int mIndex = 0;
102 int mEventCounter = 0;
103 int mTasksStarted = 0;
104
105 // Cocktail mode
106 bool mCocktailMode = false;
107 std::vector<std::vector<int>> mGroups;
108
109 // Trigger configuration
110 std::vector<ETriggerMode_t> mTriggerModes; // trigger mode for each generator
111 std::vector<std::vector<std::string>> mTriggerMacros; // trigger macros for each generator (multiple triggers for each generator possible)
112 std::vector<std::vector<std::string>> mTriggerFuncs; // trigger functions for each generator (multiple triggers for each generator possible)
113
114 // Create a task arena with a specified number of threads
115 std::thread mTBBTaskPoolRunner;
116 tbb::concurrent_bounded_queue<int> mInputTaskQueue;
117 std::vector<tbb::concurrent_bounded_queue<int>> mResultQueue;
118 tbb::task_arena mTaskArena;
119 std::atomic<bool> mStopFlag;
120 bool mIsInitialized = false;
121
122 o2::dataformats::MCEventHeader mMCEventHeader; // to capture event headers
123
124 enum class GenMode {
125 kSeq,
126 kParallel
127 };
128
129 // hybrid gen operation mode - should be either 'sequential' or 'parallel'
130 // parallel means that we have clones of the same generator collaborating on event generation
131 // sequential means that events will be produced in the order given by fractions; async processing is still happening
132 GenMode mGenerationMode = GenMode::kSeq;
133};
134
135} // namespace eventgen
136} // namespace o2
137
138#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
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 ...