2 TTOOLKIT to acces files on XRD
8 gSystem->AddIncludePath("-I$ALICE_ROOT/TPC/macros")
9 gROOT->LoadMacro("$ALICE_ROOT/TPC/macros/AliXRDPROOFtoolkit.cxx++")
12 Retrieve the list of files : POSSIBLE ONLY FOR USER WITH LOGIN ACCESS TO THE XRD MACHINES
14 AliXRDPROOFtoolkit tool;
15 tool.ListOfFiles("pp.txt","/data.local2/sma/sim/v4-05-Rev-03/pp", "AliESDs.root", kTRUE);
20 AliXRDPROOFtoolkit tool;
21 TChain * chain = tool.MakeChain("pp.txt","esdTree",10)
22 chain->Draw("fTPCncls");
25 3. Process logs - ONLY priority users - with ssh acces
26 AliXRDPROOFtoolkit tool;
27 tool.FilterSegFault();
28 TTree * treeSys = tool.DumpSys(kTRUE)
35 #include <TObjArray.h>
36 #include <TObjString.h>
50 #include <AliXRDPROOFtoolkit.h>
53 ClassImp(AliXRDPROOFtoolkit);
57 //______________________________________________________________________________
58 AliXRDPROOFtoolkit::AliXRDPROOFtoolkit () : TObject ()
61 // Default -GSI specific setup
63 for(Int_t i=256;i<268;i++)
64 listeMachine.push_back(new TString(Form("lxb%d.gsi.de", i)));
65 fUserGroup = gSystem->GetUserInfo();
66 fUserName = fUserGroup->fUser;
70 void AliXRDPROOFtoolkit::Print(Option_t* /*option*/) const{
72 // Print current setup of toolkit
74 printf("User name\t%s\n", fUserName.Data());
75 printf("List of slaves\n");
77 for(UInt_t i=0;i<listeMachine.size();i++)
78 printf("%s\n",listeMachine[i]->Data());
82 //______________________________________________________________________________
83 void AliXRDPROOFtoolkit::AddMachine (const char*name)
86 // add computer to the list
88 listeMachine.push_back( new TString(name));
92 //______________________________________________________________________________
93 Bool_t AliXRDPROOFtoolkit::ListOfFiles(const char*fileName, const char*path, const char*filter, Bool_t displayMachine)
96 // Get the list of files on "registerd slaves"
98 // fileName - Resultinfg flie with list
99 // path - starting path on slave e.g /data.local2/sma/
100 // filter - filter expression e.g. AliESDs.root
101 // display machine - not used yet
106 // FILTER expression - to get REDIRECTOR NAME
108 //what we want for sed
109 // sprintf(filterXRD,"sed s/\\/data.local2/root:\\/\\/gsiaf.gsi.de:1094\\//");
110 //what we should write
111 sprintf(filterXRD,"sed s/\\\\/data.local2/root:\\\\/\\\\/gsiaf.gsi.de:1094\\\\//");
115 gSystem->Exec(Form("echo >%s",fileName));
116 for(UInt_t i=0; i<listeMachine.size(); i++){
117 cout<<"Inspecting "<<listeMachine[i]->Data()<<" ..."<<endl;
118 sprintf(command,"lsrun -m %s find %s | grep %s | %s >> %s", listeMachine[i]->Data(), path, filter, filterXRD,fileName);
120 gSystem->Exec(command);
127 TChain* AliXRDPROOFtoolkit::MakeChain(const char*fileIn, const char * treeName, const char *fName, Int_t maxFiles, Int_t startFile)
132 TChain* chain = new TChain(treeName);
134 // Open the input stream
138 // Read the input list of files and add them to the chain
147 if (!currentFile.Contains("root")) continue; // protection
149 if (counter<startFile) continue;
150 if (counter>maxFiles+startFile) break;
151 chain->Add(currentFile.Data());
159 TChain* AliXRDPROOFtoolkit::MakeChainRandom(const char*fileIn, const char * treeName,const char *fName, Int_t maxFiles, Int_t startFile)
162 // Create a TDSet - files are in random order
164 // filein - input list text file
165 // treename - containg tree
166 // maxFiles - maximum number of files included
168 TObjArray array(10000);
170 TChain* chain = new TChain(treeName);
172 // Open the input stream
176 // Read the input list of files and add them to the chain
185 if (!currentFile.Contains("root")) continue; // protection
187 // chain->Add(currentFile.Data());
188 array.AddLast(new TObjString(currentFile));
191 Int_t entries = array.GetEntries();
192 printf("Number of entries\t%d",entries);
193 if (maxFiles<0) maxFiles=entries;
194 if (maxFiles>entries) maxFiles=entries;
198 for (Int_t i=0; i<maxFiles; i++){
199 Int_t ifile = TMath::Nint(gRandom->Rndm()*Float_t(entries));
200 if (ifile<entries && (array.At(ifile)) && array.At(ifile)->TestBit(TObject::kCannotPick)==kFALSE){
201 printf("%d\t%d\t%s\n",i, ifile, array.At(ifile)->GetName());
202 chain->Add(array.At(ifile)->GetName());
203 array.At(ifile)->SetBit(TObject::kCannotPick);
211 TDSet* AliXRDPROOFtoolkit::MakeSet(const char*fileIn, const char * treeName, const char *fName, Int_t maxFiles)
214 // Create the TDSet out of list
215 // filein - input list text file
216 // treename - containg tree
217 // maxFiles - maximum number of files included
219 TDSet* chain = new TDSet(treeName);
221 // Open the input stream
225 // Read the input list of files and add them to the chain
234 if (!currentFile.Contains("root")) continue; // protection
236 if (maxFiles>0 && counter>maxFiles) break;
237 chain->Add(currentFile.Data());
246 TDSet* AliXRDPROOFtoolkit::MakeSetRandom(const char*fileIn, const char * treeName, const char *fName, Int_t maxFiles)
249 // Create a TDSet - files are in random order
251 // filein - input list text file
252 // treename - containg tree
253 // maxFiles - maximum number of files included
255 TObjArray array(10000);
257 TDSet* chain = new TDSet(treeName);
259 // Open the input stream
263 // Read the input list of files and add them to the chain
272 if (!currentFile.Contains("root")) continue; // protection
274 // chain->Add(currentFile.Data());
275 array.AddLast(new TObjString(currentFile));
278 Int_t entries = array.GetEntries();
279 printf("Number of entries\t%d",entries);
280 if (maxFiles<0) maxFiles=entries;
281 if (maxFiles>entries) maxFiles=entries;
282 for (Int_t i=0; i<maxFiles; i++){
283 Int_t ifile = TMath::Nint(gRandom->Rndm()*Float_t(entries));
284 if (ifile<entries && (array.At(ifile)) && array.At(ifile)->TestBit(TObject::kCannotPick)==kFALSE){
285 printf("%d\t%d\t%s\n",i, ifile, array.At(ifile)->GetName());
286 chain->Add(array.At(ifile)->GetName());
287 array.At(ifile)->SetBit(TObject::kCannotPick);
296 //_______________________________________________________________________________
299 void AliXRDPROOFtoolkit::FilterSegFault(const char *filter){
301 // Print the list of slaves finished with seg fault
303 printf("List of the PROOF slaves with seg fault (Last session) \n");
304 for(UInt_t i=0; i<listeMachine.size(); i++){
305 if (HasSegFault(listeMachine[i]->Data(), filter)){
306 printf("%s\n",listeMachine[i]->Data());
311 //_______________________________________________________________________________
313 Bool_t AliXRDPROOFtoolkit::HasSegFault(const char * machine, const char *filter){
315 // check if segmentation fault on the node
319 char *path = "segfault.log";
320 Long_t id,size,flags,modtime;
322 // first check if we have a log file
323 sprintf(command0, Form("lsrun -m %s find /data.local2/proof/%s/ | grep %s | grep .log >filelist.list", machine,fUserName.Data(), filter));
325 printf("%s\n",command0);
327 gSystem->Exec(command0);
328 gSystem->GetPathInfo("filelist.list", &id, &size, &flags, &modtime);
329 if (size<1) return kFALSE;
332 // now check the content
334 sprintf(command, Form("lsrun -m %s cat `lsrun -m %s find /data.local2/proof/%s/ | grep %s|grep log ` | grep segmentation >segfault.log", machine, machine,fUserName.Data(), filter));
337 printf("%s\n",command);
339 if (fVerbose>1) gSystem->Exec(command);
340 gSystem->GetPathInfo(path, &id, &size, &flags, &modtime);
345 //--------------------------------------------------------------------
347 TTree * AliXRDPROOFtoolkit::DumpSys(Bool_t verbose){
349 // Dump memory usage on worker nodes
350 gSystem->Exec("echo > syswatch.log");
351 for(UInt_t i=0; i<listeMachine.size(); i++){
352 if (verbose) gSystem->Exec(Form("ssh %s cat /data.local2/proof/miranov/last-worker*/syswatch.log ",listeMachine[i]->Data()));
353 gSystem->Exec(Form("ssh %s cat /data.local2/proof/miranov/last-worker*/syswatch.log >> syswatch.log",listeMachine[i]->Data()));
356 TTree * tree = new TTree("asci","asci");
357 tree->SetDirectory(0);
358 // tree->ReadFile("syswatch.log","hname/C:fname/C:entry/I:time/I:mem0/F:mem1/F:mem2/F:mem3/F");
359 tree->ReadFile("syswatch.log","hname/C:fname/C:entry/I:time/I:mem0/F:mem1/F:mem2/F:mem3/F:cpu0/F:cpu1/F:cpu2/F:cpu3/F");
363 // //--------------------------------------------------------------------
365 TTree * AliXRDPROOFtoolkit::DumpSys2(Bool_t verbose){
367 // Dump memory usage on worker nodes
369 gSystem->Exec("echo > syswatch.log");
370 for(UInt_t i=0; i<listeMachine.size(); i++){
372 gSystem->Exec(Form("lsrun -m %s cat /data.local2/proof/miranov/last-worker*/syswatch.log ",listeMachine[i]->Data()));
373 gSystem->Exec(Form("lsrun -m %s cat /data.local2/proof/miranov/last-workersession/syswatch.log >> syswatch.log",listeMachine[i]->Data()));
376 TTree * tree = new TTree("asci","asci");
377 tree->SetDirectory(0);
378 // tree->ReadFile("syswatch.log","hname/C:fname/C:entry/I:time/I:mem0/F:mem1/F:mem2/F:mem3/F");
379 tree->ReadFile("syswatch.log","hname/C:fname/C:entry/I:time/I:mem0/F:mem1/F:mem2/F:mem3/F:cpu0/F:cpu1/F:cpu2/F:cpu3/F");
389 TTree* AliXRDPROOFtoolkit::DumpFiles(Bool_t verbose){
393 gSystem->Exec("touch filewatch.log");
394 for(UInt_t i=0; i<listeMachine.size(); i++){
395 if (verbose) gSystem->Exec(Form("ssh %s cat /data.local2/proof/miranov/last-worker*/worker*/filewatch.log >>filewatch.log",listeMachine[i]->Data()));
396 gSystem->Exec(Form("ssh %s cat /data.local2/proof/miranov/last-worker*/worker*/filewatch.log >>filewatch.log",listeMachine[i]->Data()));
398 TTree * tree = new TTree("asci","asci");
399 tree->SetDirectory(0);
400 tree->ReadFile("filewatch.log","hname/C:fname/C:entry/I:status/I");
408 //______________________________________________________________________________
409 Int_t AliXRDPROOFtoolkit::Read(char * str, Int_t lenght, FILE *in)
415 n=fread(str+nread, sizeof(char), lenght, in);
416 if(n<=0) return nread;
426 //______________________________________________________________________________
427 void AliXRDPROOFtoolkit::CheckFiles (const char*fileIn, UInt_t checkLevel, const char*treeToRetrieve, const char*varexp, const char*selection)
433 fic.open(fileIn, ios_base::in);
436 focGood.open(Form("%s.Good",fileIn), ios_base::out|ios_base::trunc);
437 focBad.open(Form("%s.Bad",fileIn), ios_base::out|ios_base::trunc);
440 cout<<"Can't open file "<<fileIn<<endl;
451 Float_t compressionFactor;
454 TObjString * fileName=0x0;
455 TObjString * machineName=0x0;
456 // TChain chain ("check_chain");
458 TFile fout(Form("%s.root",fileIn),"recreate");
459 TTree * tree=new TTree("stats", "stats of AliXRDPROOFtoolkit::CheckFiles function");
461 tree->Branch ("machine", "TObjString", &machineName, 256000,0);
462 tree->Branch ("file", "TObjString", &fileName, 256000,0);
463 tree->Branch ("level", &level, "level/I");
464 tree->Branch ("size", &size, "size/L");
465 tree->Branch ("nkey", &nkey, "nkey/I");
466 tree->Branch ("compress", &compressionFactor, "compress/F");
467 tree->Branch ("version", &version, "version/I");
469 // start loop over the files
470 fic.getline(buffer, sizeof(buffer));
473 // get the machine name if present in the file
474 machine=strchr(buffer, '\t');
479 machineName=new TObjString(machine);
481 machineName=new TObjString("x");
484 cout<<"Inspecting file :"<<line<<endl;
488 fileName=new TObjString(line);
490 TFile * f=TFile::Open(line);
491 // chain.AddFile(line);
495 compressionFactor=-1;
498 if (fileName->String().Contains("AliESDs.root")){
502 char fnameFriend[1000];
503 sprintf(fnameFriend,"%s/AliESDfriends.root",gSystem->DirName(fileName->String().Data()));
504 cout<<"Inspecting file :"<<fnameFriend<<endl;
505 TFile * ffriend=TFile::Open(fnameFriend);
506 if (!ffriend) level=-4;
508 if (ffriend->IsZombie()) level=-3;
509 if (ffriend->TestBit(TFile::kRecovered) || ffriend->TestBit(TFile::kWriteError)){
518 if(level>=-1 && f!=0x0){
522 compressionFactor=f->GetCompressionFactor();
523 version=f->GetVersion();
525 if(checkLevel>0 && !f->IsZombie()){
527 if(checkLevel>1 && treeToRetrieve!="" && (getTree=(TTree*)f->Get(treeToRetrieve))!=0x0){
529 Int_t tentries = getTree->GetEntries();
530 if (tentries>=0) level=4;
531 cout<<"Number of entries :"<<getTree->GetEntries()<<endl;
533 if(checkLevel>3 && varexp!="" &&tentries>0) {
534 getTree->SetBranchStatus("*",1);
536 TH1F his("his","his",100,-1,1);
537 Int_t selected = getTree->Draw(Form("%s>>his",varexp), selection, "goff", 1, tentries-1);
538 cout<<"Selected\t"<<selected<<endl;
542 //try to remove the created histogrames ...
543 // TH1F *htemp = (TH1F*)gPad->GetPrimitive("htemp"); // 1D
544 // TGraph *graph = (TGraph*)gPad->GetPrimitive("Graph"); // 2D
545 // if(htemp!=0x0) {cout<<"removing TH1D"<<endl; delete htemp;}
546 // else if(graph!=0x0) {cout<<"removing TGraph"<<endl; delete graph;}
547 // else cout<<"nothing to remove : memory leak ..."<<endl;
550 }catch(std::bad_alloc){
551 cout<<"Warning : Draw option send std::badalloc"<<endl;
560 if (level>checkLevel){
564 focBad<<line<<"\t"<<level<<endl;
569 fic.getline(buffer, sizeof(buffer));
572 //now use chain to check
573 //chain.Lookup(kTRUE);
586 Bool_t AliXRDPROOFtoolkit::XRDCopyDir(const char * idir, const char * files, const char *odir, Bool_t zip){
588 // idir - input directory
589 // odir - output directory
590 // files - the list of files to be coppied
591 // zip - not supported yet
595 // idir ="root://gsiaf.gsi.de:1094//sma/sim/v4-05-Rev-03/pp/0000";
596 // odir ="root://lxgrid2.gsi.de:1094//miranov/test/pp/0000";
597 // char *files="AliESDs.root AliESDfriend.root Kinematics.root";
599 TObjArray * array = str.Tokenize(" ");
600 Int_t nfiles = array->GetEntries();
605 for (Int_t ifile =0; ifile<nfiles; ifile++){
606 sprintf(infile,"%s/%s", idir, array->At(ifile)->GetName());
607 sprintf(outfile,"%s/%s", odir, array->At(ifile)->GetName());
608 printf("%s - %s\n",infile, outfile);
609 Bool_t result = TFile::Cp(infile,outfile);