]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/RESONANCES/macros/mini/runLocal.C
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / macros / mini / runLocal.C
CommitLineData
03d23846 1void runLocal
2(
8082e538 3 Int_t nReadFiles = 5,
03d23846 4 Int_t nSkipFiles = 0,
caef2e3c 5 Int_t nmix = 2,
03d23846 6 //const char *inputSource = "file-collections/AOD048_LHC11a10b.txt",
caef2e3c 7 //const char *options = "aod_mc_pbpb",
03d23846 8 //const char *inputSource = "file-collections/AOD049_LHC10h_pass2.txt",
caef2e3c 9 //const char *options = "aod_data_pbpb",
03d23846 10 const char *inputSource = "file-collections/ESD_LHC10d1.txt",
11 const char *options = "esd_mc",
caef2e3c 12 //const char *inputSource = "000117112.xml",
13 //const char *options = "esd_data",
14 //const char *inputSource = "aod_test.xml",
15 //const char *options = "aod_data",
16 //const char *inputSource = "LHC11a10a_bis_test.xml",
17 //const char *options = "esd_mc_pbpb",
03d23846 18 const char *outName = "test.root",
19 const char *macroPath = ".",
20 const char *setupName = "AnalysisSetupRsnMini.C"
21)
22{
23 //
24 // === PREPARATION ==============================================================================
25 //
26
caef2e3c 27 //AliLog::SetClassDebugLevel("AliRsnMiniOutput" , 2);
28 //AliLog::SetClassDebugLevel("AliRsnMiniAnalysisTask", 2);
29 //AliLog::SetClassDebugLevel("AliRsnCutKaonForPhi2010", 2);
03d23846 30
31 // execute the general setup from the apposite macro
32 // it returns also a TString value with the input tree name
33 gROOT->LoadMacro(setupName);
34 TString out = Setup(nmix, options, outName, macroPath);
35 cout << "OUT = " << out.Data() << endl;
36 if (out.Length() < 1) return;
37
38 //
39 // === BUILD INPUT LIST =========================================================================
40 //
41
42 // check extension of input to distinguish between XML and TXT
43 TString sInput(inputSource);
44 sInput.ToLower();
45 Bool_t isTXT = (!strcmp(sInput(sInput.Length() - 3, 3).Data(), "txt"));
46 cout << "Input = " << (isTXT ? "TXT" : "XML") << endl;
47
48 // if input is XML, connect to AliEn
49 if (!isTXT) TGrid::Connect("alien://");
50
51 // create TChain of input events
52 TChain *analysisChain = 0x0;
53 if (isTXT) analysisChain = CreateChainFromText(inputSource, out.Data(), nReadFiles, nSkipFiles);
54 else analysisChain = CreateChainFromXML (inputSource, out.Data(), nReadFiles, nSkipFiles);
55 if (!analysisChain) {
56 Error("runLocal", "Analysis chain not properly initialized");
57 return;
58 }
59
60 //
61 // === ANALYSIS TASK CREATION AND INCLUSION =====================================================
62 //
63
64 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
65 if (!mgr) return;
66
67 // initialize and start analysis
68 if (!mgr->InitAnalysis()) {
69 ::Error("runLocal.C", "Failed to init analysis");
70 return;
71 }
72 mgr->PrintStatus();
73 if (isTXT) mgr->StartAnalysis("local", analysisChain);
74 else mgr->StartAnalysis("alien", analysisChain);
75}
76
77//_________________________________________________________________________________________________
78TChain* CreateChainFromXML
79(const char *xmlFileName, const char *treeName, Int_t nread, Int_t nskip)
80{
81//
82// Create a TChain with all required files listed into an XML collection.
83// Necessary to run analysis in AliEn jobs.
84// ---
85// Arguments:
86// - xmlFileName = input list
87// - treeName = "esdTree" or "aodTree"
88// - nread = how many files to read (0 = all)
89// - nskip = how many files to skip from beginning
90//
91
92 // if nread argument is 0, it is disabled
93 if (nread == 0) nread = 1000000000;
94
95 // initialize output object
96 TChain *chain = new TChain(treeName);
97
98 // initialize the AliEn collection
99 TAlienCollection *myCollection = TAlienCollection::Open(xmlFileName);
100 if (!myCollection) {
101 Error("CreateChainFromXML", "Cannot create an AliEn collection from %s", xmlFileName);
102 return 0x0;
103 }
104
105 // loop on collection
106 myCollection->Reset();
107 while (myCollection->Next()) {
108 // skip until reached required number of offset
109 if (nskip > 0) {--nskip; continue;}
110
111 // stop if required number of read files is reached
112 // otherwise update the counter
113 if (nread <= 0) break;
114 nread--;
115
116 // recovery file and add it
117 Info("CreateChainFromXML", Form("Adding: %s", myCollection->GetTURL("")));
118 chain->Add(myCollection->GetTURL(""));
119 }
120
121 return chain;
122}
123
124//__________________________________________________________________________________________________
125TChain* CreateChainFromText(const char *fileName, const char *treeName, Int_t nread, Int_t nskip)
126{
127//
128// Create a TChain with all required files listed into a text file.
129// Necessary to run analysis in local jobs.
130// ---
131// Arguments:
132// - xmlFileName = input file list
133// - treeName = "esdTree" or "aodTree"
134// - nread = how many files to read (0 = all)
135// - nskip = how many files to skip from beginning
136//
137
138 // if third argument is 0, it is interpreted
139 // as "read all lines"
140 Bool_t readAll = (nread <= 0);
141
142 // initialize output object
143 TChain* target = new TChain(treeName);
144
145 // open text file
146 ifstream fileIn(fileName);
147
148 // loop on collection
149 TString line;
150 while (fileIn.good()) {
151 fileIn >> line;
152 if (line.IsNull()) continue;
153
154 // skip until reached required number of offset
155 if (nskip > 0) {--nskip; continue;}
156
157 // stop if required number of read files is reached
158 // otherwise update the counter
159 if (!readAll && nread <= 0) break;
160 nread--;
161
162 // add file
163 Info("CreateChainFromText", "Adding '%s'", line.Data());
164 target->Add(line.Data());
165 }
166
167 return target;
168}