CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
collectionMerger.collectionMerger Class Reference
Inheritance diagram for collectionMerger.collectionMerger:

Public Member Functions

def __init__ (self, input, output, sortkey=lambda x:x.pt, reverse=True, selector=None, maxObjects=None)
 
def analyze (self, event)
 
def beginFile (self, inputFile, outputFile, inputTree, wrappedOutputTree)
 
def beginJob (self)
 
def endFile (self, inputFile, outputFile, inputTree, wrappedOutputTree)
 
def endJob (self)
 
def filterBranchNames (self, branches, collection)
 

Public Attributes

 branchType
 
 brlist_all
 
 brlist_sep
 
 input
 
 is_there
 
 maxObjects
 
 nInputs
 
 out
 
 output
 
 reverse
 
 selector
 
 sortkey
 

Detailed Description

Definition at line 21 of file collectionMerger.py.

Constructor & Destructor Documentation

◆ __init__()

def collectionMerger.collectionMerger.__init__ (   self,
  input,
  output,
  sortkey = lambda x: x.pt,
  reverse = True,
  selector = None,
  maxObjects = None 
)

Definition at line 28 of file collectionMerger.py.

28  maxObjects=None):
29  self.input = input
30  self.output = output
31  self.nInputs = len(self.input)
32  self.sortkey = lambda obj_j_i1: sortkey(obj_j_i1[0])
33  self.reverse = reverse
34  # pass dict([(collection_name,lambda obj : selection(obj)])
35  self.selector = [(selector[coll] if coll in selector else
36  (lambda x: True))
37  for coll in self.input] if selector else None
38  # save only the first maxObjects objects passing the selection in the merged collection
39  self.maxObjects = maxObjects
40  self.branchType = {}
41  pass
42 

Member Function Documentation

◆ analyze()

def collectionMerger.collectionMerger.analyze (   self,
  event 
)
process event, return True (go to next module) or False (fail, go to next event)

Definition at line 104 of file collectionMerger.py.

References collectionMerger.collectionMerger.brlist_all, event.Event.input, WorkFlow.WorkFlow.input, collectionMerger.collectionMerger.input, RBCInput.input, MuonStub.input, personalPlayback.Playback.input, options.HLTProcessOptions.input, collectionMerger.collectionMerger.is_there, collectionMerger.collectionMerger.maxObjects, collectionMerger.collectionMerger.nInputs, L1TMuonOverlapParams::LayerInputNode.nInputs, exampleModule.exampleProducer.out, mhtjuProducerCpp.mhtjuProducerCpp.out, ProcMultiply.out, collectionMerger.collectionMerger.out, PhysicsTools::Calibration::ProcMultiply.out, BeamHaloAnalyzer.out, l1ct::Event.out, CSCFileDumper.output, collectionMerger.collectionMerger.output, MessageLogger.output, GeometryComparisonPlotter.output, edm::service::MessageLoggerDefaults::Destination.output, personalPlayback.Playback.output, options.HLTProcessOptions.output, PhysicsTools::MVAComputer.output, PhysicsTools::Calibration::MVAComputer.output, PhysicsTools::VarProcessor::ValueIterator.output, FastTimerService_cff.range, collectionMerger.collectionMerger.reverse, hgcalTriggerChains.HGCalTriggerChains.selector, RawDataSelector.selector, collectionMerger.collectionMerger.selector, BPHMultiSelectBase< T >::SelectElement.selector, BPHRecoBuilder::BPHRecoSource.selector, and collectionMerger.collectionMerger.sortkey.

104  def analyze(self, event):
105  """process event, return True (go to next module) or False (fail, go to next event)"""
106  coll = [Collection(event, x) for x in self.input]
107  objects = [(coll[j][i], j, i) for j in range(self.nInputs)
108  for i in range(len(coll[j]))]
109  if self.selector:
110  objects = [
111  obj_j_i for obj_j_i in objects
112  if self.selector[obj_j_i[1]](obj_j_i[0])
113  ]
114  objects.sort(key=self.sortkey, reverse=self.reverse)
115  if self.maxObjects:
116  objects = objects[:self.maxObjects]
117  for bridx, br in enumerate(self.brlist_all):
118  out = []
119  for obj, j, i in objects:
120  out.append(getattr(obj, br) if self.is_there[bridx][j] else 0)
121  self.out.fillBranch("%s_%s" % (self.output, br), out)
122  return True
123 
124 
125 # define modules using the syntax 'name = lambda : constructor' to avoid having them loaded when not needed
126 
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override

◆ beginFile()

def collectionMerger.collectionMerger.beginFile (   self,
  inputFile,
  outputFile,
  inputTree,
  wrappedOutputTree 
)

Definition at line 49 of file collectionMerger.py.

