alphatwirl

AlphaTwirl is a python library that loops over event data and summarizes them into multi-dimensional categorical data as data frames. Event data, input to AlphaTwirl, are data with one entry (or row) for one event: for example, data in ROOT TTrees with one entry per collision event of an LHC experiment at CERN. Event data are often large—too large to be loaded in memory—because they have as many entries as events. Multi-dimensional categorical data, the output of AlphaTwirl, have one row for one category. They are usually small—small enough to be loaded in memory—because they only have as many rows as categories. Users can, for example, import them as data frames into R and pandas, which usually load all data in memory, and can perform categorical data analyses with a rich set of data operations available in R and pandas.

Contents:

alphatwirl package

Subpackages

alphatwirl.binning package

Submodules

alphatwirl.binning.Binning module

class alphatwirl.binning.Binning.Binning(boundaries=None, lows=None, ups=None, retvalue='lowedge', bins=None, underflow_bin=None, overflow_bin=None, valid=ReturnTrue())[source]

Bases: object

next(bin)[source]

alphatwirl.binning.Combine module

class alphatwirl.binning.Combine.Combine(low, high, at)[source]

Bases: object

A combine two binnings.

This class uses low for the values below at and otherwise uses high.

This class requires bin labels of both binnings to be values in the bins.

next(bin)[source]

alphatwirl.binning.Echo module

class alphatwirl.binning.Echo.PlusOne[source]

Bases: object

class alphatwirl.binning.Echo.Echo(nextFunc=PlusOne(), valid=ReturnTrue())[source]

Bases: object

next(bin)[source]

alphatwirl.binning.ReturnTrue module

class alphatwirl.binning.ReturnTrue.ReturnTrue[source]

Bases: object

alphatwirl.binning.Round module

class alphatwirl.binning.Round.Round(width=1, aboundary=None, min=None, underflow_bin=None, max=None, overflow_bin=None, valid=ReturnTrue())[source]

Bases: object

next(bin)[source]

alphatwirl.binning.RoundLog module

class alphatwirl.binning.RoundLog.RoundLog(width=0.1, aboundary=1, min=None, underflow_bin=None, max=None, overflow_bin=None, valid=ReturnTrue())[source]

Bases: object

next(bin)[source]

Module contents

alphatwirl.cmsedm package

Submodules

alphatwirl.cmsedm.CMSEDMEventBuilder module

class alphatwirl.cmsedm.CMSEDMEventBuilder.CMSEDMEventBuilder(config)[source]

Bases: object

alphatwirl.cmsedm.CMSEDMEvents module

class alphatwirl.cmsedm.CMSEDMEvents.CMSEDMEvents(paths, maxEvents=-1, start=0)[source]

Bases: object

alphatwirl.cmsedm.EventBuilderConfig module

class alphatwirl.cmsedm.EventBuilderConfig.EventBuilderConfig(inputPaths, maxEvents, start, dataset, name)

Bases: tuple

dataset

Alias for field number 3

inputPaths

Alias for field number 0

maxEvents

Alias for field number 1

name

Alias for field number 4

start

Alias for field number 2

alphatwirl.cmsedm.EventBuilderConfigMaker module

class alphatwirl.cmsedm.EventBuilderConfigMaker.EventBuilderConfigMaker[source]

Bases: object

create_config_for(dataset, files, start, length)[source]
file_list_in(dataset, maxFiles)[source]
nevents_in_file(path)[source]

alphatwirl.cmsedm.load_fwlite module

alphatwirl.cmsedm.load_fwlite.load_fwlite()[source]

Module contents

alphatwirl.collector package

Submodules

alphatwirl.collector.ToDataFrame module

class alphatwirl.collector.ToDataFrame.ToDataFrame(summaryColumnNames)[source]

Bases: object

combine(dataset_readers_list)[source]

alphatwirl.collector.ToDataFrameWithDatasetColumn module

class alphatwirl.collector.ToDataFrameWithDatasetColumn.ToDataFrameWithDatasetColumn(summaryColumnNames, datasetColumnName='component')[source]

Bases: object

combine(dataset_readers_list)[source]

alphatwirl.collector.ToTupleList module

class alphatwirl.collector.ToTupleList.ToTupleList(summaryColumnNames)[source]

Bases: object

combine(dataset_readers_list)[source]

alphatwirl.collector.ToTupleListWithDatasetColumn module

class alphatwirl.collector.ToTupleListWithDatasetColumn.ToTupleListWithDatasetColumn(summaryColumnNames, datasetColumnName='component')[source]

Bases: object

combine(dataset_readers_list)[source]

alphatwirl.collector.WriteListToFile module

class alphatwirl.collector.WriteListToFile.WriteListToFile(outPath)[source]

