# Install Wire-Cell Toolkit
<!---
[[toc]]
--->
There are several ways to install Wire-Cell Toolkit on your local computer (see, e.g. [here](https://wirecell.github.io/manual.html#outline-container-orga7919bf)). To avoid choice overloading and get you started as quickly as possible, we describe an **officially recommended** way of installation: using the [cvmfs](https://cernvm.cern.ch/) network file system and the [singularity](https://singularity.lbl.gov/) container. This way allows you to both develop Wire-Cell by itself and integrate it with other software frameworks such as LArSoft.
## Install CVMFS
[CVMFS](https://cernvm.cern.ch/) (CernVM File System) is a utility that mounts remote directories over HTTP. CVMFS provides a simple way to distribute software binaries. Follow [Brett's instruction](https://github.com/WireCell/wire-cell-singularity/blob/master/cvmfs.org) for details of installation. For the lazy ubuntu'ers:
```bash
sudo apt-get install lsb-release
wget https://ecsft.cern.ch/dist/cvmfs/cvmfs-release/cvmfs-release-latest_all.deb
sudo dpkg -i cvmfs-release-latest_all.deb
sudo apt-get update
sudo apt-get install cvmfs cvmfs-config-default
sudo cvmfs_config setup
```
Create a configuration file at `/etc/cvmfs/default.local` as follows:
```bash
# required, add more if needed.
CVMFS_REPOSITORIES=larsoft.opensciencegrid.org,uboone.opensciencegrid.org,dune.opensciencegrid.org,icarus.opensciencegrid.org
# requires, replace with actual proxy, or just "DIRECT" if none
CVMFS_HTTP_PROXY="DIRECT"
# BNL Physics department users may use
# CVMFS_HTTP_PROXY="http://batch3.phy.bnl.gov:3128;DIRECT"
CVMFS_QUOTA_LIMIT=25000
CVMFS_CACHE_BASE=/mnt/ssd/cvmfs
```
Now test with
```bash
cvmfs_config probe
```
, and you should see **three** `Probing ... OK` messages.
(**Optional**) If you also want access to the data in `dune.osgstorage.org`, for example, the photon library in the protoDUNE-SP simulation as will be introduced shortly, it is required to append `dune.osgstorage.org` to `CVMFS_REPOSITORIES` in `/etc/cvmfs/default.local`. Check that the other repositories work:
```
cvmfs_config chksetup
cvmfs_config probe
```
The second command may fail on dune.osgstorage.org, we fix that next.
```
cp /cvmfs/config-osg.opensciencegrid.org/etc/cvmfs/domain.d/osgstorage.org.conf /etc/cvmfs/domain.d/
cvmfs_config chksetup
cvmfs_config probe
```
Now, `dune.osgstorage.org` should be "OK" and the directory should be accessible: `/cvmfs/dune.osgstorage.org/`
<!--
Alternatively, two files needs to be created in `/etc/cvmfs/default.d/`.
```
# /etc/cvmfs/default.d/60-osg.conf
#
# DO NOT EDIT THIS FILE
# It will be replaced on upgrade. To override, edit /etc/cvmfs/default.local
#
CVMFS_SEND_INFO_HEADER=yes
CVMFS_KEYS_DIR=/etc/cvmfs/keys/opensciencegrid.org
CVMFS_USE_GEOAPI=yes
CVMFS_CONFIG_REPOSITORY=config-osg.opensciencegrid.org
CVMFS_CONFIG_REPO_REQUIRED=yes
CVMFS_FALLBACK_PROXY=http://cvmfsbproxy.cern.ch:3126;http://cvmfsbproxy.fnal.gov:3126
# /etc/cvmfs/default.d/config-osg.opensciencegrid.org.conf (single line)
CVMFS_SERVER_URL=http://cvmfs-s1bnl.opensciencegrid.org:8000/cvmfs/@fqrn@;http://cvmfs-s1fnal.opensciencegrid.org:8000/cvmfs/@fqrn@;http://cvmfs-s1goc.opensciencegrid.org:8000/cvmfs/@fqrn@
```
-->
## Install Singularity
[Singularity](https://singularity.lbl.gov/) is a lightweight container that provides an operating-system level virtualization. It is popular in the world of scientific high-performance computing (HPC). For Wire-Cell development, we use singularity to provide a virtual [scientific linux](https://www.scientificlinux.org/) environment. Follow [here](https://sylabs.io/guides/3.0/user-guide/installation.html) for detailed installation instructions. For the lazy ubuntu'ers, first, install the `go` language:
```bash
sudo apt-get update && sudo apt-get install -y \
build-essential libssl-dev uuid-dev \
libgpgme11-dev squashfs-tools libseccomp-dev pkg-config
sudo wget https://dl.google.com/go/go1.11.5.linux-amd64.tar.gz # or other versions
sudo tar -C /usr/local -xf go1.11.5.linux-amd64.tar.gz
echo 'export GOPATH=${HOME}/go' >> ~/.bashrc && \
echo 'export PATH=/usr/local/go/bin:${PATH}:${GOPATH}/bin' >> ~/.bashrc && \
source ~/.bashrc
go get -u github.com/golang/dep/cmd/dep
```
Then, install `singularity` from source
```bash
go get -d github.com/sylabs/singularity
cd $GOPATH/src/github.com/sylabs/singularity
git checkout -b v3.0.3 v3.0.3 # or other tags
./mconfig && \
make -C ./builddir && \
sudo make -C ./builddir install
```
### Troubleshooting
Depending on the filesystem, `singularity` might not be able to mount certain drives and will abort with an error message similar to:
```
error: can't mount image /proc/self/fd/3: failed to mount squashfs filesystem: invalid argument
```
This has been patched from `v3.5.3` onwards, but to force it to work on `v3.0.3`, one can modify the source code by opening:
```bash
$EDITOR ${GOPATH}/src/github.com/sylabs/singularity/internal/pkg/util/fs/mount/mount.go
```
and replacing the codeblock:
```bash
options = fmt.Sprintf("loop,offset=%d,sizelimit=%d,errors=remount-ro", offset, sizelimit)
```
with
```bash
options = fmt.Sprintf("loop,offset=%d,sizelimit=%d", offset, sizelimit)
if fstype == "ext3" {
options += ",errors=remount-ro"
}
```
and rebuilding with the `mconfig` command as before. This is because `remount-ro` is an invalid argument to provide while mounting squashfs drives, as squashfs doesn't recognize it. More context is given [here](https://stackoverflow.com/questions/63061424/squashfs-error-when-running-singularity-after-ubuntu-upgrade)
## Use wcdo
`wcdo` is a command line tool that provides convenient methods to do stuff with Wire-Cell in a Singularity container. Follow [Brett's instruction](https://github.com/WireCell/wire-cell-singularity/blob/master/wcdo.org) to get started, or see the [next section](/f0u9JweCTxizBfufKZzvVg) for example workflows.
<!-- ::: tip
**TIP**: I usually create a symlink at `/usr/local/bin/wcdo` to point to the [wcdo.sh](https://raw.githubusercontent.com/WireCell/wire-cell-singularity/master/wcdo.sh) file in the cloned [wire-cell-singularity](https://github.com/WireCell/wire-cell-singularity) repository.
::: -->
<!--
::: tip TIP
This is a tip
:::
::: warning WARNING
This is a warning
:::
::: danger STOP
This is a dangerous, don't do it
:::
-->