Project

General

Profile

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

Jose Sepulveda-Quiroz, 08/07/2017 09:43 PM

1 1 Jose Sepulveda-Quiroz
{{toc}}
2 1 Jose Sepulveda-Quiroz
3 1 Jose Sepulveda-Quiroz
h1. How to put a variable into CAF
4 1 Jose Sepulveda-Quiroz
5 2 Jose Sepulveda-Quiroz
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. 
6 2 Jose Sepulveda-Quiroz
7 3 Jose Sepulveda-Quiroz
In the following lines we introduce a step-by-step approach on how to include a given variable into CAFs. 
8 3 Jose Sepulveda-Quiroz
9 3 Jose Sepulveda-Quiroz
Comments and feedback are welcome. The _if you see something, say something_ policy applies here, it's a wiki!
10 3 Jose Sepulveda-Quiroz
11 3 Jose Sepulveda-Quiroz
12 3 Jose Sepulveda-Quiroz
h2. Goal 
13 3 Jose Sepulveda-Quiroz
14 3 Jose Sepulveda-Quiroz
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.  
15 3 Jose Sepulveda-Quiroz
16 3 Jose Sepulveda-Quiroz
!add-var.png!
17 3 Jose Sepulveda-Quiroz
18 3 Jose Sepulveda-Quiroz
h2. Step 1: Download packages
19 3 Jose Sepulveda-Quiroz
20 3 Jose Sepulveda-Quiroz
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)
21 3 Jose Sepulveda-Quiroz
22 3 Jose Sepulveda-Quiroz
* StandardRecord
23 3 Jose Sepulveda-Quiroz
* CAFMaker
24 3 Jose Sepulveda-Quiroz
25 8 Christopher Backhouse
using the command  <pre> addpkg_svn -h <pkg name> </pre>
26 3 Jose Sepulveda-Quiroz
27 3 Jose Sepulveda-Quiroz
h2. Step 2: Define the object
28 3 Jose Sepulveda-Quiroz
29 3 Jose Sepulveda-Quiroz
Note: In this example, this step is equivalent to step 7 in the pdf version (docdb-12273).
30 3 Jose Sepulveda-Quiroz
31 3 Jose Sepulveda-Quiroz
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
32 3 Jose Sepulveda-Quiroz
33 3 Jose Sepulveda-Quiroz
<pre>
34 3 Jose Sepulveda-Quiroz
<code class="cpp"> 
35 3 Jose Sepulveda-Quiroz
namespace caf
36 3 Jose Sepulveda-Quiroz
{
37 3 Jose Sepulveda-Quiroz
   class SRNumuSandbox{
38 3 Jose Sepulveda-Quiroz
   public:
39 3 Jose Sepulveda-Quiroz
	
40 3 Jose Sepulveda-Quiroz
   ...
41 3 Jose Sepulveda-Quiroz
	
42 3 Jose Sepulveda-Quiroz
   unsigned int  nbadchan;   ///< Number of bad channels in a subrun. This is our new variable!
43 3 Jose Sepulveda-Quiroz
44 3 Jose Sepulveda-Quiroz
   void setDefault();
45 3 Jose Sepulveda-Quiroz
   };
46 3 Jose Sepulveda-Quiroz
}
47 3 Jose Sepulveda-Quiroz
</code>
48 3 Jose Sepulveda-Quiroz
</pre>
49 3 Jose Sepulveda-Quiroz
50 9 Jose Sepulveda-Quiroz
h2. -Step 3: Update class version- (Deprecated)
51 3 Jose Sepulveda-Quiroz
52 9 Jose Sepulveda-Quiroz
-Open StandardRecord/classes_def.xml and update the class version index from _i_ to _i+1_-
53 3 Jose Sepulveda-Quiroz
54 3 Jose Sepulveda-Quiroz
<pre>
55 3 Jose Sepulveda-Quiroz
<code class="cpp"> 
56 3 Jose Sepulveda-Quiroz
<lcgdict>
57 3 Jose Sepulveda-Quiroz
   ...
58 3 Jose Sepulveda-Quiroz
   <class name="caf::SRHeader"       ClassVersion="22" >
59 3 Jose Sepulveda-Quiroz
   ...
60 3 Jose Sepulveda-Quiroz
</lcgdict>  
61 3 Jose Sepulveda-Quiroz
</code>
62 3 Jose Sepulveda-Quiroz
</pre>
63 3 Jose Sepulveda-Quiroz
64 3 Jose Sepulveda-Quiroz
<pre>
65 3 Jose Sepulveda-Quiroz
<code class="cpp"> 
66 3 Jose Sepulveda-Quiroz
<lcgdict>
67 3 Jose Sepulveda-Quiroz
   ...
68 3 Jose Sepulveda-Quiroz
   <class name="caf::SRHeader"       ClassVersion="23" >