Bases: object

deliver(results)[source]

alphatwirl.collector.WritePandasDataFrameToFile module

class alphatwirl.collector.WritePandasDataFrameToFile.WritePandasDataFrameToFile(outPath)[source]

Bases: object

deliver(results)[source]

Module contents

alphatwirl.concurrently package

Submodules

alphatwirl.concurrently.CommunicationChannel module

class alphatwirl.concurrently.CommunicationChannel.CommunicationChannel(dropbox)[source]

Bases: object

A communication channel with workers in other processes.

(This docstring is outdated.)

You can send tasks to workers through this channel. The workers, running in other processes, execute the tasks in the background. You can receive the results of the tasks also through this channel.

An instance of this class can be created with two optional arguments: nprocesses, the number of workers to be created, and progressMonitor:

progressBar = ProgressBar()
progressMonitor = BProgressMonitor(progressBar)
channel = CommunicationChannel(nprocesses=10, progressMonitor=progressMonitor)

Workers will be created when begin() is called:

channel.begin()

In begin(), this class gives each worker a progressReporter, which is created by the progressMonitor.

Now, you are ready to send a task. A task is a function or any object which is callable and picklable. A task can take any number of arguments. If a task takes a named argument progressReporter, the worker will give the progressReporter to the task. A value that a task returns is the result of the task and must be picklable. For example, an instance of EventLoop can be a task. You can send a task with the method put:

channel.put(task1, 10, 20, A=30)

Here, 10, 20, A=30 are the arguments to the task.

This class sends the task to a worker. The worker which receives the task will first try to call the task with the progressReporter in addition to the arguments. If the task doesn’t take the progressReporter, it calls only with the arguments.

You can send multiple tasks:

channel.put(task2)
channel.put(task3, 100, 200)
channel.put(task4, A='abc')
channel.put(task5)

They will be executed by workers.

You can receive the results of the tasks with the method receive():

results = channel.receive()

This method will wait until all tasks are finished. If a task gives a progressReport to the progressReporter, the report will be used, for example, to update progress bars on the screen.

When all tasks end, results will be returned. The return value results is a list of results of the tasks. They are sorted in the order in which the tasks are originally put.

After receiving the results, you can put more tasks:

channel.put(task6)
channel.put(task7)

And you can receive the results of them:

results = channel.receive()

If there are no more tasks to be done, you should call the method end:

channel.end()

This will end all background processes.

begin()[source]
put(task, *args, **kwargs)[source]
receive()[source]
terminate()[source]
end()[source]

alphatwirl.concurrently.CommunicationChannel0 module

class alphatwirl.concurrently.CommunicationChannel0.CommunicationChannel0(progressMonitor=None)[source]

Bases: object

A communication channel for the single process mode

An alternative to CommunicationChannel. However, unlike CommunicationChannel, this class does not send tasks to workers. Instead, it directly executes tasks.

This class has the same interface as the class CommunicationChannel. When this class is used as a substitute for CommunicationChannel, the tasks will be sequentially executed in the foreground.

begin()[source]
put(task, *args, **kwargs)[source]
receive()[source]
terminate()[source]
end()[source]

alphatwirl.concurrently.HTCondorJobSubmitter module

class alphatwirl.concurrently.HTCondorJobSubmitter.HTCondorJobSubmitter(job_desc_extra=[])[source]

Bases: object

run(workingArea, package_index)[source]
poll()[source]

check if the jobs are running and return a list of cluster IDs for finished jobs

wait()[source]

wait until all jobs finish and return a list of cluster IDs

failed_runids(runids)[source]
terminate()[source]
alphatwirl.concurrently.HTCondorJobSubmitter.try_executing_until_succeed(procargs)[source]
alphatwirl.concurrently.HTCondorJobSubmitter.query_status_for(ids)[source]
alphatwirl.concurrently.HTCondorJobSubmitter.change_job_priority(ids, priority=10)[source]
alphatwirl.concurrently.HTCondorJobSubmitter.sample_ids(n=-1)[source]

alphatwirl.concurrently.MultiprocessingDropbox module

class alphatwirl.concurrently.MultiprocessingDropbox.MultiprocessingDropbox(nprocesses=16, progressMonitor=None)[source]

Bases: object

open()[source]
put(package)[source]
receive()[source]
terminate()[source]
close()[source]

alphatwirl.concurrently.SubprocessRunner module

class alphatwirl.concurrently.SubprocessRunner.SubprocessRunner(pipe=False)[source]

Bases: object

run(workingArea, package_index)[source]
poll()[source]

check if the jobs are running and return a list of pids for finished jobs

wait()[source]

wait until all jobs finish and return a list of pids

failed_runids(runids)[source]
terminate()[source]

