]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/trains/LocalRailway.C
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / trains / LocalRailway.C
1 /**
2  * @file   LocalRailway.C
3  * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
4  * @date   Tue Oct 16 18:59:42 2012
5  * 
6  * @brief  Local analysis helper
7  * 
8  * @ingroup pwglf_forward_trains_helper
9  * 
10  */
11 #ifndef LOCALHELPER_C
12 #define LOCALHELPER_C
13 #ifndef __CINT__
14 # include "Railway.C"
15 # include "ChainBuilder.C"
16 # include <TUrl.h>
17 # include <TString.h>
18 # include <TSystem.h>
19 # include <AliAnalysisManager.h>
20 #else
21 class TChain;
22 class Railway;
23 class TUrl;
24 #endif
25
26 // ===================================================================
27 /** 
28  * Handle local analysis jobs 
29  *
30  * This is triggered by URIs of the form 
31  *
32  * @code 
33  * local:///<datadir>[?<options>][#treeName]
34  * local:///<collection>[?<options>][#treeName]
35  * local:///<file>[?<options>][#treeName]
36  * @endcode 
37  *
38  * where 
39  *
40  * <dl>
41  *   <dt><tt>&lt;datadir&gt;</tt></dt>
42  *   <dd>is the base directory holding data files </dd>
43  *   <dt><tt>&lt;collection&gt;</tt></dt>
44  *   <dd>is an ASCII or XML list of input sources</dd>
45  *   <dt><tt>&lt;file&gt;</tt></dt>
46  *   <dd>is a single ROOT file</dd>
47  *   <dt><tt>&lt;options&gt;</tt></dt>
48  *   <dd>A &amp; separated list of options
49  *     <dl>
50  *       <dt><tt>recursive</tt></dt>
51  *       <dd>Scan &lt;datadir&gt; recursively</dd>
52  *       <dt><tt>mc</tt></dt>
53  *       <dd>Scan also for MC files (<tt>galice.root</tt>, 
54  *          <tt>Kinematics.root</tt>, and <tt>TrackRefs.root</tt>) when 
55  *          scanning &lt;datadir&gt;</dd>
56  *       <dt><tt>pattern=&lt;GLOB&gt;</tt></dt>
57  *       <dd>Shell glob pattern that files must check when scanning 
58  *         &lt;datadir&gt;</dd>
59  *      </dl>
60  *   </dd>
61  * </dl>
62  *       
63  * @ingroup pwglf_forward_trains_helper
64  */
65 struct LocalRailway : public Railway
66 {
67   /** 
68    * Constructor 
69    * 
70    * @param url   Url 
71    * @param verbose Verbosity level 
72    */
73   LocalRailway(const TUrl& url, Int_t verbose)
74     : Railway(url, verbose), fChain(0)
75   {
76     fOptions.Add("recursive","Scan recursive");
77     fOptions.Add("pattern",  "GLOB", "File name pattern", "*.root");
78   }
79   /** 
80    * Copy constructor 
81    * 
82    * @param o Object to copy from 
83    */
84   LocalRailway(const LocalRailway& o) 
85     : Railway(o), fChain(o.fChain)
86   {}
87   /** 
88    * Assignment operator 
89    * 
90    * @param o Object to assign from 
91    * 
92    * @return Reference to this 
93    */
94   LocalRailway& operator=(const LocalRailway& o) 
95   {
96     if (&o == this) return *this;
97     Railway::operator=(o);
98     fChain = o.fChain;
99     return *this;
100   }
101   /** 
102    * Destructor 
103    */
104   virtual ~LocalRailway() {}
105   /** 
106    * Load a library 
107    * 
108    * @param name    Name of library 
109    * 
110    * @return true on success
111    */
112   virtual Bool_t LoadLibrary(const TString& name, Bool_t)
113   {
114     Int_t ret = gSystem->Load(MakeLibraryName(name));
115     return ret >= 0;
116   }
117   /** 
118    * Get the execution mode 
119    *
120    * @return Always kLocal
121    */
122   virtual UShort_t Mode() const { return kLocal; }
123   /**
124    * Get the mode string used for AliAnalysisManager::StartAnalysis
125    */
126   virtual const char* ModeString() const { return "local"; }
127   /** 
128    * Set-up done before task set-ups 
129    * 
130    * @return true on success 
131    */
132   virtual Bool_t PreSetup() 
133   {
134     return true;
135   }
136   /** 
137    * Set-up done after the task set-ups 
138    *
139    * @return true on success 
140    */
141   virtual Bool_t PostSetup() 
142   {
143     TString treeName(fUrl.GetAnchor());
144     TString pattern(fOptions.Has("pattern") ? fOptions.Get("pattern") : "");
145     Bool_t  recursive = fOptions.Has("recursive");
146     Bool_t  mc        = fOptions.Has("mc");
147     TString file      = fUrl.GetFile();
148     if (file.IsNull()) {
149       Error("PostSetup", "No input source specified");
150       return false;
151     }
152
153     pattern.ReplaceAll("@", "#");
154     fChain = ChainBuilder::Create(file, treeName, pattern, mc, recursive,
155                                   fVerbose);
156     if (!fChain) { 
157       Error("PostSetup", "No chain defined "
158             "(src=%s, treeName=%s, pattern=%s, mc=%s, recursive=%s)", 
159             file.Data(), treeName.Data(), pattern.Data(), 
160             (mc ? "true" : "false"), (recursive ? "true" : "false"));
161       return false;
162     }
163
164     AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
165     if (!mgr) { 
166       Error("PostSetup", "No analysis manager defined");
167       return false;
168     }
169     return true;
170   };
171   /** 
172    * Start the analysis 
173    * 
174    * @param nEvents Number of events to analyse 
175    * 
176    * @return The return value of AliAnalysisManager::StartAnalysis
177    */
178   virtual Long64_t Run(Long64_t nEvents=-1) 
179   {
180     AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
181     
182     if (nEvents < 0) nEvents = fChain->GetEntries();
183     return mgr->StartAnalysis(fUrl.GetProtocol(), fChain, nEvents);
184   }
185   /** 
186    * @return URL help string
187    */
188   virtual const Char_t* UrlHelp() const 
189   {
190     return "local://<datadir or list>[?<options>][#<treeName>]";
191   }
192   /** 
193    * @return Short description 
194    */
195   virtual const char* Desc() const { return "Local"; }
196   TChain* fChain; // Our chain
197 };
198 #endif
199 //
200 // EOF
201 //