Updated version of the Test TPC toolkits (Marian)
[u/mrichter/AliRoot.git] / TPC / macros / testTPC / AliTPCjobs.cxx
CommitLineData
027ef365 1//#include <fstream>
2//#include <TFile.h>
3//#include <TSystem.h>
4
5
6/*
7
8 Process all jobs specified in the job.list file
9 Concurent agents acces the list
10 Once starting to procces given job the jonb is locked
11
12*/
13
14
baf19816 15
16/*
c6d9a3a0 17
18
baf19816 19.L $ALICE_ROOT/TPC/macros/testTPC/AliTPCjobs.cxx+
c6d9a3a0 20
21
baf19816 22AliTPCJobs jobs;
23jobs.fJobFile="job.list"
8b35d234 24jobs.ProcessAllJobs();
baf19816 25*/
c6d9a3a0 26
27
baf19816 28class AliTPCJobs : public TNamed{
29public:
30 AliTPCJobs();
31 void ProcessAllJobs();
32 Bool_t GetNextJob();
33 void ProcessJob(TString jobID, TString inputData, TString outputDir, TString action);
34
35 void SetLock(TString jobID);
36 void SetDone(TString jobID);
37 Bool_t IsLocked(TString jobID);
38
39 TString fJobFile;
40 TString fWorkDir;
8b35d234 41 ClassDef(AliTPCJobs,0)
baf19816 42};
43
8b35d234 44 ClassImp(AliTPCJobs)
baf19816 45
46AliTPCJobs::AliTPCJobs(){
47 //
48 //
49 //
50 gSystem->Load("libXrdClient.so");
51 gSystem->Load("libNetx.so");
52}
53
54void AliTPCJobs::ProcessAllJobs(){
55 //
56 //
57 //
58 Int_t counter=0;
59 while (GetNextJob()){
60 //
8b35d234 61 printf("PROCESSING JOB\t%d\n",counter);
baf19816 62 counter++;
63 if (!GetNextJob()) break;
64 }
65}
66
67
68Bool_t AliTPCJobs::GetNextJob(){
027ef365 69 //
70 // GetNextJob - get job from the list which is not locked
71 //
72 ifstream ins;
73 ins.open(fJobFile);
baf19816 74 TString id;
75 TString inputData;
76 TString outputDir;
77 TString action;
78 Bool_t hasJob=kFALSE;
027ef365 79 while(ins.good()) {
80 ins>>id;
81 ins>>inputData;
82 ins>>outputDir;
83 ins>>action;
baf19816 84 if (!IsLocked(id)){
85 hasJob=kTRUE;
86 break;
87 }
88 }
89 printf("Process %s\n",id.Data());
90 if (hasJob) ProcessJob(id,inputData,outputDir, action);
91 return hasJob;
92}
93
94
95void AliTPCJobs::SetLock(TString jobID){
96 printf("touch out/%s.lock\n",jobID.Data());
97 gSystem->Exec(Form("touch out/%s.lock",jobID.Data()));
98}
99
100void AliTPCJobs::SetDone(TString jobID){
101 printf("touch out/%s.done\n",jobID.Data());
102 gSystem->Exec(Form("touch out/%s.done", jobID.Data()));
103}
104
105
106Bool_t AliTPCJobs::IsLocked(TString jobID){
107 TString path = "out/";
108 path+=jobID;
109 path+=".lock";
110 Long_t pid; Long_t psize; Long_t pflags; Long_t pmodtime;
111 Int_t status = gSystem->GetPathInfo(path,&pid,&psize,&pflags,&pmodtime);
112 return (status==0);
113}
114
115
116void AliTPCJobs::ProcessJob(TString jobID, TString inputData, TString outputDir, TString action){
117 //
118 //
119 // 1. Create lock file
120 // 2. Get Input data
121 // 3. Process data
122 // 4. Create Done file
123 SetLock(jobID);
124 if (action.Contains("COPY")){
125 char command[10000];
c6d9a3a0 126 sprintf(command,"xrdcp -DIFirstConnectMaxCnt 4 -DIConnectTimeout 4 -DIRequestTimeout 4 -DIMaxRedirectcount 4 -DIRedirCntTimeout 4 %s\t%s\n",inputData.Data(), outputDir.Data());
baf19816 127 printf("Exec\t%s\n", command);
128 gSystem->Exec(command);
129 //TFile::Cp(inputData.Data(), outputDir.Data());
8b35d234 130 }else{
131 char command[10000];
132 sprintf(command,"$ALICE_ROOT/TPC/macros/testTPC/action.sh %s %s %s %s", jobID.Data(), inputData.Data(), outputDir.Data(), action.Data());
133 printf("%s\n\n",command);
134 gSystem->Exec(command);
135 printf("\n\n");
136
baf19816 137 }
8b35d234 138
baf19816 139 SetDone(jobID);
140}
c6d9a3a0 141
142
143
144void AliTPCjobs(){
145 //
146 //
147 //
148 AliTPCJobs jobs;
149 jobs.fJobFile="job.list";
150 jobs.ProcessAllJobs();
151}