xcoll 0.6.1__py3-none-any.whl → 0.6.2__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 (84) hide show
  1. xcoll/general.py +1 -1
  2. {xcoll-0.6.1.dist-info → xcoll-0.6.2.dist-info}/METADATA +5 -4
  3. xcoll-0.6.2.dist-info/RECORD +61 -0
  4. {xcoll-0.6.1.dist-info → xcoll-0.6.2.dist-info}/WHEEL +1 -1
  5. xcoll/__init__.py.orig +0 -26
  6. xcoll/general.py.orig +0 -20
  7. xcoll/initial_distribution.py.orig +0 -256
  8. xcoll/scattering_routines/fluka/flukaio/.git +0 -1
  9. xcoll/scattering_routines/fluka/flukaio/.gitignore +0 -2
  10. xcoll/scattering_routines/fluka/flukaio/CMakeLists.txt +0 -18
  11. xcoll/scattering_routines/fluka/flukaio/ComponentMakefile +0 -192
  12. xcoll/scattering_routines/fluka/flukaio/Makefile +0 -144
  13. xcoll/scattering_routines/fluka/flukaio/README +0 -26
  14. xcoll/scattering_routines/fluka/flukaio/doc/Doxyfile +0 -1551
  15. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO.asciidoc +0 -1054
  16. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO.epub +0 -0
  17. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO.html +0 -1607
  18. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO.pdf +0 -0
  19. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO__1.png +0 -0
  20. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO__2.png +0 -0
  21. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO__3.png +0 -0
  22. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO__4.png +0 -0
  23. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO__5.png +0 -0
  24. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO__6.png +0 -0
  25. xcoll/scattering_routines/fluka/flukaio/doc/FlukaIO__7.png +0 -0
  26. xcoll/scattering_routines/fluka/flukaio/doc/Makefile +0 -8
  27. xcoll/scattering_routines/fluka/flukaio/doc/docbook.xsl +0 -1690
  28. xcoll/scattering_routines/fluka/flukaio/include/Connection.h +0 -79
  29. xcoll/scattering_routines/fluka/flukaio/include/FlukaIO.h +0 -58
  30. xcoll/scattering_routines/fluka/flukaio/include/FlukaIOServer.h +0 -33
  31. xcoll/scattering_routines/fluka/flukaio/include/FortranFlukaIO.h +0 -277
  32. xcoll/scattering_routines/fluka/flukaio/include/Message.h +0 -89
  33. xcoll/scattering_routines/fluka/flukaio/include/ParticleInfo.h +0 -76
  34. xcoll/scattering_routines/fluka/flukaio/lib/libFlukaIO64.a +0 -0
  35. xcoll/scattering_routines/fluka/flukaio/lib/libFlukaIO64.so +0 -0
  36. xcoll/scattering_routines/fluka/flukaio/samples/ClientTest.c +0 -156
  37. xcoll/scattering_routines/fluka/flukaio/samples/ServerTest.c +0 -123
  38. xcoll/scattering_routines/fluka/flukaio/samples/fclient.f +0 -149
  39. xcoll/scattering_routines/fluka/flukaio/samples/fserver.f +0 -118
  40. xcoll/scattering_routines/fluka/flukaio/src/Connection.c +0 -264
  41. xcoll/scattering_routines/fluka/flukaio/src/Connection.d +0 -69
  42. xcoll/scattering_routines/fluka/flukaio/src/Connection.o +0 -0
  43. xcoll/scattering_routines/fluka/flukaio/src/FlukaIO.c +0 -211
  44. xcoll/scattering_routines/fluka/flukaio/src/FlukaIO.d +0 -46
  45. xcoll/scattering_routines/fluka/flukaio/src/FlukaIO.o +0 -0
  46. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOHandshake.c +0 -45
  47. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOHandshake.d +0 -29
  48. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOHandshake.h +0 -17
  49. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOHandshake.o +0 -0
  50. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOServer.c +0 -84
  51. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOServer.d +0 -70
  52. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOServer.o +0 -0
  53. xcoll/scattering_routines/fluka/flukaio/src/FlukaIOServer_private.h +0 -22
  54. xcoll/scattering_routines/fluka/flukaio/src/FlukaIO_private.h +0 -16
  55. xcoll/scattering_routines/fluka/flukaio/src/FortranFlukaIO.c +0 -533
  56. xcoll/scattering_routines/fluka/flukaio/src/FortranFlukaIO.d +0 -40
  57. xcoll/scattering_routines/fluka/flukaio/src/FortranFlukaIO.o +0 -0
  58. xcoll/scattering_routines/fluka/flukaio/src/NetIO.c +0 -304
  59. xcoll/scattering_routines/fluka/flukaio/src/NetIO.d +0 -66
  60. xcoll/scattering_routines/fluka/flukaio/src/NetIO.h +0 -30
  61. xcoll/scattering_routines/fluka/flukaio/src/NetIO.o +0 -0
  62. xcoll/scattering_routines/fluka/flukaio/src/tags +0 -167
  63. xcoll/scattering_routines/fluka/flukaio/tests/AllTests.cpp +0 -8
  64. xcoll/scattering_routines/fluka/flukaio/tests/CommonTest.h +0 -10
  65. xcoll/scattering_routines/fluka/flukaio/tests/ConnectionTest.cpp +0 -99
  66. xcoll/scattering_routines/fluka/flukaio/tests/FlukaIOServerTest.cpp +0 -104
  67. xcoll/scattering_routines/fluka/flukaio/tests/FlukaIOTest.cpp +0 -439
  68. xcoll/scattering_routines/fluka/flukaio/tests/FortranFlukaIOTest.cpp +0 -682
  69. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeConnection.c +0 -19
  70. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeConnection.h +0 -16
  71. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeFlukaIO.c +0 -74
  72. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeFlukaIO.h +0 -50
  73. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeFlukaIOHandshake.c +0 -16
  74. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeFlukaIOHandshake.h +0 -20
  75. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeFlukaIOServer.c +0 -12
  76. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeFlukaIOServer.h +0 -18
  77. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeFortranFlukaIO.h +0 -19
  78. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeNetIO.c +0 -80
  79. xcoll/scattering_routines/fluka/flukaio/tests/fakes/FakeNetIO.h +0 -35
  80. xcoll-0.6.1.dist-info/LICENSE +0 -201
  81. xcoll-0.6.1.dist-info/NOTICE +0 -2
  82. xcoll-0.6.1.dist-info/RECORD +0 -138
  83. /LICENSE → /xcoll-0.6.2.dist-info/LICENSE +0 -0
  84. /NOTICE → /xcoll-0.6.2.dist-info/NOTICE +0 -0
