Skip to content

Commit d9a2a5b

Browse files
preghenellaktf
authored andcommitted
Changes related to HepMC3 upgrade to 3.2.2
1 parent 64f5995 commit d9a2a5b

5 files changed

Lines changed: 109 additions & 3 deletions

File tree

Generators/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ if(HepMC_FOUND)
2020
set(hepmcTarget MC::HepMC)
2121
endif()
2222

23+
if(HepMC3_FOUND)
24+
set(hepmcTarget MC::HepMC3)
25+
endif()
26+
2327
o2_add_library(Generators
2428
SOURCES src/Generator.cxx
2529
src/Trigger.cxx
@@ -40,6 +44,7 @@ o2_add_library(Generators
4044
$<$<BOOL:${pythia_FOUND}>:src/GeneratorPythia8Param.cxx>
4145
$<$<BOOL:${pythia_FOUND}>:src/DecayerPythia8Param.cxx>
4246
$<$<BOOL:${HepMC_FOUND}>:src/GeneratorHepMC.cxx>
47+
$<$<BOOL:${HepMC3_FOUND}>:src/GeneratorHepMC.cxx>
4348
PUBLIC_LINK_LIBRARIES FairRoot::Base O2::SimConfig O2::CommonUtils
4449
O2::SimulationDataFormat ${pythia6Target} ${pythiaTarget} ${hepmcTarget}
4550
FairRoot::Gen
@@ -55,6 +60,11 @@ endif()
5560

5661
if(HepMC_FOUND)
5762
target_compile_definitions(${targetName} PUBLIC GENERATORS_WITH_HEPMC3)
63+
target_compile_definitions(${targetName} PUBLIC GENERATORS_WITH_HEPMC3_DEPRECATED)
64+
endif()
65+
66+
if(HepMC3_FOUND)
67+
target_compile_definitions(${targetName} PUBLIC GENERATORS_WITH_HEPMC3)
5868
endif()
5969

6070
set(headers
@@ -89,6 +99,10 @@ if(HepMC_FOUND)
8999
list(APPEND headers include/Generators/GeneratorHepMC.h)
90100
endif()
91101

102+
if(HepMC3_FOUND)
103+
list(APPEND headers include/Generators/GeneratorHepMC.h)
104+
endif()
105+
92106
o2_target_root_dictionary(Generators HEADERS ${headers})
93107

94108
o2_add_test_root_macro(share/external/extgen.C

Generators/include/Generators/GeneratorHepMC.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,21 @@
1616
#include "Generators/Generator.h"
1717
#include <fstream>
1818

19+
#ifdef GENERATORS_WITH_HEPMC3_DEPRECATED
1920
namespace HepMC
2021
{
2122
class Reader;
2223
class GenEvent;
2324
class FourVector;
2425
} // namespace HepMC
26+
#else
27+
namespace HepMC3
28+
{
29+
class Reader;
30+
class GenEvent;
31+
class FourVector;
32+
} // namespace HepMC3
33+
#endif
2534

2635
namespace o2
2736
{
@@ -60,14 +69,23 @@ class GeneratorHepMC : public Generator
6069
Bool_t importParticles() override;
6170

6271
/** methods **/
72+
#ifdef GENERATORS_WITH_HEPMC3_DEPRECATED
6373
const HepMC::FourVector getBoostedVector(const HepMC::FourVector& vector, Double_t boost);
74+
#else
75+
const HepMC3::FourVector getBoostedVector(const HepMC3::FourVector& vector, Double_t boost);
76+
#endif
6477

6578
/** HepMC interface **/
6679
std::ifstream mStream; //!
6780
std::string mFileName;
6881
Int_t mVersion;
82+
#ifdef GENERATORS_WITH_HEPMC3_DEPRECATED
6983
HepMC::Reader* mReader; //!
7084
HepMC::GenEvent* mEvent; //!
85+
#else
86+
HepMC3::Reader* mReader; //!
87+
HepMC3::GenEvent* mEvent; //!
88+
#endif
7189

7290
ClassDefOverride(GeneratorHepMC, 1);
7391

Generators/src/GeneratorHepMC.cxx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
/// \author R+Preghenella - August 2017
1212

13+
#ifdef GENERATORS_WITH_HEPMC3_DEPRECATED
14+
1315
#include "Generators/GeneratorHepMC.h"
1416
#include "HepMC/ReaderAscii.h"
1517
#include "HepMC/ReaderAsciiHepMC2.h"
@@ -27,6 +29,19 @@
2729
#undef DEBUG
2830
#endif
2931

32+
#else
33+
34+
#include "Generators/GeneratorHepMC.h"
35+
#include "HepMC3/ReaderAscii.h"
36+
#include "HepMC3/ReaderAsciiHepMC2.h"
37+
#include "HepMC3/GenEvent.h"
38+
#include "HepMC3/GenParticle.h"
39+
#include "HepMC3/GenVertex.h"
40+
#include "HepMC3/FourVector.h"
41+
#include "TParticle.h"
42+
43+
#endif
44+
3045
#include "FairLogger.h"
3146
#include "FairPrimaryGenerator.h"
3247
#include <cmath>
@@ -44,7 +59,11 @@ GeneratorHepMC::GeneratorHepMC()
4459
{
4560
/** default constructor **/
4661

62+
#ifdef GENERATORS_WITH_HEPMC3_DEPRECATED
4763
mEvent = new HepMC::GenEvent();
64+
#else
65+
mEvent = new HepMC3::GenEvent();
66+
#endif
4867
mInterface = reinterpret_cast<void*>(mEvent);
4968
mInterfaceName = "hepmc";
5069
}
@@ -56,7 +75,11 @@ GeneratorHepMC::GeneratorHepMC(const Char_t* name, const Char_t* title)
5675
{
5776
/** constructor **/
5877

78+
#ifdef GENERATORS_WITH_HEPMC3_DEPRECATED
5979
mEvent = new HepMC::GenEvent();
80+
#else
81+
mEvent = new HepMC3::GenEvent();
82+
#endif
6083
mInterface = reinterpret_cast<void*>(mEvent);
6184
mInterfaceName = "hepmc";
6285
}
@@ -89,7 +112,11 @@ Bool_t GeneratorHepMC::generateEvent()
89112
if (mReader->failed())
90113
return kFALSE;
91114
/** set units to desired output **/
115+
#ifdef GENERATORS_WITH_HEPMC3_DEPRECATED
92116
mEvent->set_units(HepMC::Units::GEV, HepMC::Units::MM);
117+
#else
118+
mEvent->set_units(HepMC3::Units::GEV, HepMC3::Units::MM);
119+
#endif
93120

94121
/** success **/
95122
return kTRUE;
@@ -163,10 +190,18 @@ Bool_t GeneratorHepMC::Init()
163190
switch (mVersion) {
164191
case 2:
165192
mStream.close();
193+
#ifdef GENERATORS_WITH_HEPMC3_DEPRECATED
166194
mReader = new HepMC::ReaderAsciiHepMC2(mFileName);
195+
#else
196+
mReader = new HepMC3::ReaderAsciiHepMC2(mFileName);
197+
#endif
167198
break;
168199
case 3:
200+
#ifdef GENERATORS_WITH_HEPMC3_DEPRECATED
169201
mReader = new HepMC::ReaderAscii(mStream);
202+
#else
203+
mReader = new HepMC3::ReaderAscii(mStream);
204+
#endif
170205
break;
171206
default:
172207
LOG(FATAL) << "Unsupported HepMC version: " << mVersion << std::endl;

dependencies/FindHepMC3.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright CERN and copyright holders of ALICE O2. This software is distributed
2+
# under the terms of the GNU General Public License v3 (GPL Version 3), copied
3+
# verbatim in the file "COPYING".
4+
#
5+
# See http://alice-o2.web.cern.ch/license for full licensing information.
6+
#
7+
# In applying this license CERN does not waive the privileges and immunities
8+
# granted to it by virtue of its status as an Intergovernmental Organization or
9+
# submit itself to any jurisdiction.
10+
11+
# use the HepMCConfig.cmake provided by the HepMC3 installation to create a
12+
# single target HepMC with the include directories and libraries we need
13+
14+
find_package(HepMC3 NO_MODULE)
15+
if(NOT HepMC3_FOUND)
16+
return()
17+
endif()
18+
19+
add_library(HepMC3 IMPORTED INTERFACE)
20+
21+
set_target_properties(HepMC3
22+
PROPERTIES
23+
INTERFACE_LINK_LIBRARIES "${HEPMC3_LIBRARIES}"
24+
INTERFACE_INCLUDE_DIRECTORIES "${HEPMC3_INCLUDE_DIR}")
25+
26+
# Promote the imported target to global visibility (so we can alias it)
27+
set_target_properties(HepMC3 PROPERTIES IMPORTED_GLOBAL TRUE)
28+
add_library(MC::HepMC3 ALIAS HepMC3)

dependencies/O2SimulationDependencies.cmake

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,19 @@ set_package_properties(VGM PROPERTIES TYPE ${mcPackageRequirement})
6969
find_package(HepMC MODULE)
7070
set_package_properties(HepMC
7171
PROPERTIES
72-
TYPE ${mcPackageRequirement} DESCRIPTION
73-
"the HepMC3 event record package")
72+
TYPE OPTIONAL DESCRIPTION
73+
"the HepMC3 event record package (deprecated old find_package call)")
74+
75+
find_package(HepMC3 MODULE)
76+
set_package_properties(HepMC3
77+
PROPERTIES
78+
TYPE OPTIONAL DESCRIPTION
79+
"the HepMC3 event record package")
80+
81+
if(HepMC_FOUND AND HepMC3_FOUND)
82+
message(ERROR "Both HepMC3 packages have been found, something is wrong")
83+
endif()
84+
7485
set(doBuildSimulation OFF)
7586

7687
if(pythia_FOUND
@@ -79,7 +90,7 @@ if(pythia_FOUND
7990
AND Geant4_FOUND
8091
AND Geant4VMC_FOUND
8192
AND VGM_FOUND
82-
AND HepMC_FOUND)
93+
AND (HepMC_FOUND OR HepMC3_FOUND))
8394
set(doBuildSimulation ON)
8495
endif()
8596

0 commit comments

Comments
 (0)