1 TChain *MakeAODInputChain(const char* collectionfileAOD,
2 const char* collectionfileAODfriend,Int_t nfiles=-1,
3 Bool_t stdoutCheck=kFALSE) {
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
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");
15 if(collectionfileAODfriend!="none"){
16 TAlienCollection *collectionAODfriend = TAlienCollection::Open(collectionfileAODfriend);
17 TGridResult *tagResultAODFriend = collectionAODfriend->GetGridResult("",0,0);
18 // tagResultAOD->Print();
23 Int_t lastAOD[1000],lastAODFriend[1000];
24 TArrayI ***arrAOD=new TArrayI**[1000];
25 TArrayI ***arrAODFriend=new TArrayI**[1000];
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);
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);
44 nmaxentr=tagResultAOD->GetEntries();
45 if(nfiles>0&&nmaxentr>nfiles)nmaxentr=nfiles;
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);
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]++;
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);
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");
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
109 if(!CheckStdout(aodlfn)) continue;
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"));
118 chainAOD->AddFriend(chainAODfriend);
122 //----------------------------------------------------------------------------
123 TChain *MakeAODInputChain(const char* pathname="",
124 Int_t firstdir=1,Int_t lastdir=-1) {
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
132 TChain *chainAOD = new TChain("aodTree");
133 TChain *chainAODfriend = new TChain("aodTree");
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");
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"));
153 if(lastdir==-1) { // only one pair of files
154 chainAOD->Add("AliAOD.root");
155 chainAODfriend->Add("AliAOD.VertexingHF.root");
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;
164 aodname.Append("/AliAOD.root");
165 aodHFname.Append("/AliAOD.VertexingHF.root");
166 chainAOD->Add(aodname.Data());
167 chainAODfriend->Add(aodHFname.Data());
172 chainAOD->AddFriend(chainAODfriend);
176 //----------------------------------------------------------------------------
177 TFileCollection* MakeRootArchFileCollection(const char* collectionfileAOD,
179 Bool_t stdoutCheck=kFALSE) {
181 // METHOD USEFUL FOR ANALYSIS ON THE CAF
182 // Check the presence of both AliAOD.root and AODVertexingHF.root files
184 // returns a TFileCollection suitable for storing datasets in CAF
185 // Origin: A.Rossi, andrea.rossi@ts.infn.it
188 TAlienCollection *collectionAOD = TAlienCollection::Open(collectionfileAOD);
189 TGridResult *tagResultAOD = collectionAOD->GetGridResult("",0,0);
192 TFileCollection *proofColl=new TFileCollection("proofColl","proofColl");
194 nmaxentr=tagResultAOD->GetEntries();
195 printf("Number of files %d\n",nmaxentr);
196 if(nfiles>0&&nmaxentr>nfiles)nmaxentr=nfiles;
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
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());
218 aodlfn.Append("aod_archive.zip");
219 printf("Adding file %s\n",aodlfn.Data());
220 proofColl->Add(r->GetKey(0,"turl"));
224 //----------------------------------------------------------------------------
225 void StageToCAF(TString xmlcoll="collAODLHC08x.xml",
226 TString datasetname="AODVertexingHF_LHC08x_10files",
229 // Staging a dataset to CAF
230 // andrea.dainese@pd.infn.it
233 //gROOT->LoadMacro("MakeAODInputChain.C");
235 TGrid::Connect("alien://");
237 // find -x collAODLHC08x -z /alice/cern.ch/user/r/rbala/newtrain/out_lhc08x/* AliAOD.root > collAODLHC08x.xml
239 TFileCollection *proofColl = MakeRootArchFileCollection(xmlcoll.Data(),nfiles,KTRUE);
240 proofColl->SetAnchor("AliAOD.root");
242 gEnv->SetValue("XSec.GSI.DelegProxy","2");
243 TProof::Open("dainesea:PWG3@alicecaf");
244 gProof->RegisterDataSet(datasetname.Data(),proofColl);
245 gProof->ShowDataSets();
249 //---------------------------------------------------------------------------
250 Bool_t CheckStdout(TString aodlfn) {
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;
262 Int_t ncol = fscanf(fileres,"%s %s %s %s",&text,&text,&text,&text);
263 //printf("%d %s\n",ncol,text);
265 gROOT->ProcessLine(".! rm stdoutput result");
266 if(ncol>=0) return kFALSE;