]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/macros/electrons/mymerger.C
Macros to facilitate merging by PYTHIA pt hard bin.
[u/mrichter/AliRoot.git] / PWG4 / macros / electrons / mymerger.C
1
2 //
3 // AliEn Initial PYTHIA pt hard bin-by-bin merging to prepare for rescaling
4 // Author: K. Read
5 //
6
7 void mymerger()
8 {
9   TString filename;
10   TString jdlfilename = "mergeoutscaledi.jdl";
11   //TString worksubdir = "LHC09b4b";
12   //Int_t maxbin = 15; 
13   TString worksubdir = "LHC09b2ESDb";
14   Int_t maxbin = 16;
15
16   //Later do: aliensh; cd worksubdir/output/merged; cp histoss* file:
17   //And then process files locally with MergeFileInBins.C.
18
19   gSystem->Load("libNetx.so") ;
20   gSystem->Load("libRAliEn.so");
21
22   TGrid::Connect("alien://") ;
23   if (gGrid && gGrid->IsConnected()) {
24     TString homedir = gGrid->GetHomeDirectory(); // has a trailing slash
25     TString workdir = homedir + worksubdir;
26     if (gGrid->Cd(workdir)) {
27
28       // Upload and submit JDL if listed
29       if (jdlfilename.Length()) {
30         filename = Form("%s/%s", workdir.Data(), jdlfilename.Data());
31         if (FileExists(filename)) gGrid->Rm(filename);
32         Info("Grid Upload", "Copying JDL file %s to your AliEn work directory", jdlfilename.Data());
33         TFile::Cp(Form("file:%s",jdlfilename.Data()), Form("alien://%s", filename.Data()));
34
35         for (Int_t index = 0; index <= maxbin; index++) {
36           TGridResult *res;
37           TString jobID = "";
38           res = gGrid->Command(Form("submit %s %s %d", jdlfilename.Data(),worksubdir.Data(),index));
39           Info("Launcher:",     "Submitting %s %s %d", jdlfilename.Data(),worksubdir.Data(),index);
40           if (res) {
41             const char *cjobId = res->GetKey(0,"jobId");
42             if (!cjobId) {
43               Error("Launcher:", "Your JDL %s could not be submitted", jdlfilename.Data());
44               return;
45             } 
46             else {
47               Info("Launcher:", "Your JDL %s was successfully submitted.\n\n\t\t\t THE JOB ID IS: %s\n",
48                    jdlfilename.Data(), cjobId);
49             }          
50             delete res;
51           }
52         }
53       }
54
55       // Launch alien shell
56       gSystem->Exec("aliensh");
57
58     }
59   }
60 }
61
62 Bool_t FileExists(const char *lfn) const
63 {
64 // Returns true if file exists.
65    if (!gGrid) {
66       Error("FileExists", "No connection to grid");
67       return kFALSE;
68    }
69    TGridResult *res = gGrid->Ls(lfn);
70    if (!res) return kFALSE;
71    TMap *map = dynamic_cast<TMap*>(res->At(0));
72    if (!map) {
73       delete res;
74       return kFALSE;
75    }   
76    TObjString *objs = dynamic_cast<TObjString*>(map->GetValue("name"));
77    if (!objs || !objs->GetString().Length()) {
78       delete res;
79       return kFALSE;
80    }
81    delete res;   
82    return kTRUE;
83 }