From d9039444d65b06e51731180c8e648c3dd6aeade1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?BiaoZhang=20=28=E5=BC=A0=E5=BD=AA=29?= <52267892+zhangbiao-phy@users.noreply.github.com> Date: Mon, 16 Feb 2026 19:08:30 +0100 Subject: [PATCH] Update producerCharmHadronsTrackFemtoDream.cxx --- .../producerCharmHadronsTrackFemtoDream.cxx | 76 ++++++++----------- 1 file changed, 31 insertions(+), 45 deletions(-) diff --git a/PWGHF/HFC/TableProducer/producerCharmHadronsTrackFemtoDream.cxx b/PWGHF/HFC/TableProducer/producerCharmHadronsTrackFemtoDream.cxx index 1d5c88fc543..b5bcd1a492f 100644 --- a/PWGHF/HFC/TableProducer/producerCharmHadronsTrackFemtoDream.cxx +++ b/PWGHF/HFC/TableProducer/producerCharmHadronsTrackFemtoDream.cxx @@ -302,56 +302,42 @@ struct HfProducerCharmHadronsTrackFemtoDream { bool useDstarMl = doprocessDataDstarToD0PiWithML || doprocessMcDstarToD0PiWithML; if (applyMlMode == FillMlFromNewBDT) { - if (useLcMl) { - hfMlResponseLc.configure(binsPtMl, cutsMl, cutDirMl, nClassesMl); - hfMlResponseLc.cacheInputFeaturesIndices(namesInputFeatures); - hfMlResponseLc.init(); - } - if (useDplusMl) { - hfMlResponseDplus.configure(binsPtMl, cutsMl, cutDirMl, nClassesMl); - hfMlResponseDplus.cacheInputFeaturesIndices(namesInputFeatures); - hfMlResponseDplus.init(); - } - if (useD0Ml) { - hfMlResponseD0.configure(binsPtMl, cutsMl, cutDirMl, nClassesMl); - hfMlResponseD0.cacheInputFeaturesIndices(namesInputFeatures); - hfMlResponseD0.init(); - } - if (useDstarMl) { - hfMlResponseDstar.configure(binsPtMl, cutsMl, cutDirMl, nClassesMl); - hfMlResponseDstar.cacheInputFeaturesIndices(namesInputFeatures); - hfMlResponseDstar.init(); - } - if (loadModelsFromCCDB) { - ccdbApi.init(ccdbUrl); - if (useLcMl) { - hfMlResponseLc.setModelPathsCCDB(onnxFileNames, ccdbApi, modelPathsCCDB, timestampCCDB); - } - if (useDplusMl) { - hfMlResponseDplus.setModelPathsCCDB(onnxFileNames, ccdbApi, modelPathsCCDB, timestampCCDB); - } - if (useD0Ml) { - hfMlResponseD0.setModelPathsCCDB(onnxFileNames, ccdbApi, modelPathsCCDB, timestampCCDB); - } - if (useDstarMl) { - hfMlResponseDstar.setModelPathsCCDB(onnxFileNames, ccdbApi, modelPathsCCDB, timestampCCDB); + auto setupFeatures = [&](auto& hfResponse, bool useMlFlag) { + if (!useMlFlag) { + return; } + hfResponse.configure(binsPtMl, cutsMl, cutDirMl, nClassesMl); + hfResponse.cacheInputFeaturesIndices(namesInputFeatures); + }; - } else { - if (useLcMl) { - hfMlResponseLc.setModelPathsLocal(onnxFileNames); - } - if (useDplusMl) { - hfMlResponseDplus.setModelPathsLocal(onnxFileNames); - } - if (useD0Ml) { - hfMlResponseD0.setModelPathsLocal(onnxFileNames); + setupFeatures(hfMlResponseLc, useLcMl); + setupFeatures(hfMlResponseDplus, useDplusMl); + setupFeatures(hfMlResponseD0, useD0Ml); + setupFeatures(hfMlResponseDstar, useDstarMl); + + const bool useAnyMl = useLcMl || useDplusMl || useD0Ml || useDstarMl; + if (loadModelsFromCCDB && useAnyMl) { + ccdbApi.init(ccdbUrl); + } + + auto initModel = [&](auto& hfResponse, bool useMlFlag) { + if (!useMlFlag) { + return; } - if (useDstarMl) { - hfMlResponseDstar.setModelPathsLocal(onnxFileNames); + + if (loadModelsFromCCDB) { + hfResponse.setModelPathsCCDB(onnxFileNames, ccdbApi, modelPathsCCDB, timestampCCDB); + } else { + hfResponse.setModelPathsLocal(onnxFileNames); } - } + hfResponse.init(); + }; + + initModel(hfMlResponseLc, useLcMl); + initModel(hfMlResponseDplus, useDplusMl); + initModel(hfMlResponseD0, useD0Ml); + initModel(hfMlResponseDstar, useDstarMl); } }