2 #include "TGridCollection.h"
7 #include "TGridResult.h"
9 #include "TAlienResult.h"
17 gSystem->Load("libXrdClient.so");
18 gSystem->Load("libNetx.so");
19 .L $ALICE_ROOT/TPC/macros/testTPC/AlienToolkit.cxx+
20 //Reconstructed data example
22 char *path = "/alice/cern.ch/user/m/miranov/test2007/"
24 char *mask = "07000015*.root";
25 char *path = "/alice/data/2007/LHC07w_TPC/"
28 toolkit.MakeCollection(path,mask);
31 toolkit.MakeJobList("job.list","root://gsiaf.gsi.de:1094/", "", "COPY");
37 class AlienToolkit: public TObject{
40 TGridCollection* MakeCollection(const char *path, char *mask);
42 void LocalCopy(const char* destination);
43 void RemoteCopy(const char* destination="root://gsiaf.gsi.de:1094/", Int_t maxfiles=20);
44 void MakeJobList(const char * outname, const char *outputPrefix, const char *action, const char *suffix);
45 static Bool_t IsDir(const char * name);
46 static Bool_t IsFile(const char * name);
47 static Bool_t ResubmitJobs();
49 TGridCollection *fCollection;
51 ClassDef(AlienToolkit,1)
54 ClassImp(AlienToolkit)
56 AlienToolkit::AlienToolkit():
60 TGrid::Connect("alien://",0,0,"t");
66 Bool_t AlienToolkit::IsDir(const char * name){
68 // Check if it is directory
70 void *dir = gSystem->OpenDirectory(name);
75 Bool_t AlienToolkit::IsFile(const char *name ){
77 // Check if is it file
79 Long_t id, size, flags, modtime ;
80 Int_t ret = gSystem->GetPathInfo(name,&id, &size, &flags, &modtime);
81 if (ret==0) return kFALSE;
82 if ((flags&2)>0) return kFALSE;
87 TGridCollection* AlienToolkit::MakeCollection(const char *path, char *mask){
89 /*char *mask = "root_archive.zip";
90 char *path = "/alice/cern.ch/user/m/miranov/test2007/"
93 TGridResult* query = gGrid->Query(path,mask);
94 TGridCollection* collection=gGrid->OpenCollectionQuery(query);
95 // collection->SelectFile(mask,1,20); // select files 0-100
96 collection->LookupSUrls();
97 //collection->CheckIfOnline();
99 fCollection = collection;
106 while ( (filemap = collection->Next())) {
107 TIterator *nextfile = filemap->MakeIterator();
109 while ((attributes = (TMap *) nextfile->Next())) {
110 printf("%d\t%d\t%d\n",counter, counterm,counterf);
111 TMap * map = new TMap;
112 fInfoArray.AddLast(map);
114 TObjString *surl = new TObjString(collection->GetSURL(attributes->GetName()));
115 TObjString *turl = new TObjString(collection->GetTURL(attributes->GetName()));
116 TObjString *lfn = new TObjString(collection->GetLFN(attributes->GetName()));
117 map->Add(new TObjString("alienLFN"),lfn);
118 map->Add(new TObjString("alienSURL"),surl);
119 map->Add(new TObjString("alienTURL"),turl);
122 Int_t isOnline = collection->IsOnline(attributes->GetName());
123 printf("Base Name:\t%s\n",attributes->GetName());
124 printf("Size:\t%d\n",(Int_t)collection->GetSize());
125 printf("IsOnline:\t%d\n",collection->IsOnline());
126 printf("IsSelected:\t%d\n",collection->IsSelected());
127 printf("IsOnline:\t%d\n",isOnline);
128 printf("LFN Name:\t%s\n",lfn->String().Data());
129 printf("TURL Name:\t%s\n",turl->String().Data());
130 printf("SURL Name:\t%s\n",surl->String().Data());
141 void AlienToolkit::Stage(){
143 // Stage selected alien files
145 Int_t entries = fInfoArray.GetEntries();
146 ofstream aout("stage.txt");
147 for (Int_t i=0; i<entries;i++){
148 TMap &map = *((TMap*)fInfoArray.At(i));
149 TObjString *lfn = (TObjString*)map("alienLFN");
151 printf("Staging submitfor\t%s\n",lfn->String().Data());
152 aout<<"stage "<<lfn->String().Data()<<endl;
155 gSystem->Exec("aliensh file:stage.txt");
158 void AlienToolkit::LocalCopy(const char *destination){
160 // Copy selected files to the destination directory
161 // the LFN path name translated to the directory name replacing
162 // separtor - the flat structure is created
164 Int_t entries = fInfoArray.GetEntries();
165 ofstream aout("stage.txt");
166 for (Int_t i=0; i<entries;i++){
167 TMap &map = *((TMap*)fInfoArray.At(i));
168 TObjString *lfn = (TObjString*)map("alienLFN");
170 printf("Staging submitfor\t%s\n",lfn->String().Data());
171 TString dnames=lfn->String().Data();
172 dnames.ReplaceAll(".root_dir","");
173 dnames.ReplaceAll("/","_");
174 TString dname=destination;
176 aout<<"cp "<<lfn->String().Data()<<" "<<dname.Data()<<endl;
179 gSystem->Exec("aliensh file:stage.txt");
183 void AlienToolkit::MakeJobList(const char * outname, const char *outputPrefix, const char *action, const char *suffix){
187 Int_t entries = fInfoArray.GetEntries();
188 ofstream aout(outname);
189 for (Int_t i=0; i<entries;i++){
190 TMap &map = *((TMap*)fInfoArray.At(i));
191 TObjString *lfn = (TObjString*)map("alienLFN");
192 TObjString *pfn = (TObjString*)map("alienSURL");
195 printf("Job info\t%s\n",lfn->String().Data());
196 TString jobID=lfn->String().Data();
197 jobID.ReplaceAll("/","_");
200 TString outputDir=outputPrefix;
201 outputDir+=lfn->String().Data();
203 aout<<jobID<<" "<<pfn->String().Data()<<" "<<outputDir.Data()<<" "<<action;
204 if (suffix) aout<<" "<<suffix<<"\n";
212 void AlienToolkit::RemoteCopy(const char *destination,Int_t maxfiles){
214 // Copy selected files to the destination directory
215 // the LFN path name translated to the directory name replacing
216 // separtor - the flat structure is created
218 Int_t entries = fInfoArray.GetEntries();
220 for (Int_t i=0; i<entries;i++){
222 if (aout) aout->close();
223 aout = new ofstream(Form("stage_%d.sh",i/maxfiles));
224 (*aout)<<"!/bin/bash\n";
225 (*aout)<<"source ~/.balice\n";
227 TMap &map = *((TMap*)fInfoArray.At(i));
228 TObjString *pfn = (TObjString*)map("alienSURL");
229 TObjString *lfn = (TObjString*)map("alienLFN");
232 TString dnames=lfn->String().Data();
233 TString dname=destination;
235 (*aout)<<"xrdcp -d 1 "<<pfn->String().Data()<<" "<<dname.Data()<<endl;
238 //gSystem->Exec("aliensh file:stage.txt");
241 Bool_t AlienToolkit::ResubmitJobs(){
243 // Resubmit the processes finished in error state
245 //gSystem->Exec("alien_ps | grep EE > ps.txt")
246 gSystem->Exec("alien_ps | grep EE |gawk '{print $2}' > psEE.txt");
247 gSystem->Exec("alien_ps | grep EXPIRED |gawk '{print $2}' > psEXPIRED.txt");
250 in.open("psEXPIRED.txt");
255 // line.ReplaceAll("-","");
256 printf("Resubmiting %s\n",line.Data());
257 Int_t pos = line.First("-");
258 printf("%s\n",Form("alien_resubmit %s",&line.Data()[pos+1]));
259 gSystem->Exec(Form("alien_resubmit %s",&line.Data()[pos+1]));
270 1. ???? fCollection.IsOnline("")
272 #12 0x04e9a03f in XrdClientAdmin::IsFileOnline (this=0x94a91b0, vs=@0xbfe07f60, vb=@0xbfe07f80) at ../../src/XrdClient/XrdClientVector.hh:55
273 #13 0x0423a975 in TXNetSystem::IsOnline (this=0x9652800,
274 path=0x9661488 "root://voalice04.cern.ch:1094//castor/cern.ch/alice/2005_castor2/15/23612/9e787bec-b010-11dc-a80c-000e0c3e6d91")
275 at netx/src/TXNetSystem.cxx:476
276 #14 0x04237c6e in TXNetFileStager::IsStaged (this=0x96526b8,
277 path=0x9661400 "root://voalice04.cern.ch:1094//castor/cern.ch/alice/2005_castor2/15/23612/9e787bec-b010-11dc-a80c-000e0c3e6d91")
278 at netx/src/TXNetFileStager.cxx:63
279 #15 0x00551117 in TFileStager::GetStaged (this=0x96526b8, pathlist=0x9649820) at net/src/TFileStager.cxx:58
280 #16 0x010e5d96 in TAlienCollection::CheckIfOnline (this=0x95da8d8, bulk=true) at alien/src/TAlienCollection.cxx:1143
283 2. id xrootd on voalice04.cern.ch ?
284 "root://voalice04.cern.ch:1094//castor/cern.ch/alice/2005_castor2/15/23612/9e787bec-b010-11dc-a80c-000e0c3e6d91"
286 3. How to check if the file exist in redirector ?