alphatwirl.concurrently.TaskPackage module

class alphatwirl.concurrently.TaskPackage.TaskPackage(task, args, kwargs)

Bases: tuple

args

Alias for field number 1

kwargs

Alias for field number 2

task

Alias for field number 0

alphatwirl.concurrently.TaskPackageDropbox module

class alphatwirl.concurrently.TaskPackageDropbox.TaskPackageDropbox(workingArea, dispatcher, sleep=5)[source]

Bases: object

A drop box for task packages.

It puts task packages in a working area and dispatches runners that execute the tasks.

open()[source]
put(package)[source]
receive()[source]
terminate()[source]
close()[source]

alphatwirl.concurrently.Worker module

class alphatwirl.concurrently.Worker.Worker(task_queue, result_queue, lock, progressReporter)[source]

Bases: multiprocessing.process.Process

run()[source]

alphatwirl.concurrently.WorkingArea module

class alphatwirl.concurrently.WorkingArea.WorkingArea(dir, python_modules)[source]

Bases: object

Args: dir (str): a path to a directory in which a new directory will be created

open()[source]
put_package(package)[source]
package_path(package_index)[source]
collect_result(package_index)[source]
close()[source]

alphatwirl.concurrently.example_load module

alphatwirl.concurrently.example_load_result module

alphatwirl.concurrently.example_submit_htcondor module

alphatwirl.concurrently.run module

Module contents

alphatwirl.configure package

Submodules

alphatwirl.configure.TableConfigCompleter module

class alphatwirl.configure.TableConfigCompleter.TableConfigCompleter(defaultSummaryClass=<class 'alphatwirl.summary.Count.Count'>, defaultWeight=WeightCalculatorOne(), defaultOutDir='.', createOutFileName=<alphatwirl.configure.TableFileNameComposer.TableFileNameComposer object>)[source]

Bases: object

an example complete config:

tblcfg = {
    'keyAttrNames': ('met_pt',),
    'binnings': (MockBinning(),),
    'keyIndices': None
    'valAttrNames' : None,
    'valIndices' : None,
    'keyOutColumnNames': ('met_pt',),
    'valOutColumnNames': ('n', 'nvar'),
    'weight': MockWeight(),
    'summaryClass': Count,
    'sort': True,
    'outFile': True,
    'outFileName': 'tbl_n_component_met_pt.txt',
    'outFilePath': '/tmp/tbl_n_component_met_pt.txt',
}
complete(tblcfg)[source]

alphatwirl.configure.TableFileNameComposer module

class alphatwirl.configure.TableFileNameComposer.TableFileNameComposer(default_prefix='tbl_n', default_suffix='txt', default_var_separator='.', default_idx_separator='-')[source]

Bases: object

Compose a name of a file to store the table from the column names
and indices.

For example, if column names are ‘var1’, ‘var2’, and ‘var3’ and indices are 1, None and 2, the file name will be ‘tbl_n_component.var1-1.var2.var3-2.txt’

alphatwirl.configure.build_counter_collector_pair module

alphatwirl.configure.build_counter_collector_pair.build_counter_collector_pair(tblcfg)[source]

alphatwirl.configure.build_progressMonitor_communicationChannel module

alphatwirl.configure.build_progressMonitor_communicationChannel.build_progressMonitor_communicationChannel(quiet, processes)[source]

Module contents

alphatwirl.delphes package

Submodules

alphatwirl.delphes.DelphesEventBuilder module

alphatwirl.delphes.DelphesEvents module

alphatwirl.delphes.EventBuilderConfig module

class alphatwirl.delphes.EventBuilderConfig.EventBuilderConfig(inputPaths, treeName, maxEvents, start, dataset, name)

Bases: tuple

dataset

Alias for field number 4

inputPaths

Alias for field number 0

maxEvents

Alias for field number 2

name

Alias for field number 5

start

Alias for field number 3

treeName

Alias for field number 1

alphatwirl.delphes.EventBuilderConfigMaker module

alphatwirl.delphes.TClonesArrayWrap module

class alphatwirl.delphes.TClonesArrayWrap.TClonesArrayWrap(tclonesarray)[source]

Bases: _abcoll.Sequence

wrap TClonesArray for fast access”

(under development. not used)

alphatwirl.delphes.load_delphes module

alphatwirl.delphes.load_delphes.load_delphes()[source]

Module contents

alphatwirl.heppyresult package

Submodules

alphatwirl.heppyresult.Analyzer module

class alphatwirl.heppyresult.Analyzer.Analyzer(path)[source]

Bases: object

alphatwirl.heppyresult.Component module

class alphatwirl.heppyresult.Component.Component(path)[source]

Bases: object

analyzers()[source]
config()[source]

