docs: def smart_run(job_ini, oqparam, log_level, log_file, exports, reuse_hazard):
      """
      Run calculations by storing their hazard checksum and reusing previous
      calculations if requested.
      """
      haz_checksum = readinput.get_checksum32(oqparam, hazard=True)
      # retrieve an old calculation with the right checksum, if any
      job = logs.dbcmd('get_job_from_checksum', haz_checksum)
      reuse = reuse_hazard and job and os.path.exists(job.ds_calc_dir + '.hdf5')
      # recompute the hazard and store the checksum
      ebr = (oqparam.calculation_mode == 'event_based_risk' and
             'gmfs' not in oqparam.inputs)
      if ebr:
          kw = dict(calculation_mode='event_based')
          if (oqparam.sites or 'sites' in oqparam.inputs or
                  'site_model' in oqparam.inputs):
              # remove exposure from the hazard
              kw['exposure_file'] = ''
      else:
          kw = {}
      if not reuse:
          hc_id = run_job(job_ini, log_level, log_file, exports, **kw)
          if job is None:
              logs.dbcmd('add_checksum', hc_id, haz_checksum)
          elif not reuse_hazard or not os.path.exists(job.ds_calc_dir + '.hdf5'):
              logs.dbcmd('update_job_checksum', hc_id, haz_checksum)
          if ebr:
              run_job(job_ini, log_level, log_file,
                      exports, hazard_calculation_id=hc_id)
      else:
          hc_id = job.id
          logging.info('Reusing job #%d', job.id)
          run_job(job_ini, log_level, log_file,
                  exports, hazard_calculation_id=hc_id)