10 #include "TSystemDirectory.h"
12 #include "TDirectory.h"
32 void MakeRootAFPConfFile(
const char * directory,
const char * pat =
"*.adf", Option_t * opt =
"" );
37 bool IsAGoodDir( TList * listBadDir, TList * listBadPattern,
const char * );
38 bool IsAGoodFile( TList * listOfBadPattern,
const char * );
44 TString soption = opt;
45 TList * listofBaddir =
new TList;
46 TList * listofBadPatternf =
new TList;
47 TList * listofBadPatternd =
new TList;
48 std::string ssoption = soption.Data();
54 TString presentDir = gSystem->pwd();
55 TList * listofsubdir =
new TList;
56 TList * listofFile =
new TList;
57 TList * listOfGoodFile =
new TList;
58 TString patname = pat;
61 Bool_t wildcard =
false;
62 if ( patname.Contains(
"*") )
64 TRegexp all(
"*",kTRUE), pattern(patname.Data(),wildcard);
66 if ( pattern.Status() != TRegexp::kOK )
69 std::cerr <<
"pattern [*] intead of " << patname <<
std::endl;
74 if ( gDebug > 0 ) std::cerr <<
"pattern " << patname <<
std::endl ;
77 dir.SetDirectory(directory);
78 TList *list = dir.GetListOfFiles();
82 while ( (entry = iter()) )
84 if ( entry->InheritsFrom(
"TSystemDirectory") &&
85 strncmp(entry->GetName(),
".",1) &&
87 IsAGoodDir( listofBaddir, listofBadPatternd, entry->GetName()) )
89 TString pathname = gSystem->pwd();
91 pathname += entry->GetName();
92 listofsubdir->Add(
new TNamed(entry->GetName(),pathname.Data()));
94 else if ( entry->InheritsFrom(
"TSystemFile") &&
95 strncmp(entry->GetName(),
".",1) &&
96 IsAGoodFile( listofBadPatternf, entry->GetName() ) )
98 TString pathname = gSystem->pwd();
99 listofFile->Add(
new TNamed(entry->GetName(),pathname.Data()));
104 if ( soption.Contains(
"r") )
106 while ( listofsubdir->GetSize() != 0 )
108 dir.SetDirectory(listofsubdir->At(0)->GetTitle());
109 list = dir.GetListOfFiles();
111 while ( (entry = iter2()) )
113 if ( entry->InheritsFrom(
"TSystemDirectory") &&
114 strncmp(entry->GetName(),
".",1) &&
116 IsAGoodDir( listofBaddir, listofBadPatternd, entry->GetName()) )
118 TString pathname = gSystem->pwd();
120 pathname += entry->GetName();
121 listofsubdir->Add(
new TNamed(entry->GetName(),pathname.Data()));
123 else if ( entry->InheritsFrom(
"TSystemFile") &&
124 strncmp(entry->GetName(),
".",1) &&
125 IsAGoodFile( listofBadPatternf, entry->GetName()) )
127 TString pathname = gSystem->pwd();
128 listofFile->Add(
new TNamed(entry->GetName(),pathname.Data()));
132 tmp = (TNamed*)listofsubdir->At(0);
133 listofsubdir->Remove( listofsubdir->At(0) );
138 for ( Int_t i = 0; i < listofFile->GetSize(); i++ )
140 TString testname = listofFile->At(i)->GetName();
141 if ( testname.Contains(pattern) )
142 listOfGoodFile->Add( listofFile->At(i) );
145 std::clog << listOfGoodFile->GetSize() <<
" file was found " <<
std::endl;
147 gSystem->cd(presentDir);
149 std::ofstream outputfile(
"./RootAFP.conf");
150 std::clog <<
"file is created : " << presentDir <<
"/RootAFP.conf" <<
std::endl;
151 for ( Int_t i = 0; i < listOfGoodFile->GetSize(); i++ )
153 outputfile <<
"l " << listOfGoodFile->At(i)->GetTitle() <<
"/"
154 << listOfGoodFile->At(i)->GetName() <<
std::endl;
158 listOfGoodFile->Clear();
165 for (
size_t i = 2; i < s.size(); i++ )
167 if ( s[i-2] ==
'-' && s[i-1] ==
'd' && s[i] ==
'=' )
171 for (
size_t j = i+1; j < s.size() && s[j]!=
'-';j++ )
172 newtmp.push_back(s[j]);
173 l->Add(
new TNamed(newtmp.c_str(),newtmp.c_str()));
180 for (
size_t i = 3; i < s.size(); i++ )
182 if ( s[i-3] ==
'-' && s[i-2] ==
'p' && s[i-1] ==
'd' && s[i] ==
'=' )
186 for (
size_t j = i+1; j < s.size() && s[j]!=
'-';j++ )
187 newtmp.push_back(s[j]);
188 l->Add(
new TNamed(newtmp.c_str(),newtmp.c_str()));
195 for (
size_t i = 3; i < s.size(); i++ )
197 if ( s[i-3] ==
'-' && s[i-2] ==
'p' && s[i-1] ==
'f' && s[i] ==
'=' )
201 for (
size_t j = i+1; j < s.size() && s[j]!=
'-';j++ )
202 newtmp.push_back(s[j]);
203 l->Add(
new TNamed(newtmp.c_str(),newtmp.c_str()));
208 bool IsAGoodDir( TList * listBadDir, TList * listBadPattern,
const char * name )
210 for ( Int_t i = 0; i < listBadDir->GetSize(); i++ )
211 if ( !strcmp( name, listBadDir->At(i)->GetName()) )
return(
false );
212 TString sname = name;
213 for ( Int_t i = 0; i < listBadPattern->GetSize(); i++ )
215 TString
tmp(listBadPattern->At(i)->GetName());
216 Bool_t wildcard =
false;
217 if (
tmp.Contains(
"*") )
219 TRegexp pattern(listBadPattern->At(i)->GetName(),wildcard);
220 if ( sname.Contains(pattern) )
227 TString sname = name;
228 for ( Int_t i = 0; i < listOfBadPattern->GetSize(); i++ )
230 TString
tmp(listBadPattern->At(i)->GetName());
231 Bool_t wildcard =
false;
232 if (
tmp.Contains(
"*") )
234 TRegexp pattern(listOfBadPattern->At(i)->GetName(),wildcard);
235 if ( sname.Contains(pattern) )
243 namespace { TList PingNames;
char buffer[4*1024*1024]; }
248 void LoadPing(
const char * filename, Option_t * opt =
"+" )
250 TString option = opt;
251 std::ifstream inputfile(filename);
253 std::string machineName;
254 std::string portName;
256 TNamed * tmp_name = NULL;
260 inputfile >> machineName >> portName;
261 if( inputfile.eof() )
break;
262 std::cerr << machineName <<
" " << portName <<
std::endl;
263 listName_tmp.Add(
new TNamed( machineName.c_str(),
264 portName.c_str() ) );
267 std::cerr << listName_tmp.GetSize() <<
std::endl;
268 if( PingNames.GetSize() == 0 && option.Contains(
"+") ){
269 for( Int_t i = 0; i < listName_tmp.GetSize(); i++)
270 PingNames.Add( listName_tmp.At(i) );
271 listName_tmp.Clear(
"nodelete");
273 else if( option.Contains(
"+") ){
274 for( Int_t i = 0; i<listName_tmp.GetSize(); i++){
276 for( Int_t j = 0; j<PingNames.GetSize(); j++){
277 if(std::string(PingNames.At(j)->GetName()) ==
278 std::string(listName_tmp.At(i)->GetName()) &&
279 std::string(PingNames.At(j)->GetTitle()) ==
280 std::string(listName_tmp.At(i)->GetTitle()) ) test_is =
true;
282 if( test_is ==
false ) PingNames.Add(listName_tmp.At(i));
284 listName_tmp.Clear(
"nodelete");
287 if( option.Contains(
"-") ){
288 for( Int_t i = 0; i<listName_tmp.GetSize(); i++ ){
290 for( Int_t j = 0; j<PingNames.GetSize(); j++){
291 if(std::string(PingNames.At(j)->GetName()) ==
292 std::string(listName_tmp.At(i)->GetName()) &&
293 std::string(PingNames.At(j)->GetTitle()) ==
294 std::string(listName_tmp.At(i)->GetTitle()) ){
296 tmp_name = (TNamed*)PingNames.At(j);
299 if( test_is ==
true ){
300 PingNames.Remove(tmp_name);
304 listName_tmp.Clear(
"delete");
308 for( Int_t ii = 0; ii < PingNames.GetSize(); ii++ ){
309 std::cerr << PingNames.At(ii)->GetName() <<
" " << PingNames.At(ii)->GetTitle() <<
std::endl;}
315 void Ping( UInt_t nbtimes = 5,
bool dodump =
false)
317 TIter next(&PingNames);
319 while ( (obj = next()) ) {
321 TString option = obj->GetTitle(), ifdump;
322 cout <<
"Ping on : " << obj->GetName() <<
" with Port # " << obj->GetTitle() <<
endl;
324 TSocket *fSocket =
new TSocket(obj->GetName(),option.Atoi());
326 if ( fSocket->IsValid() ) {
328 cout <<
"Select with 1 millisecond " <<
endl;
329 for (UInt_t i = 0u; i < nbtimes; i++) {
330 cout <<
" - try # " << i <<
endl;
331 ifdump = Form(
"%s_%s_%d",obj->GetName(),obj->GetTitle(),i);
333 switch ( fSocket->Select(TSocket::kRead,1000) )
336 cout <<
"--> timeout " <<
endl;
339 cout <<
"--> Error " <<
endl;
342 fSocket->RecvRaw(&bsize,
sizeof(Int_t));
343 cout <<
" Size expected " << bsize <<
endl;
344 ret = fSocket->RecvRaw(buffer, bsize);
345 cout <<
" Size received " << ret <<
endl;
347 ofstream file(ifdump.Data(),ios_base::app);
349 file.write(buffer,bsize);
355 else cout <<
" *** Invalid connection *** " <<
endl;
357 else cout <<
" *** Invalid connection *** " <<
endl;
362 void Ping(
const char *machine, UInt_t port, UInt_t nbtimes = 5, Option_t *opt =
"")
364 TString option = opt, sport = Form(
"%d",port);
366 TNamed * tmp_name = NULL;
368 if ( option.Contains(
"+") ) {
370 for( Int_t i = 0; i < PingNames.GetSize(); i++ )
371 if( std::string(PingNames.At(i)->GetName()) == std::string(machine) &&
372 std::string(PingNames.At(i)->GetTitle()) == std::string(sport) ) test_is =
true;
373 if( test_is ==
false )
374 PingNames.Add (
new TNamed(machine,sport.Data()) );
376 if ( option.Contains(
"-") ){
378 for( Int_t i = 0; i < PingNames.GetSize(); i++ )
379 if( std::string(PingNames.At(i)->GetName()) == std::string(machine) &&
380 std::string(PingNames.At(i)->GetTitle()) == std::string(sport) ) {
382 tmp_name = (TNamed*)PingNames.At(i);
384 if ( test_is ==
true ) {
385 PingNames.Remove(tmp_name);
396 void SSHPing( UInt_t nbtimes = 1,
bool dodump =
false)
402 TNamed *obj =
new TNamed(
"localhost",
"10001");
404 TString option = obj->GetTitle(), ifdump;
405 cout <<
"Ping on : " << obj->GetName() <<
" with Port # " << obj->GetTitle() <<
endl;
408 TSocket *fSocket =
new TSocket(obj->GetName(),option.Atoi());
410 if ( fSocket->IsValid() ) {
412 cout <<
"Select with 1 millisecond " <<
endl;
413 for (UInt_t i = 0u; i < nbtimes; i++) {
414 cout <<
" - try # " << i <<
endl;
415 ifdump = Form(
"%s_%s_%d",obj->GetName(),obj->GetTitle(),i);
417 switch ( fSocket->Select(TSocket::kRead,1000) )
420 cout <<
"--> timeout " <<
endl;
423 cout <<
"--> Error " <<
endl;
426 fSocket->RecvRaw(&bsize,
sizeof(Int_t));
427 cout <<
" Size expected " << bsize <<
endl;
428 ret = fSocket->RecvRaw(buffer, bsize);
429 cout <<
" Size received " << ret <<
endl;
431 ofstream file(ifdump.Data(),ios_base::app);
433 file.write(buffer,bsize);
439 else cout <<
" *** Invalid connection *** " <<
endl;
441 else cout <<
" *** Invalid connection *** " <<
endl;
453 gSystem->Exec(
"rm -rf DefaultWatchers/*_C.so DefaultWatchers/*_C.d DefaultWatchers/*.o ./*_C.so ./*_C.d ./*.o");
454 gSystem->Exec(
"rm -rf MyWatchers/*_C.so MyWatchers/*_C.d MyWatchers/*.o ./*_C.so ./*_C.d ./*.o");
void GetListOfBadDirPatternFromOption(TList *, std::string)
void Ping(UInt_t nbtimes=5, bool dodump=false)
function to check if a watcher connexion is possible with an actor
bool IsAGoodFile(TList *listOfBadPattern, const char *)
void SSHPing(UInt_t nbtimes=1, bool dodump=false)
function to check if a watcher connexion is possible with an actor
void MakeRootAFPConfFile(const char *directory, const char *pat="*.adf", Option_t *opt="")
function to construct a RootAFP.conf file
void LoadPing(const char *filename, Option_t *opt="+")
Load list of server to ping from a file.
void GetListOfBadFilePatternFromOption(TList *, std::string)
bool IsAGoodDir(TList *listBadDir, TList *listBadPattern, const char *)
ADF::LogMessage & endl(ADF::LogMessage &log)
void GetListOfBadDirFromOption(TList *, std::string)