# Tai Sakuma <tai.sakuma@cern.ch>
from ..Summary import Summarizer, NextKeyComposer, KeyValueComposer
from ..CombineIntoList import CombineIntoList
from ..WriteListToFile import WriteListToFile
from ..Loop import Collector

##__________________________________________________________________||
def build_counter_collector_pair(tblcfg):
    keyValComposer = KeyValueComposer(
        keyAttrNames = tblcfg['branchNames'],
        binnings = tblcfg['binnings'],
        keyIndices = tblcfg['indices']
    )
    nextKeyComposer = NextKeyComposer(tblcfg['binnings'])
    summarizer = Summarizer(
        keyValComposer = keyValComposer,
        summary = tblcfg['countsClass'](),
        nextKeyComposer = nextKeyComposer,
        weightCalculator = tblcfg['weight']
    )
    resultsCombinationMethod = CombineIntoList(keyNames = tblcfg['outColumnNames'], valNames = ('n', 'nvar'))
    deliveryMethod = WriteListToFile(tblcfg['outFilePath']) if tblcfg['outFile'] else None
    collector = Collector(resultsCombinationMethod, deliveryMethod)
    return summarizer, collector

##__________________________________________________________________||

@@ -404,14 +404,15 @@
 fg%5B'
-branch
+keyAttr
 Name
@@ -484,17 +484,20 @@
 tblcfg%5B'
-i
+keyI
 ndices'%5D
@@ -661,14 +661,15 @@
 fg%5B'
-counts
+summary
 Clas

update key names in tblcfg in build_counter_collector_pair()