Skip to content

Commit

Permalink
Add documentation for new capabilities and links
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Oct 2, 2024
1 parent df9f1d5 commit c796d07
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
32 changes: 32 additions & 0 deletions doc/datamodel_syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,38 @@ define which `Types` can be used with this interface class, in this case the
not allow for mutable access to their data.** They can be used in relations
between objects, just like normal `datatypes`.

## Definition of links
Podio offers a templated `Link` class ([see here for more details](links.md))
that allows to link two arbitrary datatypes without having to introduce a
`OneToOneRelation` or `OneToManyRelation` inside the corresponding datatypes. In
order to keep the full definition of a datamodel in the YAML file it is possible
to declare `links` in the YAML file:

```yaml
links:
ExampleLink:
Description: "A link between two (podio generated) objects"
Author: "It could be you"
From: ExampleHit
To: TypeWithEnergy
```

This definition will yield the following typedefs
```cpp
using ExampleLinkCollection = podio::LinkCollection<ExampleHit, TypeWithEnergy>;
using ExampleLink = typename ExampleLinkCollection::value_type;
// this is equivalent to
// using ExampleLink = podio::Link<ExampleHit, TypeWithEnergy>;
using MutableExampleLink = typename ExampleLinkCollection::mutable_type;
// this is equivalent to
// using MutableExampleLink = podio::MutableLink<ExampleHit, TypeWithEnergy>;
```

additionally, this will generate the necessary code to enable I/O for this link
type.

### Assigning to interface types

Interface types support the same functionality as normal (immutable) datatypes.
Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Welcome to PODIO's documentation!
examples.md
frame.md
userdata.md
links.md
storage_details.md
cmake.md
advanced_topics.md
Expand Down
15 changes: 9 additions & 6 deletions doc/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ For a more detailed explanation of the internals and the actual implementation
see [the implementation details](#implementation-details).

## How to use `Link`s
Using `Link`s is quite simple. In line with other datatypes that are
generated by podio all the functionality can be gained by including the
corresponding `Collection` header. After that it is generally recommended to
introduce a type alias for easier usage. **As a general rule `Links` need
to be declared with the default (immutable) types.** Trying to instantiate them
with `Mutable` types will result in a compilation error.
Using `Link`s is quite simple. The most straight forward way is to simply
declare them as part of the datamodel, [as described
here](datamodel_syntax.md#definition-of-links). That will result in code
generation that effectiely does what is described here. In line with other
datatypes that are generated by podio all the functionality can be gained by
including the corresponding `Collection` header. After that it is generally
recommended to introduce a type alias for easier usage. **As a general rule
`Links` need to be declared with the default (immutable) types.** Trying to
instantiate them with `Mutable` types will result in a compilation error.

```cpp
#include "podio/LinkCollection.h"
Expand Down

0 comments on commit c796d07

Please sign in to comment.