---
# System prepended metadata

title: Analysis preservation workshop solutions

---

# Analysis preservation workshop solutions

## Docker

### python3.11 (easy)

```
docker pull python:3.11.1-bullseye
```

then run it and do something like `import tomllib` to confirm that you have python3.11

### python3.11 (intermediate)

Dockerfile:

```
FROM python:3.11.1-bullseye

RUN pip install --no-cache-dir -q uproot

WORKDIR /home/docker
```

then

```
docker build -f py311_dockerfile -t py311_dockerfile:latest .
```

#### Option 1

Create `requirements.txt` with e.g., `uproot` in it

then

```
FROM python:3.11.1-bullseye

COPY requirements.txt requirements.txt

RUN pip install --no-cache-dir -q -r requirements.txt

WORKDIR /home/docker
```

## Singularity

### Doing the same as with docker (interactively)

This is basically [this exercise from the training](https://hsf-training.github.io/hsf-training-singularity-webpage/04-building-containers/index.html#execute-python-with-pyroot-available)

### Doing the same as with docker (definition file)

```
BootStrap: docker
From: python:3.11

%post
    pip install uproot

%runscript
    python -c "import uproot; print(uproot.__version__)"

```

### CMS example analysis

Perform the CMS example analysis in a single execution using a definition file. Save the plots in the execution directory.


```
BootStrap: docker
From: rootproject/root:6.22.06-conda

%post
    # Save the files for the analysis in a top-level dir
    mkdir /analysis
    git clone https://github.com/hsf-training/hsf-training-cms-analysis.git /analysis

%environment
    # Not mandatory, but for example you can define where to store files
    # (Remember that $HOME is shared with the host by default)
    export SKIMS_DIR=$HOME/analysis_tmp/skims

%runscript
    # Create the file to store the skims
    mkdir -p $SKIMS_DIR
    # Move the analysis files to local dir (required for compile)
    cp /analysis/* .
    # Run the skims
    bash skim.sh root://eospublic.cern.ch//eos/root-eos/HiggsTauTauReduced/ $SKIMS_DIR
    # Get the histograms
    mkdir -p histograms
    bash histograms.sh $SKIMS_DIR histograms/
    # Produce the plots
    mkdir -p plots
    bash plot.sh histograms/histograms.root plots

%labels
    Author HSFTraining
    Version v1

%help
    Example container running the CMS analysis example.
    Execute with the HOME shared with the host to save the skimmed files.
```

Then
```bash
singularity build --fakeroot awesome_analysis.sif awesome_analysis.def
```

### Jupyter notebooks

```

```


## CI/CD

### From zero to hero

A few things to remember:

* Don't forget to install `pytest` in the action
* Add a `.gitignore` to avoid tracking cache files while local testing
* [Full repository for GHA](https://github.com/hsf-training/hsf-training-minimal-github-actions-pytest)
* [Full repository for gitlab](https://gitlab.com/klieret/hsf-training-minimal-gitlab-ci-pytest)

### LaTeX documents (GHA only)

* Use https://github.com/xu-cheng/latex-action
* Example: [kilian's ICSC lecture](https://github.com/klieret/icsc-paradigms-and-patterns/blob/master/.github/workflows/workflow.yml)

### Build docker container (GHA)

Build a docker container in GitHub Actions using the [appropriate action](https://github.com/marketplace/actions/build-and-push-docker-images).

* [Full repository for GHA](https://github.com/hsf-training/hsf-training-minimal-github-actions-docker-build-push)