alphatwirl.heppyresult.ComponentLoop module

class alphatwirl.heppyresult.ComponentLoop.ComponentLoop(heppyResult, reader)[source]

Bases: object

alphatwirl.heppyresult.ComponentReaderComposite module

class alphatwirl.heppyresult.ComponentReaderComposite.ComponentReaderComposite[source]

Bases: object

add(reader)[source]
begin()[source]
read(component)[source]
end()[source]

alphatwirl.heppyresult.EventBuilder module

alphatwirl.heppyresult.EventBuilderConfig module

class alphatwirl.heppyresult.EventBuilderConfig.EventBuilderConfig(base, component)

Bases: tuple

base

Alias for field number 0

component

Alias for field number 1

alphatwirl.heppyresult.EventBuilderConfigMaker module

alphatwirl.heppyresult.HeppyResult module

class alphatwirl.heppyresult.HeppyResult.HeppyResult(path, componentNames=None, excludeList=['Chunks', 'failed'], componentHasTheseFiles=['config.pck', 'config.txt'], isComponent=None)[source]

Bases: object

A Heppy result

Parameters:
  • path (str) – the path to the Heppy result
  • componentNames (list, optional) – the list of the names of the components to read. If not given, all components except the ones listed in excludeList will be read.
  • excludeList (list, optional) – a list of the names of the directory in the Heppy result directory which are to be excluded to be considered as components. if not given, DEFAULT_EXCLUDE_LIST will be used.
  • componentHasTheseFiles (list, optional) – the directories with there files are considered as components. if not given, DEFAULT_COMPONENT_HAS_THESE_FILES will be used.
  • isComponent (function, optional) – a function that determines if a directory is a Heppy component. if not give, IsComponent will be used.
components()[source]
versionInfo()[source]
class alphatwirl.heppyresult.HeppyResult.IsComponent(excludeList, componentHasTheseFiles)[source]

Bases: object

alphatwirl.heppyresult.ReadComponentConfig module

class alphatwirl.heppyresult.ReadComponentConfig.ReadComponentConfig[source]

Bases: object

alphatwirl.heppyresult.ReadCounter module

class alphatwirl.heppyresult.ReadCounter.ReadCounter[source]

Bases: object

alphatwirl.heppyresult.ReadVersionInfo module

class alphatwirl.heppyresult.ReadVersionInfo.ReadVersionInfo[source]

Bases: object

alphatwirl.heppyresult.TblBranch module

alphatwirl.heppyresult.TblBrilCalc module

class alphatwirl.heppyresult.TblBrilCalc.TblBrilCalc(outPath, csvFileName='brilcalc.csv')[source]

Bases: object

This class reads brilcalc results in csv.

Parameters:
  • outPath (str) – a path to the output file
  • csvFileName (str) – the name of the CSV file with the brilcalc results
begin()[source]
read(component)[source]
end()[source]

alphatwirl.heppyresult.TblComponentConfig module

class alphatwirl.heppyresult.TblComponentConfig.TblComponentConfig(outPath, columnNames, keys)[source]

Bases: object

begin()[source]
read(component)[source]
end()[source]

alphatwirl.heppyresult.TblCounter module

class alphatwirl.heppyresult.TblCounter.TblCounter(analyzerName, fileName, outPath, levels=None, columnNames=None)[source]

Bases: object

This class reads counter files of HeppyResult.

Parameters:
  • analyzerName (str) – the name of the Heppy analyzer, e.g., skimAnalyzerCount
  • fileName (str) – the name of the counter file, e.g., SkimReport.txt
  • outPath (str) – a path to the output file
  • levels (list) – a list of the levels to read. If not given, all levels will be read
  • columnNames (list) – a list of the column names of the output file. If not given, the levels will be used
begin()[source]
read(component)[source]
end()[source]

alphatwirl.heppyresult.TblCounterLong module

class alphatwirl.heppyresult.TblCounterLong.TblCounterLong(analyzerName, fileName, outPath, levels=None, columnNames=('component', 'level', 'count'))[source]

Bases: object

An alternative class to TblCounter.

While TblCounter writes results in the wide format, this class writes results in the long format. Eventually, this class will replace TblCounter.

Parameters:
  • analyzerName (str) – the name of the Heppy analyzer, e.g., skimAnalyzerCount
  • fileName (str) – the name of the counter file, e.g., SkimReport.txt
  • outPath (str) – a path to the output file
  • levels (list) – a list of the levels to read. If not given, all levels will be read
  • columnNames (list) – a list of the column names of the output file. the default is (‘component’, ‘level’, ‘count’)
begin()[source]
read(component)[source]
end()[source]

alphatwirl.heppyresult.TblTree module

Module contents

alphatwirl.loop package

Submodules

