@@ -59,10 +59,12 @@ GeneratorHepMC::~GeneratorHepMC()
5959{
6060 /* * default destructor **/
6161 LOG (info) << " Destructing GeneratorHepMC" ;
62- if (mReader )
62+ if (mReader ) {
6363 mReader ->close ();
64- if (mEvent )
64+ }
65+ if (mEvent ) {
6566 delete mEvent ;
67+ }
6668 removeTemp ();
6769}
6870
@@ -71,21 +73,28 @@ void GeneratorHepMC::setup(const GeneratorFileOrCmdParam& param0,
7173 const GeneratorHepMCParam& param,
7274 const conf::SimConfig& config)
7375{
76+ if (not param.fileName .empty ()) {
77+ LOG (fatal) << " The use of the key \" HepMC.fileName\" is "
78+ << " no longer supported, use \" FileOrCmd.fileNames\" instead" ;
79+ }
80+ if (param.version != 0 )
81+ LOG (warn) << " The key \" HepMC.version\" is no longer used. The "
82+ << " version of the input files are automatically deduced." ;
7483 GeneratorFileOrCmd::setup (param0, config);
7584 setEventsToSkip (param.eventsToSkip );
7685}
7786
7887/* ****************************************************************/
79-
8088Bool_t GeneratorHepMC::generateEvent ()
8189{
8290 LOG (debug) << " Generating an event" ;
8391 /* * generate event **/
8492 int tries = 0 ;
8593 do {
8694 LOG (debug) << " try # " << ++tries;
87- if (not mReader and not makeReader ())
95+ if (not mReader and not makeReader ()) {
8896 return false ;
97+ }
8998
9099 /* * clear and read event **/
91100 mEvent ->clear ();
@@ -153,34 +162,71 @@ Bool_t GeneratorHepMC::importParticles()
153162
154163namespace
155164{
165+ template <typename AttributeType, typename TargetType>
166+ bool putAttributeInfoImpl (o2::dataformats::MCEventHeader* eventHeader,
167+ const std::string& name,
168+ const std::shared_ptr<HepMC3::Attribute>& a)
169+ {
170+ if (auto * p = dynamic_cast <AttributeType*>(a.get ())) {
171+ eventHeader->putInfo <TargetType>(name, p->value ());
172+ return true ;
173+ }
174+ return false ;
175+ }
176+
156177void putAttributeInfo (o2::dataformats::MCEventHeader* eventHeader,
157178 const std::string& name,
158179 const std::shared_ptr<HepMC3::Attribute>& a)
159180{
160- if (auto * p = dynamic_cast <HepMC3::IntAttribute*>(a.get ()))
161- eventHeader->putInfo <int >(name, p->value ());
162- if (auto * p = dynamic_cast <HepMC3::LongAttribute*>(a.get ()))
163- eventHeader->putInfo <int >(name, p->value ());
164- if (auto * p = dynamic_cast <HepMC3::FloatAttribute*>(a.get ()))
165- eventHeader->putInfo <float >(name, p->value ());
166- if (auto * p = dynamic_cast <HepMC3::DoubleAttribute*>(a.get ()))
167- eventHeader->putInfo <float >(name, p->value ());
168- if (auto * p = dynamic_cast <HepMC3::StringAttribute*>(a.get ()))
169- eventHeader->putInfo <std::string>(name, p->value ());
170- if (auto * p = dynamic_cast <HepMC3::CharAttribute*>(a.get ()))
171- eventHeader->putInfo <char >(name, p->value ());
172- if (auto * p = dynamic_cast <HepMC3::LongLongAttribute*>(a.get ()))
173- eventHeader->putInfo <int >(name, p->value ());
174- if (auto * p = dynamic_cast <HepMC3::LongDoubleAttribute*>(a.get ()))
175- eventHeader->putInfo <float >(name, p->value ());
176- if (auto * p = dynamic_cast <HepMC3::UIntAttribute*>(a.get ()))
177- eventHeader->putInfo <int >(name, p->value ());
178- if (auto * p = dynamic_cast <HepMC3::ULongAttribute*>(a.get ()))
179- eventHeader->putInfo <int >(name, p->value ());
180- if (auto * p = dynamic_cast <HepMC3::ULongLongAttribute*>(a.get ()))
181- eventHeader->putInfo <int >(name, p->value ());
182- if (auto * p = dynamic_cast <HepMC3::BoolAttribute*>(a.get ()))
183- eventHeader->putInfo <bool >(name, p->value ());
181+ using IntAttribute = HepMC3::IntAttribute;
182+ using LongAttribute = HepMC3::LongAttribute;
183+ using FloatAttribute = HepMC3::FloatAttribute;
184+ using DoubleAttribute = HepMC3::DoubleAttribute;
185+ using StringAttribute = HepMC3::StringAttribute;
186+ using CharAttribute = HepMC3::CharAttribute;
187+ using LongLongAttribute = HepMC3::LongLongAttribute;
188+ using LongDoubleAttribute = HepMC3::LongDoubleAttribute;
189+ using UIntAttribute = HepMC3::UIntAttribute;
190+ using ULongAttribute = HepMC3::ULongAttribute;
191+ using ULongLongAttribute = HepMC3::ULongLongAttribute;
192+ using BoolAttribute = HepMC3::BoolAttribute;
193+
194+ if (putAttributeInfoImpl<IntAttribute, int >(eventHeader, name, a)) {
195+ return ;
196+ }
197+ if (putAttributeInfoImpl<LongAttribute, int >(eventHeader, name, a)) {
198+ return ;
199+ }
200+ if (putAttributeInfoImpl<FloatAttribute, float >(eventHeader, name, a)) {
201+ return ;
202+ }
203+ if (putAttributeInfoImpl<DoubleAttribute, float >(eventHeader, name, a)) {
204+ return ;
205+ }
206+ if (putAttributeInfoImpl<StringAttribute, std::string>(eventHeader, name, a)) {
207+ return ;
208+ }
209+ if (putAttributeInfoImpl<CharAttribute, char >(eventHeader, name, a)) {
210+ return ;
211+ }
212+ if (putAttributeInfoImpl<LongLongAttribute, int >(eventHeader, name, a)) {
213+ return ;
214+ }
215+ if (putAttributeInfoImpl<LongDoubleAttribute, float >(eventHeader, name, a)) {
216+ return ;
217+ }
218+ if (putAttributeInfoImpl<UIntAttribute, int >(eventHeader, name, a)) {
219+ return ;
220+ }
221+ if (putAttributeInfoImpl<ULongAttribute, int >(eventHeader, name, a)) {
222+ return ;
223+ }
224+ if (putAttributeInfoImpl<ULongLongAttribute, int >(eventHeader, name, a)) {
225+ return ;
226+ }
227+ if (putAttributeInfoImpl<BoolAttribute, bool >(eventHeader, name, a)) {
228+ return ;
229+ }
184230}
185231} // namespace
186232
@@ -264,8 +310,9 @@ void GeneratorHepMC::updateHeader(o2::dataformats::MCEventHeader* eventHeader)
264310 std::string name = na.first ;
265311 if (name == " GenPdfInfo" ||
266312 name == " GenCrossSection" ||
267- name == " GenHeavyIon" )
313+ name == " GenHeavyIon" ) {
268314 continue ;
315+ }
269316
270317 for (auto ia : na.second ) {
271318 int no = ia.first ;
@@ -354,12 +401,14 @@ Bool_t GeneratorHepMC::Init()
354401 // around the actual EG program.
355402 if (not mCmd .empty ()) {
356403 // Set filename to be a temporary name
357- if (not makeTemp ())
404+ if (not makeTemp ()) {
358405 return false ;
406+ }
359407
360408 // Make a fifo
361- if (not makeFifo ())
409+ if (not makeFifo ()) {
362410 return false ;
411+ }
363412
364413 // Build command line, rediret stdout to our fifo and put
365414 std::string cmd = makeCmdLine ();
@@ -390,8 +439,9 @@ Bool_t GeneratorHepMC::Init()
390439 //
391440 // However, here we will assume system local files. If _any_ of
392441 // the listed files do not exist, then we fail.
393- if (not ensureFiles ())
442+ if (not ensureFiles ()) {
394443 return false ;
444+ }
395445 }
396446
397447 // Create reader for current (first) file
0 commit comments