Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NodesCleanup.C
Go to the documentation of this file.
1 // This macro is used to remove temporary cwb files from the remote nodes
2 // Works only in ATLAS cluster
3 // WARNING : no jobs must be running !!!
4 // Author : Gabriele Vedovato
5 //
6 // Macro scan all the availables nodes and remove :
7 // wave_*, job_*, CWB_Plugin_Config_* files
8 //
9 
10 //#define GET_SIZE // get total file size (MB)
11 #define FILE_CLEANUP // remove temporary files
12 #define DUMMY // file are not removed
13 //#define VERBOSE // print remove command
14 
15 int GetSize(TString dir);
16 int FilesCleanup(TString dir, int& fsize);
17 
18 void NodesCleanup() {
19 
20  CWB::Toolbox::checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
21  gROOT->Macro(gSystem->ExpandPathName("$CWB_PARAMETERS_FILE"));
22 
23  // ---------------------------------------------------
24  // get node list
25  // ---------------------------------------------------
26  vector<TString> nodeList;
27 
28  cout << "NodesCleanup.C : get node list ..." << endl;
29  char cmd[1024]; strcpy(cmd,"condor_status -format \"%s\n\" Machine");
30  FILE* fp = gSystem->OpenPipe(cmd, "r");
31  if(fp != NULL) {
32  char cmdout[1024];
33  while(fgets(cmdout, sizeof(cmdout)-1, fp)!=NULL) {
34  cmdout[strlen(cmdout)-1]=0; // strip new line char
35  if(TString(cmdout).BeginsWith("a")) {
36  bool check=false;
37  // check if node is already in the list
38  for(int j=0;j<(int)nodeList.size();j++) {
39  if(TString(nodeList[j])==cmdout) {check=true;break;}
40  }
41  if(!check) nodeList.push_back(cmdout);
42  }
43  }
44  }
45  gSystem->ClosePipe(fp);
46 
47  UserGroup_t* uinfo = gSystem->GetUserInfo();
48  TString uname = uinfo->fUser;
49 
50  int fsize=0;
51  int tot_fsize=0;
52  int tot_fsize2=0;
53  int nfiles=0;
54  int tot_nfiles=0;
55  int nodes = nodeList.size();
56  for(int i=0;i<nodes;i++) {
57  //cout << i << " " << nodeList[i] << endl;
58  char node_user_path[1024];
59  sprintf(node_user_path,"/atlas/node/%s/user/%s",nodeList[i].Data(),uname.Data());
60  cout << "NODE : " << node_user_path << " (" << i << "/" << nodes << ")" << endl;
61  Long_t id,size,flags,mt;
62  int estat = gSystem->GetPathInfo(node_user_path,&id,&size,&flags,&mt);
63  if (estat==0) { // dir exist
64 #ifdef GET_SIZE
65  fsize = GetSize(node_user_path); // get total file size (MB)
66  tot_fsize+=fsize;
67 #endif
68 #ifdef FILE_CLEANUP
69  nfiles = FilesCleanup(node_user_path,fsize); // remove temporary files
70  tot_fsize2+=fsize;
71  tot_nfiles+=nfiles;
72 #endif
73  }
74  cout << endl;
75  }
76 
77 #ifdef GET_SIZE
78  cout << "total file size : " << tot_fsize << " MB" << endl;
79 #endif
80 #ifdef FILE_CLEANUP
81  cout << "tot deleted files : " << tot_nfiles << " - tot size " << tot_fsize2 << " MB" << endl;
82 #endif
83 
84  gSystem->Exit(0);
85 }
86 
87 int FilesCleanup(TString dir, int& fsize) {
88 
89  char cmd[1024];
90  int size_tot=0;
91  int nfiles=0;
92 
93  // remove temporary files
94  vector<TString> fileList = CWB::Toolbox::getFileListFromDir(dir);
95  for(int j=0;j<fileList.size();j++) {
96  bool toBeRemoved=false;
97  if(fileList[j].Contains("/wave_")) toBeRemoved=true;
98  if(fileList[j].Contains("/job_")) toBeRemoved=true;
99  if(fileList[j].Contains("/CWB_Plugin_")) toBeRemoved=true;
100  if(toBeRemoved) {
101  Long_t id,size,flags,mt;
102  int estat = gSystem->GetPathInfo(fileList[j].Data(),&id,&size,&flags,&mt);
103  if (estat==0) { // file exist
104  //cout << size << endl;
105  size_tot+=size;
106  sprintf(cmd,"rm %s",fileList[j].Data());
107 #ifdef VERBOSE
108  cout << cmd << endl;
109 #endif
110 #ifndef DUMMY
111  gSystem->Exec(cmd);
112 #endif
113  nfiles++;
114  }
115  }
116  }
117 
118  fsize=(int)size_tot/(1024.*1024.);
119 
120  cout << "deleted files : " << nfiles << " - size " << fsize << " MB" << endl;
121 
122  return nfiles;
123 }
124 
125 int GetSize(TString dir) {
126 
127  int size=0;
128 
129  char cmd[1024];
130  sprintf(cmd,"du -sm %s",dir.Data());
131  //cout << cmd << endl;
132  FILE* fp = gSystem->OpenPipe(cmd, "r");
133  if(fp != NULL) {
134  char cmdout[512];
135  if(fgets(cmdout, sizeof(cmdout)-1, fp)!=NULL) {
136  //cout << cmdout << endl;
137  TString SIZE = TString(cmdout);
138  // size is separated from path by a tab (0x9)
139  // 9711 /atlas/node/a0134.atlas.local/user/vedovato
140  SIZE.Resize(SIZE.First(0x9));
141  if(SIZE.IsDigit()) size=SIZE.Atoi();
142  //cout << size << endl;
143  }
144  }
145  gSystem->ClosePipe(fp);
146 
147  cout << "total file size " << size << " MB" << endl;
148 
149  return size;
150 }
void NodesCleanup()
Definition: NodesCleanup.C:18
static vector< TString > getFileListFromDir(TString dir_name, TString endString="", TString beginString="", TString containString="", bool fast=false)
Definition: Toolbox.cc:4333
int nfiles
char cmd[1024]
int FilesCleanup(TString dir, int &fsize)
Definition: NodesCleanup.C:87
TString("c")
Long_t flags
Long_t size
int j
Definition: cwb_net.C:10
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:3956
TString uname
i() int(T_cor *100))
UserGroup_t * uinfo
Definition: cwb_frdisplay.C:73
#define SIZE
cout<< "Starting reading output directory ..."<< endl;vector< TString > fileList
int estat
strcpy(RunLabel, RUN_LABEL)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
Long_t mt
Long_t id
int check
std::vector< wavenode > nodes
Definition: wavepath.hh:42
int GetSize(TString dir)
Definition: NodesCleanup.C:125