alphatwirl.loop.Collector module

class alphatwirl.loop.Collector.Collector(resultsCombinationMethod, deliveryMethod=None)[source]

Bases: object

This class collects results, i.e., this class combines results of readers and deliver them.

Methods for combination and delivery are specified at the instantiation.

Readers are typically instances of the same class initialized in the same way. Each reader reads a data set..

The method collect is called with a list of pairs of a data set and a reader after the event loop. It returns the combined results.

collect(dataset_readers_list)[source]
class alphatwirl.loop.Collector.NullDeliveryMethod[source]

Bases: object

deliver(results)[source]

alphatwirl.loop.CollectorComposite module

class alphatwirl.loop.CollectorComposite.CollectorComposite(progressReporter=None)[source]

Bases: object

A composite of collectors.

This class is a composite in the composite pattern.

Examples of collectors are instances of Collector, NullCollector, and this class.

add(collector)[source]

add a collector

Parameters:collector – the collector to be added
collect(dataset_readers_list)[source]

collect results

Returns:a list of results

alphatwirl.loop.CollectorDelegate module

class alphatwirl.loop.CollectorDelegate.CollectorDelegate(collector)[source]

Bases: object

collect(dataset_readers_list)[source]

alphatwirl.loop.DatasetIntoEventBuildersSplitter module

class alphatwirl.loop.DatasetIntoEventBuildersSplitter.DatasetIntoEventBuildersSplitter(EventBuilder, eventBuilderConfigMaker, maxEvents=-1, maxEventsPerRun=-1, maxFiles=-1, maxFilesPerRun=1)[source]

Bases: object

alphatwirl.loop.EventLoop module

class alphatwirl.loop.EventLoop.EventLoop(build_events, reader)[source]

Bases: object

An event loop

alphatwirl.loop.EventLoopProgressReportWriter module

class alphatwirl.loop.EventLoopProgressReportWriter.EventLoopProgressReportWriter[source]

Bases: object

A progress report writer of an event loop

write(taskid, config, event)[source]

alphatwirl.loop.EventLoopRunner module

class alphatwirl.loop.EventLoopRunner.EventLoopRunner(progressMonitor=None)[source]

Bases: object

This class runs instances of EventLoop and keeps the results. It will return the results when end() is called.

begin()[source]
run(eventLoop)[source]
end()[source]

alphatwirl.loop.EventsInDatasetReader module

class alphatwirl.loop.EventsInDatasetReader.EventsInDatasetReader(eventLoopRunner, reader, collector, split_into_build_events)[source]

Bases: object

This class manages objects involved in reading events in data sets.

On receiving a data set, this class calls the function split_into_build_events(), which splits the data set into chunks, creates the function build_events() for each chunk, and returns a list of the functions. Then, for each build_events(), This class creates a copy of the reader, creates an event loop, and send it to the event loop runner.

At the end, this class receives results from the event loop runner and have the collector collect them.

begin()[source]
read(dataset)[source]
end()[source]

alphatwirl.loop.MPEventLoopRunner module

class alphatwirl.loop.MPEventLoopRunner.MPEventLoopRunner(communicationChannel)[source]

Bases: object

This class (concurrently) runs instances of EventLoop.

An instance of this class needs to be initialized with a communication channel with workers that actually run the EventLoop:

runner = MPEventLoopRunner(communicationChannel)

An example of a communication channel is an instance of CommunicationChannel.

The method begin() does nothing in the current version:

runner.begin()

In older versions, multiple processes are forked in this method.

Then, you can give an EventLoop with the method run():

runner.run(eventLoop1)

This class will send the EventLoop to a worker through the communication channel. The worker, then, runs the EventLoop.

You can call the method run() mutiple times:

runner.run(eventLoop2)
runner.run(eventLoop3)
runner.run(eventLoop4)

If workers are in the background, this method immediately returns. Worker are concurrently running the event loops in the background. If the worker is in the foreground, this method won’t return until the worker finishes running the event loop. Whether workers are in the background or foreground depends on the communication channel with which this class is initialized.

After giving all event loops that you need to run to this class, you need to call the method end():

results = runner.end()

If workers are in the background, this method will wait until workers finish running all event loops. If the worker is in the foreground, this method immediately returns. This method returns the results, the list of the values eventLoops return, sorted in the order given with run().

begin()[source]

does nothing.

Older versions of this class had implementations.

run(eventLoop)[source]

run the event loop in the background.

Parameters:eventLoop (EventLoop) – an event loop to run
end()[source]

wait until all event loops end and returns the results.

alphatwirl.loop.NullCollector module

class alphatwirl.loop.NullCollector.NullCollector[source]

Bases: object

collect(*_, **__)[source]

