|
20 | 20 | "\n",
|
21 | 21 | "## Object instantiation\n",
|
22 | 22 | "\n",
|
23 |
| - "We start by instantiating some very simple object of type `G4Box`.\n", |
24 |
| - "\n", |
25 |
| - "Note that:\n", |
26 |
| - "- the C++ constructor that is called is `G4Box::G4Box(const G4String &pName, G4double pX, G4double pY, G4double pZ)`\n", |
27 |
| - "- the conversion of Julia type `Int64` to C++ `G4double` is implicit, as well as the `String` to `G4String` " |
| 23 | + "We start by instantiating some very simple object of type `G4Box`." |
28 | 24 | ]
|
29 | 25 | },
|
30 | 26 | {
|
|
43 | 39 | "box = G4Box(\"MyBox\", 1, 2, 3) # the C++ contructor called G4Box (const G4String &pName, G4double pX, G4double pY, G4double pZ)"
|
44 | 40 | ]
|
45 | 41 | },
|
| 42 | + { |
| 43 | + "cell_type": "markdown", |
| 44 | + "metadata": {}, |
| 45 | + "source": [ |
| 46 | + "Note that:\n", |
| 47 | + "- the C++ constructor that is called is `G4Box::G4Box(const G4String &pName, G4double pX, G4double pY, G4double pZ)`\n", |
| 48 | + "- the conversion of Julia type `Int64` to C++ `G4double` is implicit, as well as the `String` to `G4String` " |
| 49 | + ] |
| 50 | + }, |
46 | 51 | {
|
47 | 52 | "cell_type": "markdown",
|
48 | 53 | "metadata": {
|
|
177 | 182 | },
|
178 | 183 | "source": [
|
179 | 184 | "### Calling object methods\n",
|
180 |
| - "In julia, `methods` are instances of functions of a given name, of which the multi-dispatch functionality will select the best one that matches the actual argument types. To call a C++ method of a class we need to pass the wrapped object as first argument." |
| 185 | + "In Julia, `methods` are instances of functions of a given name, of which the multi-dispatch functionality will select the best one that matches the actual argument types. To call a C++ method of a class we need to pass the wrapped object as first argument." |
181 | 186 | ]
|
182 | 187 | },
|
183 | 188 | {
|
|
266 | 271 | "tags": []
|
267 | 272 | },
|
268 | 273 | "source": [
|
269 |
| - "### Working in the inheritance\n", |
| 274 | + "### Working with inheritance\n", |
270 | 275 | "In Geant4 all solid types inherit from a common base class `G4VSolid`. The method `Clone` returns a pointer to this base class. "
|
271 | 276 | ]
|
272 | 277 | },
|
|
300 | 305 | },
|
301 | 306 | "source": [
|
302 | 307 | "### Object ownership\n",
|
303 |
| - "By default all objects instantiated by Julia will garbage collected (deleted) by Julia. this may pose problems with Geant4 since in many occasions the ownership is transferred implicitly to the toolkit, which will take care of doing a cleanup at the adequate moment. If we do nor pay attention we may get crashes (use a deleted objects and double deletions).\n", |
| 308 | + "By default all objects instantiated by Julia will be garbage collected (deleted) by Julia. This may pose problems with Geant4 since in many occasions the ownership of the object is transferred implicitly to the toolkit, which will take care of doing a cleanup at the adequate moment. If we do not pay attention we may get crashes (use a deleted object or eventually double deletions).\n", |
304 | 309 | "\n",
|
305 | 310 | "There are nevertheless some exceptions that have been added to simplify the interactions for the following classes: `G4PVPlacement`,\n",
|
306 | 311 | "`G4LogicalVolume`, `G4PVReplica`, `G4Material`, `G4Isotope`, `G4Element`, `G4JLParticleGun`, \n",
|
|
324 | 329 | "source": [
|
325 | 330 | "box1 = G4Box(\"box1\", 1,1,3) # construct boxes\n",
|
326 | 331 | "box2 = G4Box(\"box2\", 1,3,1) \n",
|
327 |
| - "union = G4UnionSolid(\"union\", CxxPtr(box1), CxxPtr(box2)) # construct a union solid with the same box\n", |
| 332 | + "union = G4UnionSolid(\"union\", CxxPtr(box1), CxxPtr(box2)) # construct a union solid with the two boxes\n", |
328 | 333 | "@show GetCubicVolume(union)\n",
|
329 | 334 | "@show DistanceToIn(union, G4ThreeVector(10,10,10))\n"
|
330 | 335 | ]
|
|
354 | 359 | },
|
355 | 360 | "outputs": [],
|
356 | 361 | "source": [
|
357 |
| - "box1 = box2 = nothing\n", |
358 |
| - "GC.gc()\n", |
| 362 | + "box1 = box2 = nothing # removed the reference to the G4Box objects\n", |
| 363 | + "GC.gc() # force a garbage collection now\n", |
359 | 364 | "@show GetCubicVolume(union) # G4BooleanSolid cashes the volume\n",
|
360 | 365 | "# DistanceToIn(union, G4ThreeVector(10,10,10)) # this will probably crash the program"
|
361 | 366 | ]
|
|
0 commit comments