]>
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 | |
71 | * @param opts Options | |
72 | */ | |
73 | LocalHelper(const TUrl& url, Int_t verbose) | |
74 | : Helper(url, verbose), fChain(0) | |
75 | { | |
76 | fOptions.Add("mc", "Scan for MC files (galice,kinematics,trackrefs)"); | |
77 | fOptions.Add("recursive","Scan recursive"); | |
78 | fOptions.Add("pattern", "GLOB", "File name pattern", "*.root"); | |
79 | } | |
80 | /** | |
81 | * Destructor | |
82 | */ | |
83 | virtual ~LocalHelper() {} | |
84 | /** | |
85 | * Load a library | |
86 | * | |
87 | * @param name Name of library | |
88 | * | |
89 | * @return true on success | |
90 | */ | |
91 | virtual Bool_t LoadLibrary(const TString& name, Bool_t) | |
92 | { | |
93 | Int_t ret = gSystem->Load(MakeLibraryName(name)); | |
94 | return ret >= 0; | |
95 | } | |
96 | /** | |
97 | * Get the execution mode | |
98 | * | |
99 | * @return Always kLocal | |
100 | */ | |
101 | virtual UShort_t Mode() const { return kLocal; } | |
102 | /** | |
103 | * Get the mode string used for AliAnalysisManager::StartAnalysis | |
104 | */ | |
105 | virtual const char* ModeString() const { return "local"; } | |
106 | /** | |
107 | * Set-up done before task set-ups | |
108 | * | |
109 | * @return true on success | |
110 | */ | |
111 | virtual Bool_t PreSetup() | |
112 | { | |
113 | return true; | |
114 | } | |
115 | /** | |
116 | * Set-up done after the task set-ups | |
117 | * | |
118 | * @return true on success | |
119 | */ | |
120 | virtual Bool_t PostSetup() | |
121 | { | |
122 | TString treeName(fUrl.GetAnchor()); | |
123 | TString pattern(fOptions.Has("pattern") ? fOptions.Get("pattern") : ""); | |
124 | Bool_t recursive = fOptions.Has("recursive"); | |
125 | Bool_t mc = fOptions.Has("mc"); | |
126 | ||
127 | fChain = ChainBuilder::Create(fUrl.GetFile(), treeName, | |
128 | pattern, mc, recursive); | |
129 | ||
130 | AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager(); | |
131 | if (!mgr) { | |
132 | Error("PostSetup", "No analysis manager defined"); | |
133 | return false; | |
134 | } | |
135 | return true; | |
136 | }; | |
137 | /** | |
138 | * Start the analysis | |
139 | * | |
140 | * @param nEvents Number of events to analyse | |
141 | * | |
142 | * @return The return value of AliAnalysisManager::StartAnalysis | |
143 | */ | |
144 | virtual Long64_t Run(Long64_t nEvents=-1) | |
145 | { | |
146 | AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager(); | |
147 | ||
148 | if (nEvents < 0) nEvents = fChain->GetEntries(); | |
149 | return mgr->StartAnalysis(fUrl.GetProtocol(), fChain, nEvents); | |
150 | } | |
151 | /** | |
152 | * @return URL help string | |
153 | */ | |
154 | virtual const Char_t* UrlHelp() const | |
155 | { | |
156 | return "local://<datadir or list>[?<options>][#<treeName>]"; | |
157 | } | |
158 | /** | |
159 | * @return Short description | |
160 | */ | |
161 | virtual const char* Desc() const { return "Local"; } | |
162 | TChain* fChain; // Our chain | |
163 | }; | |
164 | #endif | |
165 | // | |
166 | // EOF | |
167 | // |