]>
Commit | Line | Data |
---|---|---|
fdfd93b4 | 1 | /** |
2 | * @file LocalHelper.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 "Helper.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 Helper; | |
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><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 | |
49 | * <dl> | |
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> | |
59 | * </dl> | |
60 | * </dd> | |
61 | * </dl> | |
62 | * | |
63 | * @ingroup pwglf_forward_trains_helper | |
64 | */ | |
65 | struct LocalHelper : public Helper | |
66 | { | |
67 | /** | |
68 | * Constructor | |
69 | * | |
70 | * @param url Url | |
33438b4c | 71 | * @param verbose Verbosity level |
fdfd93b4 | 72 | */ |
73 | LocalHelper(const TUrl& url, Int_t verbose) | |
74 | : Helper(url, verbose), fChain(0) | |
75 | { | |
fdfd93b4 | 76 | fOptions.Add("recursive","Scan recursive"); |
77 | fOptions.Add("pattern", "GLOB", "File name pattern", "*.root"); | |
78 | } | |
46b25775 | 79 | /** |
80 | * Copy constructor | |
81 | * | |
82 | * @param o Object to copy from | |
83 | */ | |
84 | LocalHelper(const LocalHelper& o) | |
85 | : Helper(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 | LocalHelper& operator=(const LocalHelper& o) | |
95 | { | |
96 | if (&o == this) return *this; | |
97 | Helper::operator=(o); | |
98 | fChain = o.fChain; | |
99 | return *this; | |
100 | } | |
fdfd93b4 | 101 | /** |
102 | * Destructor | |
103 | */ | |
104 | virtual ~LocalHelper() {} | |
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 | ||
148 | fChain = ChainBuilder::Create(fUrl.GetFile(), treeName, | |
149 | pattern, mc, recursive); | |
150 | ||
151 | AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager(); | |
152 | if (!mgr) { | |
153 | Error("PostSetup", "No analysis manager defined"); | |
154 | return false; | |
155 | } | |
156 | return true; | |
157 | }; | |
158 | /** | |
159 | * Start the analysis | |
160 | * | |
161 | * @param nEvents Number of events to analyse | |
162 | * | |
163 | * @return The return value of AliAnalysisManager::StartAnalysis | |
164 | */ | |
165 | virtual Long64_t Run(Long64_t nEvents=-1) | |
166 | { | |
167 | AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager(); | |
168 | ||
169 | if (nEvents < 0) nEvents = fChain->GetEntries(); | |
170 | return mgr->StartAnalysis(fUrl.GetProtocol(), fChain, nEvents); | |
171 | } | |
172 | /** | |
173 | * @return URL help string | |
174 | */ | |
175 | virtual const Char_t* UrlHelp() const | |
176 | { | |
177 | return "local://<datadir or list>[?<options>][#<treeName>]"; | |
178 | } | |
179 | /** | |
180 | * @return Short description | |
181 | */ | |
182 | virtual const char* Desc() const { return "Local"; } | |
183 | TChain* fChain; // Our chain | |
184 | }; | |
185 | #endif | |
186 | // | |
187 | // EOF | |
188 | // |