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