xcoll 0.6.1__py3-none-any.whl → 0.6.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of xcoll might be problematic. Click here for more details.

Files changed (90) hide show
  1. xcoll/__init__.py +1 -1
  2. xcoll/general.py +1 -1
  3. xcoll/prebuild_kernels/__init__.py +7 -0
  4. xcoll/prebuild_kernels/element_inits.py +6 -0
  5. xcoll/prebuild_kernels/elements.py +20 -0
  6. xcoll/rf_sweep.py +158 -173
  7. {xcoll-0.6.1.dist-info → xcoll-0.6.3.dist-info}/METADATA +18 -13
  8. xcoll-0.6.3.dist-info/RECORD +65 -0
  9. {xcoll-0.6.1.dist-info → xcoll-0.6.3.dist-info}/WHEEL +1 -1
  10. xcoll-0.6.3.dist-info/entry_points.txt +3 -0
  11. xcoll/__init__.py.orig +0 -26
  12. xcoll/general.py.orig +0 -20
  13. xcoll/initial_distribution.py.orig +0 -256
  14. xcoll/scattering_routines/fluka/flukaio/.git +0 -1
  15. xcoll/scattering_routines/fluka/flukaio/.gitignore +0 -2
  16. xcoll/scattering_routines/fluka/flukaio/CMakeLists.txt +0 -18
  17. xcoll/scattering_routines/fluka/flukaio/ComponentMakefile +0 -192
  18. xcoll/scattering_routines/fluka/flukaio/Makefile +0 -144
  19. xcoll/scattering_routines/fluka/flukaio/README +0 -26
  20. xcoll/scattering_routines/fluka/flukaio/doc/Doxyfile +0 -1551
  21. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO.asciidoc +0 -1054
  22. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO.epub +0 -0
  23. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO.html +0 -1607
  24. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO.pdf +0 -0
  25. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO__1.png +0 -0
  26. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO__2.png +0 -0
  27. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO__3.png +0 -0
  28. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO__4.png +0 -0
  29. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO__5.png +0 -0
  30. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO__6.png +0 -0
  31. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO__7.png +0 -0
  32. xcoll/scattering_routines/fluka/flukaio/doc/Makefile +0 -8
  33. xcoll/scattering_routines/fluka/flukaio/doc/docbook.xsl +0 -1690
  34. xcoll/scattering_routines/fluka/flukaio/include/Connection.h +0 -79
  35. xcoll/scattering_routines/fluka/flukaio/include/FlukaIO.h +0 -58
  36. xcoll/scattering_routines/fluka/flukaio/include/FlukaIOServer.h +0 -33
  37. xcoll/scattering_routines/fluka/flukaio/include/FortranFlukaIO.h +0 -277
  38. xcoll/scattering_routines/fluka/flukaio/include/Message.h +0 -89
  39. xcoll/scattering_routines/fluka/flukaio/include/ParticleInfo.h +0 -76
  40. xcoll/scattering_routines/fluka/flukaio/lib/libFlukaIO64.a +0 -0
  41. xcoll/scattering_routines/fluka/flukaio/lib/libFlukaIO64.so +0 -0
  42. xcoll/scattering_routines/fluka/flukaio/samples/ClientTest.c +0 -156
  43. xcoll/scattering_routines/fluka/flukaio/samples/ServerTest.c +0 -123
  44. xcoll/scattering_routines/fluka/flukaio/samples/fclient.f +0 -149
  45. xcoll/scattering_routines/fluka/flukaio/samples/fserver.f +0 -118
  46. xcoll/scattering_routines/fluka/flukaio/src/Connection.c +0 -264
  47. xcoll/scattering_routines/fluka/flukaio/src/Connection.d +0 -69
  48. xcoll/scattering_routines/fluka/flukaio/src/Connection.o +0 -0
  49. xcoll/scattering_routines/fluka/flukaio/src/FlukaIO.c +0 -211
  50. xcoll/scattering_routines/fluka/flukaio/src/FlukaIO.d +0 -46
  51. xcoll/scattering_routines/fluka/flukaio/src/FlukaIO.o +0 -0
  52. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOHandshake.c +0 -45
  53. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOHandshake.d +0 -29
  54. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOHandshake.h +0 -17
  55. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOHandshake.o +0 -0
  56. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOServer.c +0 -84
  57. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOServer.d +0 -70
  58. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOServer.o +0 -0
  59. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOServer_private.h +0 -22
  60. xcoll/scattering_routines/fluka/flukaio/src/FlukaIO_private.h +0 -16
  61. xcoll/scattering_routines/fluka/flukaio/src/FortranFlukaIO.c +0 -533
  62. xcoll/scattering_routines/fluka/flukaio/src/FortranFlukaIO.d +0 -40
  63. xcoll/scattering_routines/fluka/flukaio/src/FortranFlukaIO.o +0 -0
  64. xcoll/scattering_routines/fluka/flukaio/src/NetIO.c +0 -304
  65. xcoll/scattering_routines/fluka/flukaio/src/NetIO.d +0 -66
  66. xcoll/scattering_routines/fluka/flukaio/src/NetIO.h +0 -30
  67. xcoll/scattering_routines/fluka/flukaio/src/NetIO.o +0 -0
  68. xcoll/scattering_routines/fluka/flukaio/src/tags +0 -167
  69. xcoll/scattering_routines/fluka/flukaio/tests/AllTests.cpp +0 -8
  70. xcoll/scattering_routines/fluka/flukaio/tests/CommonTest.h +0 -10
  71. xcoll/scattering_routines/fluka/flukaio/tests/ConnectionTest.cpp +0 -99
  72. xcoll/scattering_routines/fluka/flukaio/tests/FlukaIOServerTest.cpp +0 -104
  73. xcoll/scattering_routines/fluka/flukaio/tests/FlukaIOTest.cpp +0 -439
  74. xcoll/scattering_routines/fluka/flukaio/tests/FortranFlukaIOTest.cpp +0 -682
  75. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeConnection.c +0 -19
  76. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeConnection.h +0 -16
  77. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeFlukaIO.c +0 -74
  78. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeFlukaIO.h +0 -50
  79. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeFlukaIOHandshake.c +0 -16
  80. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeFlukaIOHandshake.h +0 -20
  81. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeFlukaIOServer.c +0 -12
  82. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeFlukaIOServer.h +0 -18
  83. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeFortranFlukaIO.h +0 -19
  84. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeNetIO.c +0 -80
  85. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeNetIO.h +0 -35
  86. xcoll-0.6.1.dist-info/LICENSE +0 -201
  87. xcoll-0.6.1.dist-info/NOTICE +0 -2
  88. xcoll-0.6.1.dist-info/RECORD +0 -138
  89. /LICENSE → /xcoll-0.6.3.dist-info/LICENSE +0 -0
  90. /NOTICE → /xcoll-0.6.3.dist-info/NOTICE +0 -0
