Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
generic.models.Organizational.PlotID Class Reference
Inheritance diagram for generic.models.Organizational.PlotID:
object

Public Member Functions

def __init__ (self, init)
 
def id_str (self)
 
def id_str (self, val)
 
def __contains__ (self, other)
 
def __eq__ (self, other)
 
def __repr__ (self)
 

Public Attributes

 id_str
 
 categories
 
 groups
 
 name
 
short int type
 
short int number
 
cat_entry star
 

Static Public Attributes

 CATEGORY_PATTERN = re.compile(r"(\{group=(?P<group>.+?),cat=(?P<group_cat>.+?)\}|\{(?P<cat>.+?)\})")
 
string OVERLAY_STRING = "all_overlay"
 
string SUM_STRING = "all_sum"
 

Private Member Functions

def _Parse (self)
 

Private Attributes

 _id_str
 

Detailed Description

Wrapper around plot identifier.  Simplifies access to 'group' interface. 

    ID string as input should have the following format:
    
       name_string<group1_string><group2_string>[possibly more <group_string>s]
    
    where the <group_string>s can either be formatted as
    
       {category_name}
    
    or
    
       {group=group name,cat=category name}

    Valid example:
       sample_plot{nocuts}{group=MC,cat=DIS}

    Note that if you specify a category using the category-only syntax ('{category_name}'),
    you must ensure it always occurs in the same sequence in any plots that are intended
    to be grouped together (i.e., have the same name_string).

Definition at line 74 of file Organizational.py.

Constructor & Destructor Documentation

def generic.models.Organizational.PlotID.__init__ (   self,
  init 
)

Definition at line 101 of file Organizational.py.

101  def __init__(self, init):
102  # passed a path string
103  if isinstance(init, basestring):
104  self.id_str = init
105  # passed another PlotID instance -- just copy
106  elif hasattr(init, "id_str"):
107  self.id_str = init.id_str
108  # passed a dictionary with the name, categories, and possibly groups specified
109  elif hasattr(init, "__contains__") and all(prop in init for prop in ("name", "categories")):
110  id_str = init["name"]
111  groups_by_idx = {} if "groups" not in init else dict(zip(init["groups"].itervalues(), init["groups"].iterkeys()))
112  for idx, cat in enumerate(init["categories"]):
113  if idx in groups_by_idx:
114  id_str += "{group=%s,cat=%s}" % (groups_by_idx[idx], cat)
115  else:
116  id_str += "{%s}" % cat
117  self.id_str = id_str
118 
119  # categories, groups will now be re-deduced from the string
120  # check that we got the same thing we began with...
121  assert self.categories == init["categories"] and \
122  ( ("groups" not in init and len(self.groups) == 0) or \
123  (init["groups"] == self.groups) ), \
124  "Didn't correctly reconstruct groups and categories for PlotID. Given: %s, %s; reconstructed: %s, %s" \
125  % (init["groups"], init["categories"], self.groups, self.categories)
126 

Member Function Documentation

def generic.models.Organizational.PlotID.__contains__ (   self,
  other 
)
This ID 'contains' another if:
      * they share the same 'name'
      * this ID has at least as long a category list
      * the categories match up to the end of the shorter list
      * the group lists contain no incompatible category links. 

Definition at line 136 of file Organizational.py.

References bp_docdb.Document.categories, generic.models.Organizational.PlotID.categories, generic.models.Organizational.PlotID.groups, fabricate._Groups.groups, min(), Table.name, ana::HistDef.name, ana::MultiHistDef.name, Plot.name, HistDef.name, CutDef.name, ana::NuTruthHistDef.name, bp_plot.Plot.name, ColumnDef.name, Weight.name, ana::VarDef.name, ana::CutDef.name, ana::PIDCutDef.name, ana::WeightDef.name, IntConfig.name, object.name, ana::GenieMultiverseSpectra::knob_sampling_mode.name, ana::GenieMultiverseParameters::knob_sampling_mode.name, ExtrapDef.name, ana::predictions.name, and std_candles.PlotConfig.name.