49  def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
50 
51  # Find list of activated branches in input tree
52  _brlist_in = inputTree.GetListOfBranches()
53  branches_in = set(
54  [_brlist_in.At(i) for i in range(_brlist_in.GetEntries())])
55  branches_in = [
56  x for x in branches_in if inputTree.GetBranchStatus(x.GetName())
57  ]
58 
59  # Find list of activated branches in output tree
60  _brlist_out = wrappedOutputTree._tree.GetListOfBranches()
61  branches_out = set(
62  [_brlist_out.At(i) for i in range(_brlist_out.GetEntries())])
63  branches_out = [
64  x for x in branches_out
65  if wrappedOutputTree._tree.GetBranchStatus(x.GetName())
66  ]
67 
68  # Use both
69  branches = branches_in + branches_out
70 
71  # Only keep branches with right collection name
72  self.brlist_sep = [
73  self.filterBranchNames(branches, x) for x in self.input
74  ]
75  self.brlist_all = set(itertools.chain(*(self.brlist_sep)))
76 
77  self.is_there = np.zeros(shape=(len(self.brlist_all), self.nInputs),
78  dtype=bool)
79  for bridx, br in enumerate(self.brlist_all):
80  for j in range(self.nInputs):
81  if br in self.brlist_sep[j]:
82  self.is_there[bridx][j] = True
83 
84  # Create output branches
85  self.out = wrappedOutputTree
86  for br in self.brlist_all:
87  self.out.branch("%s_%s" % (self.output, br),
88  _rootLeafType2rootBranchType[self.branchType[br]],
89  lenVar="n%s" % self.output)
90 

◆ beginJob()

def collectionMerger.collectionMerger.beginJob (   self)

Definition at line 43 of file collectionMerger.py.

43  def beginJob(self):
44  pass
45 
void beginJob()
Definition: Breakpoints.cc:14

◆ endFile()

def collectionMerger.collectionMerger.endFile (   self,
  inputFile,
  outputFile,
  inputTree,
  wrappedOutputTree 
)

Definition at line 91 of file collectionMerger.py.

91  def endFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
92  pass
93 

◆ endJob()

def collectionMerger.collectionMerger.endJob (   self)

Definition at line 46 of file collectionMerger.py.

46  def endJob(self):
47  pass
48 

◆ filterBranchNames()

def collectionMerger.collectionMerger.filterBranchNames (   self,
  branches,
  collection 
)

Definition at line 94 of file collectionMerger.py.

94  def filterBranchNames(self, branches, collection):
95  out = []
96  for br in branches:
97  name = br.GetName()
98  if not name.startswith(collection + '_'):
99  continue
100  out.append(name.replace(collection + '_', ''))
101  self.branchType[out[-1]] = br.FindLeaf(br.GetName()).GetTypeName()
102  return out
103 

Member Data Documentation

◆ branchType

collectionMerger.collectionMerger.branchType

Definition at line 40 of file collectionMerger.py.

◆ brlist_all

collectionMerger.collectionMerger.brlist_all

Definition at line 75 of file collectionMerger.py.

Referenced by collectionMerger.collectionMerger.analyze().

◆ brlist_sep

collectionMerger.collectionMerger.brlist_sep

Definition at line 72 of file collectionMerger.py.

◆ input

collectionMerger.collectionMerger.input

Definition at line 29 of file collectionMerger.py.

Referenced by collectionMerger.collectionMerger.analyze().

◆ is_there

collectionMerger.collectionMerger.is_there

Definition at line 77 of file collectionMerger.py.

Referenced by collectionMerger.collectionMerger.analyze().

◆ maxObjects

collectionMerger.collectionMerger.maxObjects

Definition at line 39 of file collectionMerger.py.

Referenced by collectionMerger.collectionMerger.analyze().

◆ nInputs

collectionMerger.collectionMerger.nInputs

Definition at line 31 of file collectionMerger.py.

Referenced by collectionMerger.collectionMerger.analyze().

◆ out

collectionMerger.collectionMerger.out

Definition at line 85 of file collectionMerger.py.

Referenced by collectionMerger.collectionMerger.analyze().

◆ output

collectionMerger.collectionMerger.output

Definition at line 30 of file collectionMerger.py.

Referenced by collectionMerger.collectionMerger.analyze().

◆ reverse

collectionMerger.collectionMerger.reverse

Definition at line 33 of file collectionMerger.py.

Referenced by collectionMerger.collectionMerger.analyze().

◆ selector

collectionMerger.collectionMerger.selector

Definition at line 35 of file collectionMerger.py.

Referenced by collectionMerger.collectionMerger.analyze().

◆ sortkey

collectionMerger.collectionMerger.sortkey

Definition at line 32 of file collectionMerger.py.

Referenced by collectionMerger.collectionMerger.analyze().