@@ -55,21 +55,26 @@ namespace o2
5555 if (mConfigs [index].compare (" " ) == 0 ) {
5656 gens.push_back (std::make_unique<o2::eventgen::BoxGenerator>());
5757 } else {
58- std::stringstream ss (mConfigs [index]);
59- std::string pars;
60- std::vector<double > params;
61- while (std::getline (ss, pars, ' ,' )) {
62- params.push_back (std::stod (pars));
63- }
64- gens.push_back (std::make_unique<o2::eventgen::BoxGenerator>(int (params[0 ]), int (params[1 ]), params[2 ], params[3 ], params[4 ], params[5 ], params[6 ], params[7 ]));
58+ // Get the index of boxgen configuration
59+ int confBoxIndex = std::stoi (mConfigs [index].substr (7 ));
60+ gens.push_back (std::make_unique<o2::eventgen::BoxGenerator>(*mBoxGenConfigs [confBoxIndex]));
6561 }
6662 mGens .push_back (gen);
6763 } else if (gen.compare (0 , 7 , " pythia8" ) == 0 ) {
68- gens.push_back (std::make_unique<o2::eventgen::GeneratorPythia8>());
64+ // Check if mConfigs[index] contains pythia8_ and a number
65+ if (mConfigs [index].compare (" " ) == 0 ) {
66+ gens.push_back (std::make_unique<o2::eventgen::GeneratorPythia8>());
67+ }
68+ else {
69+ // Get the index of pythia8 configuration
70+ int confPythia8Index = std::stoi (mConfigs [index].substr (8 ));
71+ gens.push_back (std::make_unique<o2::eventgen::GeneratorPythia8>(*mPythia8GenConfigs [confPythia8Index]));
72+ }
6973 mConfsPythia8 .push_back (mConfigs [index]);
7074 mGens .push_back (gen);
7175 } else if (gen.compare (" extkinO2" ) == 0 ){
72- gens.push_back (std::make_unique<o2::eventgen::GeneratorFromO2Kine>(mConfigs [index].c_str ()));
76+ int confO2KineIndex = std::stoi (mConfigs [index].substr (9 ));
77+ gens.push_back (std::make_unique<o2::eventgen::GeneratorFromO2Kine>(*mO2KineGenConfigs [confO2KineIndex]));
7378 mGens .push_back (gen);
7479 } else if (gen.compare (" external" ) == 0 ) {
7580 if (mConfigs [index].compare (" " ) == 0 ) {
@@ -122,11 +127,7 @@ namespace o2
122127 int count = 0 ;
123128 for (auto & gen : mGens )
124129 {
125- if (gen == " pythia8" ){
126- auto config = std::string (std::getenv (" O2_ROOT" )) + mConfsPythia8 [count];
127- LOG (info) << " Setting \' Pythia8\' base configuration: " << config << std::endl;
128- dynamic_cast <o2::eventgen::GeneratorPythia8*>(gens[count].get ())->setConfig (config);
129- } else if (gen == " pythia8pp" ) {
130+ if (gen == " pythia8pp" ) {
130131 auto config = std::string (std::getenv (" O2_ROOT" )) + " /share/Generators/egconfig/pythia8_inel.cfg" ;
131132 LOG (info) << " Setting \' Pythia8\' base configuration: " << config << std::endl;
132133 dynamic_cast <o2::eventgen::GeneratorPythia8*>(gens[count].get ())->setConfig (config);
@@ -190,6 +191,15 @@ namespace o2
190191 return true ;
191192 }
192193
194+ template <typename T>
195+ std::string GeneratorHybrid::jsonValueToString (const T& value)
196+ {
197+ rapidjson::StringBuffer buffer;
198+ rapidjson::Writer<rapidjson::StringBuffer> writer (buffer);
199+ value.Accept (writer);
200+ return buffer.GetString ();
201+ }
202+
193203 Bool_t GeneratorHybrid::parseJSON (const std::string& path)
194204 {
195205 // Parse JSON file to build map
@@ -213,9 +223,29 @@ namespace o2
213223 const auto & gens = doc[" generators" ];
214224 for (const auto & gen : gens.GetArray ()) {
215225 // push in mInputGens the "name" of the generator
216- mInputGens .push_back (gen[" name" ].GetString ());
226+ std::string name = gen[" name" ].GetString ();
227+ mInputGens .push_back (name);
217228 if (gen.HasMember (" config" )) {
218229 // Check if config is an array
230+ if (name == " boxgen" ) {
231+ const auto & boxconf = gen[" config" ];
232+ auto boxConfig = TBufferJSON::FromJSON<o2::eventgen::BoxGenConfig>(jsonValueToString (boxconf).c_str ());
233+ mBoxGenConfigs .push_back (std::move (boxConfig));
234+ mConfigs .push_back (" boxgen_" + std::to_string (mBoxGenConfigs .size () - 1 ));
235+ continue ;
236+ } else if (name == " pythia8" ) {
237+ const auto & pythia8conf = gen[" config" ];
238+ auto pythia8Config = TBufferJSON::FromJSON<o2::eventgen::Pythia8GenConfig>(jsonValueToString (pythia8conf).c_str ());
239+ mPythia8GenConfigs .push_back (std::move (pythia8Config));
240+ mConfigs .push_back (" pythia8_" + std::to_string (mPythia8GenConfigs .size () - 1 ));
241+ continue ;
242+ } else if (name == " extkinO2" ) {
243+ const auto & o2kineconf = gen[" config" ];
244+ auto o2kineConfig = TBufferJSON::FromJSON<o2::eventgen::O2KineGenConfig>(jsonValueToString (o2kineconf).c_str ());
245+ mO2KineGenConfigs .push_back (std::move (o2kineConfig));
246+ mConfigs .push_back (" extkinO2_" + std::to_string (mO2KineGenConfigs .size () - 1 ));
247+ continue ;
248+ }
219249 if (gen[" config" ].IsArray ()) {
220250 std::string config = " " ;
221251 for (const auto & conf : gen[" config" ].GetArray ()) {
0 commit comments