ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FGolf/Tools/getMyHistosNames.C
(Generate patch)

Comparing UserCode/FGolf/Tools/getMyHistosNames.C (file contents):
Revision 1.2 by fgolf, Fri Sep 3 23:16:17 2010 UTC vs.
Revision 1.3 by fgolf, Tue Sep 7 22:18:44 2010 UTC

# Line 32 | Line 32
32   // Added feature to skip 2D histograms
33   //--------------------------------------------------------
34  
35 < TObjArray* getMyHistosNames( const char* prefix, const char* postfix, bool keep2D) {
35 > TObjArray* getMyHistosNames (const char* prefix, const char* postfix, bool keep2D)
36 > {
37 >         TObjArray* array = new TObjArray();
38 >         bool skip2D      = !keep2D;
39 >
40 >         // Get a list of object and their iterator
41 >         TList* list     = gDirectory->GetList() ;
42 >         TIterator* iter = list->MakeIterator();
43 >
44 >         // Loop over objects
45 >         TObject* obj;
46 >         while ((obj = iter->Next()))
47 >         {
48 >                  // Only look at objects beginning with 'prefix' and ending with 'postfix'
49 >                  TString name = obj->GetName();
50 >                  if (name.BeginsWith(prefix) && name.EndsWith(postfix))
51 >                  {
52 >                           if (skip2D && obj->IsA()->InheritsFrom(TH2::Class()))
53 >                                        continue;
54 >
55 >                           // Only look at objects that inherit from TH1 or TH2
56 >                           if (obj->IsA()->InheritsFrom(TH1::Class()) || obj->IsA()->InheritsFrom(TH2::Class()))
57 >                           {
58 >                                        // Find the central key, ie, the YY
59 >                                        TObjArray* t = name.Tokenize("_");
60 >                                        TString z = TString(t->At(1)->GetName());
61 >                                        if (t->GetEntries() == 4)
62 >                                                 z = TString(Form("%s_%s", t->At(1)->GetName(), t->At(2)->GetName()));
63 >
64 >                                        // add to the output array
65 >                                        TObjString* zobj = new TObjString(z);
66 >                                        array->Add(zobj);
67 >                           }
68 >                  }
69 >         }
70  
71 <
38 <  TObjArray* array = new TObjArray();
39 <  bool skip2D = !keep2D;
40 <
41 <  // Get a list of object and their iterator
42 <  TList* list = gDirectory->GetList() ;
43 <  TIterator* iter = list->MakeIterator();
44 <
45 <  // Loop over objects
46 <  TObject* obj;
47 <  while((obj=iter->Next())) {
48 <
49 <    // Only look at objects beginning with 'prefix' and ending with 'postfix'
50 <    TString name = obj->GetName();
51 <    if (name.BeginsWith(prefix) && name.EndsWith(postfix)) {
52 <      
53 <      if (skip2D && obj->IsA()->InheritsFrom(TH2::Class())) continue;
54 <
55 <      // Only look at objects that inherit from TH1 or TH2
56 <      if (obj->IsA()->InheritsFrom(TH1::Class()) ||
57 <          obj->IsA()->InheritsFrom(TH2::Class())) {
58 <
59 <        // Find the central key, ie, the YY
60 <        TObjArray* t = name.Tokenize("_");
61 <        TString z = TString(t->At(1)->GetName());
62 <        if (t->GetEntries() == 4){
63 <          z = TString(Form("%s_%s",t->At(1)->GetName(),t->At(2)->GetName()));
64 <        }
65 <        // cout << t->At(1)->GetName() << endl;
66 <        
67 <        // add to the output array
68 <        TObjString* zobj = new TObjString(z);
69 <        array->Add(zobj);
70 <
71 <      }
72 <    }
73 <  }
74 <
75 <  return array;
71 >         return array;
72   }
73  
74   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines