def _set(self, key, value, **kw_args): # Was the RZ ID specified as a keyword argument? rz_id = kw_args.get("rz_id", None) if rz_id is None: if hasattr(object, "rz_id"): # The object has an 'rz_id' attribute, so use its value. rz_id = int(object.rz_id) else: # No RZ ID specified; choose an ID. rz_id = self._make_rz_id() if hep.isMap(value): type = "directory" # Make a directory. ext.hcdir(self.__rz_path, " ") ext.hmdir(key, " ") # Fill in the initial entries, if some where specified. if len(value) > 0: self.get(key, **kw_args).update(value, **kw_args) # Invalidate the directory cache. if key in self.__subdirs: del self.__subdirs[key] elif hep.hist.isHistogram(value): # Make the histogram object in PAWC memory. if value.dimensions == 1: type = "1D histogram" self._make1DHistogram(value, key, rz_id) elif value.dimensions == 2: type = "2D histogram" self._make2DHistogram(value, key, rz_id) else: raise NotImplementedError, \ "cannot save an %d-D histogram in an HBOOK file" \ % dimensions # Save the histogram to the HBOOK file. ext.hcdir(self.__rz_path, " ") ext.hrout(rz_id, " ") # Clean up the in-memory PAW histogram. ext.hcdir("//PAWC", " ") ext.hdelet(rz_id) else: raise NotImplementedError, \ "cannot save a %s in an HBOOK file" \ % type(value).__name__ # Update the info cache. self.__info[key] = self.__makeinfo(key, rz_id, type)
def _get(self, key, **kw_args): # Look up the specified path. info = self.__info[key] if info.type == "directory": # It's a directory. Return a 'Directory' object, checking # the cache first. if not self.__subdirs.has_key(key): self.__subdirs[key] = Directory( self.__file, join(self.__path, key), self.purge_cycles) return self.__subdirs[key] # Otherwise, load it into memory. ext.hcdir(self.__rz_path, " ") ext.hrin(info.rz_id, 999999, 0) # Construct a Python object for it. if info.type == "table": # Build a table handle. table = ext.openTuple( info.rz_id, self.__rz_path, self.writable) # Associate this file with this table, so that the file # isn't closed while the table handle still exists. table.file = self return table elif info.type == "1D histogram": histogram = self._read1DHistogram(info.rz_id) # Remove the HBOOK object from memory. ext.hcdir("//PAWC", " ") ext.hdelet(info.rz_id) # Return the histogram. return histogram elif info.type == "2D histogram": histogram = self._read2DHistogram(info.rz_id) # Remove the HBOOK object from memory. ext.hcdir("//PAWC", " ") ext.hdelet(info.rz_id) # Return the histogram. return histogram else: raise NotImplementedError, "type '%s'" % info.type