/////////////////////////////////////////////////////////////////////////////// namespace dcache { int get_name(const char* File, const char* Book, TString& Name) { /* dcap://cdfdca3.fnal.gov:25160/pnfs/fnal.gov/usr/cdfen/filesets /CB/CB24/CB2421/CB2421.1/ar02bca5.0002phys */ TCdf2Files fr; int rc = cdfofprd.GetFile(File,Book,&fr); if (rc < 0) { printf("can\'t find file %s in book %s\n",File,Book); return rc; } // file exists, make DCACHE name out of it const char* server = "dcap://cdfdca2.fnal.gov:25154" ; const int door = 25154; const char* dir = "pnfs/fnal.gov/usr/cdfen/filesets"; const char* s = fr.fFILESET_NAME.Data(); TString s2 = fr.fFILESET_NAME(0,2); TString s4 = fr.fFILESET_NAME(0,4); TString s6 = fr.fFILESET_NAME(0,6); Name = Form("%s/%s/%s/%s/%s/%s/%s", server,dir,s2.Data(),s4.Data(), s6.Data(),s,File); return 0; } //_____________________________________________________________________________ TFile* open_file(const char* File="gr02bca5.0002phys", const char* Book="filecatalog") { int ok; TString dcache_file; get_name(File,Book,dcache_file); printf("dcache file: %s\n",dcache_file.Data()); ok = TDCacheFile::CheckFile(dcache_file.Data(),0); if (! ok) { printf(" --- file not staged, will try to stage\n"); ok = TDCacheFile::Stage(dcache_file.Data(),0); printf(" --- staging code: %i\n",ok); if (! ok) return 0; } TFile* f = TFile::Open(dcache_file.Data()); // this should work return f; } //_____________________________________________________________________________ int check_file(const char* Book="", const char* Filename, Int_t Stage = 0, int Verbose = 0) { TString dcache_name; TString book; book = Book; if (book == "") book = "filecatalog"; dcache::get_name(Filename,book.Data(),dcache_name); if (Verbose) { printf("trying to check file: %s\n",dcache_name.Data()); } int ok = TDCacheFile::CheckFile(dcache_name.Data(),0); if (! ok) { printf(" -- file %s not staged\n",dcache_name.Data()); if (Stage != 0) { ok = TDCacheFile::Stage(dcache_name.Data(),0); printf(" -- staging submitted, return code: %i\n",ok); } } else { printf(" -- ok= %i, file %s in cache\n",ok, Filename); } return ok; } //_____________________________________________________________________________ int check_list_of_files(const char* Filename, const char* Book = "filecatalog", Int_t Stage = 0) { // `Filename` is the ASCII file containing 1 line (FN BOOK stage) per file TString dcache_name; char s[1000], fn[100], book[100]; int ok; FILE* file = fopen(Filename,"r"); while (fgets(s,1000,file)) { sscanf(s,"%s",fn); dcache::get_name(fn,Book,dcache_name); ok = TDCacheFile::CheckFile(dcache_name.Data(),0); if (! ok) { printf(" -- %s.%s -- is not staged",Book,fn); if (Stage != 0) { ok = TDCacheFile::Stage(dcache_name.Data(),0); printf(", staging submitted, return code: %i\n",ok); } else { printf("\n"); } } else { printf(" -- %s.%s -- is in cache\n",Book,fn); } } fclose(file); } //_____________________________________________________________________________ int check_strip_status(const char* Dataset) { // `Filename` is the ASCII file containing 1 line (FN BOOK stage) per file TString dcache_name; const char* Book = "filecatalog"; int ok, number; char s[1000], fn[100], book[100],status_file[200], cmd[200]; sprintf(status_file,"/cdf/opr2/cdfopr/strip/%s/.%s.status",Dataset,Dataset); sprintf(cmd,"cat %s | grep \"not in cache\"",status_file); FILE* file = gSystem->OpenPipe(cmd,"r"); while (fgets(s,1000,file)) { // printf("%s\n",s); sscanf(s,"%i %s",&number,fn); printf(" %i %s ",number,fn); dcache::get_name(fn,Book,dcache_name); ok = TDCacheFile::CheckFile(dcache_name.Data(),0); if (! ok) { printf(" -- %s.%s -- is not staged",Book,fn); ok = TDCacheFile::Stage(dcache_name.Data(),0); printf(", staging submitted, return code: %i\n",ok); } else { printf(" -- %s.%s -- is in cache\n",Book,fn); } } fclose(file); } //_____________________________________________________________________________ int stage_fileset(const char* Fileset, const char* Book="filecatalog", Int_t Verbose = 0) { // example: dcache::stage_fileset("GI4827.0","cdfpewk",1) TObjArray list; int rc = cdfofprd.GetListOfFiles(&list,Book,0,Fileset); TString dcache_name; if (rc < 0) { printf(" cant find fileset %s Fileset in book %s\n",Fileset,Book); return rc; } int ok; int n_to_stage = 0; int n=list.GetEntriesFast(); TFile* file; const char* name; for (int i=0; ifFILE_NAME.Data(); dcache::get_name(name,Book,dcache_name); if (Verbose) { printf(" checking file : %s\n",name); } ok = TDCacheFile::CheckFile(dcache_name.Data(),0); if (! ok) { printf(" --- file %s not staged, will try to stage\n", dcache_name.Data()); ok = TDCacheFile::Stage(dcache_name.Data(),0); n_to_stage++; printf(" --- staging submitted, return code: %i\n",ok); if (! ok) return 0; } } printf(" -- staging requests: %i files\n",n_to_stage); } //_____________________________________________________________________________ int check_fileset(const char* Fileset, const char* Book="filecatalog") { // example: dcache::check_fileset("GI4827.0","cdfpewk",1) TObjArray list; int rc = cdfofprd.GetListOfFiles(&list,Book,0,Fileset); TString dcache_name; if (rc < 0) { printf(" cant find fileset %s Fileset in book %s\n",Fileset,Book); return rc; } int ok; int n_to_stage = 0; int n=list.GetEntriesFast(); TFile* file; const char* name; for (int i=0; ifFILE_NAME.Data(); dcache::get_name(name,Book,dcache_name); printf(" file : %s",name); ok = TDCacheFile::CheckFile(dcache_name.Data(),0); if (ok) printf(" is staged \n"); else printf(" is not staged\n"); } } //_____________________________________________________________________________ int check_dataset(const char* Book, const char* Dataset, int MinRun = 0, int MaxRun = 9999999, int Stage = 0, int Verbose = 0) { // example: dcache::check_dataset("stntuple/dev_240","gmbs08") const char* fn; int ok, nfiles, n_to_stage, n_submitted; TStnDataset* dataset = new TStnDataset(Book,Dataset,MinRun,MaxRun); TStnCatalog catalog; catalog.InitDataset(dataset); nfiles = dataset->GetNFiles(); n_to_stage = 0; for (int i=0; iGetChain()->GetListOfFiles()->At(i); // files have fully qualified names TUrl url = file->GetTitle(); fn = url.GetUrl(); printf("file: %s\n",fn); if (strcmp(url.GetProtocol(),"dcap") == 0) { ok = TDCacheFile::CheckFile(fn,0); if (ok) { if (Verbose) printf(" - file %s is staged\n",fn); } else { if (Verbose) printf(" - file %s not staged\n",fn); n_to_stage++; if (Stage != 0) { ok = TDCacheFile::Stage(fn,0); if (Verbose) printf(" - staging submitted, return code: %i\n",ok); n_submitted++; } } } else if (strcmp(url.GetProtocol(),"root") == 0) { // static file } } printf(" N(submitted staging requests) = %4i\n",n_submitted); return n_to_stage; } }