CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
List of all members | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes
XML2Python.DataNode Class Reference
Inheritance diagram for XML2Python.DataNode:

Public Member Functions

def __contains__ (self, name)
 
def __contains__ (self, name)
 
def __getattr__ (self, name)
 
def __getattr__ (self, name)
 
def __getitem__ (self, key)
 
def __getitem__ (self, key)
 
def __init__ (self, kwargs)
 
def __init__ (self, kwargs)
 
def __len__ (self)
 
def __len__ (self)
 
def __nonzero__ (self)
 
def __nonzero__ (self)
 
def __repr__ (self)
 
def __repr__ (self)
 
def __str__ (self)
 
def __str__ (self)
 
def attributes (self)
 
def attributes (self)
 
def stringify (self, name='', offset=0)
 

Static Public Member Functions

def isiterable (obj)
 

Static Public Attributes

 spaces
 

Private Member Functions

def _add_xml_attr (self, name, value)
 
def _add_xml_attr (self, name, value)
 

Static Private Member Functions

def _outputValues (obj, name, offset)
 

Private Attributes

 _attrs
 
 _data
 
 _ncDict
 

Detailed Description

Definition at line 11 of file XML2Python.py.

Constructor & Destructor Documentation

◆ __init__() [1/2]

def XML2Python.DataNode.__init__ (   self,
  kwargs 
)

Definition at line 15 of file XML2Python.py.

Referenced by XML2Python.DataNode.__init__().

15  def __init__ (self, **kwargs):
16  self._attrs = {} # XML attributes and child elements
17  self._data = None # child text data
18  self._ncDict = kwargs.get ('nameChangeDict', {})
19 
20 
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)

◆ __init__() [2/2]

def XML2Python.DataNode.__init__ (   self,
  kwargs 
)

Definition at line 11 of file XML2Python.py.

References XML2Python.DataNode.__init__(), XML2Python.DataNode._attrs, SeedingNode< DATA >._data, data_sources.node._data, XML2Python.DataNode._data, data_sources.json_file._data, data_sources.sqlite_schema._data, data_sources.json_data_node._data, data_sources.json_list._data, conddb2hdf5.DBPayload._data, data_sources.json_dict._data, data_sources.json_basic._data, DTTFBitArray< N >._data, and XML2Python.DataNode._ncDict.

11  def __init__ (self, **kwargs):
12  self._attrs = {} # XML attributes and child elements
13  self._data = None # child text data
14  self._ncDict = kwargs.get ('nameChangeDict', {})
15 
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)

Member Function Documentation

◆ __contains__() [1/2]

def XML2Python.DataNode.__contains__ (   self,
  name 
)

Definition at line 26 of file XML2Python.py.

References XML2Python.DataNode.__contains__(), and XML2Python.DataNode._attrs.

26  def __contains__ (self, name):
27  return name in self._attrs
28 

◆ __contains__() [2/2]

def XML2Python.DataNode.__contains__ (   self,
  name 
)

Definition at line 33 of file XML2Python.py.

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.__contains__().

33  def __contains__ (self, name):
34  return name in self._attrs
35 
36 

◆ __getattr__() [1/2]

def XML2Python.DataNode.__getattr__ (   self,
  name 
)

Definition at line 32 of file XML2Python.py.

References XML2Python.DataNode.__getattr__(), and XML2Python.DataNode._attrs.

32  def __getattr__ (self, name):
33  if name.startswith('__'):
34  # need to do this for Python special methods???
35  raise AttributeError (name)
36  return self._attrs.get (name, None)
37 

◆ __getattr__() [2/2]

def XML2Python.DataNode.__getattr__ (   self,
  name 
)

Definition at line 41 of file XML2Python.py.

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.__getattr__(), datamodel.Event.__getitem__(), and datamodel.Object.__getitem__().

41  def __getattr__ (self, name):
42  if name.startswith('__'):
43  # need to do this for Python special methods???
44  raise AttributeError (name)
45  return self._attrs.get (name, None)
46 
47 

◆ __getitem__() [1/2]

def XML2Python.DataNode.__getitem__ (   self,
  key 
)

Definition at line 20 of file XML2Python.py.

References XML2Python.DataNode.__getitem__(), and XML2Python.DataNode._attrs.

20  def __getitem__ (self, key):
21  if isinstance (key, str):
22  return self._attrs.get(key,None)
23  else:
24  return [self][key]
25 

◆ __getitem__() [2/2]

def XML2Python.DataNode.__getitem__ (   self,
  key 
)

