CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
branchselection.BranchSelection Class Reference

Public Member Functions

def __init__ (self, branchsel)
 
def selectBranches (self, tree)
 

Private Attributes

 _ops
 

Detailed Description

Definition at line 9 of file branchselection.py.

Constructor & Destructor Documentation

◆ __init__()

def branchselection.BranchSelection.__init__ (   self,
  branchsel 
)

Definition at line 10 of file branchselection.py.

References print(), and nano_mu_digi_cff.strip.

10  def __init__(self, branchsel):
11  comment = re.compile(r"#.*")
12  ops = []
13 
14  if isinstance(branchsel, list):
15  # branchsel is a list of commands
16  lines = branchsel
17  elif isinstance(branchsel, str):
18  # branchsel is a filename
19  lines=[]
20  for line in open(branchsel, 'r'): line = line.strip()
21  if len(line) == 0 or line[0] == '#':
22  continue
23  line = re.sub(comment, "", line)
24  while line[-1] == "\\":
25  line = line[:-1] + " " + file.next().strip()
26  line = re.sub(comment, "", line)
27  lines.append(line)
28 
29  for line in lines:
30  try:
31  (op, sel) = line.split()
32  if op == "keep":
33  ops.append((sel, 1))
34  elif op == "drop":
35  ops.append((sel, 0))
36  elif op == "keepmatch":
37  ops.append((re.compile("(:?%s)$" % sel), 1))
38  elif op == "dropmatch":
39  ops.append((re.compile("(:?%s)$" % sel), 0))
40  else:
41  print("Error in branchsel: line '%s': "% (line)
42  + "it's not (keep|keepmatch|drop|dropmatch) "
43  + "<branch_pattern>"
44  )
45  except ValueError as e:
46  print("Error in branchsel: line '%s': " % (line)
47  + "it's not (keep|keepmatch|drop|dropmatch) "
48  + "<branch_pattern>"
49  )
50  self._ops = ops
51 
52 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

Member Function Documentation

◆ selectBranches()

def branchselection.BranchSelection.selectBranches (   self,
  tree 
)

Definition at line 53 of file branchselection.py.

References branchselection.BranchSelection._ops.

53  def selectBranches(self, tree):
54  tree.SetBranchStatus("*", 1)
55  branchNames = [b.GetName() for b in tree.GetListOfBranches()]
56  for bre, stat in self._ops:
57  if type(bre) == Pattern:
58  for n in branchNames:
59  if re.match(bre, n):
60  tree.SetBranchStatus(n, stat)
61  else:
62  tree.SetBranchStatus(bre, stat)
63 

Member Data Documentation

◆ _ops

branchselection.BranchSelection._ops
private

Definition at line 51 of file branchselection.py.

Referenced by branchselection.BranchSelection.selectBranches().