22 : fTmp(""), fPath(""), fPass(""), fRuns(""), fDebug(false)
26 Bool_t Run(const TString& name, Bool_t mc=false, ULong_t minSize=1000000)
29 gSystem->TempFileName(fTmp);
30 gSystem->Unlink(fTmp);
32 if (fDebug) Info("", "TMP=%s", fTmp.Data());
38 if (!GetJobUrl(name, mc, job)) return false;
40 if (!GetRuns(job, mc, minSize)) return false;
42 if (!fPass.IsNull()) fPass.Append("/");
43 Printf("alien://%s?pattern=%s*/AliESDs.root&runs=%s",
44 fPath.Data(), fPass.Data(), fRuns.Data());
46 gSystem->Unlink(fTmp);
49 Bool_t GetJobUrl(const TString& name, Bool_t mc, TString& url)
52 TString index("raw.jsp");
53 if (!Download((mc ? "job_details.jsp" : "production/raw.jsp"), index))
56 std::ifstream in(index.Data());
58 TString tgt(Form("<td class=\"table_row\">%s</td>", name.Data()));
61 if (!line.Contains(tgt)) continue;
63 Int_t first = line.Index("href=\"");
64 Int_t last = line.Index("\"", first+7);
65 url = line(first+6,last-first-6);
72 Error("GetJobUrl", "Production %s not found", name.Data());
78 Bool_t GetRuns(const TString& url, Bool_t mc, ULong_t minSize)
81 if (!Download(Form("%s%s", (mc ? "" : "raw/"), url.Data()), index))
84 std::ifstream in(index.Data());
85 TString tgt1(mc ? "window.open" : "runDetails");
89 if (!line.Contains(tgt1)) continue;
93 first = line.Index(tgt1);
94 last = line.Index(")", first+tgt1.Length()+1);
97 Int_t tmp = line.Index(">");
98 first = line.Index(">", tmp+1);
99 last = line.Index("<", first);
101 if (first == kNPOS || last == kNPOS) {
102 Error("GetDir", "Failed to get directory from %s", line.Data());
105 first += (mc ? 1 : tgt1.Length()+1);
107 TString srun = line(first, last);
108 ULong_t runNo = srun.Atoll();
109 if (fDebug) Info("", "Got run %lu (%s)", runNo, srun.Data());
111 if (!GetSize(in, runNo, mc, minSize)) continue;
112 if (!GetDir(in, runNo, mc)) continue;
114 if (!fRuns.IsNull()) fRuns.Append(",");
115 fRuns.Append(Form("%lu", runNo));
118 if (fRuns.IsNull()) return false;
122 Bool_t GetSize(std::istream& in, ULong_t runNo,
123 Bool_t mc, ULong_t minSize=100000)
126 TString tgt2(mc ? "table_row_right" : "ESDs size");
130 if (!line.Contains(tgt2)) continue;
132 if (mc && cnt < 3) continue;
133 if (!mc) line.ReadLine(in);
134 if (fDebug) Info("", line);
138 Int_t first = line.Index(">");
139 Int_t last = line.Index("<",first+1);
140 if (first == kNPOS || last == kNPOS) {
141 Error("GetDir", "Failed to get directory from %s", line.Data());
144 ssiz = line(first+1, last-first-1);
147 for (Int_t i = 0; i < line.Length(); i++) {
148 if (line[i] == '<') break;
149 if (line[i] == ' ' || line[i] == '\t' || line[i] == ',') continue;
150 ssiz.Append(line[i]);
153 Long_t size = ssiz.Atoll();
154 if (fDebug) Info("", "Got run %lu %lu" , runNo, size);
156 Error("GetSize", "Failed to extract size for run %lu", runNo);
159 if (ULong_t(size) < minSize) {
160 Warning("GetSize","Run %lu does not have enough events %lu",runNo,size);
167 Bool_t GetDir(std::istream& in, ULong_t runNo, Bool_t mc)
170 TString tgt3("/catalogue/index.jsp");
173 // Info("", "line=%s", line.Data());
174 if (!line.Contains(tgt3)) continue;
175 if (fDebug) Info("", line);
176 Int_t tmp = mc ? line.Index(">")+1 : 0;
177 Int_t first = line.Index(">", tmp);
178 Int_t last = line.Index("<",first+1);
179 if (first == kNPOS || last == kNPOS) {
180 Error("GetDir", "Failed to get directory from %s", line.Data());
184 TString dir = line(first+1,last-first-1);
186 if (fDebug) Info("", "Got run %lu %s", runNo, dir.Data());
188 if (!GetPathPass(dir, runNo, path, pass)) return false;
190 if (fDebug) Info("", "Got run %lu %s %s", runNo,path.Data(),pass.Data());
192 if (fPath.IsNull()) fPath = path;
193 else if (!fPath.EqualTo(path)) {
194 Warning("GetDir", "Run %lu location %s not %s",
195 runNo, path.Data(), fPath.Data());
199 if (fPass.IsNull()) fPass = pass;
200 else if (!fPass.EqualTo(pass)) {
201 Warning("GetDir", "Run %lu pass %s not %s",
202 runNo, pass.Data(), fPass.Data());
209 Bool_t GetPathPass(const TString& dir, ULong_t run,
210 TString& path, TString& pass)
212 Int_t first = dir.Index(Form("%lu", run));
213 Int_t last = dir.Index("/", first);
214 if (last == kNPOS) last = dir.Length();
215 if (first == kNPOS) {
216 Error("GetPathPass", "Run number %lu not in path %s", run, dir.Data());
219 while (dir[first-1] == '0') first--;
220 path = dir(0, first);
221 pass = dir(last+1,dir.Length()-last-1);
224 Bool_t Download(const TString& url, TString& out)
226 const TString base("http://alimonitor.cern.ch");
227 out = Form("%s/%s", fTmp.Data(), out.Data());
228 TString cmd(Form("wget -q \"%s/%s\" -O \"%s\"",
229 base.Data(), url.Data(), out.Data()));
230 if (fDebug) Info("Download", "%s", cmd.Data());
231 Int_t ret = gSystem->Exec(cmd.Data());
233 Error("Download", "Failed to get %s/%s -> %s",
234 base.Data(), url.Data(), out.Data());