bool JPetParamBankHandlerTask::generateParamBankFromConfig(const JPetParams& params)
{
  using namespace jpet_options_tools;
  auto options = params.getOptions();

  if (getRunNumber(options) == -1 || !isLocalDB(options)) {
    ERROR("LocalDB and run number are required for Hld, HldRoot or Scope files");
    return false;
  }

  auto paramMgr = params.getParamManager();
  if (!paramMgr) {
    ERROR("Param manager is not set");
    return false;
  }
  auto runNum = getRunNumber(options);
  if (runNum >= 0) {
    try {
      paramMgr->fillParameterBank(runNum);
    } catch (const std::exception& e) {
      ERROR(std::string("Param bank was not generated correctly with error: ") + e.what() + "\n The run number used:" + JPetCommonTools::intToString(runNum));
      return false;
    }
    if (isLocalDBCreate(options)) {
      JPetParamSaverAscii saver;
      saver.saveParamBank(paramMgr->getParamBank(), runNum, getLocalDBCreate(options));
    }
  }
  return true;
}
bool JPetTaskChainExecutorUtils::process(const JPetOptions& options, JPetParamManager* paramMgr, std::list<JPetTaskRunnerInterface*>& tasks)
{
  assert(paramMgr);
  auto runNum = options.getRunNumber();
  if (runNum >= 0) {
    try {
      paramMgr->fillParameterBank(runNum);
    } catch (...) {
      ERROR("Param bank was not generated correctly.\n The run number used:" + JPetCommonTools::intToString(runNum));
      return false;
    }
    if (options.isLocalDBCreate()) {
      JPetParamSaverAscii saver;
      saver.saveParamBank(paramMgr->getParamBank(), runNum, options.getLocalDBCreate());
    }
  }
  auto inputFile = options.getInputFile();
  auto inputFileType = options.getInputFileType();
  if (inputFileType == JPetOptions::kScope) {
    if (!createScopeTaskAndAddToTaskList(options, paramMgr, tasks)) {
      ERROR("Scope task not added correctly!!!");
      return false;
    }
  } else if (inputFileType == JPetOptions::kHld) {
    unpackFile(inputFile, options.getTotalEvents());
  }
  /// Assumption that if the file is zipped than it is in the hld format
  /// and we will also unpack if from hld  after unzipping.
  else if ( inputFileType == JPetOptions::kZip) {
    INFO( std::string("Unzipping file before unpacking") );
    if ( !unzipFile(inputFile) ) {
      ERROR( std::string("Problem with unpacking file: ") + inputFile );
      return false;
    } else {
      INFO( std::string("Unpacking") );
      auto unzippedFilename = JPetCommonTools::stripFileNameSuffix(std::string(inputFile)).c_str();
      unpackFile(unzippedFilename, options.getTotalEvents());
    }
  }

  if (options.getInputFileType() == JPetOptions::kUndefinedFileType)
    ERROR( Form("Unknown file type provided for file: %s", options.getInputFile()) );
  return true;
}