ATLAS Offline Software
Functions | Variables
chains.cxx File Reference
#include <iostream>
#include <string>
#include "TFile.h"
#include "TDirectory.h"
#include "TList.h"
#include "TKey.h"
#include "TH1D.h"
Include dependency graph for chains.cxx:

Go to the source code of this file.

Functions

void descend (TDirectory *d, int level, int maxdepth, const std::vector< std::string > &labels)
 
int usage (std::ostream &s, int argc, char **argv)
 
int main (int argc, char **argv)
 
double hsum (TH1 *h)
 sum the bin contents including the over and underflow bins More...
 

Variables

bool verbose = false
 very lazy!!! should not use unnessecary global variables !!!! More...
 
bool always_descend = false
 
std::string histogram = ""
 
bool fast = false
 

Detailed Description

Author
mark sutton
Date
Fri 11 Jan 2019 07:41:26 CET

Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration

Definition in file chains.cxx.

Function Documentation

◆ descend()

void descend ( TDirectory *  d,
int  level,
int  maxdepth,
const std::vector< std::string > &  labels 
)

Definition at line 107 of file chains.cxx.

107  {
108 
109  if ( verbose ) std::cout << "level " << level << "\tmaxdepth " << maxdepth << std::endl;
110 
111  if ( d==0 ) return;
112 
113  TList* tl = d->GetListOfKeys();
114 
115  if ( verbose ) std::cout << "list of keys " << tl << " " << ( tl ? tl->Capacity() : 0 ) << std::endl;
116 
117  if ( tl==0 ) return;
118 
119  std::string name = d->GetName();
120 
121  int plevel = level;
122 
123  if ( !verbose ) if ( plevel>0 ) plevel--;
124 
125  for ( int ip=plevel ; ip-- ; ) std::cout << "\t";
126 
127  bool displayed = false;
128 
129  int dsize = 0;
130 
131  if ( verbose ) std::cout << "Directory: ";
132  if ( verbose || level>0 ) {
133  std::cout<< name;
134  displayed = true;
135  dsize = name.size();
136  if ( dsize<60 ) std::cout << "\t";
137  }
138 
139  // struct timeval tv = simpletimer_start();
140 
141  if ( verbose ) std::cout << "level " << level << "\tmaxdepth " << maxdepth << std::endl;
142 
143  for ( int i=tl->GetSize() ; i-- ; ) {
144 
145  TKey* tobj = (TKey*)tl->At(i);
146 
147  if ( tobj==0 ) continue;
148 
149 
150  // for ( int ip=level+1 ; ip-- ; ) std::cout << "\t";
151  // std::cout << "tobj " << tobj << " : \t" << tobj->GetName() << std::endl;
152 
153  if ( std::string(tobj->GetClassName()).find("TDirectory")!=std::string::npos ) {
154  // std::cout << ns << "Directory " << tobj->GetName() << std::endl;
155  TDirectory* tnd = (TDirectory*)tobj->ReadObj();
156 
157  if ( tnd==0 ) continue;
158 
159  std::string dname = tnd->GetName();
160 
161 
162  // if ( dname.find("L2_")!=std::string::npos ||
163  // dname.find("EF_")!=std::string::npos ||
164  // dname.find("HLT_")!=std::string::npos )
165  if ( level<maxdepth ) {
166  bool dscnd = true;
167  if ( !always_descend && labels.size() ) {
168  dscnd = false;
169  for ( unsigned il=labels.size() ; il-- ; ) {
170  if ( dname.find(labels[il])!=std::string::npos) dscnd = true;
171  }
172  }
173  if ( dscnd ) descend( tnd, level+1, maxdepth, labels );
174  }
175  }
176  else {
177  if ( histogram != "" ){
178  if ( std::string(tobj->GetClassName()).find("TH1")!=std::string::npos ||
179  // std::string(tobj->GetClassName()).find("TH2")!=std::string::npos ||
180  std::string(tobj->GetClassName()).find("TProfile")!=std::string::npos ) {
181 
182  TH1* th = (TH1*)tobj->ReadObj();
183 
184  if ( th && std::string(th->GetName()) == histogram ) {
185 
186  double d = hsum( th );
187 
188  std::cout << "\t" << d << std::endl;
189 
190  displayed = false;
191 
192  }
193  }
194  }
195  }
196  }
197  if ( displayed ) std::cout << std::endl;
198 }

◆ hsum()

double hsum ( TH1 *  h)

sum the bin contents including the over and underflow bins

Definition at line 101 of file chains.cxx.