@@ -1,256 +0,0 @@
1
- # copyright ############################### #
2
- # This file is part of the Xcoll package. #
3
- # Copyright (c) CERN, 2025. #
4
- # ######################################### #
5
-
6
- import numpy as np
7
- from warnings import warn
8
-
9
- import xtrack as xt
10
- import xobjects as xo
11
- import xpart as xp
12
-
13
- <<<<<<< HEAD
14
- from .beam_elements import collimator_classes, EverestCrystal, Geant4Collimator
15
- =======
16
- from .beam_elements import collimator_classes, BaseCrystal
17
- >>>>>>> main
18
-
19
-
20
- def generate_pencil_on_collimator(line, name, num_particles, *, side='+-', pencil_spread=1e-6,
21
- impact_parameter=0, sigma_z=7.61e-2, twiss=None, longitudinal=None,
22
- longitudinal_betatron_cut=None, _capacity=None, tw=None,
23
- _longitudinal_coords=None, **kwargs):
24
- """Generate a pencil beam on a collimator."""
25
-
26
- # Do some general checks
27
- if not line._has_valid_tracker():
28
- raise ValueError("Please build tracker before generating pencil distribution!")
29
- coll = line[name]
30
- if not isinstance(coll, tuple(collimator_classes)):
31
- raise ValueError("Need to provide a valid collimator!")
32
- if coll.optics is None:
33
- raise ValueError("Need to assign optics to collimators before generating pencil distribution!")
34
- num_particles = int(num_particles)
35
- if len(line.get_elements_of_type(Geant4Collimator)[0]) > 0:
36
- kwargs.setdefault('_capacity', 2*num_particles)
37
-
38
- # Define the plane
39
- angle = coll.angle
40
- if abs(np.mod(angle-90,180)-90) < 1e-6:
41
- plane = 'x'
42
- transv_plane = 'y'
43
- elif abs(np.mod(angle,180)-90) < 1e-6:
44
- plane = 'y'
45
- transv_plane = 'x'
46
- else:
47
- raise NotImplementedError("Pencil beam on a skew collimator not yet supported!")
48
-
49
- if coll.side == 'left':
50
- if side == '-':
51
- raise ValueError("Cannot generate a pencil on the right jaw of a left-"
52
- "sided collimator!")
53
- side = '+'
54
- if coll.side == 'right':
55
- if side == '+':
56
- raise ValueError("Cannot generate a pencil on the left jaw of a right-"
57
- "sided collimator!")
58
- side = '-'
59
-
60
- if tw is not None:
61
- warn("The argument tw is deprecated. Please use twiss instead.", FutureWarning)
62
- if twiss is None:
63
- twiss = tw
64
-
65
- if twiss is None:
66
- twiss = line.twiss()
67
-
68
- # Longitudinal plane
69
- if _longitudinal_coords:
70
- zeta = _longitudinal_coords[0]
71
- delta = _longitudinal_coords[1]
72
-
73
- else:
74
- zeta, delta = _generate_longitudinal_dist(line, num_particles, sigma_z, longitudinal)
75
-
76
- # Generate 4D coordinates
77
- # TODO: there is some looping in the calculation here and in xpart. Can it be improved?
78
- if side == '+-':
79
- num_plus = int(num_particles/2)
80
- num_min = int(num_particles - num_plus)
81
- zeta_plus = zeta[:num_plus] if hasattr(zeta, '__iter__') else zeta
82
- zeta_min = zeta[num_plus:] if hasattr(zeta, '__iter__') else zeta
83
- delta_plus = delta[:num_plus] if hasattr(delta, '__iter__') else delta
84
- delta_min = delta[num_plus:] if hasattr(delta, '__iter__') else delta
85
- if _capacity:
86
- _capacity_plus = int(_capacity/2)
87
- _capacity_min = int(_capacity - _capacity_plus)
88
- else:
89
- _capacity_plus = None
90
- _capacity_min = None
91
- part_plus = generate_pencil_on_collimator(line=line, name=name, num_particles=num_plus,
92
- impact_parameter=impact_parameter, _capacity=_capacity_plus,
93
- side='+', pencil_spread=pencil_spread, twiss=twiss,
94
- _longitudinal_coords=[zeta_plus, delta_plus],
95
- **kwargs)
96
- part_min = generate_pencil_on_collimator(line=line, name=name, num_particles=num_min,
97
- impact_parameter=impact_parameter, _capacity=_capacity_min,
98
- side='-', pencil_spread=pencil_spread, twiss=twiss,
99
- _longitudinal_coords=[zeta_min, delta_min],
100
- **kwargs)
101
-
102
- part = xt.Particles.merge([part_plus, part_min])
103
- part.start_tracking_at_element = part_plus.start_tracking_at_element
104
- assert part.start_tracking_at_element == part_min.start_tracking_at_element
105
- return part
106
-
107
- pencil, p_pencil, transverse_norm, p_transverse_norm, is_converging, at_element = \
108
- _generate_4D_pencil_one_jaw(line, name, num_particles, plane, side,
109
- impact_parameter, pencil_spread, twiss, **kwargs)
110
-
111
- # Build the particles
112
- if plane == 'x':
113
- part = xp.build_particles(
114
- x=pencil, px=p_pencil, y_norm=transverse_norm, py_norm=p_transverse_norm,
115
- zeta=zeta, delta=delta, nemitt_x=coll.nemitt_x, nemitt_y=coll.nemitt_y,
116
- line=line, at_element=at_element, _context=coll._buffer.context, **kwargs
117
- )
118
- else:
119
- part = xp.build_particles(
120
- x_norm=transverse_norm, px_norm=p_transverse_norm, y=pencil, py=p_pencil,
121
- zeta=zeta, delta=delta, nemitt_x=coll.nemitt_x, nemitt_y=coll.nemitt_y,
122
- line=line, at_element=at_element, _context=coll._buffer.context, **kwargs
123
- )
124
-
125
- part._init_random_number_generator()
126
-
127
- if not is_converging:
128
- dri = xt.Drift(length=-coll.length)
129
- dri.track(part)
130
- part.start_tracking_at_element -= 1
131
- part.at_element -= 1
132
-
133
- return part
134
-
135
-
136
- def generate_delta_from_dispersion(line, at_element, *, plane, position_mm, nemitt_x, nemitt_y,
137
- twiss=None, betatron_cut=0, match_at_front=True):
138
- if line.tracker is None:
139
- raise ValueError("Need to build tracker first!")
140
- if not hasattr(betatron_cut, '__iter__'):
141
- if hasattr(position_mm, '__iter__'):
142
- betatron_cut = np.full_like(position_mm, betatron_cut)
143
- elif not hasattr(position_mm, '__iter__'):
144
- position_mm = np.full_like(betatron_cut, position_mm)
145
- elif len(position_mm) != len(betatron_cut):
146
- raise ValueError
147
- if plane not in ['x', 'y']:
148
- raise ValueError("The variable 'plane' needs to be either 'x' or 'y'!")
149
-
150
- if twiss is None:
151
- twiss = line.twiss()
152
-
153
- beam_sizes = twiss.get_beam_covariance(nemitt_x=nemitt_x, nemitt_y=nemitt_y)
154
- beam_sizes = beam_sizes.rows[at_element:f'{at_element}>>1'][f'sigma_{plane}']
155
- sigma = beam_sizes[0] if match_at_front else beam_sizes[1]
156
- delta = (position_mm - betatron_cut*sigma - twiss.rows[at_element][plane])
157
- delta /= twiss.rows[at_element][f'd{plane}']
158
-
159
- return delta
160
-
161
-
162
- def _generate_4D_pencil_one_jaw(line, name, num_particles, plane, side, impact_parameter,
163
- pencil_spread, twiss=None, _capacity=None, **kwargs):
164
- coll = line[name]
165
- beam_sizes = twiss.get_beam_covariance(nemitt_x=coll.nemitt_x, nemitt_y=coll.nemitt_y)
166
-
167
- # Is it converging or diverging?
168
- # TODO: dispersion might change this
169
- # TODO: skew collimators
170
- tolerance_tilt = 1e-12 # 0.1 urad tolerance on jaw tilt => we prioritise converging
171
- divergence = coll.divergence
172
- if side == '+':
173
- if isinstance(coll, BaseCrystal):
174
- # A pencil on the crystal should always be upstream
175
- is_converging = True
176
- pencil_pos = coll.jaw_U + impact_parameter
177
- else:
178
- betatron_angle = coll.gap_L * divergence
179
- is_converging = coll.tilt_L + tolerance_tilt >= betatron_angle
180
- print(f"Left jaw of collimator {name} is {'con' if is_converging else 'di'}verging.")
181
- if is_converging:
182
- pencil_pos = coll.jaw_LU + impact_parameter
183
- else:
184
- pencil_pos = coll.jaw_LD + impact_parameter
185
- elif side == '-':
186
- if isinstance(coll, BaseCrystal):
187
- # A pencil on the crystal should always be upstream
188
- is_converging = True
189
- pencil_pos = coll.jaw_U - impact_parameter
190
- else:
191
- betatron_angle = coll.gap_R * divergence
192
- is_converging = coll.tilt_R - tolerance_tilt <= betatron_angle
193
- print(f"Right jaw of collimator {name} is {'con' if is_converging else 'di'}verging.")
194
- if is_converging:
195
- pencil_pos = coll.jaw_RU - impact_parameter
196
- else:
197
- pencil_pos = coll.jaw_RD - impact_parameter
198
- else:
199
- raise ValueError(f"Sinde {side} not supported in _generate_4D_pencil_one_jaw!")
200
-
201
- if is_converging:
202
- # pencil at front of jaw
203
- sigma = beam_sizes.rows[name:f'{name}>>1'][f'sigma_{plane}'][0]
204
- tw_at_s = twiss.rows[name]
205
- at_element = name
206
- else:
207
- # pencil at back of jaw
208
- sigma = beam_sizes.rows[name:f'{name}>>1'][f'sigma_{plane}'][1]
209
- tw_at_s = twiss.rows[f'{name}>>1']
210
- at_element = line.element_names[line.element_names.index(name)+1]
211
-
212
- dr_sigmas = pencil_spread/sigma
213
-
214
- # Collimator plane: generate pencil distribution
215
- pencil, p_pencil = xp.generate_2D_pencil_with_absolute_cut(
216
- num_particles, plane=plane, absolute_cut=pencil_pos, line=line,
217
- dr_sigmas=dr_sigmas, nemitt_x=coll.nemitt_x, nemitt_y=coll.nemitt_y,
218
- at_element=at_element, side=side, twiss=tw_at_s, **kwargs
219
- )
220
-
221
- # Other plane: generate gaussian distribution in normalized coordinates
222
- transverse_norm = np.random.normal(size=num_particles)
223
- p_transverse_norm = np.random.normal(size=num_particles)
224
-
225
- return pencil, p_pencil, transverse_norm, p_transverse_norm, is_converging, at_element
226
-
227
-
228
- def _generate_longitudinal_dist(line, num_particles, sigma_z, longitudinal):
229
- # TODO: make this more general, make this better
230
- if longitudinal is None:
231
- return 0, 0
232
- elif longitudinal == 'matched_dispersion':
233
- raise NotImplementedError
234
- # if longitudinal_betatron_cut is None:
235
- # cut = 0
236
- # else:
237
- # cut = np.random.uniform(-longitudinal_betatron_cut, longitudinal_betatron_cut,
238
- # num_particles)
239
- # delta = generate_delta_from_dispersion(line, name, plane=plane, position_mm=pencil,
240
- # nemitt_x=nemitt_x, nemitt_y=nemitt_y, twiss=tw,
241
- # betatron_cut=cut, match_at_front=is_converging)
242
- # zeta = 0
243
- elif longitudinal == 'bucket':
244
- return xp.generate_longitudinal_coordinates(
245
- num_particles=num_particles, distribution='gaussian', sigma_z=sigma_z, line=line
246
- )
247
- elif not hasattr(longitudinal, '__iter__'):
248
- raise ValueError
249
- elif len(longitudinal) != 2:
250
- raise ValueError
251
- elif isinstance(longitudinal, str):
252
- raise ValueError
253
- elif isinstance(longitudinal, dict):
254
- return longitudinal['zeta'], longitudinal['delta']
255
- else:
256
- return longitudinal[0], longitudinal[1]
@@ -1 +0,0 @@
1
- gitdir: ../../../../.git/modules/xcoll/scattering_routines/fluka/flukaio
@@ -1,2 +0,0 @@
1
- lib
2
- src/*.d
@@ -1,18 +0,0 @@
1
- PROJECT(FLUKA_IO)
2
- cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
3
-
4
- SET(LIBFLUKAIO_SOURCES src/Connection.c src/FlukaIO.c src/FlukaIOHandshake.c src/FlukaIOServer.c src/FortranFlukaIO.c src/NetIO.c)
5
-
6
- include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
7
-
8
- add_library(flukaIO STATIC ${LIBFLUKAIO_SOURCES})
9
-
10
- if(${CMAKE_SYSTEM_PROCESSOR} MATCHES AMD64 OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64 OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES i686)
11
- if(32BIT)
12
- target_compile_options(flukaIO PRIVATE -m32)
13
- endif(32BIT)
14
-
15
- if(64BIT)
16
- target_compile_options(flukaIO PRIVATE -m64)
17
- endif(64BIT)
18
- endif()
@@ -1,192 +0,0 @@
1
- #---------
2
- #
3
- # ComponentMakefile
4
- #
5
- # Include this file in your makefile
6
- # It makes
7
- # A static library
8
- # A test executable
9
- #
10
- # The necessary parameters are shown in
11
- # ComponentMakefileExampleParameters
12
- #
13
- # Inputs
14
- # SRC_FILES - Specific source files to build into library
15
- # SRC_DIRS - Directories od source file to built into the library
16
- # TEST_SRC - unit test code build into the unit test runner
17
- # MOCKS_SRC - mock objects build into the test runner
18
- # INCLUDES - List of -I files
19
- # CPPUTEST_CXXFLAGS - flags for the C++ compiler
20
- # CPPUTEST_CPPFLAGS - flags for the C++ AND C compiler
21
- # CPPUTEST_CFLAGS - C complier
22
- # CPPUTEST_LDFLAGS - Linker flags
23
- # TARGET_LIB - the created library
24
- # TEST_TARGET - the created test executable
25
- # OTHER_MAKEFILE_TO_INCLUDE - a hook to use this makefile to make
26
- # other targets. Like CSlim, which is part of fitnesse
27
- #----------
28
-
29
- #Helper Functions
30
- get_src_from_dir = $(wildcard $1/*.cpp) $(wildcard $1/*.c)
31
- get_dirs_from_dirspec = $(wildcard $1)
32
- get_src_from_dir_list = $(foreach dir, $1, $(call get_src_from_dir,$(dir)))
33
- src_to_o = $(subst .c,.o, $(subst .cpp,.o,$1))
34
- src_to_d = $(subst .c,.d, $(subst .cpp,.d,$1))
35
- #move_file_location = $(patsubst %.d,build/%.d, $1)
36
- src_to = $(subst .c,$1, $(subst .cpp,$1,$2))
37
-
38
- #Derived
39
- STUFF_TO_CLEAN += $(TEST_TARGET) $(TEST_TARGET).exe $(TARGET_LIB)
40
-
41
- SRC += $(call get_src_from_dir_list, $(SRC_DIRS)) $(SRC_FILES)
42
- OBJ = $(call src_to_o,$(SRC))
43
- STUFF_TO_CLEAN += $(OBJ)
44
-
45
- TEST_SRC = $(call get_src_from_dir_list, $(TEST_SRC_DIRS))
46
- TEST_OBJS = $(call src_to_o,$(TEST_SRC))
47
- STUFF_TO_CLEAN += $(TEST_OBJS)
48
-
49
- MOCKS_SRC = $(call get_src_from_dir_list, $(MOCKS_SRC_DIRS))
50
- MOCKS_OBJS = $(call src_to_o,$(MOCKS_SRC))
51
- STUFF_TO_CLEAN += $(MOCKS_OBJS)
52
-
53
- ALL_SRC = $(SRC) $(TEST_SRC) $(MOCKS_SRC)
54
-
55
- #Test coverage with gcov
56
- GCOV_OUTPUT = gcov_output.txt
57
- GCOV_REPORT = gcov_report.txt
58
- GCOV_ERROR = gcov_error.txt
59
- GCOV_GCDA_FILES = $(call src_to,.gcda, $(ALL_SRC))
60
- GCOV_GCNO_FILES = $(call src_to,.gcno, $(ALL_SRC))
61
- TEST_OUTPUT = $(TEST_TARGET).txt
62
- STUFF_TO_CLEAN += \
63
- $(GCOV_OUTPUT)\
64
- $(GCOV_REPORT)\
65
- $(GCOV_ERROR)\
66
- $(GCOV_GCDA_FILES)\
67
- $(GCOV_GCNO_FILES)\
68
- $(TEST_OUTPUT)
69
-
70
-
71
- #Other stuff needed
72
- CPPUTEST_LIB = $(CPPUTEST_HOME)/lib/libCppUTest.a
73
-
74
- CPPUTEST_CPPFLAGS += $(INCLUDES) $(GCOVFLAGS)
75
-
76
- #The gcda files for gcov need to be deleted before each run
77
- #To avoid annoying messages.
78
- GCOV_CLEAN = $(SILENCE)rm -f $(GCOV_GCDA_FILES) $(GCOV_OUTPUT) $(GCOV_REPORT) $(GCOV_ERROR)
79
- RUN_TEST_TARGET = $(SILENCE) $(GCOV_CLEAN) ; echo "Running $(TEST_TARGET)"; ./$(TEST_TARGET)
80
-
81
- ifneq "$(OTHER_MAKEFILE_TO_INCLUDE)" ""
82
- -include $(OTHER_MAKEFILE_TO_INCLUDE)
83
- endif
84
-
85
- ifneq "$(MAP_FILE)" ""
86
- CPPUTEST_LDFLAGS += -Wl,-map,$(MAP_FILE)
87
- endif
88
-
89
- INCLUDES_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(INCLUDE_DIRS))
90
- INCLUDES += $(foreach dir, $(INCLUDES_DIRS_EXPANDED), -I$(dir))
91
- MOCK_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(MOCKS_SRC_DIRS))
92
- INCLUDES += $(foreach dir, $(MOCK_DIRS_EXPANDED), -I$(dir))
93
-
94
-
95
- DEP_FILES = $(call src_to_d, $(ALL_SRC))
96
- STUFF_TO_CLEAN += $(DEP_FILES) + $(PRODUCTION_CODE_START) + $(PRODUCTION_CODE_END)
97
- STUFF_TO_CLEAN += $(STDLIB_CODE_START) + $(MAP_FILE) + cpputest_*.xml junit_run_output
98
-
99
- # We'll use the CPPUTEST_CFLAGS etc so that you can override AND add to the CppUTest flags
100
- CFLAGS = $(CPPUTEST_CFLAGS) $(CPPUTEST_ADDITIONAL_CFLAGS)
101
- CPPFLAGS = $(CPPUTEST_CPPFLAGS) $(CPPUTEST_ADDITIONAL_CPPFLAGS)
102
- CXXFLAGS = $(CPPUTEST_CXXFLAGS) $(CPPUTEST_ADDITIONAL_CXXFLAGS)
103
- LDFLAGS = $(CPPUTEST_LDFLAGS) $(CPPUTEST_ADDITIONAL_LDFLAGS)
104
-
105
- # Targets
106
- .PHONY: all
107
- all: $(TEST_TARGET)
108
- $(RUN_TEST_TARGET)
109
-
110
- .PHONY: all_no_tests
111
- all_no_tests: $(TEST_TARGET)
112
-
113
- .PHONY: flags
114
- flags:
115
- $(SILENCE)echo Compile with these flags:
116
- $(SILENCE)for f in $(CPPFLAGS) ; do \
117
- echo " C++ $$f" ; \
118
- done
119
- $(SILENCE)for f in $(CFLAGS) ; do \
120
- echo " C $$f" ; \
121
- done
122
- $(SILENCE)for f in $(LDFLAGS) ; do \
123
- echo " LD $$f" ; \
124
- done
125
- $(SILENCE)for f in $(ARFLAGS) ; do \
126
- echo " AR $$f" ; \
127
- done
128
-
129
-
130
- $(TEST_TARGET): $(TEST_OBJS) $(MOCKS_OBJS) $(PRODUCTION_CODE_START) $(TARGET_LIB) $(USER_LIBS) $(PRODUCTION_CODE_END) $(CPPUTEST_LIB) $(STDLIB_CODE_START)
131
- $(SILENCE)echo Linking $@
132
- $(SILENCE)echo command $(LINK.o) -o $@ $^ $(LD_LIBRARIES)
133
- $(SILENCE)$(LINK.o) -o $@ $^ $(LD_LIBRARIES)
134
-
135
- $(TARGET_LIB): $(OBJ)
136
- $(SILENCE)echo Building archive $@
137
- $(SILENCE)mkdir -p lib
138
- $(SILENCE)echo command $(AR) $(ARFLAGS) $@ $^
139
- $(SILENCE)$(AR) $(ARFLAGS) $@ $^
140
- $(SILENCE)ranlib $@
141
-
142
- test: $(TEST_TARGET)
143
- $(RUN_TEST_TARGET) | tee $(TEST_OUTPUT)
144
-
145
- vtest: $(TEST_TARGET)
146
- $(RUN_TEST_TARGET) -v | tee $(TEST_OUTPUT)
147
-
148
- %.o: %.cpp
149
- @echo compiling $(notdir $<)
150
- $(SILENCE)echo command $(COMPILE.cpp) -M -MF $(subst .o,.d,$@) -MT "$@ $(subst .o,.d,$@)" $<
151
- $(SILENCE)$(COMPILE.cpp) -M -MF $(subst .o,.d,$@) -MT "$@ $(subst .o,.d,$@)" $<
152
- $(SILENCE)echo command $(COMPILE.cpp) $(OUTPUT_OPTION) $<
153
- $(SILENCE)$(COMPILE.cpp) $(OUTPUT_OPTION) $<
154
-
155
- %.o: %.c
156
- @echo compiling $(notdir $<)
157
- $(SILENCE)echo command $(COMPILE.c) -M -MF $(subst .o,.d,$@) -MT "$@ $(subst .o,.d,$@)" $<
158
- $(SILENCE)$(COMPILE.c) -M -MF $(subst .o,.d,$@) -MT "$@ $(subst .o,.d,$@)" $<
159
- $(SILENCE)echo command $(COMPILE.c) $(OUTPUT_OPTION) $<
160
- $(SILENCE)$(COMPILE.c) $(OUTPUT_OPTION) $<
161
-
162
- ifneq "$(MAKECMDGOALS)" "clean"
163
- -include $(DEP_FILES)
164
- endif
165
-
166
- .PHONY: clean
167
- clean:
168
- $(SILENCE)echo Making clean
169
- $(SILENCE)$(RM) -rf $(STUFF_TO_CLEAN)
170
- $(SILENCE)find . -name \*.gcov | xargs rm -f
171
-
172
- gcov: test
173
- $(SILENCE)for d in $(SRC_DIRS) ; do \
174
- gcov -o $$d $$d/*.c $$d/*.cpp >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \
175
- done
176
- $(CPPUTEST_HOME)/scripts/filterGcov.sh $(GCOV_OUTPUT) $(GCOV_ERROR) $(GCOV_REPORT) $(TEST_OUTPUT)
177
- cat $(GCOV_REPORT)
178
-
179
- .PHONEY: format
180
- format:
181
- $(CPPUTEST_HOME)/scripts/reformat.sh $(PROJECT_HOME_DIR)
182
-
183
- debug:
184
- echo Stuff to clean
185
- $(SILENCE)for f in $(STUFF_TO_CLEAN) ; do \
186
- echo "$$f" ; \
187
- done
188
- echo Includes
189
- $(SILENCE)for i in $(INCLUDES) ; do \
190
- echo "$$i" ; \
191
- done
192
-
@@ -1,144 +0,0 @@
1
- #Set this to @ to keep the makefile quiet
2
- SILENCE = @
3
-
4
- #---- Outputs ----#
5
- COMPONENT_NAME = FlukaIO
6
- TARGET_LIB = \
7
- lib/lib$(COMPONENT_NAME).a
8
- TARGET_SHARED_LIB = \
9
- lib/lib$(COMPONENT_NAME).so
10
-
11
- TEST_TARGET = \
12
- $(COMPONENT_NAME)_tests
13
-
14
- ifeq ($(BUILD64), Y)
15
- TARGET_SUFFIX = 64
16
- CPPUTEST_CPPFLAGS += -m64
17
- G77FLAGS += -m64
18
- endif
19
- ifeq ($(BUILD32), Y)
20
- TARGET_SUFFIX = 32
21
- CPPUTEST_CPPFLAGS += -m32
22
- CPPUTEST_LDFLAGS += -m32
23
- G77FLAGS += -m32
24
- endif
25
-
26
- COMPONENT_NAME = FlukaIO
27
- TARGET_LIB = \
28
- lib/lib$(COMPONENT_NAME)$(TARGET_SUFFIX).a
29
- TARGET_SHARED_LIB = \
30
- lib/lib$(COMPONENT_NAME)$(TARGET_SUFFIX).so
31
-
32
- TEST_TARGET = \
33
- $(COMPONENT_NAME)$(TARGET_SUFFIX)_tests
34
-
35
- #--- Inputs ----#
36
- PROJECT_HOME_DIR = .
37
- #CPPUTEST_HOME = /home/dsinuela/src/cpputest
38
- CPP_PLATFORM = Gcc
39
-
40
- # in case of Ubuntu 16.04, comment out -Werror
41
- WARNINGFLAGS = -Wall -Wswitch-default -Wswitch-enum -Werror
42
- #CPPUTEST_CFLAGS are set to override malloc and free to get memory leak detection in C programs
43
- #CPPUTEST_CFLAGS = -Dmalloc=cpputest_malloc -Dfree=cpputest_free
44
- #GCOVFLAGS = -fprofile-arcs -ftest-coverage
45
-
46
- CPPUTEST_CPPFLAGS += $(WARNINGFLAGS)
47
- CPPUTEST_CPPFLAGS += -g
48
- CPPUTEST_CPPFLAGS += -fpic
49
- #CPPUTEST_CPPFLAGS += -DFLUKAIO_NODELAY
50
-
51
- G77 = gfortran
52
- G77FLAGS += $(WARNINGFLAGS)
53
- G77FLAGS += -g
54
-
55
- #SRC_DIRS is a list of source directories that make up the target library
56
- #If test files are in these directories, their IMPORT_TEST_GROUPs need
57
- #to be included in main to force them to be linked in. By convention
58
- #put them into an AllTests.h file in each directory
59
- SRC_DIRS = \
60
- src
61
-
62
- #TEST_SRC_DIRS is a list of directories including
63
- # - A test main (AllTests.cpp by conventin)
64
- # - OBJ files in these directories are included in the TEST_TARGET
65
- # - Consequently - AllTests.h containing the IMPORT_TEST_GROUPS is not needed
66
- # -
67
- TEST_SRC_DIRS = \
68
- tests \
69
- tests/fakes
70
-
71
- #includes for all compiles
72
- INCLUDES =\
73
- -I.\
74
- -Iinclude
75
- # -I$(CPPUTEST_HOME)/include\
76
-
77
- #Flags to pass to ld
78
- USER_LIBS =
79
- LD_LIBRARIES += -lstdc++
80
-
81
- include ComponentMakefile
82
-
83
- all: $(TARGET_LIB) $(TARGET_SHARED_LIB)
84
-
85
- libs: $(TARGET_LIB) $(TARGET_SHARED_LIB)
86
-
87
- $(TARGET_SHARED_LIB): $(OBJ)
88
- $(SILENCE)echo Building archive $@
89
- $(SILENCE)$(CC) --version
90
- $(SILENCE)echo command $(CC) $(LDFLAGS) -shared -o $@ $^
91
- $(SILENCE)mkdir -p lib
92
- $(SILENCE)$(CC) $(LDFLAGS) -shared -o $@ $^
93
-
94
- STUFF_TO_CLEAN += $(TARGET_SHARED_LIB)
95
-
96
- # Samples
97
-
98
- .PHONY: clean_samples
99
-
100
- clean_samples:
101
- rm -rf samples/{ServerTest,ClientTest,fserver,fclient}
102
-
103
- samples: ServerTest ClientTest fserver fclient
104
-
105
- ServerTest: samples/ServerTest.c $(TARGET_LIB)
106
- $(CC) $^ $(CPPFLAGS) -I./include -o samples/$@
107
-
108
- ClientTest: samples/ClientTest.c $(TARGET_LIB)
109
- $(CC) $^ $(CPPFLAGS) -I./include -o samples/$@
110
-
111
- fserver: samples/fserver.f $(TARGET_LIB)
112
- $(G77) $^ $(G77FLAGS) -o samples/$@
113
-
114
- fclient: samples/fclient.f $(TARGET_LIB)
115
- $(G77) $^ $(G77FLAGS) -o samples/$@
116
-
117
- STUFF_TO_CLEAN += samples/ServerTest
118
- STUFF_TO_CLEAN += samples/ClientTest
119
- STUFF_TO_CLEAN += samples/fserver
120
- STUFF_TO_CLEAN += samples/fclient
121
-
122
- # Documentation
123
-
124
- .PHONY: doc
125
-
126
- doc:
127
- @echo Making documentation
128
- $(SILENCE)doxygen doc/Doxyfile 1> doxygen.log
129
- #@$(RM) doxygen.log
130
- cd doc; make
131
-
132
- STUFF_TO_CLEAN += doc/html doxygen.log
133
-
134
- show:
135
- @echo "CPPFLAGS=$(CPPFLAGS)"
136
- @echo "LDFLAGS=$(LDFLAGS)"
137
-
138
- .PHONY: clean_all
139
-
140
- clean_all:
141
- $(SILENCE)echo "Making clean_all"
142
- $(SILENCE)make clean BUILD32=Y > /dev/null
143
- $(SILENCE)make clean BUILD64=Y > /dev/null
144
-
@@ -1,26 +0,0 @@
1
- FlukaIO
2
- =======
3
-
4
- How to compile
5
- ==============
6
-
7
- In a machine with CppUTest correctly configured, it can be compiled and tested running "make".
8
-
9
- In a machine without CppUTest both 32 and 64 bit versions of the libraries can be compiled issuing the following commands:
10
-
11
- make libs BUILD32=Y
12
- make clean
13
- make libs BUILD64=Y
14
-
15
- The resulting libraries will be compiled under the directory "lib".
16
-
17
- Documentation
18
- =============
19
-
20
- The doxygen documentation can be generated with the command "make doc"
21
-
22
- Compiling samples
23
- =================
24
-
25
- Run "make samples" to compile sample clients and servers under samples directory.
26
-