Other api/dybtest

Table Of Contents

Previous topic


Next topic


This Page

Daya Bay Links

Content Skeleton



This provides the connector between the the Run machinery in run.py and histo comparisons in cfroot.py

Simply adding a histref argument

Run("nuwa.py ...." , histref="path/to/myhistname.root" )

with value that points to a .root file containing the histograms, switches on the comparison of histograms with reference.

Created histograms become the “blessed” reference when the above is invoked and the reference path does not exist : path/to/histref_myhistname.root

Thus to bless the current hists simply delete the reference and rerun.

NB splitting up the time consuming steps and the histo creators is perfectly acceptable, as is use of python scripts or root .C histo creators (although using python modules with nuwa.py is recommended), eg:

def test_time_consuming_creation():
    Run("nuwa.py ..... ")

def test_quick_nuwa_ana():
    Run("nuwa.py ..."  , histref="histos1.root" )
def test_quick_py_ana():
    Run("python blah.py", histref="histos2.root" )
def test_quick_root_ana():
    Run("root -b -q maker.C ", histref="histos3.root" )


Usage examples:

cfr = CfRoot(['ex1.root','ex2.root','ex3.root'], ['TH1F','TH2F'] )
rcr = cfr()       ## compare all correspondings hists between the files
if rcr == 0:print "consistent"   
print cfr

Compare the last hist between the files, by accessing a list of keys:

cfh = CfHist(cfr[-1])
rch = cfh()
if rch == 0:print "consistent"   
print cfh
class dybtest.cfroot.CfHist(keys)[source]

Facilitate comparisons between multiple histograms specified by lists of keys. Consistency is assessed by roots KolmogorovTest with fixed cut of 0.9. To change that:

from dybtest.cfroot import CfHist
CfHist.kolmogorov_cut = 0.95
class dybtest.cfroot.CfRoot(paths, cls)[source]

Facilitate comparisons between multiple root files by holding KeyList’s into each of them, allowing list access to corresponding objects from all the files

Usage examples:

cf = CfRoot(['ex1.root','ex2.root','ex3.root'], ['TH1F','TH2F'] )
rc = cf()
print cf

for i in len(cf):
    cfi = cf[i]
class dybtest.cfroot.KeyList(path, cls)[source]

Recursive walk the TDirectory structure inside a single TFile providing list access to all keys that hold instances of classes within the cls list or all classes if cls is an empty list

Usage examples:

kl = KeyList( "path/to/histos.root" , ['TH1F', 'TH2F'] )
print len(kl)
for k in kl:
    print k
print kl[0], kl[-1]
provides filename, directory within the file and key name::
[‘ex2.root’, ‘red/aa/bb/cc’, ‘h2’, ‘TH1F’ ]

skip the file name


for gbl.cout/gbl.stringstream to be available/usable from python observe that must kickstart ROOT for example with “from ROOT import TObject” prior to “from GaudiPython import gbl”

When GaudiPython comes first get:

AttributeError: class _global_cpp has no attribute 'cout'
class dybtest.capture.Capture(arg='')[source]

Bases: object

Allows capturing of logging output in a generic way, allowing tests to be made on the logging output. This can be a shortcut way of testing as functionality can be tested without exposing underlying classes to python.

Usage example:

from dybtest import Capture

def test_dbimaketimestamp():
    c = Capture("capture Dbi.MakeTimeStamp ... " )
    t = Dbi.MakeTimeStamp("")
    t = Dbi.MakeTimeStamp("")
    assert str(c).find("Bad date string") > -1

Redirect cout into contained stringstream