136  def __contains__(self, other):
137  """ This ID 'contains' another if:
138  * they share the same 'name'
139  * this ID has at least as long a category list
140  * the categories match up to the end of the shorter list
141  * the group lists contain no incompatible category links. """
142 
143  if not all( hasattr(other, prop) for prop in ("name", "categories", "groups") ):
144  return False
145 
146  if self.name != other.name:
147  return False
148 
149  if len(self.categories) > len(other.categories):
150  return False
151 
152  min_length = min(len(self.categories), len(other.categories))
153  if self.categories[:min_length] != other.categories[:min_length]:
154  return False
155 
156  # make sure the category indices point to the same group names,
157  # where they overlap...
158  for key in set(self.groups) & set(other.groups):
159  if self.groups[key] != other.groups[key]:
160  return False
161 
162  # also make sure that the groups always point to the same
163  # category indices as well
164  my_reverse_map = {v:k for k, v in self.groups.iteritems()}
165  other_reverse_map = {v:k for k, v in other.groups.iteritems()}
166  for key in set(my_reverse_map) & set(other_reverse_map):
167  if my_reverse_map[key] != other_reverse_map[key]:
168  return False
169 
170  return True
171 
172 
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
char name[SIZE_OF_OBJ_NAME]
Definition: novas.h:116
def generic.models.Organizational.PlotID.__eq__ (   self,
  other 
)

Definition at line 173 of file Organizational.py.

References generic.models.Organizational.PlotID.id_str.

173  def __eq__(self, other):
174  return hasattr(other, "id_str") and self.id_str == other.id_str
175 
def generic.models.Organizational.PlotID.__repr__ (   self)

Definition at line 176 of file Organizational.py.

References generic.models.Organizational.PlotID.id_str.

176  def __repr__(self):
177  return "'%s'" % self.id_str
178 
def generic.models.Organizational.PlotID._Parse (   self)
private
Try to understand the ID string. 

Definition at line 179 of file Organizational.py.

References bp_docdb.Document.categories, and generic.models.Organizational.PlotID.categories.

179  def _Parse(self):
180  """ Try to understand the ID string. """
181 
182  # sequential list of categories buried in the ID
183  self.categories = []
184 
185  # the indices of named groups in the category list above
186  # (so, e.g., the category within group "MC_breakdown" might
187  # correspond to index number 2 in the list:
188  # groups["MC_breakdown"] = 2)
189  self.groups = {}
190 
191  splitted = self.id_str.split("{", 1)
192  self.name = splitted[0]
193  if len(splitted) == 1:
194  return
195 
196  remnants = "{" + splitted[1] # the initial "{" got eaten by the split... gotta put it back
197  for match in PlotID.CATEGORY_PATTERN.finditer(remnants):
198  if all([match.group(k) for k in ("group","group_cat")]):
199  self.categories.append(match.group("group_cat"))
200  self.groups[match.group("group")] = len(self.categories) - 1
201  elif match.group("cat"):
202  self.categories.append(match.group("cat"))
203  else:
204  # can't be a match any other way...
205  raise ValueError("Something bizarre happened in parsing PlotID. Matched string pieces: %s" % match.groupdict())
206 
207  # strip off the matched part
208  remnants = remnants.replace(match.group(0), "", 1)
209 
210  if len(remnants) > 0:
211  raise ValueError("Couldn't parse plot name. Full string: '%s'; unprocessed leftover text: '%s'" % (self.id_str, remnants))
212 
char name[SIZE_OF_OBJ_NAME]
Definition: novas.h:116
def generic.models.Organizational.PlotID.id_str (   self)
def generic.models.Organizational.PlotID.id_str (   self,
  val 
)

Member Data Documentation

generic.models.Organizational.PlotID._id_str
private

Definition at line 133 of file Organizational.py.

Referenced by generic.models.Organizational.PlotID.id_str().

generic.models.Organizational.PlotID.categories
generic.models.Organizational.PlotID.CATEGORY_PATTERN = re.compile(r"(\{group=(?P<group>.+?),cat=(?P<group_cat>.+?)\}|\{(?P<cat>.+?)\})")
static

Definition at line 97 of file Organizational.py.

generic.models.Organizational.PlotID.groups
generic.models.Organizational.PlotID.id_str
generic.models.Organizational.PlotID.name
short int object::number
inherited

Definition at line 115 of file novas.h.

string generic.models.Organizational.PlotID.OVERLAY_STRING = "all_overlay"
static

Definition at line 98 of file Organizational.py.

cat_entry object::star
inherited

Definition at line 117 of file novas.h.

string generic.models.Organizational.PlotID.SUM_STRING = "all_sum"
static

Definition at line 99 of file Organizational.py.

short int object::type
inherited

Definition at line 114 of file novas.h.


The documentation for this class was generated from the following file: