Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Generators/include/Generators/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ class Generator : public FairGenerator
void setTriggerMode(ETriggerMode_t val) { mTriggerMode = val; };
void addTrigger(Trigger trigger) { mTriggers.push_back(trigger); };
void addDeepTrigger(DeepTrigger trigger) { mDeepTriggers.push_back(trigger); };
// setter for global number of events
static void setTotalNEvents(unsigned int& n) { gTotalNEvents = n; }

/** getters **/
const std::vector<TParticle>& getParticles() const { return mParticles; }; //!
static unsigned int getTotalNEvents() { return gTotalNEvents; };

/** other **/
void clearParticles() { mParticles.clear(); };
Expand Down Expand Up @@ -152,6 +155,9 @@ class Generator : public FairGenerator
// the current ID of the sub-generator used in the current event (if applicable)
int mSubGeneratorId = -1;

// global static information about (upper limit of) number of events to be generated
static unsigned int gTotalNEvents;

ClassDefOverride(Generator, 2);

}; /** class Generator **/
Expand Down
3 changes: 0 additions & 3 deletions Generators/include/Generators/GeneratorHybrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ class GeneratorHybrid : public Generator
Bool_t importParticles() override;
void updateHeader(o2::dataformats::MCEventHeader* eventHeader) override;

void setNEvents(int n) { mNEvents = n; }

Bool_t parseJSON(const std::string& path);
Bool_t confSetter(const auto& gen);
template <typename T>
Expand Down Expand Up @@ -116,7 +114,6 @@ class GeneratorHybrid : public Generator
std::atomic<bool> mStopFlag;
bool mIsInitialized = false;

int mNEvents = -1; // the number of events to be done, if known (helps initiating cleanup)
o2::dataformats::MCEventHeader mMCEventHeader; // to capture event headers

enum class GenMode {
Expand Down
2 changes: 1 addition & 1 deletion Generators/src/Generator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace eventgen
{

std::atomic<int> Generator::InstanceCounter{0};

unsigned int Generator::gTotalNEvents = 0;
/*****************************************************************/
/*****************************************************************/

Expand Down
1 change: 0 additions & 1 deletion Generators/src/GeneratorFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair
return;
}
auto hybrid = new o2::eventgen::GeneratorHybrid(config);
hybrid->setNEvents(conf.getNEvents());
primGen->AddGenerator(hybrid);
#endif
} else {
Expand Down
2 changes: 1 addition & 1 deletion Generators/src/GeneratorHybrid.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ bool GeneratorHybrid::importParticles()

mseqCounter++;
mEventCounter++;
if (mEventCounter == mNEvents) {
if (mEventCounter == getTotalNEvents()) {
LOG(info) << "HybridGen: Stopping TBB task pool";
mStopFlag = true;
}
Expand Down
2 changes: 2 additions & 0 deletions Generators/src/GeneratorService.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Generators/GeneratorService.h"
#include "Generators/GeneratorFactory.h"
#include "SimConfig/SimConfig.h"
#include "Generators/Generator.h"
#include "DataFormatsCalibration/MeanVertexObject.h"

using namespace o2::eventgen;
Expand All @@ -23,6 +24,7 @@ void GeneratorService::initService(std::string const& genName,
auto localSimConfig = o2::conf::SimConfig::make();
localSimConfig.getConfigData().mGenerator = genName;
localSimConfig.getConfigData().mTrigger = triggerName;
localSimConfig.getConfigData().mNEvents = o2::eventgen::Generator::getTotalNEvents();

o2::eventgen::GeneratorFactory::setPrimaryGenerator(localSimConfig, &mPrimGen);

Expand Down
4 changes: 4 additions & 0 deletions macro/o2sim.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#if !defined(__CLING__) || defined(__ROOTCLING__)
#include <Generators/PrimaryGenerator.h>
#include <Generators/GeneratorFactory.h>
#include <Generators/Generator.h>
#include "SimulationDataFormat/O2DatabasePDG.h"
#include "SimulationDataFormat/MCEventHeader.h"
#include <SimConfig/SimConfig.h>
Expand Down Expand Up @@ -61,6 +62,9 @@ void check_notransport()
FairRunSim* o2sim_init(bool asservice, bool evalmat = false)
{
auto& confref = o2::conf::SimConfig::Instance();
// set the global information about the number of events to be generated
unsigned int nTotalEvents = confref.getNEvents();
o2::eventgen::Generator::setTotalNEvents(nTotalEvents);
// initialize CCDB service
auto& ccdbmgr = o2::ccdb::BasicCCDBManager::instance();
// fix the timestamp early
Expand Down
5 changes: 5 additions & 0 deletions run/O2PrimaryServerDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <SimulationDataFormat/PrimaryChunk.h>
#include <Generators/GeneratorFromFile.h>
#include <Generators/PrimaryGenerator.h>
#include <Generators/Generator.h>
#include <SimConfig/SimConfig.h>
#include <CommonUtils/ConfigurableParam.h>
#include <CommonUtils/RngHelper.h>
Expand Down Expand Up @@ -87,6 +88,10 @@ class O2PrimaryServerDevice final : public fair::mq::Device
ccdbmgr.setURL(conf.getConfigData().mCCDBUrl);
ccdbmgr.setTimestamp(conf.getTimestamp());

// set the global information about the number of events to be generated
unsigned int nTotalEvents = conf.getNEvents();
o2::eventgen::Generator::setTotalNEvents(nTotalEvents);

// init magnetic field as it might be needed by the generator
if (TGeoGlobalMagField::Instance()->GetField() == nullptr) {
TGeoGlobalMagField::Instance()->SetField(o2::base::SimFieldUtils::createMagField());
Expand Down
7 changes: 7 additions & 0 deletions run/dpl_eventgen.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "SimulationDataFormat/MCTrack.h"
#include "Framework/runDataProcessing.h"
#include <Generators/GeneratorService.h>
#include <Generators/Generator.h>
#include <CommonUtils/ConfigurableParam.h>
#include <CommonUtils/RngHelper.h>
#include <TStopwatch.h> // simple timer from ROOT
Expand Down Expand Up @@ -63,6 +64,12 @@ struct GeneratorTask {
// update config key params
o2::conf::ConfigurableParam::updateFromFile(iniFile);
o2::conf::ConfigurableParam::updateFromString((std::string)params);
// set the number of events in the static Generator variable gTotalNEvents.
// Variable is unset if nEvents exceeds the uint maximum value
if (nEvents <= std::numeric_limits<unsigned int>::max()) {
unsigned int castNEvents = static_cast<unsigned int>(nEvents);
o2::eventgen::Generator::setTotalNEvents(castNEvents);
}
// initialize the service
if (vtxmode == o2::conf::VertexMode::kDiamondParam) {
genservice->initService(generator, trigger, o2::eventgen::DiamondParamVertexOption());
Expand Down