alphatwirl.loop.ReaderComposite module

class alphatwirl.loop.ReaderComposite.ReaderComposite[source]

Bases: object

A composite of event readers”

This class is a composite in the composite pattern.

Examples of event readers are instances of Summarizer and this class.

When event() is called, it calls event() of each reader in the order in which the readers are added. If a reader returns False, it won’t call the remaining readers.

add(reader)[source]
begin(event)[source]
event(event)[source]
end()[source]

alphatwirl.loop.splitfuncs module

alphatwirl.loop.splitfuncs.create_file_start_length_list(file_nevents_list, max_events_per_run=-1, max_events_total=-1, max_files_per_run=1)[source]

Module contents

alphatwirl.misc package

Submodules

alphatwirl.misc.listToAlignedText module

alphatwirl.misc.listToAlignedText.listToAlignedText(src, formatDict=None, leftAlignLastColumn=False)[source]

alphatwirl.misc.list_to_aligned_text module

alphatwirl.misc.list_to_aligned_text.list_to_aligned_text(src, format_dict=None, left_align_last_column=False)[source]

alphatwirl.misc.mkdir_p module

alphatwirl.misc.mkdir_p.mkdir_p(path)[source]

alphatwirl.misc.quote_string module

alphatwirl.misc.quote_string.quote_string(text)[source]

Module contents

alphatwirl.progressbar package

Submodules

alphatwirl.progressbar.BProgressMonitor module

class alphatwirl.progressbar.BProgressMonitor.BProgressMonitor(presentation)[source]

Bases: object

A progress monitor of tasks.

This class monitors the progress of tasks and present it.

Tasks can be concurrently executed. The progress can be presented in an arbitrary way specified at the initialization.

This class monitors the progress and present it in the background by using ProgressReportPickup.

In order for a progress to be monitored by this class, an object that executes a task needs to send the ProgressReport through the ProgressReporter created by this class.

Examples

A presentation method needs to be specified at the initialization. For example, to use ProgressBar:

presentation = ProgressBar()
monitor = BProgressMonitor(presentation)

After the initialization, start monitoring:

monitor.begin()

Then, create as many reporters (ProgressReporter) as the number of the tasks whose progresses need to be monitored:

reporter1 = monitor.createReporter()
reporter2 = monitor.createReporter()
reporter3 = monitor.createReporter()

These reporters can be given to objects which execute the tasks. These objects can be in other processes as long as the reporters are properly passed to them.

If a ProgressReport is given to these reporters:

reporter1.report(report)

the report will be received by ProgressReportPickup, which will use the report to present the progress in the way specified.

When all tasks are finished, end monitoring:

monitor.end()

This will ends ProgressReportPickup, which is running in a different process.

begin()[source]
end()[source]
createReporter()[source]

alphatwirl.progressbar.NullProgressMonitor module

class alphatwirl.progressbar.NullProgressMonitor.NullProgressMonitor[source]

Bases: object

createReporter()[source]
begin()[source]
end()[source]

alphatwirl.progressbar.ProgressBar module

class alphatwirl.progressbar.ProgressBar.ProgressBar[source]

Bases: object

nreports()[source]
present(report)[source]
createLine(report)[source]

alphatwirl.progressbar.ProgressMonitor module

class alphatwirl.progressbar.ProgressMonitor.Queue(presentation)[source]

Bases: object

put(report)[source]
class alphatwirl.progressbar.ProgressMonitor.ProgressMonitor(presentation)[source]

Bases: object

begin()[source]
end()[source]
createReporter()[source]

alphatwirl.progressbar.ProgressPrint module

class alphatwirl.progressbar.ProgressPrint.ProgressPrint[source]

Bases: object

nreports()[source]
present(report)[source]
createLine(report)[source]

alphatwirl.progressbar.ProgressReport module

class alphatwirl.progressbar.ProgressReport.ProgressReport(name, done, total, taskid=None)[source]

Bases: object

A progress report

Parameters:
  • name (str) – the name of the task. if taskid is None, used to identify the task
  • done (int) – the number of the iterations done so far
  • total (int) – the total iterations to be done
  • taskid (immutable, optional) – if given, used to identify the task. useful if multiple tasks have the same name
last()[source]
first()[source]

alphatwirl.progressbar.ProgressReportPickup module

class alphatwirl.progressbar.ProgressReportPickup.ProgressReportPickup(queue, presentation)[source]

Bases: multiprocessing.process.Process

run()[source]

alphatwirl.progressbar.ProgressReporter module

class alphatwirl.progressbar.ProgressReporter.ProgressReporter(queue)[source]

Bases: object

A progress reporter

This class sends a ProgressReport to a progress monitor, e.g., ProgressMonitor or BProgressMonitor, which, for example, uses the reports to update ProgressBar on the screen.

