16 # include <TObjArray.h> 41 return TString::Format(
"%s%s.%s", name.Data(),
42 (merge ?
"_merge" :
""), ext.Data());
91 TString fn = TString::Format(
"%s%s.%s", name.Data(),
92 (merge ?
"_merge" :
""), ext.Data());
93 std::ifstream in(fn.Data());
95 Error(
"ReadCacheFile",
"Failed to open %s", fn.Data());
102 if (ln.IsNull())
return 0;
103 return ln.Tokenize(
" \t");
148 if (!jobIds)
return false;
150 Int_t n = jobIds->GetEntries();
154 for (
Int_t i = 0; i < n; i++) {
155 TObjString*
id =
static_cast<TObjString*
>(jobIds->At(i));
156 const TString& s =
id->String();
157 ret.SetAt(s.Atoi(), i);
175 case 'D': out =
"DONE";
break;
176 case 'E': out =
"ERROR";
break;
177 case 'R': out =
"RUNNING";
break;
178 case 'W': out =
"WAITING";
break;
179 case 'O': out =
"WAITING_QUOTA";
break;
180 case 'A': out =
"ASSIGNED";
break;
181 case 'S': out =
"STARTED" ;
break;
182 case 'I': out =
"INSERTING";
break;
183 case 'K': out =
"KILLED";
break;
184 default: out =
"UNKNOWN";
return false;
186 if (status[1] !=
'\0' &&
187 (status[0] !=
'O' || status[0] !=
'S')) {
190 case 'S': out.Append(status[0] ==
'E' ?
"SUBMIT" :
"SPLIT");
break;
191 case 'X': out.Append(
"EXPIRED");
break;
192 case 'A': out.Append(
"ASSIGNING");
break;
193 case 'E': out.Append(
"EXECUTING");
break;
195 if (status[0] ==
'S') out =
"SAVING";
196 else out.Append(
"VALIDATING");
199 if (status[0] ==
'I') {
200 out =
"INTERACTIVE_IDLE";
204 if (status[0] ==
'I') {
205 out =
"INTERACTIVE_USED";
208 default: out.Append(
"UNKNOWN");
return false;
210 if (status[2] !=
'\0') {
212 case 'V':
if (status[0] ==
'E') out.ReplaceAll(
"SUBMIT",
"SAVING");
214 default: out.Append(
"_UNKNOWN");
231 FILE* fp =
gSystem->TempFileName(tmp);
237 gGrid->Command(
"ps -Ax");
246 gSystem->Exec(Form(
"gbbox ps -Ax >> %s", tmp.Data()));
268 std::ifstream in(fn.Data());
276 if (tokens->GetEntries() < 2)
break;
279 TString sjid = tokens->At(1)->GetName();
280 TString stat = tokens->At(2)->GetName();
281 Int_t jid = sjid.Atoi();
283 if (jid != jobId)
continue;
307 Int_t n = jobs.GetSize();
309 for (
Int_t i = 0; i < n; i++) {
310 TObjString* s =
static_cast<TObjString*
>(states.At(i));
311 if (!s) states.AddAt(s =
new TObjString(
""), i);
312 s->SetString(
"MISSING");
318 std::ifstream in(fn.Data());
324 if (l.IsNull())
continue;
327 if (tokens->GetEntries() < 3) {
328 Warning(
"GetJobStates",
"Got too few tokens (%d): %s",
329 tokens->GetEntries(), l.Data());
335 TString sjid = tokens->At(1)->GetName();
336 TString stat = tokens->At(2)->GetName();
337 Int_t jid = sjid.Atoi();
339 for (
Int_t i = 0; i < n; i++) {
340 if (jid != jobs.At(i))
continue;
341 TObjString* s =
static_cast<TObjString*
>(states.At(i));
362 Int_t ret =
gSystem->Exec(
"alien-token-info > /dev/null 2>&1");
364 Printf(
"=== AliEn token not valid");
386 TString l =
gSystem->GetFromPipe(Form(
"cat /tmp/gclient_token_%d",
389 TObjString* sline = 0;
392 while ((sline = static_cast<TObjString*>(next()))) {
393 TString& line = sline->String();
394 if (!line.BeginsWith(
"Expiretime"))
continue;
396 Size_t eq = line.Index(
"=");
397 TString sdatime = line(eq+2, line.Length()-eq-2);
398 expire = sdatime.Atoi();
404 Int_t diff = (expire - now);
405 if (now > expire || diff < 30*60) renew =
true;
407 Printf(
"=== Now: %d, Expires: %d, in %03d:%02d:%02d -> %s",
408 now, expire, diff/60/60, (diff/60 % 60), (diff % 60),
409 (renew ?
"renew" :
"nothing"));
416 Printf(
"=== Refreshing AliEn token");
417 gSystem->Exec(
"alien-token-init");
418 Printf(
"=== Done refreshing AliEn token");
442 TFileHandler h(0, 0x1);
447 Printf(
"--- %4d/%02d/%02d %02d:%02d:%02d [Press enter to pause] ---",
448 t.GetYear(), t.GetMonth(), t.GetDay(),
449 t.GetHour(), t.GetMinute(), t.GetSecond());
450 UInt_t now = t.Convert(
true);
456 Int_t total = jobs.GetSize();
458 for (
Int_t i = 0; i < total; i++) {
459 Int_t job = jobs.At(i);
461 if (job < 0)
continue;
463 TObjString* obj =
static_cast<TObjString*
>(states.At(i));
464 const TString& state = obj->String();
466 if (state.BeginsWith(
"ERROR_"))
468 else if (state.EqualTo(
"MISSING"))
470 else if (!state.EqualTo(
"DONE"))
474 Printf(
" %d(%s)=%s", job, stages->At(i)->GetName(), state.Data());
480 if (missing >= total) {
481 Error(
"GetJobStates",
"Info on all jobs missing");
485 if (
gSystem->Select(&h, 1000*delay)) {
488 std::getline(std::cin, l);
489 std::cout <<
"Do you want to terminate now [yN]? " << std::flush;
490 std::getline(std::cin, l);
491 if (l[0] ==
'y' || l[0] ==
'Y') {
519 gEnv->SetValue(
"XSec.GSI.DelegProxy",
"2");
520 TGrid::Connect(
"alien:///");
522 Error(
"GridWatch",
"Failed to connect to the Grid");
530 if (!jobIDs || !stages)
return;
538 if (!
WaitForJobs(jobs, stages, delay, batch))
return;
548 Printf(
"Now executing terminate");
549 gSystem->Exec(
"aliroot -l -b -q Terminate.C");
553 Printf(
"Reading job ids");
558 Error(
"GridWatch",
"Failed to parse job ids %s",
563 if (!
WaitForJobs(jobs, stages, delay, batch))
return;
566 for (
Int_t i = 0; i < jobs.GetSize(); i++) {
567 if (jobs.At(i) < 0)
continue;
569 const TString& s =
static_cast<TObjString*
>(stages->At(i))->String();
570 if (!s.BeginsWith(
"final_")) allFinal =
false;
576 Printf(
"All jobs in final stage");
Bool_t WaitForJobs(TArrayI &jobs, TObjArray *stages, Int_t delay, Bool_t batch)
Bool_t ParseState(const TString &status, TString &out)
void RemoveCacheFile(const TString &name, const TString &ext, Bool_t merge=false)
TObjArray * ReadJobIDs(const TString &name, bool merge=false)
TString CacheFileName(const TString &name, const TString &ext, Bool_t merge=false)
TObjArray * ReadStages(const TString &name, bool merge=false)
void GridWatch(const TString &name, Bool_t batch=false, UShort_t delay=5 *60)
Bool_t GridPs(TString &tmp)
Bool_t GetJobStates(const TArrayI &jobs, TObjArray &states)
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
TObjArray * ReadCacheFile(const TString &name, const TString &ext, bool merge=false)
Bool_t ParseJobIDs(const TObjArray *jobIds, TArrayI &ret)
Bool_t CheckCacheFile(const TString &name, const TString &ext, Bool_t merge=false)
Bool_t GetJobState(Int_t jobId, TString &out)
void RefreshAlienToken(UInt_t now, Bool_t force=false)