AliPhysics  a88b1f0 (a88b1f0)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MakeAODInputChain.C
Go to the documentation of this file.
1 TChain *MakeAODInputChain(const char* collectionfileAOD,
2  const char* collectionfileAODfriend,Int_t nfiles=-1,
3  Bool_t stdoutCheck=kFALSE) {
4  //
5  // Check one-to-one correspondence of the two collections
6  // Create AOD chain with friend AODVertexingHF chain
7  // Origin: A.Rossi, andrea.rossi@ts.infn.it
8  //
9 
10  TAlienCollection *collectionAOD = TAlienCollection::Open(collectionfileAOD);
11  TGridResult *tagResultAOD = collectionAOD->GetGridResult("",0,0);
12  TChain *chainAOD = new TChain("aodTree");
13  TChain *chainAODfriend = new TChain("aodTree");
14  Int_t nmaxentr;
15  if(collectionfileAODfriend!="none"){
16  TAlienCollection *collectionAODfriend = TAlienCollection::Open(collectionfileAODfriend);
17  TGridResult *tagResultAODFriend = collectionAODfriend->GetGridResult("",0,0);
18  // tagResultAOD->Print();
19  TMap *mappa;
20  TObjString *filename;
21  Int_t event,dir,pos;
22  string str;
23  Int_t lastAOD[1000],lastAODFriend[1000];
24  TArrayI ***arrAOD=new TArrayI**[1000];
25  TArrayI ***arrAODFriend=new TArrayI**[1000];
26 
27  for(Int_t j=0;j<1000;j++) {
28  arrAOD[j]=new TArrayI*[2];
29  arrAOD[j][0]=new TArrayI(100);
30  arrAOD[j][0]->Reset(0);
31  arrAOD[j][1]=new TArrayI(100);
32  arrAOD[j][1]->Reset(-1);
33 
34  arrAODFriend[j]=new TArrayI*[2];
35  arrAODFriend[j][0]=new TArrayI(100);
36  arrAODFriend[j][0]->Reset(0);
37  arrAODFriend[j][1]=new TArrayI(100);
38  arrAODFriend[j][1]->Reset(-1);
39 
40  lastAOD[j]=0;
41  lastAODFriend[j]=0;
42  }
43 
44  nmaxentr=tagResultAOD->GetEntries();
45  if(nfiles>0&&nmaxentr>nfiles)nmaxentr=nfiles;
46 
47  for(Int_t j=0;j<tagResultAOD->GetEntries();j++) {
48  mappa=(TMap*)tagResultAOD->At(j);
49  filename=(TObjString*)mappa->GetValue("turl");
50  str=filename->GetString();
51  pos=str.find_last_of("/");
52  str.string::replace(pos,50,"");
53  pos=str.find_last_of("/");
54  str.string::replace(pos,1," ");
55  sscanf(str.data(),"%*s %d",&event);
56  pos=str.find_last_of("/");
57  str.string::replace(pos,1," ");
58  sscanf(str.data(),"%*s %d",&dir);
59  arrAOD[event][0]->AddAt(dir,lastAOD[event]);
60  arrAOD[event][1]->AddAt(j,lastAOD[event]);
61  // printf("Adding AOD, event:%d,dir:%d,position:%d\n",event,dir,j);
62  lastAOD[event]++;
63  }
64 
65  for(Int_t j=0;j<tagResultAODFriend->GetEntries();j++) {
66  mappa=(TMap*)tagResultAODFriend->At(j);
67  filename=(TObjString*)mappa->GetValue("turl");
68  str=filename->GetString();
69  pos=str.find_last_of("/");
70  str.string::replace(pos,50,"");
71  pos=str.find_last_of("/");
72  str.string::replace(pos,1," ");
73  sscanf(str.data(),"%*s %d",&event);
74  pos=str.find_last_of("/");
75  str.string::replace(pos,1," ");
76  sscanf(str.data(),"%*s %d",&dir);
77  arrAODFriend[event][0]->AddAt(dir,lastAODFriend[event]);
78  arrAODFriend[event][1]->AddAt(j,lastAODFriend[event]);
79  //printf("Adding AODFriend, event:%d,dir:%d,position:%d\n",event,dir,j);
80  lastAODFriend[event]++;
81  }
82 
83 
84  for(Int_t ev=0;ev<1000;ev++) {
85  for(Int_t j=0;j<lastAOD[ev];j++) {
86  dir= arrAOD[ev][0]->At(j);
87  for(Int_t k=0;k<lastAODFriend[ev];k++) {
88  if(arrAODFriend[ev][0]->At(k)==dir){
89  chainAOD->Add((((TObjString*)((TMap*)tagResultAOD->At(arrAOD[ev][1]->At(j)))->GetValue("turl"))->GetString()).Data());
90  chainAODfriend->Add((((TObjString*)((TMap*)tagResultAODFriend->At(arrAODFriend[ev][1]->At(k)))->GetValue("turl"))->GetString()).Data());
91  printf("Events: %d, adding AOD at position %d,dir:%d posarray:%d \n and Friend at %d, dir:%d , posarray: %d \n \n",ev,arrAOD[ev][1]->At(j),arrAOD[ev][0]->At(j),j,arrAODFriend[ev][1]->At(k),arrAODFriend[ev][0]->At(k),k);
92  break;
93  }
94  }
95  }
96  }
97  } else {
98  nmaxentr=tagResultAOD->GetEntries();
99  if(nfiles>0&&nmaxentr>nfiles)nmaxentr=nfiles;
100  TString aodlfn,vertexlfn;
101  for(Int_t ifile=0; ifile<nmaxentr; ifile++) {
102  aodlfn=tagResultAOD->GetKey(ifile,"lfn");
103  vertexlfn=aodlfn;
104  vertexlfn.ReplaceAll("AliAOD.root","");
105  TGridResult *r=gGrid->Query(vertexlfn.Data(),"AliAOD.VertexingHF.root");
106  if(r->GetEntries()!=1)continue;
107  // check error in the stdout
108  if(stdoutCheck) {
109  if(!CheckStdout(aodlfn)) continue;
110  }
111  printf("Adding file : %s \n",tagResultAOD->GetKey(ifile,"turl"));
112  chainAOD->Add(tagResultAOD->GetKey(ifile,"turl"));
113  printf("Adding friend file : %s \n \n",r->GetKey(0,"turl"));
114  chainAODfriend->Add(r->GetKey(0,"turl"));
115  }
116  }
117 
118  chainAOD->AddFriend(chainAODfriend);
119 
120  return chainAOD;
121 }
122 //----------------------------------------------------------------------------
123 TChain *MakeAODInputChain(const char* pathname="",
124  Int_t firstdir=1,Int_t lastdir=-1) {
125  //
126  // Create AOD chain with friend AODVertexingHF chain
127  // Example path: "alien:///alice/cern.ch/user/r/rbala/analysis/out_lhcw/290001/"
128  // Origin: A.Rossi, andrea.rossi@ts.infn.it
129  //
130 
131 
132  TChain *chainAOD = new TChain("aodTree");
133  TChain *chainAODfriend = new TChain("aodTree");
134 
135 
136  if(firstdir==-1) {
137  // require the path is an alien path (!!!but without alien::// or /alien/ ), use lastdir as the requested number of files
138  TGridResult* resultAOD=gGrid->Query(pathname,"AliAOD.root","","");
139  Int_t nfiles=resultAOD->GetEntries();
140  TString aodlfn,vertexlfn;
141  if(lastdir>nfiles)lastdir=nfiles;
142  for(Int_t ifile=0; ifile<nfiles; ifile++) {
143  aodlfn=resultAOD->GetKey(ifile,"lfn");
144  vertexlfn=aodlfn;
145  vertexlfn.ReplaceAll("AliAOD.root","");
146  TGridResult *r=gGrid->Query(vertexlfn.Data(),"AliAOD.VertexingHF.root");
147  if(r->GetEntries()!=1)continue;
148  chainAOD->Add(resultAOD->GetKey(ifile,"turl"));
149  chainAODfriend->Add(r->GetKey(0,"turl"));
150  }
151  }
152  else{
153  if(lastdir==-1) { // only one pair of files
154  chainAOD->Add("AliAOD.root");
155  chainAODfriend->Add("AliAOD.VertexingHF.root");
156  } else {
157 
158  // set the path to the files (can be local or on alien)
159  for(Int_t idir=firstdir; idir<=lastdir; idir++) {
160  TString aodname=pathname;
161  TString aodHFname=pathname;
162  aodname+=idir;
163  aodHFname+=idir;
164  aodname.Append("/AliAOD.root");
165  aodHFname.Append("/AliAOD.VertexingHF.root");
166  chainAOD->Add(aodname.Data());
167  chainAODfriend->Add(aodHFname.Data());
168  }
169  }
170  }
171 
172  chainAOD->AddFriend(chainAODfriend);
173 
174  return chainAOD;
175 }
176 //----------------------------------------------------------------------------
177 TFileCollection* MakeRootArchFileCollection(const char* collectionfileAOD,
178  Int_t nfiles=-1,
179  Bool_t stdoutCheck=kFALSE) {
180 
181  // METHOD USEFUL FOR ANALYSIS ON THE CAF
182  // Check the presence of both AliAOD.root and AODVertexingHF.root files
183  // in the same path
184  // returns a TFileCollection suitable for storing datasets in CAF
185  // Origin: A.Rossi, andrea.rossi@ts.infn.it
186  //
187 
188  TAlienCollection *collectionAOD = TAlienCollection::Open(collectionfileAOD);
189  TGridResult *tagResultAOD = collectionAOD->GetGridResult("",0,0);
190 
191  Int_t nmaxentr;
192  TFileCollection *proofColl=new TFileCollection("proofColl","proofColl");
193 
194  nmaxentr=tagResultAOD->GetEntries();
195  printf("Number of files %d\n",nmaxentr);
196  if(nfiles>0&&nmaxentr>nfiles)nmaxentr=nfiles;
197  TString aodlfn;
198  for(Int_t ifile=0; ifile<nmaxentr; ifile++) {
199  printf("file %d\n",ifile);
200  aodlfn=tagResultAOD->GetKey(ifile,"lfn");
201  TString aodlfncopy=aodlfn;
202  aodlfn.ReplaceAll("AliAOD.root","");
203  aodlfn.ReplaceAll("AliAODs.root","");
204  TGridResult *r=gGrid->Query(aodlfn.Data(),"AliAOD.VertexingHF.root");
205  if(r->GetEntries()!=1)continue;
206  r=gGrid->Query(aodlfn.Data(),"aod_archive.zip");
207  if(r->GetEntries()!=1)continue;
208  // check error in the stdout
209  if(stdoutCheck) {
210  if(!CheckStdout(aodlfncopy)) {
211  FILE *fout=fopen("errors.txt","a");
212  aodlfncopy.ReplaceAll("AliAOD.root","AliAOD.VertexingHF.root");
213  fprintf(fout,"%s\n",aodlfncopy.Data());
214  fclose(fout);
215  continue;
216  }
217  }
218  aodlfn.Append("aod_archive.zip");
219  printf("Adding file %s\n",aodlfn.Data());
220  proofColl->Add(r->GetKey(0,"turl"));
221  }
222  return proofColl;
223 }
224 //----------------------------------------------------------------------------
225 void StageToCAF(TString xmlcoll="collAODLHC08x.xml",
226  TString datasetname="AODVertexingHF_LHC08x_10files",
227  Int_t nfiles=-1) {
228  //
229  // Staging a dataset to CAF
230  // andrea.dainese@pd.infn.it
231  //
232 
233  //gROOT->LoadMacro("MakeAODInputChain.C");
234 
235  TGrid::Connect("alien://");
236 
237  // find -x collAODLHC08x -z /alice/cern.ch/user/r/rbala/newtrain/out_lhc08x/* AliAOD.root > collAODLHC08x.xml
238 
239  TFileCollection *proofColl = MakeRootArchFileCollection(xmlcoll.Data(),nfiles,KTRUE);
240  proofColl->SetAnchor("AliAOD.root");
241 
242  gEnv->SetValue("XSec.GSI.DelegProxy","2");
243  TProof::Open("dainesea:PWG3@alicecaf");
244  gProof->RegisterDataSet(datasetname.Data(),proofColl);
245  gProof->ShowDataSets();
246 
247  return;
248 }
249 //---------------------------------------------------------------------------
251 
252  TString stderrlfn=aodlfn;
253  stderrlfn.ReplaceAll("AliAOD.root","stdout");
254  TString aliencp=".! alien_cp -t 10 alien://";
255  aliencp.Append(stderrlfn.Data());
256  aliencp.Append(" file:stdoutput");
257  gROOT->ProcessLine(aliencp.Data());
258  gROOT->ProcessLine(".! grep \"no debugging symbols found\" stdoutput > result");
259  FILE *fileres=fopen("result","r");
260  if(!fileres) return kFALSE;
261  Char_t text[100];
262  Int_t ncol = fscanf(fileres,"%s %s %s %s",&text,&text,&text,&text);
263  //printf("%d %s\n",ncol,text);
264  fclose(fileres);
265  gROOT->ProcessLine(".! rm stdoutput result");
266  if(ncol>=0) return kFALSE;
267 
268  return kTRUE;
269 }
const char * filename
Definition: TestFCM.C:1
return jsonbuilder str().c_str()
char Char_t
Definition: External.C:18
void StageToCAF(TString xmlcoll="collAODLHC08x.xml", TString datasetname="AODVertexingHF_LHC08x_10files", Int_t nfiles=-1)
int Int_t
Definition: External.C:63
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
Bool_t CheckStdout(TString aodlfn)
TChain * MakeAODInputChain(const char *collectionfileAOD, const char *collectionfileAODfriend, Int_t nfiles=-1, Bool_t stdoutCheck=kFALSE)
TFileCollection * MakeRootArchFileCollection(const char *collectionfileAOD, Int_t nfiles=-1, Bool_t stdoutCheck=kFALSE)
bool Bool_t
Definition: External.C:53