An instance of this class is initialized with a message queue:

reporter = ProgressReporter(queue)

A reporter, an instance of this class, is typically created and initialized by a progress monitor (ProgressMonitor or BProgressMonitor), which keeps the other end of the message queue. A reporter and a monitor might be running in different processes.

A report, an instance of ProgressReport, can be sent as:

reporter.report(report)

This method can be frequently called multiple times. However, after sending one report, the reporter wait for a certain interval (0.1 seconds by default) before sending another report. Reports received within this interval will be discarded. The exception for this is the last report. The last report, which indicates the completion of the task, will be always sent to the progress monitor regardless of whether it is given within the interval.

report(report)[source]

send report to a progress monitor

Parameters:report (ProgressReport) – a progress report

Module contents

alphatwirl.roottree package

Submodules

alphatwirl.roottree.BEventBuilder module

alphatwirl.roottree.BEvents module

alphatwirl.roottree.Branch module

class alphatwirl.roottree.Branch.Branch(name, array, countarray)[source]

Bases: object

This class encloses an array.array object, which is typically used to set the address of a branch of a ROOT TTree. This class is useful for fast access to contents of TTree.

While TTree can hold many types of data, including objects of user defined classes, this class can be used only for objects of simple types, such as Int_t, Double_t, and arrays of simple types.

Examples

Suppose jet_pt is an instance of this class and the corresponding object in TTree is an array.

>>> len(jet_pt)
3
>>> [v for v in jet_pt]
[127.16558074951172, 68.16969299316406, 53.75463104248047]

When the corresponding object in TTree is not an array but a simple type, the length is 1 and the only element is the value.

>>> len(mht)
1
>>> mht[0]
73.7677

alphatwirl.roottree.BranchAddressManager module

class alphatwirl.roottree.BranchAddressManager.BranchAddressManager[source]

Bases: object

The branch address manager for ROOT TTree

This class manages array.array objects used for branch addresses of ROOT TTree. The main purpose of this class is to prevent multiple arrays from being created for the same branch.

All instances of this class share the data.

arrayDict = {}
counterArrayDict = {}
getArrays(tree, branchName)[source]

return the array.array objects for the branch and its counter branch

This method returns a pair of the array.array objects. The first one is for the given tree and branch name. The second one is for its counter branch. The second one will be None when the branch does not have a counter. A pair of None will be returned when the tree does not have the branch.

alphatwirl.roottree.BranchAddressManager.inspectLeaf(tree, bname)[source]
alphatwirl.roottree.BranchAddressManager.IsROOTNullPointer(tobject)[source]

alphatwirl.roottree.BranchAddressManagerForVector module

alphatwirl.roottree.BranchBuilder module

alphatwirl.roottree.EventBuilder module

alphatwirl.roottree.EventBuilderConfig module

class alphatwirl.roottree.EventBuilderConfig.EventBuilderConfig(inputPaths, treeName, maxEvents, start, name)

Bases: tuple

inputPaths

Alias for field number 0

maxEvents

Alias for field number 2

name

Alias for field number 4

start

Alias for field number 3

treeName

Alias for field number 1

alphatwirl.roottree.Events module

class alphatwirl.roottree.Events.Events(tree, maxEvents=-1, start=0)[source]

Bases: object

An iterative object for events.

You can use this class to iterate over entries in a ROOT TTree.

You can instantiate this class with a TTree object and an optionally a maximum number of entries to loop over:

inputFile = ROOT.TFile.Open(inputPath)
tree = inputFile.Get(treeName)
events = Events(tree)

Then, the “for” loop for the tree entries can be:

for event in events:

Note: “event” and “events” are the same object. In each iteration, “event” (and “events”) is loaded with the next entry in the tree.

A content of the tree, e.g., a branch, can be accessed as an attribute of “event”:

event.jet_pt

In order to access to a particular entry, you can use an index. For example, to get 11th entry (the index for the first entry is 0):

event = events[10]

Note: Again “event” and “events” are the same object.

alphatwirl.roottree.inspect module

alphatwirl.roottree.inspect.IsROOTNullPointer(tobject)[source]
alphatwirl.roottree.inspect.inspect_tree(tree)[source]
alphatwirl.roottree.inspect.inspect_leaf(leaf)[source]
alphatwirl.roottree.inspect.inspect_leaf_definition(leaf)[source]
alphatwirl.roottree.inspect.inspect_leaf_size(leaf)[source]

Module contents

alphatwirl.selection package

Subpackages

alphatwirl.selection.modules package
Submodules
alphatwirl.selection.modules.Count module
class alphatwirl.selection.modules.Count.Count[source]

Bases: object