Definition at line 26 of file XML2Python.py.

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.__getitem__().

26  def __getitem__ (self, key):
27  if isinstance (key, str):
28  return self._attrs.get(key,None)
29  else:
30  return [self][key]
31 
32 

◆ __len__() [1/2]

def XML2Python.DataNode.__len__ (   self)

Definition at line 16 of file XML2Python.py.

References XML2Python.DataNode.__len__().

16  def __len__ (self):
17  # treat single element as a list of 1
18  return 1
19 

◆ __len__() [2/2]

def XML2Python.DataNode.__len__ (   self)

Definition at line 21 of file XML2Python.py.

Referenced by XML2Python.DataNode.__len__().

21  def __len__ (self):
22  # treat single element as a list of 1
23  return 1
24 
25 

◆ __nonzero__() [1/2]

def XML2Python.DataNode.__nonzero__ (   self)

◆ __nonzero__() [2/2]

def XML2Python.DataNode.__nonzero__ (   self)

◆ __repr__() [1/2]

def XML2Python.DataNode.__repr__ (   self)

Definition at line 55 of file XML2Python.py.

References XML2Python.DataNode.__repr__(), XML2Python.DataNode._attrs, SeedingNode< DATA >._data, data_sources.node._data, XML2Python.DataNode._data, data_sources.json_file._data, data_sources.sqlite_schema._data, data_sources.json_data_node._data, data_sources.json_list._data, conddb2hdf5.DBPayload._data, data_sources.json_dict._data, data_sources.json_basic._data, DTTFBitArray< N >._data, mps_monitormerge.items, and join().

55  def __repr__ (self):
56  items = sorted (self._attrs.items())
57  if self._data:
58  items.append(('data', self._data))
59  return u'{%s}' % ', '.join([u'%s:%s' % (k,repr(v)) for k,v in items])
60 
static std::string join(char **cmd)
Definition: RemoteFile.cc:21

◆ __repr__() [2/2]

def XML2Python.DataNode.__repr__ (   self)

Definition at line 67 of file XML2Python.py.

References XML2Python.DataNode._attrs, SeedingNode< DATA >._data, data_sources.node._data, XML2Python.DataNode._data, data_sources.json_file._data, data_sources.sqlite_schema._data, data_sources.json_data_node._data, data_sources.json_list._data, conddb2hdf5.DBPayload._data, data_sources.json_dict._data, data_sources.json_basic._data, DTTFBitArray< N >._data, mps_monitormerge.items, and join().

Referenced by XML2Python.DataNode.__repr__(), and datamodel.Object.__str__().

67  def __repr__ (self):
68  items = sorted (self._attrs.items())
69  if self._data:
70  items.append(('data', self._data))
71  return u'{%s}' % ', '.join([u'%s:%s' % (k,repr(v)) for k,v in items])
72 
73 
static std::string join(char **cmd)
Definition: RemoteFile.cc:21

◆ __str__() [1/2]

def XML2Python.DataNode.__str__ (   self)

◆ __str__() [2/2]

def XML2Python.DataNode.__str__ (   self)

Definition at line 63 of file XML2Python.py.

References XML2Python.DataNode.stringify().

Referenced by XML2Python.DataNode.__str__().

63  def __str__ (self):
64  return self.stringify()
65 
66 

◆ _add_xml_attr() [1/2]

def XML2Python.DataNode._add_xml_attr (   self,
  name,
  value 
)
private

Definition at line 38 of file XML2Python.py.

References XML2Python.DataNode._add_xml_attr(), XML2Python.DataNode._attrs, and XML2Python.DataNode._ncDict.

38  def _add_xml_attr (self, name, value):
39  change = self._ncDict.get (name)
40  if change:
41  name = change
42  if name in self._attrs:
43  # multiple attribute of the same name are represented by a list
44  children = self._attrs[name]
45  if not isinstance(children, list):
46  children = [children]
47  self._attrs[name] = children
48  children.append(value)
49  else:
50  self._attrs[name] = value
51 

◆ _add_xml_attr() [2/2]

def XML2Python.DataNode._add_xml_attr (   self,
  name,
  value 
)
private

Definition at line 48 of file XML2Python.py.

References XML2Python.DataNode._attrs, and XML2Python.DataNode._ncDict.

Referenced by XML2Python.DataNode._add_xml_attr().

