Project

General

Profile

How to put a variable into CAF » History » Version 3

Version 2 (Jose Sepulveda-Quiroz, 12/04/2015 07:55 PM) → Version 3/10 (Jose Sepulveda-Quiroz, 12/04/2015 09:38 PM)

{{toc}}

h1. How to put a variable into CAF

This wiki is intended to be an **updated** and more **reliable** version of "docdb-12273":http://nova-docdb.fnal.gov:8080/cgi-bin/ShowDocument?docid=12273.

In the following lines we introduce a step-by-step approach on how to include a given variable into CAFs.

Comments and feedback are welcome. The _if you see something, say something_ policy applies here, it's a wiki!

h2. Goal

Our goal is to add a variable that stores the number of bad channels in a subrun, for example. For illustration purposes, we have decided we are going to include that variable in the header branch.

!add-var.png!

h2. Step 1: Download packages

Under development release (if you think you will be committing your work to the repository) or in any stable tag (if you do not know yet) and after setting up your environment <pre> srt setup -a </pre> download the following packages (for this example)

* StandardRecord
* CAFMaker

using the command <pre> addpkg svn -h <pkg name> </pre>

h2. Step 2: Define the object

Note: In this example, this step is equivalent to step 7 in the pdf version (docdb-12273).

Since we want to put our variable into the header branch (hdr) we open StandardRecord/SRHeader.h and add the type, name and a brief description of it at the end of the file

<pre>
<code class="cpp">
namespace caf
{
class SRNumuSandbox{
public:

...

unsigned int nbadchan; ///< Number of bad channels in a subrun. This is our new variable!

void setDefault();
};
}
</code>
</pre>

h2. Step 3: Update class version

Open StandardRecord/classes_def.xml and update the class version index from _i_ to _i+1_

<pre>
<code class="cpp">
<lcgdict>
...
<class name="caf::SRHeader" ClassVersion="22" >
...
</lcgdict>
</code>
</pre>

<pre>
<code class="cpp">
<lcgdict>
...
<class name="caf::SRHeader" ClassVersion="23" >
...
</lcgdict>
</code>
</pre>

h2. Step 4: Compile

After saving file the previous changes, go to your $SRT_PRIVATE_CONTEXT area compile StandardRecord package

<pre>
<novagpvm08.fnal.gov> make StandardRecord.all
</pre>

You will get an error message like this (NOTE: that was the case at the time of writing the pdf version of this tutorial)

<pre>
...
class caf::SRLid
<**compiling**> StandardRecord_dict.cc
<**linking**> libStandardRecord_dict.so
<**checking class version numbers**> libStandardRecord_dict.so
INFO: adding version info for class 'caf::SRHeader':
<version ClassVersion="23" checksum="2291111394"/>
WARNING: classes_def.xml files have been updated: rebuild
dictionaries.
make[1]: *** [/nova/app/users/jasq/devel/lib/
Linux2.6-GCC-maxopt/libStandardRecord_dict.so] Error 2
make: *** [StandardRecord.all] Error 2
</pre>

h2. Step 5: Compile again

The solution to the previous error is simply compile again

<pre>
<novagpvm08.fnal.gov> make StandardRecord.all
...
class caf::SRLid
<**compiling**> StandardRecord_dict.cc
<**linking**> libStandardRecord_dict.so
<**checking class version numbers**> libStandardRecord_dict.so
<**compiling**> StandardRecord_map.cc
<**linking**> libStandardRecord_map.so
<novagpvm08.fnal.gov>
</pre>

h2. Step 6: Add into CAFMaker

Open CAFMaker/CAFMaker_module.cc but be aware that this is gonna be a huge file. The trick is search for keywords (i.e. header).
This is one of the most important parts since is in here where you are defining the instructions to put your variable into the CAF framework.

<pre>
<code class="cpp">

...

//#######################################################
// Fill header.
//#######################################################
// Get metadata information for header
unsigned int run = evt.run();
...

unsigned int nbadchan = bc->NBadInSubRun(subrun); // This is our new variable!

...

rec.hdr = SRHeader();

rec.hdr.run = run;

...

rec.hdr.nbadchan = nbadchan; // This is our new variable!

...
</code>
</pre>

After this, save it. Compile

<pre>
make CAFMaker.all
</pre>

You should not get any error messages.

h2. Step 7: Almost done

In order to test that your variable is producing reasonable values, let's test it. You will need two things

* An input ART root file (i.e. reco/pid)
* A .fcl file (for example, CAFMaker/cafmakerjob.fcl or the one in the job/ folder)

h2. Step 8: Produce the CAF

In the area you have been working, you can produce the CAF by doing

<pre>
nova -c job/cafmakerjob.fcl -n 2 <input ART root file>
</pre>

after that, open it

<pre>
cafe <file_name>
</pre>

!result.png!

Your variable has been added and filled!

h2. Making it real

Thinking your variable is ready for submission? Send an email to nova_offline or contact any group convener before commit.

h2. References/Documentation

The following material was consulted when preparing at this tutorial

* "Description of variables in CAFs - from the NOvA art-wiki":https://cdcvs.fnal.gov/redmine/projects/novaart/wiki/CAF_Tree_Structure_and_Variable_Listing