copy()[source]
add(selection)[source]
count(pass_)[source]
increment_depth(by=1)[source]
insert(i, other)[source]
results()[source]
to_tuple_list()[source]
alphatwirl.selection.modules.LambdaStr module
class alphatwirl.selection.modules.LambdaStr.LambdaStr(lambda_str, name=None)[source]

Bases: object

select events to which a lambda returns True.

A lambda should be given as a string to __init__ and will be evaluated in begin(). This is because a lambda is not picklable.

In the multiprocessing mode, __init__() is called in the main process. Then, the instance will be pickled and sent to subprocesses. begin() will be called in the subprocesses.

begin(event)[source]
event(event)[source]
end()[source]
alphatwirl.selection.modules.basic module
class alphatwirl.selection.modules.basic.All(name=None)[source]

Bases: object

select events that meet all conditions

add(selection)[source]
begin(event)[source]
event(event)[source]
end()[source]
class alphatwirl.selection.modules.basic.Any(name=None)[source]

Bases: object

select events that meet any of the conditions

add(selection)[source]
begin(event)[source]
event(event)[source]
end()[source]
class alphatwirl.selection.modules.basic.Not(selection, name=None)[source]

Bases: object

select events that do NOT pass the selection

begin(event)[source]
event(event)[source]
end()[source]
alphatwirl.selection.modules.with_count module
class alphatwirl.selection.modules.with_count.AllwCount(name=None)[source]

Bases: object

select events that meet all conditions

add(selection)[source]
begin(event)[source]
event(event)[source]
end()[source]
results(increment=False)[source]
class alphatwirl.selection.modules.with_count.AnywCount(name=None)[source]

Bases: object

select events that meet all conditions

add(selection)[source]
begin(event)[source]
event(event)[source]
end()[source]
results(increment=False)[source]
class alphatwirl.selection.modules.with_count.NotwCount(selection, name=None)[source]

Bases: object

select events that do NOT pass the selection

begin(event)[source]
event(event)[source]
end()[source]
results(increment=False)[source]
Module contents

Submodules

alphatwirl.selection.funcs module

alphatwirl.selection.funcs.build_selection(**kargs)[source]

Module contents

alphatwirl.summary package

Submodules

alphatwirl.summary.BackrefMultipleArrayReader module

class alphatwirl.summary.BackrefMultipleArrayReader.BackrefMultipleArrayReader(arrays, idxs_conf, backref_idxs=None)[source]

Bases: object

read()[source]

alphatwirl.summary.Count module

class alphatwirl.summary.Count.Count(val=None, weight=1, contents=None)[source]

Bases: object

Parameters:
  • val – If None, initialize with 0. i.e., not counted. Otherwise, typically an empty tuple, counted with the weight. Ignored if contents are given.
  • weight (float) – The weight
  • contents – Specified contents unless None

alphatwirl.summary.KeyValueComposer module

class alphatwirl.summary.KeyValueComposer.KeyValueComposer(keyAttrNames=None, binnings=None, keyIndices=None, valAttrNames=None, valIndices=None)[source]

Bases: object

This class composes keys and values for the event

(this docstring is under development.)

This class can be used with BEvents.

This class supports inclusive indices ‘*’

This class supports back references.

begin(event)[source]

alphatwirl.summary.NextKeyComposer module

class alphatwirl.summary.NextKeyComposer.NextKeyComposer(binnings)[source]

Bases: object

alphatwirl.summary.Reader module

class alphatwirl.summary.Reader.Reader(keyValComposer, summarizer, nextKeyComposer=None, weightCalculator=WeightCalculatorOne(), nevents=None)[source]

Bases: object

begin(event)[source]
event(event)[source]
end()[source]
results()[source]

alphatwirl.summary.Scan module

class alphatwirl.summary.Scan.Scan(val=None, weight=1, contents=None)[source]

Bases: object

alphatwirl.summary.Sum module

class alphatwirl.summary.Sum.Sum(val=None, weight=1, contents=None)[source]

Bases: object

alphatwirl.summary.Summarizer module

class alphatwirl.summary.Summarizer.Summarizer(Summary)[source]

Bases: object

add(key, val=None, weight=1)[source]
add_key(key)[source]
keys()[source]
results()[source]
to_key_vals_dict()[source]
to_tuple_list()[source]
alphatwirl.summary.Summarizer.convert_key_vals_dict_to_tuple_list(dict_, fill=nan)[source]

alphatwirl.summary.WeightCalculatorOne module

class alphatwirl.summary.WeightCalculatorOne.WeightCalculatorOne[source]

Bases: object

alphatwirl.summary.parse_indices_config module

alphatwirl.summary.parse_indices_config.parse_indices_config(indices)[source]

Module contents

Module contents

Indices and tables