48  def _add_xml_attr (self, name, value):
49  change = self._ncDict.get (name)
50  if change:
51  name = change
52  if name in self._attrs:
53  # multiple attribute of the same name are represented by a list
54  children = self._attrs[name]
55  if not isinstance(children, list):
56  children = [children]
57  self._attrs[name] = children
58  children.append(value)
59  else:
60  self._attrs[name] = value
61 
62 

◆ _outputValues()

def XML2Python.DataNode._outputValues (   obj,
  name,
  offset 
)
staticprivate

Definition at line 84 of file XML2Python.py.

References print().

84  def _outputValues (obj, name, offset):
85  retval = ' ' * offset
86  if name:
87  retval += '%s: ' % name
88  offset += len (name) + DataNode.spaces
89  # if this is a list
90  if isinstance (obj, list):
91  first = True
92  for value in obj:
93  print("value", value, value.__class__.__name__)
94  if first:
95  tempoffset = offset
96  first = False
97  retval += '[\n ' + ' ' * offset
98  else:
99  retval += ',\n ' + ' ' * offset
100  tempoffset = offset
101  if isinstance (value, DataNode):
102  retval += value.stringify (offset=tempoffset)
103  print(" calling stringify for %s" % value)
104  elif DataNode.isiterable (value):
105  retval += DataNode._outputValues (value, '', offset)
106  else:
107  retval += "%s" % value
108  retval += '\n' + ' ' * (offset - 2) +']\n'
109  return retval
110  retval += pprint.pformat(obj,
111  indent= offset,
112  width=1)
113  return retval
114 
115 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ attributes() [1/2]

def XML2Python.DataNode.attributes (   self)

Definition at line 61 of file XML2Python.py.

References XML2Python.DataNode._attrs, and XML2Python.DataNode.attributes().

61  def attributes (self):
62  return self._attrs
63 
64 

◆ attributes() [2/2]

def XML2Python.DataNode.attributes (   self)

Definition at line 74 of file XML2Python.py.

References XML2Python.DataNode._attrs.

Referenced by XML2Python.DataNode.attributes().

74  def attributes (self):
75  return self._attrs
76 
77 

◆ isiterable()

def XML2Python.DataNode.isiterable (   obj)
static

Definition at line 79 of file XML2Python.py.

79  def isiterable (obj):
80  return getattr (obj, '__iter__', False)
81 
82 

◆ stringify()

def XML2Python.DataNode.stringify (   self,
  name = '',
  offset = 0 
)

Definition at line 116 of file XML2Python.py.

References XML2Python.DataNode._attrs, SeedingNode< DATA >._data, data_sources.node._data, XML2Python.DataNode._data, data_sources.json_file._data, data_sources.sqlite_schema._data, data_sources.json_data_node._data, data_sources.json_list._data, conddb2hdf5.DBPayload._data, data_sources.json_dict._data, data_sources.json_basic._data, DTTFBitArray< N >._data, and mps_monitormerge.items.

Referenced by XML2Python.DataNode.__str__().

116  def stringify (self, name = '', offset = 0):
117  # is this just data and nothing below
118  if self._data and not len (self._attrs):
119  return _outputValues (self._data, name, offset)
120  retval = ' ' * offset
121  if name:
122  retval += '%s : %s\n' % \
123  (name,
124  pprint.pformat (self._data,
125  indent= offset+DataNode.spaces,
126  width=1) )
127  else:
128  retval += pprint.pformat (self._data,
129  indent=offset+DataNode.spaces,
130  width=1)
131  return retval
132  # this has attributes
133  retval = ''
134  if name:
135  retval += '\n' + ' ' * offset
136  retval += '%s: ' % name
137  first = True
138  for key, value in sorted (self._attrs.items()):
139  if first:
140  retval += '{ \n'
141  tempspace = offset + 3
142  first = False
143  else:
144  retval += ',\n'
145  tempspace = offset + 3
146  if isinstance (value, DataNode):
147  retval += value.stringify (key, tempspace)
148  else:
149  retval += DataNode._outputValues (value, key, tempspace)
150  # this has data too
151  if self._data:
152  retval += ',\n'
153  tempspace = offset + 3
154  retval += DataNode._ouptputValues (self._data, name, tempspace)
155  retval += '\n ' + ' ' * offset + '}'
156  return retval
157 
158 
159 
std::string stringify(const T &t)

Member Data Documentation

◆ _attrs

XML2Python.DataNode._attrs
private

◆ _data

XML2Python.DataNode._data
private

◆ _ncDict

XML2Python.DataNode._ncDict
private

◆ spaces

XML2Python.DataNode.spaces
static

Definition at line 13 of file XML2Python.py.