#include #include #include #include //using namespace std; //by alienplugin make xml files for some period/run TString kDestDir = "./"; TString kPeriod = ""; TFile* kSourceFile; class AliAnalysisAlien; copyFilesAlien2Loc( const char *destDir = "" , const char *period = "LHC10d4",const char* xmlfile, Int_t startIter = 0){ if(strlen(destDir)) kDestDir = TString(destDir); TAlienCollection* myCollection = TAlienCollection::Open(xmlfile); TList* fileList = new TList(); myCollection->Reset() ; Printf("gona open xml file"); while ( myCollection->Next() ) { TString* url = new TString(myCollection->GetTURL("")); fileList->Add((TObject*)url) ; } Printf("xml file opened"); TGrid::Connect("alien://"); TFile* kSourceFile = 0; ofstream myfile; ofstream log; myfile.open("files.txt"); log.open("copyFiles.log"); for(Int_t i = 0; i < fileList->GetEntries(); i++){ Printf("iterating %d",i); if(iAt(i); Printf("fileurl: %s", fileurl->Data()); //make dest dir TObjArray *subStrL = TPRegexp(Form("(alien.*(%s)/([0-9/]+))(.+root)",period)).MatchS(fileurl->Data()); TString subDir = ((TObjString *)subStrL->At(2))->GetString(); TString filename = ((TObjString *)subStrL->At(4))->GetString(); TString fileDir = ((TObjString *)subStrL->At(1))->GetString(); //try to open file for check the connection std::string str_path = fileurl->Data(); Int_t t = TPRegexp("alien").Substitute(fileurl->Data(), "root"); TFile* sfile = 0; if(OpenAlienFile(0, str_path.c_str(), sfile) < 0){ Printf("Cant open file: %s", fileurl->Data()); log << Form("Cant open file: %s", fileurl->Data()); if(sfile) sfile->Close("R"); delete sfile; delete gFile; continue; } else { //if(sfile) sfile->Close("R"); system(Form("mkdir -p %s/%s/%s", kDestDir.Data(),period,subDir.Data())); TString localPath = Form("file:%s/%s/%s/%s", kDestDir.Data(), period, subDir.Data(),filename.Data()); Printf(Form("Gona copy")); if(TFile::Cp(fileurl->Data(), localPath.Data()))myfile << localPath.Data(); //if(sfile->Cp(localPath.Data(), kTRUE, 1000000)) myfile << localPath.Data(); else Printf("Failed to copy file"); } //Printf(Form("Delete sfile")); delete sfile; if(gFile != 0 && gFile->IsOpen()){ Printf("File opened: %s", fileurl->Data()); gFile->Close("R"); Printf("File closed"); } }//for fileList->GetEntries() if(kSourceFile) kSourceFile->Close(); if(kSourceFile) delete kSourceFile; myfile.close(); log << "Done"; Printf("Done"); } Int_t OpenAlienFile(Int_t trial, char* fileUrl, TFile* file){ if(fileUrl){ file = TFile::Open(fileUrl, "TIMEOUT=10 READ"); if(!file){ if(trial<=0){ Printf(Form("::Message: Could not open file %s (trial %d), try again ...", fileUrl, trial)); OpenAlienFile(trial+1, fileUrl, file); } else { Printf(Form("::Error: Could not open file %s, give up ...",fileUrl)); return -1; } } else {Printf(Form("::Success: File opened: %s.", fileUrl)); return 0;} } else { Printf(Form("::Error: No file url: %s.", fileUrl)); } return -1; }