Updated cut classes and macro for Sigma* analysis (M. Venaruzzo)
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / macros / lego_train / old / RsnGridPlugin.C
1 #ifndef __CINT__
2 #include <Riostream.h>
3 #include <TGrid.h>
4 #include <TGridResult.h>
5 #endif
6 void RsnGridPlugin(TString analysisMode) {
7
8    Bool_t valid = kTRUE;
9    TString dsConfig = AliAnalysisManager::GetGlobalStr("rsnTrainDSConfig",valid);
10    Int_t globalTrainID = AliAnalysisManager::GetGlobalInt("rsnGlobalTrainID",valid);
11
12    Int_t numRuns = AliAnalysisManager::GetGlobalInt("rsnGridNumRuns",valid);
13    Int_t numRunsSkip = AliAnalysisManager::GetGlobalInt("rsnGridNumRunsSkip",valid);
14
15    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
16    if (!mgr) {
17       Printf("Error[RsnGridPlugin] mgr is null !!!");
18       return;
19    }
20
21    AliAnalysisAlien *plugin = (AliAnalysisAlien *) mgr->GetGridHandler();
22    if (!plugin) {
23       Printf("Error[RsnGridPlugin] : plugin is null !!!");
24       return;
25    }
26
27    // getting latest train id
28    TString rsnTrainName = gSystem->BaseName(dsConfig.Data());
29    rsnTrainName.ReplaceAll(".txt","");
30    rsnTrainName.Append(TString::Format("/%03d/%d_%d",globalTrainID,numRunsSkip,numRuns).Data());
31
32    if (!gGrid) TGrid::Connect("alien://");
33    if (!gGrid) return;
34    TGridResult *r = gGrid->Query(TString::Format("%s/RsnTrain/%s",gGrid->GetHomeDirectory(),rsnTrainName.Data()).Data(),"*/analysis.root");
35    Int_t idRsnTrain = 0;
36    if (r) {
37       TString s = r->GetKey(r->GetSize()-1,"lfn");
38       s.ReplaceAll("/analysis.root","");
39       s = gSystem->BaseName(s);
40       if (!s.IsNull()) idRsnTrain = s.Atoi();
41       if (!analysisMode.CompareTo("full")) idRsnTrain++;
42    }
43    rsnTrainName.Append(Form("/%03d",idRsnTrain));
44
45    TString rsnTrainWkDir = TString::Format("RsnTrain/%s",rsnTrainName.Data()).Data();
46    Info("RsnGridPlugin()",TString::Format("RSN Train directory : %s%s",gGrid->GetHomeDirectory(),rsnTrainWkDir.Data()).Data());
47
48    plugin->SetGridWorkingDir(rsnTrainWkDir.Data());
49    plugin->SetGridOutputDir("output"); // In this case will be $HOME/work/output
50
51    plugin->SetAPIVersion("V1.1x");
52
53    TString rootver = AliAnalysisManager::GetGlobalStr("rsnLegoTrainROOTversion",valid);
54    plugin->SetROOTVersion(rootver.Data());
55
56    TString alirootVersion = AliAnalysisManager::GetGlobalStr("rsnLegoTrainAliROOTversion",valid);
57    if (alirootVersion.IsNull()) {
58       if (gSystem->Getenv("ALICE_ROOT")) alirootVersion = gSystem->GetFromPipe("aliroot --version | awk '{print $3}'");
59    }
60    plugin->SetAliROOTVersion(alirootVersion.Data());
61
62    plugin->SetExecutableCommand("aliroot -b -q");
63
64    plugin->SetAnalysisMacro("RsnTrain.C");
65    plugin->SetMasterResubmitThreshold(90);
66    plugin->SetTTL(84600);
67    plugin->SetInputFormat("xml-single");
68    plugin->SetJDLName("RsnTrain.jdl");
69    plugin->SetPrice(1);
70    plugin->SetSplitMode("se");
71    plugin->SetNtestFiles(2);
72    plugin->SetMergeViaJDL();
73    plugin->SetOverwriteMode(kFALSE);
74    //    plugin->SetKeepLogs(kTRUE);
75
76    RsnSetData(plugin,dsConfig,numRuns,numRunsSkip,1000);
77
78    plugin->SetSplitMaxInputFileNumber(25);
79
80    //   Fatal("RsnDataSet","No dataset found !!!");
81 }
82
83 void RsnSetData(AliAnalysisAlien *plugin,TString dsConf,Int_t numRuns = 1000,Int_t numRunsSkip=0,Int_t maxRunsPerMaster = 1000) {
84
85    Bool_t dsFound = kTRUE;
86    Int_t nRunsPerMaster = 0;
87
88    Bool_t valid = kTRUE;
89    TString legoTrainPath = AliAnalysisManager::GetGlobalStr("rsnLegoTrainPath",valid);
90
91    if (gSystem->AccessPathName(dsConf.Data())) dsConf.Prepend(Form("%s/",legoTrainPath.Data()));
92    dsConf = gSystem->ExpandPathName(dsConf.Data());
93
94    if (dsConf.Contains(".txt")) {
95       ifstream in;
96       in.open(dsConf.Data());
97       if (!in.is_open()) Fatal("RsnSetData",Form("File %s was not found !!!",dsConf.Data()));
98       Printf("DS config file : %s",dsConf.Data());
99       TString line;
100       Bool_t isRun = kFALSE;
101       while (in.good())
102       {
103          in >> line;
104          if (line.IsNull()) continue;
105          if (line.Contains("BASE")) {
106             GetParameterFromConfig(line);
107             plugin->SetGridDataDir(line.Data());
108             Printf("BASE -> %s",line.Data());
109             continue;
110          }
111          if (line.Contains("PREFIX")) {
112             GetParameterFromConfig(line);
113             plugin->SetRunPrefix(line.Data());
114             Printf("PREFIX -> %s",line.Data());
115             continue;
116          }
117          if (line.Contains("DATA_PATTERN")) {
118             GetParameterFromConfig(line);
119             plugin->SetDataPattern(line.Data());
120             Printf("DATA_PATTERN -> %s",line.Data());
121             continue;
122          }
123          if (!line.CompareTo("RUNS")) {
124             isRun = kTRUE;
125             in >> line;
126          }
127          if (isRun) {
128             if (numRunsSkip>0) {
129                numRunsSkip--;
130                continue;
131             } else {
132                if (nRunsPerMaster < numRuns ) {
133                   Printf("Adding RUN : %s",line.Data());
134                   plugin->AddRunNumber(line.Data());
135                   nRunsPerMaster++;
136                } else {
137                   break;
138                }
139
140             }
141          }
142       }
143    } else {
144       plugin->SetGridDataDir("");
145       plugin->SetDataPattern("");
146       Fatal("RsnDataSet","No dataset found !!!");
147    }
148
149    if (nRunsPerMaster > maxRunsPerMaster) nRunsPerMaster = maxRunsPerMaster;
150    plugin->SetNrunsPerMaster(nRunsPerMaster);
151
152 }
153
154 void GetParameterFromConfig(TString &str,TString token="=") {
155    TObjArray *array = str.Tokenize(token.Data());
156    TObjString *strObj = (TObjString *)array->At(1);
157    if (strObj) str = strObj->GetString();
158    else str = "";
159 }
160