Example #1
0
    def persist_services(self, io_conf, chain=None):
        """Persist process services in files.

        :param dict io_conf: I/O config as returned by ConfigObject.io_conf
        :param str chain: name of chain for which data is persisted
        """
        # parse I/O config
        io_conf = ConfigObject.IoConfig(**io_conf)

        # parse specified chain
        if chain:
            # prepend underscore for output directory
            chain = '_{}'.format(chain)
        else:
            # use default directory if chain not specified
            chain = 'default'

        # get chain path and set link of latest data
        base_path = persistence.io_dir('proc_service_data', io_conf)
        chain_path = '{0:s}/{1:s}'.format(base_path, chain)
        persistence.create_dir(chain_path)
        self.logger.debug('Persisting process services in "{path}".',
                          path=chain_path)
        try:
            # remove old symlink
            os.remove('{}/latest'.format(base_path))
        except OSError:
            pass
        try:
            # create new symlink
            os.symlink(chain, '{}/latest'.format(base_path))
        except OSError as exc:
            self.logger.fatal(
                'Unable to create symlink to latest version of services: <{path}/latest>.',
                path=base_path)
            raise exc

        # remove old data
        service_paths = glob.glob('{}/*.pkl'.format(chain_path))
        try:
            for path in service_paths:
                os.remove(path)
        except Exception as exc:
            self.logger.fatal(
                'Unable to remove previously persisted process services.')
            raise exc

        # persist services
        for cls in self.get_services():
            self.service(cls).persist_in_file('{0:s}/{1!s}.pkl'.format(
                chain_path, cls))
Example #2
0
    def initialize(self):
        """Inititialize the TruncExpFit execution"""

        # check input arguments
        self.check_arg_types(read_key=str,
                             max_var_data_key=str,
                             model_name=str,
                             results_path=str)
        self.check_arg_vals('read_key', 'model_name')

        # create process-manager and service instances
        proc_mgr = ProcessManager()
        settings = proc_mgr.service(ConfigObject)
        rfm = proc_mgr.service(RooFitManager)

        # check if model exists
        model = rfm.model(self.model_name)
        if not model:
            self.log().warning(
                'Model "{}" does not exist; creating with default values'.
                format(self.model_name))
            model = rfm.model(self.model_name, model_cls=TruncExponential)

        # check if model PDF has been built
        if not model.is_built:
            model.build_model()

        # process command arguments for fit function
        self._fit_cmd_args = create_roofit_opts(
            'fit', ConditionalObservables=model.max_var_set, **self.kwargs)

        # get path to results directory
        if not self.results_path:
            self.results_path = persistence.io_dir('results_data',
                                                   settings.io_conf())
        persistence.create_dir(self.results_path)

        return StatusCode.Success
Example #3
0
 def _process_results_path(self):
     """Process results_path argument."""
     if not self.results_path:
         self.results_path = persistence.io_path('results_data', 'report')
     persistence.create_dir(self.results_path)