Adding job handler (Marian)
[u/mrichter/AliRoot.git] / TPC / macros / testTPC / AliTPCjobs.cxx
CommitLineData
baf19816 1#include <fstream>
2#include <TFile.h>
3#include <TSystem.h>
4
5/*
6.L $ALICE_ROOT/TPC/macros/testTPC/AliTPCjobs.cxx+
7AliTPCJobs jobs;
8jobs.fJobFile="job.list"
9*/
10class AliTPCJobs : public TNamed{
11public:
12 AliTPCJobs();
13 void ProcessAllJobs();
14 Bool_t GetNextJob();
15 void ProcessJob(TString jobID, TString inputData, TString outputDir, TString action);
16
17 void SetLock(TString jobID);
18 void SetDone(TString jobID);
19 Bool_t IsLocked(TString jobID);
20
21 TString fJobFile;
22 TString fWorkDir;
23};
24
25
26AliTPCJobs::AliTPCJobs(){
27 //
28 //
29 //
30 gSystem->Load("libXrdClient.so");
31 gSystem->Load("libNetx.so");
32}
33
34void AliTPCJobs::ProcessAllJobs(){
35 //
36 //
37 //
38 Int_t counter=0;
39 while (GetNextJob()){
40 //
41 printf("PROCESSING JOB\n",counter);
42 counter++;
43 if (!GetNextJob()) break;
44 }
45}
46
47
48Bool_t AliTPCJobs::GetNextJob(){
49 ifstream in;
50 in.open(fJobFile);
51 TString id;
52 TString inputData;
53 TString outputDir;
54 TString action;
55 Bool_t hasJob=kFALSE;
56 while(in.good()) {
57 in>>id;
58 in>>inputData;
59 in>>outputDir;
60 in>>action;
61 if (!IsLocked(id)){
62 hasJob=kTRUE;
63 break;
64 }
65 }
66 printf("Process %s\n",id.Data());
67 if (hasJob) ProcessJob(id,inputData,outputDir, action);
68 return hasJob;
69}
70
71
72void AliTPCJobs::SetLock(TString jobID){
73 printf("touch out/%s.lock\n",jobID.Data());
74 gSystem->Exec(Form("touch out/%s.lock",jobID.Data()));
75}
76
77void AliTPCJobs::SetDone(TString jobID){
78 printf("touch out/%s.done\n",jobID.Data());
79 gSystem->Exec(Form("touch out/%s.done", jobID.Data()));
80}
81
82
83Bool_t AliTPCJobs::IsLocked(TString jobID){
84 TString path = "out/";
85 path+=jobID;
86 path+=".lock";
87 Long_t pid; Long_t psize; Long_t pflags; Long_t pmodtime;
88 Int_t status = gSystem->GetPathInfo(path,&pid,&psize,&pflags,&pmodtime);
89 return (status==0);
90}
91
92
93void AliTPCJobs::ProcessJob(TString jobID, TString inputData, TString outputDir, TString action){
94 //
95 //
96 // 1. Create lock file
97 // 2. Get Input data
98 // 3. Process data
99 // 4. Create Done file
100 SetLock(jobID);
101 if (action.Contains("COPY")){
102 char command[10000];
103 sprintf(command,"xrdcp -d 1 -DIFirstConnectMaxCnt 2 -DIConnectTimeout 2 -DIRequestTimeout 2 -DIMaxRedirectcount 2 -DIRedirCntTimeout 2 %s\t%s\n",inputData.Data(), outputDir.Data());
104 printf("Exec\t%s\n", command);
105 gSystem->Exec(command);
106 //TFile::Cp(inputData.Data(), outputDir.Data());
107 }
108 SetDone(jobID);
109}