101  {
102  double d=0;
103  for ( int i=0 ; i<=h->GetNbinsX()+1 ; i++ ) d += h->GetBinContent(i);
104  return d;
105 }

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 55 of file chains.cxx.

55  {
56 
57  std::vector<std::string> args;
58 
59  int maxdepth = 2;
60 
61 
62  for ( int i=1 ; i<argc ; i++ ) {
63  std::string arg = argv[i];
64  if ( arg=="-h" || arg=="--help" ) return usage( std::cout, argc, argv );
65  else if ( arg=="-v" || arg=="--verbose" ) verbose = true;
66  else if ( arg=="-f" || arg=="--fast" ) fast = true;
67  else if ( arg=="-a" || arg=="--always" ) always_descend = true;
68  else if ( arg=="-d" || arg=="--depth" ) {
69  if ( ++i<argc ) maxdepth = std::atoi(argv[i]);
70  else return usage( std::cout, argc, argv );
71  }
72  else if ( arg=="-c" || arg=="--contents" ) {
73  if ( ++i<argc ) histogram = argv[i];
74  else return usage( std::cout, argc, argv );
75  }
76 
77  else args.push_back(arg);
78  }
79 
80  std::vector<std::string> labels;
81  labels.push_back("L2_");
82  labels.push_back("EF_");
83  labels.push_back("HLT_");
84 
85  for ( unsigned i=0 ; i<args.size() ; i++ ) {
86  TFile f( args[i].c_str() );
87 
88  if ( !f.IsOpen() || f.IsZombie() ) {
89  std::cerr << "Error: could not open input file: " << args[i] << std::endl;
90  std::exit(1);
91  }
92 
93  // gDirectory->ls();
95  }
96 
97  return 0;
98 }

◆ usage()

int usage ( std::ostream &  s,
int  argc,
char **  argv 
)

should never be the case

Definition at line 29 of file chains.cxx.

29  {
30  if ( argc<1 ) return -1;
31  s << "Usage: " << argv[0] << " [OPTIONS] <file1> <file2> ... \n\n";
32  s << " writes names of chains from files\n\n";
33  s << "Options: \n";
34  s << " -a, --always \t always descend, \n";
35  s << " -d, --depth maxdepth \t maximum depth to descend, \n";
36  s << " -c, --contents histogram \t display number of entries in histogram, \n";
37  s << " -f, --fast \t bomb out as soon as a single chain has been found, \n";
38  s << " -v, --verbose \t verbose output, \n";
39  s << " -h, --help \t this help,\n";
40  // s << "\nSee " << PACKAGE_URL << " for more details\n";
41  // s << "\nReport bugs to <" << PACKAGE_BUGREPORT << ">";
42  s << std::endl;
43  return 0;
44 }

Variable Documentation

◆ always_descend

bool always_descend = false

Definition at line 51 of file chains.cxx.

◆ fast

bool fast = false

Definition at line 53 of file chains.cxx.

◆ histogram

std::string histogram = ""

Definition at line 52 of file chains.cxx.

◆ verbose

bool verbose = false

very lazy!!! should not use unnessecary global variables !!!!

Definition at line 50 of file chains.cxx.

PlotCalibFromCool.il
il
Definition: PlotCalibFromCool.py:381
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
hist_file_dump.d
d
Definition: hist_file_dump.py:137
hsum
double hsum(TH1 *h)
sum the bin contents including the over and underflow bins
Definition: chains.cxx:101
descend
void descend(TDirectory *d, int level, int maxdepth, const std::vector< std::string > &labels)
Definition: chains.cxx:107
maxdepth
int maxdepth
Definition: listroot.cxx:202
verbose
bool verbose
very lazy!!! should not use unnessecary global variables !!!!
Definition: chains.cxx:50
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
beamspotnt.labels
list labels
Definition: bin/beamspotnt.py:1447
python.TriggerHandler.th
th
Definition: TriggerHandler.py:296
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
hist_file_dump.f
f
Definition: hist_file_dump.py:135
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
calibdata.exit
exit
Definition: calibdata.py:236
fast
bool fast
Definition: chains.cxx:53
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
usage
int usage(std::ostream &s, int argc, char **argv)
Definition: chains.cxx:29
h
dq_defect_create_virtual_defects.dname
dname
Definition: dq_defect_create_virtual_defects.py:71
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
always_descend
bool always_descend
Definition: chains.cxx:51
dqt_zlumi_alleff_HIST.tl
tl
Definition: dqt_zlumi_alleff_HIST.py:73
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
histogram
std::string histogram
Definition: chains.cxx:52