@@ -1,1054 +0,0 @@
1
- FlukaIO: A library for particle exchange
2
- ========================================
3
- :Author: David Siñuela Pastor
4
- :Email: david.sinuela.pastor@cern.ch
5
- :Revision: 3.0RC2
6
- :toc2:
7
- :icons:
8
- :numbered:
9
-
10
-
11
- [abstract]
12
- .Abstract
13
- --
14
-
15
- This document describes the FlukaIO protocol and discusses the implementation of
16
- the FlukaIO library. FlukaIO is a message passing protocol on top of TCP/IP, it
17
- was developed to enable the on-line communication of the Fluka Monte Carlo
18
- particle tracker and single particle trackers as SixTrack or Icosim.
19
-
20
- --
21
-
22
- == Introduction
23
-
24
- Two families of highly specialized simulators can be used to study the effects
25
- of a beam in an accelerator. One family is used to study the effects of the
26
- interaction of the beam with static matter, simulating individual particles and
27
- their interactions as they go though the matter. This kind of simulations are
28
- based on the Monte Carlo technique, after thousands of particles simulated the
29
- averaged results are very similar to those observed in reality. The second
30
- family, the single particle trackers, simulate the particles as they orbit
31
- throughout the accelerator ring. These kind of trackers simulate individual
32
- particles flying in the ring by applying them the optical functions of the ring
33
- elements.
34
-
35
- For certain studies it is interesting to evaluate the long-term effects of the
36
- beam-matter interactions on the beam dynamics and vice versa. Therefore each
37
- kind of simulator plays an important role in these studies.
38
-
39
- The current coupling infrastructure was designed to support a simulation where
40
- the beam circulates along the beam during thousands of turns. The trackig of the
41
- particles is performed by a single particle tracker as SixTrack or Icosim, and
42
- the Monte Carlo tracker Fluka is used to simulate one or more areas of the ring
43
- where the beam-matter interaction effects are important.
44
-
45
- The test case simulation comprised a section of the accelerator with a moving
46
- scraper, a scraper is a piece of matter that moves into the beam pipe producing
47
- a reduction of the beam halo. With the infrastructure here described we were
48
- able to simulate the long term effects of the scraper on the beam stability. Two
49
- kind of outputs were obtained by these simulations: the pattern of lost
50
- particles along the ring and the energy deposition on the scraper geometry.
51
-
52
- FlukaIO is the protocol and the library that provides the API for managing the
53
- communication between the trackers. The library implements a message passing
54
- protocol on top of TCP/IP and can be easily linked to other codes.
55
-
56
- Both trackers must run at the same time and they will transport the particles in
57
- the portion of the accelerator that they are in charge to simulate. One of the
58
- two processes acts as the server and the other acts as the client. The
59
- disctinction only means that one process starts listening on one network port
60
- and the other starts the connection to that process. After the connection is
61
- established there is no disctinction in the way the server or the client work.
62
-
63
- In the current implementation Fluka is set up to be the server and the single
64
- particle tracker acts as the client. By doing so we can easily change the single
65
- particle tracker keeping the server code (which is slightly more complicated)
66
- intact.
67
-
68
- === Getting the library
69
-
70
- The library is distributed via the main CERN's subversion repository
71
- <<flukaiosvn>> as a source code package that must be compiled by the user.
72
- There exist several tags on the repository marking stable releases, please try
73
- to always use one of these. Compatible versions (API and protocol) are kept
74
- under the same major version number. That is, applications using release version
75
- 2.0 can safely migrate to 2.1 and are encouraged to do so.
76
-
77
- === Compiling and Linking
78
-
79
- The detailed instructions on how to compile FlukaIO can be found in the README
80
- file. The resulting library can be linked to a variety of languages, please
81
- refer to the documentation of your language to learn how to interoperate with C
82
- libraries. We have successfully linked the library to software written in
83
- Fortran 77, Fortran 90, C, C++ and Matlab.
84
-
85
- For C/C++ code the header files `FlukaIO.h` and `FlukaIOServer.h` must be
86
- included. In the case of Fortran the interface is defined in `FortranFlukaIO.h`
87
- and `FortranFlukaIOServer.h`.
88
-
89
- Four sample programs are provided in the `samples` folder, one
90
- link:../samples/ClientTest.c[client] and link:../samples/ServerTest.c[server] in
91
- C and one link:../samples/fclient.f[client] and
92
- link:../samples/fserver.f[server] in Fortran. These can be used as a starting
93
- point for developing new servers or clients.
94
-
95
- == User Guide
96
-
97
- === Execution flow
98
-
99
- In our setup both processes start executing aproximately at the same time.
100
- Fluka takes the role of the server and starts listening on a network port and
101
- the single particle tracker connects to the Fluka server.
102
-
103
- A handshake takes place when the communication is started and both processes
104
- tell the other the version of the protocol they implement. If the major version
105
- of the protocol differs they end the connection and an error is reported.
106
-
107
- Once the two processes have succesfully established the connection the
108
- simulation starts on the single particle tracker.
109
-
110
- The particles are inserted and tracked along the lattice. The simulation
111
- continues as normal until it reaches an element in the lattice labelled as a
112
- Fluka element. At this point the simulation has to continue in Fluka, therefore
113
- all the particles have to be sent to the Fluka process.
114
-
115
- Before sending the particles the single particle tracker must tell Fluka where
116
- in space and time the particles have to be inserted. For that purpose the SPT
117
- sends an Insertion PoinT message (IPT) which the lattice element number and
118
- current turn. There must be a convention for Fluka to know which element number
119
- corresponds to which position in the Fluka space and the turn number can be used
120
- to compute the time shift in cases where it is important for the simulation.
121
-
122
- The particles are then sent to the Fluka process in individual messages followed
123
- an End Of Bunch message (EOB). The SPT then remains waiting for incoming network
124
- messages. Fluka tracks the particles one by one and sends them back to the SPT
125
- if they reach the exit region of the geometry. Once all the particles received
126
- by Fluka are sent or lost Fluka sends the end of bunch message to the SPT. Once
127
- the SPT receives the EOB message knows all the remaining particles have been
128
- received. The simulation continues in the single particle tracker from the next
129
- element.
130
-
131
- The simulation will finish when the number of turns requested is exhausted or
132
- because all the particles were lost. The SPT will send an End of Communication
133
- message (EOC) and Fluka will reply with and EOC message to notify that the
134
- message was received and the process is going to finish.
135
-
136
- The following diagram shows the data flow between the two processes:
137
-
138
- ["aafigure",format="png",aspect="0.5",scaledwidth="50%",foreground="#073763"]
139
- ----
140
- +-----------------+ +-------------------+
141
- | | | |
142
- | "Fluka Process" | | "Tracker Process" |
143
- | (Server) | | (Client) |
144
- | | | |
145
- +--------+--------+ +--------+----------+
146
- | |
147
- | |
148
- -----+----- |
149
- Starts listening |
150
- on network |
151
- -----+----- |
152
- | |
153
- | "Connect and handsake"|
154
- +<----------------------+
155
- | |
156
- ------------------------------------
157
- "Connection established"
158
- ------------------------------------
159
- | |
160
- | X Tracking
161
- | X
162
- | X
163
- | "Insert pt 1, turn 1" |
164
- +<----------------------+
165
- | |
166
- | "Particle 1" |
167
- +<----------------------+
168
- | |
169
- | "Particle 2" |
170
- +<----------------------+
171
- | |
172
- | ... |
173
- | |
174
- | |
175
- | "Particle n" |
176
- +<----------------------+
177
- | |
178
- | "End of batch" |
179
- +<----------------------+
180
- | |
181
- Tracking X |
182
- X |
183
- X |
184
- | "Particle 1" |
185
- +---------------------->+
186
- | |
187
- | "Particle 2" |
188
- +---------------------->+
189
- | |
190
- | ... |
191
- | |
192
- | |
193
- | "Particle n'" | "More (or less) than n particles"
194
- +---------------------->+ "can be returned"
195
- | |
196
- | "End of batch" |
197
- +---------------------->+
198
- | |
199
- ------------------------------------
200
- "End of element"
201
- ------------------------------------
202
- | X
203
- | X
204
- | X Tracking
205
- | |
206
- | "End of communication"|
207
- +<----------------------+
208
- | |
209
- | "End of communication"|
210
- +---------------------->+
211
- | |
212
- ------------------------------------
213
- "The communication is closed"
214
- ------------------------------------
215
- | |
216
- X X
217
- ----
218
-
219
- Notice that the number of particles is always variable, not only particles can
220
- be lost in the accelerator tracker or in the Fluka section but also new
221
- particles can be generated in Fluka. Moreover, this processes can alter the
222
- order of the particles sent back to the original process.
223
-
224
- === Types of Messages
225
-
226
-
227
- *Particle Message*
228
-
229
- A message containing the data of a particle:
230
-
231
- - id: particle id
232
- - gen: particle generation
233
- - weigth: statistical weigth
234
- - x: position in cm
235
- - y: position in cm
236
- - z: position in cm
237
- - tx: director cosine along the x axis
238
- - ty: director cosine along the y axis
239
- - tz: director cosine along the z axis
240
- - aa: mass number
241
- - zz: ion charge
242
- - m: rest mass in GeV/c^2
243
- - p: momentum in GeV/c
244
- - t: time shift with respect to reference particle
245
-
246
- *End of batch*
247
-
248
- A message specifying that all the particles of the current turn/batch have been
249
- processed and sent.
250
-
251
- *End of computation*
252
-
253
- Tells the other side that is ready to finish the simulation, the other end
254
- should then reply with an end of computation message and finish the process.
255
-
256
- *Insertion point*
257
-
258
- Usually sent from the tracker to the Fluka process, it contains the turn number
259
- and the elemenet number, instructing Fluka where the upcoming batch of particles
260
- has to be inserted.
261
-
262
- As explained before, certain convention must exist among Fluka and the SPT,
263
- Fluka must be able to know which position in the space corresponds to each of
264
- the element identifiers.
265
-
266
- === API
267
-
268
- The API is splitted in two major sections: the client API and the server API.
269
- The client API is used by both the client and the server, while the server API
270
- contains only those functions needed to start the server. Two equivalent APIs
271
- are provided, one in C and the other in Fortran. Since Fluka is implemented in
272
- Fortran the Fortran interface is needed to use FlukaIO.
273
-
274
- .Note
275
- All the API functions return -1 in case of error, the return value of every call
276
- should always be checked.
277
-
278
-
279
- ==== Client API
280
-
281
- ===== Create the connection object
282
-
283
- [source,c]
284
- .C
285
- ----
286
- flukaio_connection_t *flukaio_connect(const char *host, int port);
287
- ----
288
-
289
- [source,fortran]
290
- .Fortran
291
- ----
292
- integer function ntconnect(host, port)
293
- character(len=*) :: host
294
- integer :: port
295
- ----
296
-
297
- ===== Connect to a FlukaIO server through host and port
298
-
299
- This call connects the current process to a FlukaIO server and returns the
300
- connection information. The connection should be opened at the initialization
301
- phase of the program and closed before finishing the process.
302
-
303
- [source,c]
304
- .C
305
- ----
306
- flukaio_connection_t *flukaio_connect(flukaio_connection_t *conn, const char *host, int port);
307
- ----
308
-
309
- It returns a pointer to a new flukaio_connection_t structure that must be passed
310
- to all subsequent calls to the functions of the API.
311
-
312
- As it is usually the first call to flukaio in the client code it is recommended
313
- to use it like follows:
314
-
315
- [source,c]
316
- .C
317
- ----
318
- flukaio_connection_t *conn = flukaio_connect(flukaio_conn(), "host", 1234);
319
- ----
320
-
321
- [source,fortran]
322
- .Fortran
323
- ----
324
- integer function ntconnect(host, port)
325
- character(len=*) :: host
326
- integer :: port
327
- ----
328
-
329
- In the case of Fortran the function returns an integer with the connection
330
- identifier that should be passed to all the following calls to the API. If the
331
- identifier is smaller than 0 an error occurred.
332
-
333
-
334
- ===== Disconnect
335
-
336
- Closes the connection to the server and releases its resources. The connection
337
- memory is freed inside the call.
338
-
339
- [source,c]
340
- .C
341
- ----
342
- void flukaio_disconnect(flukaio_connection_t *conn);
343
- ----
344
-
345
- [source,fortran]
346
- .Fortran
347
- ----
348
- integer function ntend(cid)
349
- integer :: cid
350
- ----
351
-
352
-
353
- ===== Configure connection read timeout
354
-
355
- Two functions are provided to read incoming particles: read_message and
356
- wait_message, the latter blocks the process until a message is received or an
357
- error occurred. It can happen that the other end of the communication never
358
- sends any message and therefore the process would keep waiting forever. This
359
- timeout specifies the maximum amount of time a wait_message call should wait.
360
-
361
- [source,c]
362
- .C
363
- ----
364
- int connection_set_read_timeout(flukaio_connection_t *conn, long timeout);
365
- ----
366
-
367
- [source,fortran]
368
- .Fortran
369
- ----
370
- integer function ntrtimeout(cid, seconds)
371
- integer :: cid
372
- integer :: seconds
373
- ----
374
-
375
-
376
- ===== Configure connection write timeout
377
-
378
- [source,c]
379
- .C
380
- ----
381
- int connection_set_write_timeout(flukaio_connection_t *conn, long timeout);
382
- ----
383
-
384
- [source,fortran]
385
- .Fortran
386
- ----
387
- integer function ntwtimeout(cid, seconds)
388
- integer :: cid
389
- integer :: seconds
390
- ----
391
-
392
-
393
- ===== Send a particle
394
-
395
- This call creates a particle message with the particle information provided and
396
- saves it in the outgoing buffer. The particle information can be safely modified
397
- immediately after calling this function.
398
-
399
- In the case of C a particle_info_t pointer with the particle data must be passed
400
- and in the case of Fortran all the particle properties must be passed as
401
- arguments.
402
-
403
- [source,c]
404
- .C
405
- ----
406
- ssize_t
407
- flukaio_send_particle(flukaio_connection_t *conn, const particle_info_t *part);
408
- ----
409
-
410
- [source,fortran]
411
- .Fortran
412
- ----
413
- integer function ntsendp(cid, id, gen, wgt, x, y, z, tx, ty, tz, aa, zz, m, p, t)
414
- integer :: cid
415
- integer(kind=4) :: id
416
- integer(kind=4) :: gen
417
- real(kind=8) :: wgt
418
- real(kind=8) :: x
419
- real(kind=8) :: y
420
- real(kind=8) :: z
421
- real(kind=8) :: tx
422
- real(kind=8) :: ty
423
- real(kind=8) :: tz
424
- integer(kind=2) :: aa
425
- integer(kind=2) :: zz
426
- real(kind=8) :: m
427
- real(kind=8) :: p
428
- real(kind=8) :: t
429
- ----
430
-
431
-
432
- ===== Send End Of Batch message
433
-
434
- End of turn message tells the other end that all the particles in the current
435
- batch were sent.
436
-
437
- [source,c]
438
- .C
439
- ----
440
- ssize_t flukaio_send_eob(flukaio_connection_t *conn);
441
- ----
442
-
443
- [source,fortran]
444
- .Fortran
445
- ----
446
- integer function ntsendeob(cid)
447
- integer :: cid
448
- ----
449
-
450
- ===== Send Insertion Point
451
-
452
- Tells the other end where the following particles should be inserted. It sends
453
- an integer with the insertion point identifier and an integer with the turn
454
- number.
455
-
456
- [source,c]
457
- .C
458
- ----
459
- ssize_t flukaio_send_ipt(flukaio_connection_t *conn, uint32_t turn, uint32_t ipt);
460
- ----
461
-
462
- [source,fortran]
463
- .Fortran
464
- ----
465
- integer function ntsendipt(cid, ipt, turn)
466
- integer :: cid
467
- integer(kind=4) :: ipt
468
- integer(kind=4) :: turn
469
- ----
470
-
471
-
472
- ===== Send End Of Computation message
473
-
474
- Informs the other end that the simulation has finished.
475
-
476
- [source,c]
477
- .C
478
- ----
479
- ssize_t flukaio_send_eoc(flukaio_connection_t *conn);
480
- ----
481
-
482
- [source,fortran]
483
- .Fortran
484
- ----
485
- integer function ntsendeoc(cid)
486
- integer :: cid
487
- ----
488
-
489
-
490
- ===== Read a message (non-blocking)
491
-
492
- Reads messages from the incoming buffer, if nothing was read from the network
493
- returns -1, otherwise it returns the size of the read message.
494
-
495
- [source,c]
496
- .C
497
- ----
498
- ssize_t
499
- flukaio_receive_message(flukaio_connection_t *conn, flukaio_message_t *msg);
500
- ----
501
-
502
- Stores the incoming message in msg. The type of the message can be inspected by
503
- looking at the msg.type field.
504
-
505
- [source,fortran]
506
- .Fortran
507
- ----
508
- integer function ntrecv(cid, mtype, id, gen, wgt, x, y, z, tx, ty, tz, aa, zz, m, p, t)
509
- integer :: cid
510
- integer :: mtype
511
- integer(kind=4) :: id
512
- integer(kind=4) :: gen
513
- real(kind=8) :: wgt
514
- real(kind=8) :: x
515
- real(kind=8) :: y
516
- real(kind=8) :: z
517
- real(kind=8) :: tx
518
- real(kind=8) :: ty
519
- real(kind=8) :: tz
520
- integer(kind=2) :: aa
521
- integer(kind=2) :: zz
522
- real(kind=8) :: m
523
- real(kind=8) :: p
524
- real(kind=8) :: t
525
- ----
526
-
527
- Stores the incoming message in the arguments, the type of the message is stored
528
- in mtype.
529
-
530
-
531
- ===== Read a message (blocking)
532
-
533
- If no message was received it blocks the application until a message arrives.
534
- Returns -1 if an error occurred (the other end disconnected or the read
535
- operation timed out).
536
-
537
- [source,c]
538
- .C
539
- ----
540
- ssize_t
541
- flukaio_wait_message(flukaio_connection_t *conn, flukaio_message_t *msg);
542
- ----
543
-
544
- Stores the incoming message in msg. The type of the message can be inspected by
545
- looking at the msg.type field.
546
-
547
- [source,fortran]
548
- .Fortran
549
- ----
550
- integer function ntwait(cid, mtype, id, gen, wgt, x, y, z, tx, ty, tz, aa, zz, m, p, t)
551
- integer :: cid
552
- integer :: mtype
553
- integer(kind=4) :: id
554
- integer(kind=4) :: gen
555
- real(kind=8) :: wgt
556
- real(kind=8) :: x
557
- real(kind=8) :: y
558
- real(kind=8) :: z
559
- real(kind=8) :: tx
560
- real(kind=8) :: ty
561
- real(kind=8) :: tz
562
- integer(kind=2) :: aa
563
- integer(kind=2) :: zz
564
- real(kind=8) :: m
565
- real(kind=8) :: p
566
- real(kind=8) :: t
567
- ----
568
-
569
- Stores the incoming message in the arguments, the type of the message is stored
570
- in mtype.
571
-
572
-
573
- ==== Server API
574
-
575
- ===== Create server object.
576
-
577
- [source,c]
578
- .C
579
- ----
580
- flukaio_server_t* flukaio_server_create();
581
- ----
582
-
583
- This creates a structure holding all server attributes. This structure has to be
584
- used to call all other server operations.
585
-
586
- [source,fortran]
587
- .Fortran
588
- ----
589
- integer function ntserver()
590
- ----
591
-
592
- Returns the server identified to be used to all subsequetn calls.
593
-
594
- ===== Setup a server listening on port
595
-
596
- Returns the assigned port or -1 if error. The desired port can be specified in
597
- the port argument, if 0 is provided the port will be randomly assigned by the
598
- operating system.
599
-
600
- [source,c]
601
- .C
602
- ----
603
- int flukaio_server_start(flukaio_server_t* server, unsigned int port);
604
- ----
605
-
606
- [source,fortran]
607
- .Fortran
608
- ----
609
- integer function ntstart(sid, port)
610
- integer :: sid
611
- integer :: port
612
- ----
613
-
614
- The first variable is the serverid obtained with ntserver().
615
-
616
-
617
- ===== Accept connection
618
-
619
- Waits for a client connection and returns a structure with the connection
620
- information.
621
-
622
- [source,c]
623
- .C
624
- ----
625
- flukaio_connection_t *flukaio_server_accept(flukaio_server_t* server);
626
- ----
627
-
628
- This returns the incoming connection object that can be used with the client
629
- API.
630
-
631
- [source,fortran]
632
- .Fortran
633
- ----
634
- integer function ntaccept(sid)
635
- integer :: sid
636
- ----
637
-
638
- Returns a connection identifier if there was a connection, otherwise -1.
639
-
640
-
641
- ===== Shutdown server
642
-
643
- Frees all server resources, stops listening for connections.
644
-
645
- [source,c]
646
- .C
647
- ----
648
- int flukaio_server_shutdown(flukaio_server_t* server);
649
- ----
650
-
651
- [source,fortran]
652
- .Fortran
653
- ----
654
- integer function ntshwnd()
655
- integer :: sid
656
- ----
657
-
658
-
659
- ===== Get server port
660
-
661
- Returns the port number on which the server is listening.
662
-
663
- [source,c]
664
- .C
665
- ----
666
- int flukaio_server_get_port(flukaio_server_t* server);
667
- ----
668
-
669
- [source,fortran]
670
- .Fortran
671
- ----
672
- integer function ntgetport(sid)
673
- integer :: sid
674
- ----
675
-
676
-
677
- === Troubleshooting
678
-
679
- The source code is distributed with a complete test suite under the folder
680
- “tests”. In order to run the tests the CppUTest [1] test harness must be
681
- correctly installed. If CppUTest is installed the test suite is executed and a
682
- report is generated each time the code is compiled using make.
683
-
684
- If something is failing please run the test suite and check that everything is
685
- working as expected. If that is the case try to sniff the network connection
686
- with `tcpdump`.
687
-
688
-
689
- == Technical documentation
690
-
691
- === Main FlukaIO features
692
-
693
- Although FlukaIO is meant to link Fluka to single particle tracking codes it has
694
- been designed to be extensible, a small list of features follows:
695
-
696
- - Two equivalent APIs, the native C API and a compatibility layer for Fortran
697
- codes.
698
- - TCP/IP communication: enabling client/server architectures
699
- - Variable size messages to use minimum bandwidth
700
- - Extensible list of message types, implemented now: particle, end of turn, end
701
- of computation and insertion point
702
- - Buffered input and output to improve performance
703
- - Modular Object-Oriented architecture
704
- - Complete test-suite
705
-
706
- === Protocol Description
707
-
708
- ==== Message format
709
-
710
- The messages have this common header format:
711
-
712
- ["aafigure",format="png",aspect="0.5",scaledwidth="50%"]
713
- ----
714
- 0 16 24
715
- +--------------------+----------+-----------------------------------+
716
- | size | type | data... |
717
- +--------------------+----------+-----------------------------------+
718
- ----
719
-
720
- The header of the message contains the total size of the message in bytes
721
- (unsigned integer: 2 bytes) and the type of message (unsigned integer: 1 byte),
722
- 3 bytes in total.
723
-
724
- ==== Types of Messages
725
-
726
- The type field in a message can have one of these values:
727
-
728
- - *0 = ERR*: Error (used internally)
729
- - *1 = PART*: A message containing a particle
730
- - *2 = TURN*: End of turn message
731
- - *3 = END*: End of computation
732
- - *4 = CONF*: Configuration, reserved
733
- - *5 = IPT*: Insertion point
734
-
735
- The message types and their meanings are not strictly defined, interpretation
736
- depends on the application. Following definitions are just a guideline.
737
-
738
- ===== Error message
739
-
740
- When the reads a message of type ERR means that the incoming message was not
741
- recognised. It is used internally, but it is also the type of message that the
742
- functions read_message and wait_message return when there is an error (in
743
- addition to returning -1).
744
-
745
- ===== Particle message
746
-
747
- Contains a particle in the data section, for more details read the header file
748
- `include/ParticleInfo.h`:
749
-
750
- ["aafigure",format="png",aspect="0.5",scaledwidth="50%"]
751
- ----
752
- 0 16 32
753
- +--------------------------------------------+
754
- | id: particle id |
755
- +--------------------------------------------+
756
- | gen: particle generation |
757
- +---------------------+----------------------+
758
- | "aa: mass number" | "zz: ion charge" |
759
- +---------------------+----------------------+
760
- | statistical weight: real number |
761
- | |
762
- +--------------------------------------------+
763
- | x: position in cm |
764
- | |
765
- +--------------------------------------------+
766
- | y: position in cm |
767
- | |
768
- +--------------------------------------------+
769
- | z: position in cm |
770
- | |
771
- +--------------------------------------------+
772
- | tx: director cosine in x |
773
- | |
774
- +--------------------------------------------+
775
- | ty: director cosine in y |
776
- | |
777
- +--------------------------------------------+
778
- | tz: director cosine in z |
779
- | |
780
- +--------------------------------------------+
781
- | "m: Rest mass (GeV/c^2)" |
782
- | |
783
- +--------------------------------------------+
784
- | "p: Momentum (GeV/c)" |
785
- | |
786
- +--------------------------------------------+
787
- | t: time shift with respect to ref. particle|
788
- | |
789
- +--------------------------------------------+
790
- ----
791
-
792
- ===== End Of Batch message
793
-
794
- Empty message communicating that all the particles were sent.
795
-
796
- ===== End Of Computation message
797
-
798
- Informs the other end that computation was finished and must disconnect. Doesn’t
799
- contain any data.
800
-
801
- ===== Insertion point
802
-
803
- Contains a 4 bytes unsigned integer with the insertion point number, and a 4
804
- bytes unsigned integer with the turn number.
805
-
806
- ["aafigure",format="png",aspect="0.5",scaledwidth="50%"]
807
- ----
808
- 0 16 32
809
- +--------------------------------------------+
810
- | idp: insertion point number |
811
- +--------------------------------------------+
812
- | turn: turn number |
813
- +---------------------+----------------------+
814
- ----
815
-
816
-
817
- === Logical Structure
818
-
819
- ["aafigure",format="png",aspect="0.5",scaledwidth="50%",foreground="#073763"]
820
- ----
821
- +------------------+ +------------------------+
822
- | | | |
823
- | <<API>>FlukaIO | | <<API>>FlukaIOServer |
824
- | | | |
825
- +--------+---------+ +--+---------+-----------+
826
- | / |
827
- | / |
828
- | / |
829
- | / |
830
- | / |
831
- uses | uses / |
832
- | / |
833
- | / |
834
- | / |
835
- | / |
836
- | / |
837
- | / |
838
- +--------+--------++ +------------+-----------+
839
- | | | |
840
- | "Connection" +--------+ NetIO or FakeNetIO |
841
- | | | |
842
- +------------------+ +------------------------+
843
-
844
- ----
845
-
846
- The library offers two APIs: FlukaIO and FlukaIOServer, a client application
847
- would normally use only FlukaIO while a server application would use both.
848
-
849
- When a connection is established the FlukaIO library returns a Connection object
850
- (or connection id in the Fortran interface) which holds all the data needed
851
- during a communication session.
852
-
853
- All the incoming and outgoing messages are sent through a Connection object,
854
- which stores them in the appropriate buffer if needed. When enough data is
855
- stored in the output buffer or a flush operation is requested the connection
856
- object sends all the contents of the output buffer and erases them from memory.
857
-
858
- All network operations are defined as function pointers in the Connection
859
- struct. This is used to replace all operating system calls during tests avoiding
860
- hitting the network and providing reliable and replicable test results.
861
-
862
- === Data flow diagrams
863
-
864
- In this section of the document an overview of the data flow is provided showing
865
- the collaboration between the different components of the library.
866
-
867
- ==== Starting and ending communication
868
-
869
- ["aafigure",format="png",aspect="0.5",scaledwidth="80%",foreground="#073763"]
870
- ----------------------------------------------------------------------------------------------------------------------------------
871
- +---------------+ +-----------------+ +------------+ +---------------------+
872
- | "Application" | |"FlukaIO library"| |"Connection"| | NetIO implementation|
873
- +----+----------+ +----+------------+ +----+-------+ +---------+-----------+
874
- | | | |
875
- +------+--------------+-----------------------+----------------------------------------+-------------------------+-----------+
876
- |"Communication start"| | | | |
877
- +------+--------------/ | | | |
878
- | | "flukaio_connection(host, port)" | | | |
879
- | +------------------------------------->X X | |
880
- | | X "connection_connect(host, port)" X | |
881
- | | X--------------------------------------->X "connect(host, port)" | | +-------+
882
- | | X X------------------------>X-----------+--->|Network|
883
- | | X X "socket_fd" X | +-------+
884
- | | X "connection" X<------------------------X |
885
- | | X<---------------------------------------X | |
886
- | | "connection" X X | |
887
- | |<-------------------------------------X X | |
888
- | | | X | |
889
- +------+--------------------------------------+----------------------------------------X-------------------------+-----------+
890
- | | X |
891
- | | X |
892
- +---------------------+------------------------------------------------------------------------------------------------------+
893
- |"Communication" | |
894
- +---------------------/ ... |
895
- | |
896
- +----------------------------------------------------------------------------------------------------------------------------+
897
- | | X |
898
- | | X |
899
- +------+--------------+-----------------------+----------------------------------------X-------------------------+-----------+
900
- |"Communication end" | | X | |
901
- +------+--------------/ | X | |
902
- | | "flukaio_disconnect(connection)" | X | |
903
- | +------------------------------------->X X | |
904
- | | X "connection_destroy()" X | |
905
- | | X--------------------------------------->X "disconnect(socket_fd)" | | +-------+
906
- | | X X------------------------>X-----------+--->|Network|
907
- | | X X "ok" X | +-------+
908
- | | X "ok" X<------------------------X |
909
- | | X<---------------------------------------X | |
910
- | | X | | |
911
- | | X \|/ | |
912
- | | "ok" X + | |
913
- | |<-------------------------------------X /|\ | |
914
- | | | | | |
915
- +------+--------------------------------------+----------------------------------------+-------------------------+-----------+
916
- | | | |
917
- | | | |
918
- ----------------------------------------------------------------------------------------------------------------------------------
919
-
920
- ==== Sending messages
921
-
922
- ["aafigure",format="png",aspect="0.5",scaledwidth="80%",foreground="#073763"]
923
- ----------------------------------------------------------------------------------------------------------------------------------
924
- +---------------+ +-----------------+ +------------+ +---------------------+
925
- | "Application" | |"FlukaIO library"| |"Connection"| | NetIO implementation|
926
- +----+----------+ +----+------------+ +----+-------+ +---------+-----------+
927
- | | | |
928
- +---------------------+------------------------------------------------------------------------------------------------------+
929
- |"Communication Start"| |
930
- +---------------------/ ... |
931
- | |
932
- +----------------------------------------------------------------------------------------------------------------------------+
933
- | | | |
934
- +------+-----------------+--------------------+----------------------------------------+-------------------------+-----------+
935
- |"Send particle: x times"| | | | |
936
- +------+-----------------/ | | | |
937
- | | "flukaio_send_particle(particle)" | | | |
938
- | +------------------------------------->X | | |
939
- | | X "connection_write(binary_message)" | | |
940
- | | X--------------------------------------->X--+ "Store message" | |
941
- | | X "ok" X | "in output buffer" | |
942
- | | X<---------------------------------------X<-+ | |
943
- | | X | | |
944
- | | +------------------+----------------------------------------+-------------------------+-----------+---+
945
- | | | "If output buffer fuller than" | | | | |
946
- | | | "threshold" | | | | |
947
- | | +------------------+-------------/ | | | |
948
- | | | X "connection_flush()" | | | |
949
- | | | X--------------------------------------->X "send(output_buffer)" | | |
950
- | | | X X------------------------>X | | +-------+
951
- | | | X X X<----------+---+----->|Network|
952
- | | | X X "ok" X | | +-------+
953
- | | | X X<------------------------X | |
954
- | | | X "ok" X | | |
955
- | | | X<---------------------------------------X | | |
956
- | | | X | | | |
957
- | | +------------------+----------------------------------------+-------------------------+-----------+---+
958
- | | X | | |
959
- | | "ok" X | | |
960
- | |<-------------------------------------X | | |
961
- | | | | | |
962
- +------+--------------------------------------+----------------------------------------|-------------------------+-----------+
963
- | | | |
964
- | | | |
965
- | | | |
966
- +------+--------------+-----------------------+----------------------------------------|-------------------------+-----------+
967
- |"End of turn" | | | | |
968
- +------+--------------/ | | | |
969
- | | "flukaio_send_eob()" | | | |
970
- | +------------------------------------->X | | |
971
- | | X | | |
972
- | | X "connection_write(binary_message)" | | |
973
- | | X--------------------------------------->X--+ "Store message" | |
974
- | | X X | "in output buffer" | |
975
- | | X X<-+ | |
976
- | | X "connection_flush()" | | |
977
- | | X--------------------------------------->X "send(output_buffer)" | | +-------+
978
- | | X X------------------------>X-----------+--->|Network|
979
- | | X X "ok" X | +-------+
980
- | | X "ok" X<------------------------X |
981
- | | X<---------------------------------------X | |
982
- | | "ok" X | | |
983
- | |<-------------------------------------X | | |
984
- | | | | | |
985
- +------+--------------------------------------+----------------------------------------+-------------------------+-----------+
986
- | | | |
987
- +---------------------+------------------------------------------------------------------------------------------------------+
988
- |"Communication End" | |
989
- +---------------------/ ... |
990
- | |
991
- +----------------------------------------------------------------------------------------------------------------------------+
992
- | | | |
993
- ----------------------------------------------------------------------------------------------------------------------------------
994
-
995
- End Of Computation messages are not shown in the diagram because they follow the
996
- same execution flow as the End Of Batch in the sense that they are synchronous
997
- as well.
998
-
999
- === How to
1000
-
1001
- ==== Add new fields to particles
1002
-
1003
- If the partile structure is to be modified this approach is recommended:
1004
-
1005
- 1. Add the field to particle_info_t (`include/ParticleInfo.h`)
1006
- 2. Update `PARTICLES_EQUAL` helpers in tests (`tests/FlukaIOTest.cpp` and
1007
- `tests/FortranFlukaIO.cpp`)
1008
- 3. Run the tests and correct the code if they fail.
1009
-
1010
- The Fortran interface will need more work than the C interface because it
1011
- exposes each individual field in the function signatures. Because of this the
1012
- Fortran samples have to be updated to reflect the new interface. The C samples
1013
- should still be working after the change.
1014
-
1015
- ==== Add new message types
1016
-
1017
- New message types can be introduced by adding the message id to the enum
1018
- `message_type_t` found in `include/message.h` and modifying the FlukaIO logic.
1019
- In case more variable size messages have to be implemented the data union field
1020
- in flukaio_message_t structure can be modified to store the new data.
1021
-
1022
-
1023
-
1024
-
1025
- == Credits
1026
-
1027
- - David Siñuela Pastor <david.sinuela.pastor@cern.ch>
1028
- - Alessio Mereghetti <Alessio.Mereghetti@cern.ch>
1029
- - Vasilis Vlachoudis <Vasilis.Vlachoudis@cern.ch>
1030
- - Francesco Cerutti <Francesco.Cerutti@cern.ch>
1031
- - Joel Francois Clivaz <joel.francois.clivaz@cern.ch>
1032
-
1033
-
1034
-
1035
-
1036
- == References
1037
-
1038
- [bibliography]
1039
- - [[[flukaiosvn]]] . 'FlukaIO subversion repository' .
1040
- http://svnweb.cern.ch/world/wsvn/FlukaIO
1041
- - [[[cpputest]]] . 'CppUTest'. http://sourceforge.net/projects/cpputest/
1042
- - [[[flukadesc]]] . G. Battistoni, S. Muraro, P.R. Sala, F. Cerutti, A.
1043
- Ferrari, S. Roesler, A. Fasso`, J. Ranft . 'The FLUKA code: Description and
1044
- benchmarking' . Proceedings of the Hadronic Shower Simulation Workshop 2006,
1045
- Fermilab 6--8 September 2006, M. Albrow, R. Raja eds., AIP Conference Proceeding
1046
- 896, 31-49, (2007)
1047
- - [[[flukacode]]] . A. Fasso`, A. Ferrari, J. Ranft, and P.R. Sala . 'FLUKA: a
1048
- multi-particle transport code' . CERN-2005-10 (2005), INFN/TC_05/11, SLAC-R-773
1049
- - [[[sixtrack]]] . F. Schmidt . 'SixTrack, User’s Reference Manual' . CERN
1050
- SL/94-56 (AP), 1994.
1051
- - [[[icosim]]] . Holden, N . 'Development of the ICOSIM Program and Application
1052
- to Magnetised Collimators in the LHC' . CERN-AB-Note-2008-054, 2008
1053
-
1054
-