StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Ls.C
1 // $Id: Ls.C,v 3.2 2009/03/27 19:06:15 fine Exp $
2 // Author: Valeri Fine (fine@bnl.gov) 27.03.2009
3 
5 // if its name match the /a pattern,
6 // where /a pattern can be either the TRegexp or "wildcard" as
7 // the parameter /a wildcard defines
8 //
9 // Example: to print all histograms with the names
10 // ======= those contain the "hpy" substring
11 // type: Ls("hpy");
12 
13 #ifndef __CINT__
14 # include "TDirectory.h"
15 # include "StFileIter.h"
16 # include "TRegexp.h"
17 # include "TKey.h"
18 #endif
19 int Ls(TDirectory *dir, const char *pattern="*", Bool_t wildcard=kTRUE)
20 {
21  int counter = 0;
22  if (!dir) dir = gDirectory;
23  if (dir) {
24  StFileIter iter(dir);
25  TRegexp cmp(pattern,wildcard);
26  TKey *key = 0;
27  Ssiz_t len=0;
28  while (key = iter.NextEventKey()) {
29  const char *name = key->GetName();
30  Ssiz_t test = cmp.Index(name,&len);
31  if ((test>=0) && len) {
32  Printf("- %s class: %s", name, key->GetClassName());
33  counter++;
34  }
35  }
36  Printf(" ------------");
37  Printf(" %d object%s ha%s been found", counter
38  , ((counter>1) ? "s" : "")
39  , ((counter>1) ? "ve": "s")
40  );
41  }
42  return counter;
43 }
44 
46 // if its name match the /a pattern.
47 // where /a pattern can be either the TRegexp or "wildcard" as
48 // the parameter /a wildcard defines
49 //
50 int Ls(const char *pattern="*", Bool_t wildcard=kTRUE)
51 {
52  return Ls(gDirectory,pattern, wildcard);
53 }