@@ -77,45 +77,26 @@ namespace o2
7777 gens.push_back (std::make_unique<o2::eventgen::GeneratorFromO2Kine>(*mO2KineGenConfigs [confO2KineIndex]));
7878 mGens .push_back (gen);
7979 } else if (gen.compare (" external" ) == 0 ) {
80- if (mConfigs [index].compare (" " ) == 0 ) {
81- LOG (fatal) << " No configuration provided" ;
80+ int confextIndex = std::stoi (mConfigs [index].substr (9 ));
81+ auto & extgen_filename = mExternalGenConfigs [confextIndex]->fileName ;
82+ auto & extgen_func = mExternalGenConfigs [confextIndex]->funcName ;
83+ auto extGen = std::unique_ptr<o2::eventgen::Generator>(o2::conf::GetFromMacro<o2::eventgen::Generator*>(extgen_filename, extgen_func, " FairGenerator*" , " extgen" ));
84+ if (!extGen) {
85+ LOG (fatal) << " Failed to load external generator from " << extgen_filename << " with function " << extgen_func;
8286 exit (1 );
83- } else {
84- std::stringstream ss (mConfigs [index]);
85- std::string pars;
86- std::vector<std::string> params;
87- while (std::getline (ss, pars, ' ,' )) {
88- params.push_back (pars);
89- }
90- auto & extgen_filename = params[0 ];
91- auto & extgen_func = params[1 ];
92- auto extGen = std::unique_ptr<o2::eventgen::Generator>(o2::conf::GetFromMacro<o2::eventgen::Generator*>(extgen_filename, extgen_func, " FairGenerator*" , " extgen" ));
93- if (!extGen) {
94- LOG (fatal) << " Failed to load external generator from " << extgen_filename << " with function " << extgen_func;
95- exit (1 );
96- }
97- gens.push_back (std::move (extGen));
98- mGens .push_back (gen);
9987 }
88+ gens.push_back (std::move (extGen));
89+ mGens .push_back (gen);
10090 } else if (gen.compare (" hepmc" ) == 0 ) {
101- if (mConfigs [index].compare (" " ) == 0 ) {
102- LOG (fatal) << " No configuration provided" ;
103- exit (1 );
104- } else {
105- std::stringstream ss (mConfigs [index]);
106- std::string pars;
107- std::vector<std::string> params;
108- while (std::getline (ss, pars, ' ,' )) {
109- params.push_back (pars);
110- }
111- gens.push_back (std::make_unique<o2::eventgen::GeneratorHepMC>());
112- dynamic_cast <o2::eventgen::GeneratorHepMC*>(gens.back ().get ())->setFileNames (std::string (params[0 ]));
113- dynamic_cast <o2::eventgen::GeneratorHepMC*>(gens.back ().get ())->setVersion (std::stoi (params[1 ]));
114- mGens .push_back (gen);
115- }
91+ int confHepMCIndex = std::stoi (mConfigs [index].substr (6 ));
92+ gens.push_back (std::make_unique<o2::eventgen::GeneratorHepMC>());
93+ auto & globalConfig = o2::conf::SimConfig::Instance ();
94+ dynamic_cast <o2::eventgen::GeneratorHepMC*>(gens.back ().get ())->setup (*mFileOrCmdGenConfigs [confHepMCIndex], *mHepMCGenConfigs [confHepMCIndex], globalConfig);
95+ mGens .push_back (gen);
11696 } else {
117- LOG (info) << " Generator " << gen << " not found in the list of available generators \n " ;
118- }
97+ LOG (fatal) << " Generator " << gen << " not found in the list of available generators \n " ;
98+ exit (1 );
99+ }
119100 }
120101 index++;
121102 }
@@ -165,7 +146,10 @@ namespace o2
165146 }
166147 mIndex = mCurrentFraction ;
167148 }
168- LOG (info) << " GeneratorHybrid: generating event with generator " << mGens [mIndex ];
149+ if (mConfigs [mIndex ].compare (" " ) == 0 )
150+ LOG (info) << " GeneratorHybrid: generating event with generator " << mGens [mIndex ];
151+ else
152+ LOG (info) << " GeneratorHybrid: generating event with generator " << mConfigs [mIndex ];
169153 gens[mIndex ]->clearParticles (); // clear container of this class
170154 gens[mIndex ]->generateEvent ();
171155 // notify the sub event generator
@@ -214,7 +198,6 @@ namespace o2
214198 if (doc.HasParseError ()) {
215199 LOG (error) << " Error parsing provided json file " << path;
216200 LOG (error) << " - Error -> " << rapidjson::GetParseError_En (doc.GetParseError ());
217- LOG (error) << " - Offset -> " << doc.GetErrorOffset ();
218201 return false ;
219202 }
220203
@@ -245,20 +228,33 @@ namespace o2
245228 mO2KineGenConfigs .push_back (std::move (o2kineConfig));
246229 mConfigs .push_back (" extkinO2_" + std::to_string (mO2KineGenConfigs .size () - 1 ));
247230 continue ;
248- }
249- if (gen[" config" ].IsArray ()) {
250- std::string config = " " ;
251- for (const auto & conf : gen[" config" ].GetArray ()) {
252- config += conf.GetString ();
253- config += " ," ;
254- }
255- mConfigs .push_back (config);
231+ } else if (name == " external" ) {
232+ const auto & extconf = gen[" config" ];
233+ auto extConfig = TBufferJSON::FromJSON<o2::eventgen::ExternalGenConfig>(jsonValueToString (extconf).c_str ());
234+ mExternalGenConfigs .push_back (std::move (extConfig));
235+ mConfigs .push_back (" external_" + std::to_string (mExternalGenConfigs .size () - 1 ));
236+ continue ;
237+ } else if (name == " hepmc" ) {
238+ const auto & genconf = gen[" config" ];
239+ const auto & cmdconf = genconf[" configcmd" ];
240+ const auto & hepmcconf = genconf[" confighepmc" ];
241+ auto cmdConfig = TBufferJSON::FromJSON<o2::eventgen::FileOrCmdGenConfig>(jsonValueToString (cmdconf).c_str ());
242+ auto hepmcConfig = TBufferJSON::FromJSON<o2::eventgen::HepMCGenConfig>(jsonValueToString (hepmcconf).c_str ());
243+ mFileOrCmdGenConfigs .push_back (std::move (cmdConfig));
244+ mHepMCGenConfigs .push_back (std::move (hepmcConfig));
245+ mConfigs .push_back (" hepmc_" + std::to_string (mFileOrCmdGenConfigs .size () - 1 ));
246+ continue ;
256247 } else {
257- mConfigs .push_back (gen[ " config " ]. GetString () );
248+ mConfigs .push_back (" " );
258249 }
259250 }
260251 else {
261- mConfigs .push_back (" " );
252+ if (name == " boxgen" || name == " pythia8" || name == " extkinO2" || name == " external" || name == " hepmc" ){
253+ LOG (fatal) << " No configuration provided for generator " << name;
254+ return false ;
255+ }
256+ else
257+ mConfigs .push_back (" " );
262258 }
263259 }
264260 }
@@ -277,7 +273,6 @@ namespace o2
277273 mFractions .push_back (1 );
278274 }
279275 }
280-
281276 return true ;
282277 }
283278
0 commit comments