sample image

UWO MR Systems Development Lab Computing Code


Subject Headings

Introduction

What is MPCode?

Setting up the Environment

Where to Find the Code

Documentation

Using CVS

 

Link to HTML documentation of MPCode

 

Introduction

Coding properly is not about writing the fastest, cleverest code you can.  A brilliant piece of code is absolutely useless if the person who wrote it leaves and nobody understands the code.  The secret of coding in a useful way is to code for clarity, consistency and to use comments.   Code that is written according to a standard is more easily integrated into a code structure as a whole, it is more easily understood and correctly used by others and it is more likely to save work and to get the job done which is the whole point.   Remember the KISS principle, Keep It Simple Stupid.

Most of the code structure used at the Medical Physics Group is intended to further these ends. A complete explanation of the medical physics coding standards is written up as a html document and a perusal is strongly encouraged for anyone intending to add to, or to use, mpcode. Bear in mind that this project is in its infancy so do not expect perfection, otherwise you will be sorely disappointed.

What is MPCODE?

MPCODE is simply the collection of code written by the Medical Physics Group at the University of Western Ontario.  Code is written here to do the following things.

  • Design a Split Field Magnetic Resonance Imaging System

  • Simulate a combined PET Split Field Magnetic Resonance Imaging using GEANT

  • Monte Carlo of magnetostimulation experiments to aid in experiment design

  • Calculations of electrical fields and nerve responses for objects in a Split Field MR and normal gradient coils

  • Gradient coil design for head and breast imaging

We have integrated our own code with the ROOT libraries to make use of the large number of useful classes already written for that project.  ROOT is the Object Oriented Data Analysis tool written in C++ used by the particle and nuclear physics community.

Setting up the Environment

Before doing anything else you need to be working in the correct environment.  Unix machines, of which the Apple Mac is now a variety, use environment variables fo a large number of things (type printenv in a terminal).  The code structure uses environment variables to signify where the mpcode is located, the ROOT code is located, libraries ae located, executables are located etc etc etc.  These environment variables are complicated to setup so it is automated upon installation and can be done for either bash shells or c style October 30, 2006ne entry program running within the xterm window). To run tcsh set up properly for coding on the macs at Western you can place this .tcshrc shellscript in your home directory which is then sourced whenever you start a new shell. A good editor to use is emacs, the following .emacs file is setup correctly for Macs running Mac OsX panther and sets up the tabbing in line with medical physics group coding standards. The xterm defaults on macs are not so nice, use this .Xdefaults file to change the defaults to more useful settings.

Where to find the code

The code exists in several places. The latest versions of the code are stored in a cvs repository on the server which is located at /Volumes/D/cvshome.  For instructions on downloading the code from CVS for modification see the section below. A current version of the compiled mpcode is also available both on the server and shared to local machines where it is located at the /mpcode sharepoint on the local macintosh machines for general use on the local network. To use this version of the code follow the instructions below:

To have access to the ROOT libraries and program, in addition to the MPCODE libraries you need to source (run) the following shellscript:

  • source /mpcode/mpcode_7/config/netsetup_mp.csh (if running csh or tcsh)

  • source /mpcode/mpcode_7/config/netsetup_mp.sh (if running bash)

The local libraries (not the ROOT libraries, most of them are already loaded, though not all) can be loaded at startup by root by placing this rootlogon.C macro in your home directory. This file is automatically read by root when you start root if you have this file rootrc file in your home directory, so you can add style choices to it as well, have a look at the ROOT users guide for more details.

Documentation

One of the many advantages of the ROOT system is that it has already implemented a splendid method for generating documentation using the comments embedded in the code. Have a look at the ROOT web page in the class reference link to see the html generated for the ROOT code. The same method is applied to the mpcode and the resulting web pages can be found here. This is the main purpose for the comments on comments in our coding standards document and is a great aid to use and developement of the code.

Using CVS

CVS, the concurrent version system, is a powerful tool used to keep track of changes made to code over time and to allow multiple authors to work on code development concurrently.  CVS needs to be used with care.  Think before you jump.  Anybody with a an account on Clarke has access to the CVS repository so please be careful.
IMPORTANT NOTE:  You have to be logged on to Clarke to use cvs.  You cannot logon to clarke properly if you are logged into a local machine so I reccomend you use the testuser account to access cvs.


CVS Can be used in two ways, either command line or via the gui:

GUI CVS

You can run a gui to check out code into your network account on clarke as follows;

ssh user@clarke
setenv CVSROOT /Volumes/D/cvshome
tkcvs &


Using the gui might take a bit of practise, it makes perfect sense once you are used to CVS itself.  You can use it to check out, check in, export a version from a certain date, look at the differences between versions etc.  It is a very powerful tool so be careful.

COMMAND LINE CVS

  1. You can check out all of mpcode for modification

  2. Or you can check out a single module

Checking out the whole thing

You check out all of the mpcode using the following commands

ssh user@clarke
setenv CVSROOT /Volumes/D/cvshome
cvs checkout mpcode


This will make a directory in whatever directory you are in called mpcode which contains everything in mpcode.  If you want to use this version of MPCODE rather than the servers version then you need to install MPCODE.

cd mpcode
./install_mpcode
source config/setup.csh


Everytime you wish to use this version of the code you should source the startup script as above to ensure that you environment is set u correctly.

When you have finished modifiying the code you can recommit it to the repository.

cd ..
cvs commit mpcode

You will be prompted to enter what changes you have made in an editor, make your comments useful.

Checking out a single module

You can check out a single module if you only need to edit a single module.  To do this you need to be able to compile it so setup a my_mpcode directory as follows.

cd
mkdir mpcode
cd mpcode
ln -s $MP_ROOT/config
ln -s $MP_ROOT/Makefile
cp $MP_ROOT/Modules.mk .
cd ..

ssh testuser@clarke
cvs checkout mpcode/pcoil
scp -r mpcode/pcoil me@clarke:~/my_mpcode/.

You should now be able to compile pcoil yourself in your mpcode directory.

The code is recommitted to the repository by

ssh testuser@clarke
scp -r me@clarke:~/my_mpcode/pcoil mpcode/.

cvs commit mpcode/pcoil

Adding new code to the repository

You need to be logged onto clarke to add new code.  And you need a checkedout version.  Put the new code in an existing module or put a new module in.

cd
cvs add mpcode/pcoil/PNewClass.h
cvs add mpcode/pcoil/PNewClass.cxx
cvs commit mpcode/pcoil

Adding a new module

 

cd
cvs add mpcode/pnewmodule
cvs commit

Erasing a checked out version of the code


Do not simply erase the mpcode directory, you may have forgotten to check something in.  Instead do the following

cd
cvs release mpcode

If there are no unaltered files then hit y .  It is then safe to delete the mpcode directory.

IMPORTANT NOTE: If the version of the code you have is a bit old, you can update it instead of checking out a new version by running

cd
cvs update mpcode