3 * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
4 * @date Tue Oct 16 18:59:42 2012
6 * @brief Local analysis helper
8 * @ingroup pwglf_forward_trains_helper
15 # include "ChainBuilder.C"
19 # include <AliAnalysisManager.h>
26 // ===================================================================
28 * Handle local analysis jobs
30 * This is triggered by URIs of the form
33 * local:///<datadir>[?<options>][#treeName]
34 * local:///<collection>[?<options>][#treeName]
35 * local:///<file>[?<options>][#treeName]
41 * <dt><tt><datadir></tt></dt>
42 * <dd>is the base directory holding data files </dd>
43 * <dt><tt><collection></tt></dt>
44 * <dd>is an ASCII or XML list of input sources</dd>
45 * <dt><tt><file></tt></dt>
46 * <dd>is a single ROOT file</dd>
47 * <dt><tt><options></tt></dt>
48 * <dd>A & separated list of options
50 * <dt><tt>recursive</tt></dt>
51 * <dd>Scan <datadir> 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 <datadir></dd>
56 * <dt><tt>pattern=<GLOB></tt></dt>
57 * <dd>Shell glob pattern that files must check when scanning
58 * <datadir></dd>
63 * @ingroup pwglf_forward_trains_helper
65 struct LocalRailway : public Railway
71 * @param verbose Verbosity level
73 LocalRailway(const TUrl& url, Int_t verbose)
74 : Railway(url, verbose), fChain(0)
76 fOptions.Add("recursive","Scan recursive");
77 fOptions.Add("pattern", "GLOB", "File name pattern", "*.root");
82 * @param o Object to copy from
84 LocalRailway(const LocalRailway& o)
85 : Railway(o), fChain(o.fChain)
90 * @param o Object to assign from
92 * @return Reference to this
94 LocalRailway& operator=(const LocalRailway& o)
96 if (&o == this) return *this;
97 Railway::operator=(o);
104 virtual ~LocalRailway() {}
108 * @param name Name of library
110 * @return true on success
112 virtual Bool_t LoadLibrary(const TString& name, Bool_t)
114 Int_t ret = gSystem->Load(MakeLibraryName(name));
118 * Get the execution mode
120 * @return Always kLocal
122 virtual UShort_t Mode() const { return kLocal; }
124 * Get the mode string used for AliAnalysisManager::StartAnalysis
126 virtual const char* ModeString() const { return "local"; }
128 * Set-up done before task set-ups
130 * @return true on success
132 virtual Bool_t PreSetup()
137 * Set-up done after the task set-ups
139 * @return true on success
141 virtual Bool_t PostSetup()
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();
149 Error("PostSetup", "No input source specified");
153 pattern.ReplaceAll("@", "#");
154 fChain = ChainBuilder::Create(file, treeName, pattern, mc, recursive,
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"));
164 AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
166 Error("PostSetup", "No analysis manager defined");
174 * @param nEvents Number of events to analyse
176 * @return The return value of AliAnalysisManager::StartAnalysis
178 virtual Long64_t Run(Long64_t nEvents=-1)
180 AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
182 if (nEvents < 0) nEvents = fChain->GetEntries();
183 return mgr->StartAnalysis(fUrl.GetProtocol(), fChain, nEvents);
186 * @return URL help string
188 virtual const Char_t* UrlHelp() const
190 return "local://<datadir or list>[?<options>][#<treeName>]";
193 * @return Short description
195 virtual const char* Desc() const { return "Local"; }
196 TChain* fChain; // Our chain