69 3 Jose Sepulveda-Quiroz
   ...
70 3 Jose Sepulveda-Quiroz
</lcgdict>  
71 3 Jose Sepulveda-Quiroz
</code>
72 3 Jose Sepulveda-Quiroz
</pre>
73 3 Jose Sepulveda-Quiroz
74 3 Jose Sepulveda-Quiroz
h2. Step 4: Compile 
75 3 Jose Sepulveda-Quiroz
76 3 Jose Sepulveda-Quiroz
After saving file the previous changes, go to your $SRT_PRIVATE_CONTEXT area compile StandardRecord package
77 3 Jose Sepulveda-Quiroz
78 3 Jose Sepulveda-Quiroz
<pre>
79 3 Jose Sepulveda-Quiroz
<novagpvm08.fnal.gov> make StandardRecord.all
80 3 Jose Sepulveda-Quiroz
</pre>
81 3 Jose Sepulveda-Quiroz
82 3 Jose Sepulveda-Quiroz
You will get an error message like this (NOTE: that was the case at the time of writing the pdf version of this tutorial)
83 3 Jose Sepulveda-Quiroz
84 3 Jose Sepulveda-Quiroz
<pre>
85 3 Jose Sepulveda-Quiroz
...
86 3 Jose Sepulveda-Quiroz
class caf::SRLid
87 3 Jose Sepulveda-Quiroz
<**compiling**> StandardRecord_dict.cc
88 3 Jose Sepulveda-Quiroz
<**linking**> libStandardRecord_dict.so
89 3 Jose Sepulveda-Quiroz
<**checking class version numbers**> libStandardRecord_dict.so
90 3 Jose Sepulveda-Quiroz
INFO: adding version info for class 'caf::SRHeader':
91 3 Jose Sepulveda-Quiroz
<version ClassVersion="23" checksum="2291111394"/>
92 3 Jose Sepulveda-Quiroz
WARNING: classes_def.xml files have been updated: rebuild 
93 3 Jose Sepulveda-Quiroz
dictionaries.
94 3 Jose Sepulveda-Quiroz
make[1]: *** [/nova/app/users/jasq/devel/lib/
95 3 Jose Sepulveda-Quiroz
Linux2.6-GCC-maxopt/libStandardRecord_dict.so] Error 2
96 3 Jose Sepulveda-Quiroz
make: *** [StandardRecord.all] Error 2
97 3 Jose Sepulveda-Quiroz
</pre>
98 3 Jose Sepulveda-Quiroz
99 3 Jose Sepulveda-Quiroz
h2. Step 5: Compile again
100 3 Jose Sepulveda-Quiroz
101 3 Jose Sepulveda-Quiroz
The solution to the previous error is simply compile again
102 3 Jose Sepulveda-Quiroz
103 3 Jose Sepulveda-Quiroz
<pre>
104 3 Jose Sepulveda-Quiroz
<novagpvm08.fnal.gov>  make StandardRecord.all
105 3 Jose Sepulveda-Quiroz
...
106 3 Jose Sepulveda-Quiroz
class caf::SRLid
107 3 Jose Sepulveda-Quiroz
<**compiling**> StandardRecord_dict.cc
108 3 Jose Sepulveda-Quiroz
<**linking**> libStandardRecord_dict.so
109 3 Jose Sepulveda-Quiroz
<**checking class version numbers**> libStandardRecord_dict.so
110 3 Jose Sepulveda-Quiroz
<**compiling**> StandardRecord_map.cc
111 3 Jose Sepulveda-Quiroz
<**linking**> libStandardRecord_map.so
112 3 Jose Sepulveda-Quiroz
<novagpvm08.fnal.gov>
113 3 Jose Sepulveda-Quiroz
</pre>
114 3 Jose Sepulveda-Quiroz
115 3 Jose Sepulveda-Quiroz
h2. Step 6: Add into CAFMaker
116 3 Jose Sepulveda-Quiroz
117 3 Jose Sepulveda-Quiroz
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). 
118 3 Jose Sepulveda-Quiroz
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.
119 3 Jose Sepulveda-Quiroz
120 3 Jose Sepulveda-Quiroz
<pre>
121 3 Jose Sepulveda-Quiroz
<code class="cpp"> 
122 3 Jose Sepulveda-Quiroz
123 3 Jose Sepulveda-Quiroz
      ...
124 3 Jose Sepulveda-Quiroz
125 3 Jose Sepulveda-Quiroz
      //#######################################################
126 3 Jose Sepulveda-Quiroz
      // Fill header.
127 3 Jose Sepulveda-Quiroz
      //#######################################################
128 3 Jose Sepulveda-Quiroz
      // Get metadata information for header
129 3 Jose Sepulveda-Quiroz
      unsigned int run = evt.run();
130 3 Jose Sepulveda-Quiroz
      ...
131 3 Jose Sepulveda-Quiroz
132 3 Jose Sepulveda-Quiroz
      unsigned int nbadchan = bc->NBadInSubRun(subrun);     // This is our new variable!
133 3 Jose Sepulveda-Quiroz
134 3 Jose Sepulveda-Quiroz
      ...
135 3 Jose Sepulveda-Quiroz
136 3 Jose Sepulveda-Quiroz
      rec.hdr = SRHeader();
137 3 Jose Sepulveda-Quiroz
      
138 3 Jose Sepulveda-Quiroz
      rec.hdr.run             = run;
139 3 Jose Sepulveda-Quiroz
140 3 Jose Sepulveda-Quiroz
      ...
141 3 Jose Sepulveda-Quiroz
142 3 Jose Sepulveda-Quiroz
      rec.hdr.nbadchan        = nbadchan;                   // This is our new variable!
143 3 Jose Sepulveda-Quiroz
144 3 Jose Sepulveda-Quiroz
      ...
145 3 Jose Sepulveda-Quiroz
</code>
146 3 Jose Sepulveda-Quiroz
</pre>
147 3 Jose Sepulveda-Quiroz
148 3 Jose Sepulveda-Quiroz
149 3 Jose Sepulveda-Quiroz
After this, save it. Compile
150 3 Jose Sepulveda-Quiroz
151 3 Jose Sepulveda-Quiroz
<pre>
152 3 Jose Sepulveda-Quiroz
make CAFMaker.all
153 3 Jose Sepulveda-Quiroz
</pre> 
154 3 Jose Sepulveda-Quiroz
155 3 Jose Sepulveda-Quiroz
You should not get any error messages.
156 3 Jose Sepulveda-Quiroz
157 3 Jose Sepulveda-Quiroz
h2. Step 7: Almost done
158 3 Jose Sepulveda-Quiroz
159 3 Jose Sepulveda-Quiroz
In order to test that your variable is producing reasonable values, let's test it. You will need two things
160 3 Jose Sepulveda-Quiroz
161 3 Jose Sepulveda-Quiroz
* An input ART root file (i.e.  reco/pid)
162 3 Jose Sepulveda-Quiroz
* A .fcl file (for example, CAFMaker/cafmakerjob.fcl or the one in the job/ folder)
163 3 Jose Sepulveda-Quiroz
164 3 Jose Sepulveda-Quiroz
h2. Step 8: Produce the CAF
165 3 Jose Sepulveda-Quiroz
166 3 Jose Sepulveda-Quiroz
In the area you have been working, you can produce the CAF by doing
167 3 Jose Sepulveda-Quiroz
168 3 Jose Sepulveda-Quiroz
<pre>
169 3 Jose Sepulveda-Quiroz
nova -c job/cafmakerjob.fcl -n 2 <input ART root file>
170 3 Jose Sepulveda-Quiroz
</pre>
171 3 Jose Sepulveda-Quiroz
172 3 Jose Sepulveda-Quiroz
after that, open it
173 3 Jose Sepulveda-Quiroz
174 3 Jose Sepulveda-Quiroz
<pre>
175 3 Jose Sepulveda-Quiroz
cafe <file_name>
176 3 Jose Sepulveda-Quiroz
</pre>
177 3 Jose Sepulveda-Quiroz
178 3 Jose Sepulveda-Quiroz
!result.png!
179 3 Jose Sepulveda-Quiroz
180 3 Jose Sepulveda-Quiroz
Your variable has been added and filled!
181 3 Jose Sepulveda-Quiroz
182 3 Jose Sepulveda-Quiroz
h2. Making it real
183 3 Jose Sepulveda-Quiroz
184 3 Jose Sepulveda-Quiroz
Thinking your variable is ready for submission? Send an email to nova_offline or contact any group convener before commit.
185 3 Jose Sepulveda-Quiroz
186 3 Jose Sepulveda-Quiroz
h2. References/Documentation
187 3 Jose Sepulveda-Quiroz
188 7 Jose Sepulveda-Quiroz
The following material was consulted when preparing this tutorial
189 3 Jose Sepulveda-Quiroz
190 5 Jose Sepulveda-Quiroz
* "Description of variables in CAFs from the NOvA art-wiki":https://cdcvs.fnal.gov/redmine/projects/novaart/wiki/CAF_Tree_Structure_and_Variable_Listing
191 5 Jose Sepulveda-Quiroz
* "Introduction to the Common Analysis Files by Dominick Rocco":http://nova-docdb.fnal.gov:8080/cgi-bin/ShowDocument?docid=11002
192 6 Jose Sepulveda-Quiroz
* "Introduction to CAFAna framework by Gavin Davies":http://nova-docdb.fnal.gov:8080/cgi-bin/ShowDocument?docid=11008