Resource on the Internet, locally cached. More...
Public Member Functions | |
download (self, bool force=False) | |
Download the remote resource is not available locally or if forced. | |
Static Public Attributes | |
str | remote_url |
Optional | local_filename = None |
Protected Attributes | |
_file | |
Static Protected Attributes | |
Optional | _file = PrivateAttr() |
Resource on the Internet, locally cached.
Most of the parametrizations Lamarr relies on are committed and maintained in remote repositories. The PyLamarr.RemoteResource class implements a simple caching mechanism to download the remote parametrizations on demand in case they are not available locally. A hash of the URL identifying the remote resource is used to represent the local cache of the remote resource. Note that in case the remote resource is updated without modifying its URL, the local cache is not automatically updated.
Consider the file PrimaryVertexSmearing.db
encoding the parametrizations for Primary Vertex reconstruction, and made available publicly here: https://github.com/LamarrSim/SQLamarr/raw/master/temporary_data/PrimaryVertex/PrimaryVertexSmearing.db
The following snippet of code enables caching the file locally:
Now, in case the remote file is updated, it may be necessary to download the updated version. This can be achieved forcing the download with:
or, replacing the connection attempt in the previous example:
A local resourcce can be encapsulated inside RemoteResource
which is the expected format for most of the parametrization test_data in PyLamarr
.
For example, if testing your local version of MyPrimaryVertexSmearing.db
, you can write
Note, however, that forcing the download of a local resource would raise an Exception.
Most of the parametrizations relying on external dependencies expect an instance of RemoteResource
identifying the file to obtain the parametrization from. An implicit cast from string to RemoteResource
enables passing directly a string with a URL (possibly pointing to a local file), which gets transparently converted into a RemoteResource
instance and used in the file.
Definition at line 11 of file RemoteResource.py.
PyLamarr.RemoteResource.RemoteResource.download | ( | self, | |
bool | force = False |
||
) |
Download the remote resource is not available locally or if forced.
Can raise an exception if the download fails or upon attempts of downloading local resources (represented by protocol file://
)
force | Force the download of the remote resource independently of the cache availability |
RemoteResource
(self
) Definition at line 143 of file RemoteResource.py.
|
staticprotected |
Definition at line 90 of file RemoteResource.py.
|
protected |
Definition at line 103 of file RemoteResource.py.
|
static |
Definition at line 89 of file RemoteResource.py.
|
static |
Definition at line 88 of file RemoteResource.py.