diff --git a/PWGLF/TableProducer/Strangeness/strangenessbuilder.cxx b/PWGLF/TableProducer/Strangeness/strangenessbuilder.cxx index 22bc5c6a6e6..c38c792f5e1 100644 --- a/PWGLF/TableProducer/Strangeness/strangenessbuilder.cxx +++ b/PWGLF/TableProducer/Strangeness/strangenessbuilder.cxx @@ -301,6 +301,9 @@ struct StrangenessBuilder { Configurable mc_findableMode{"mc_findableMode", 0, "0: disabled; 1: add findable-but-not-found to existing V0s from AO2D; 2: reset V0s and generate only findable-but-not-found"}; + // Autoconfigure process functions + Configurable autoConfigureProcess{"autoConfigureProcess", false, "if true, will configure process function switches based on metadata"}; + // V0 building options struct : ConfigurableGroup { std::string prefix = "v0BuilderOpts"; @@ -2646,6 +2649,75 @@ struct StrangenessBuilder { WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) { + auto strangenessBuilderTask = adaptAnalysisTask(cfgc); + bool isRun3 = true, hasRunInfo = false; + bool isMC = false, hasDataTypeInfo = false; + if (cfgc.options().hasOption("aod-metadata-Run") == true) { + hasRunInfo = true; + if (cfgc.options().get("aod-metadata-Run") == "2") { + isRun3 = false; + } + } + if (cfgc.options().hasOption("aod-metadata-DataType") == true) { + hasDataTypeInfo = true; + if (cfgc.options().get("aod-metadata-DataType") == "MC") { + isMC = true; + } + } + + int idxSwitches[8]; // 8 switches (real / real r2 / MC / MC r2 + PID) + bool autoConfigureProcessConfig = true; + bool withPID = false; + + for (size_t ipar = 0; ipar < strangenessBuilderTask.options.size(); ipar++) { + auto option = strangenessBuilderTask.options[ipar]; + if (option.name == "processRealData") { + idxSwitches[0] = ipar; + } + if (option.name == "processRealDataRun2") { + idxSwitches[1] = ipar; + } + if (option.name == "processMonteCarlo") { + idxSwitches[2] = ipar; + } + if (option.name == "processMonteCarloRun2") { + idxSwitches[3] = ipar; + } + if (option.name == "processRealDataWithPID") { + idxSwitches[4] = ipar; + } + if (option.name == "processRealDataRun2WithPID") { + idxSwitches[5] = ipar; + } + if (option.name == "processMonteCarloWithPID") { + idxSwitches[6] = ipar; + } + if (option.name == "processMonteCarloRun2WithPID") { + idxSwitches[7] = ipar; + } + if (option.name == "autoConfigureProcess") { + autoConfigureProcessConfig = option.defaultValue.get(); // check if autoconfig requested + } + // use withPID in case preselection is requested + if (option.name == "preSelectOpts.preselectOnlyDesiredV0s" || option.name == "preSelectOpts.preselectOnlyDesiredCascades") { + withPID = withPID || option.defaultValue.get(); + } + } + if ((!hasRunInfo || !hasDataTypeInfo) && autoConfigureProcessConfig) { + throw std::runtime_error("Autoconfigure requested but no metadata information found! Please check if --aod-file was used in the last workflow added in the execution and if the AO2D in question has metadata saved in it."); + } + + // positions of switches are known. Next: flip if asked for + if (autoConfigureProcessConfig) { + int relevantProcess = static_cast(!isRun3) + 2 * static_cast(isMC) + 4 * static_cast(withPID); + LOGF(info, "Automatic configuration of process switches requested! Autodetected settings: isRun3? %i, isMC? %i, withPID? %i (switch #%i)", hasRunInfo, hasDataTypeInfo, isRun3, isMC, withPID, relevantProcess); + for (size_t idx = 0; idx < 8; idx++) { + auto option = strangenessBuilderTask.options[idxSwitches[idx]]; + option.defaultValue = false; // switch all off + } + strangenessBuilderTask.options[idxSwitches[relevantProcess]].defaultValue = true; + } + return WorkflowSpec{ - adaptAnalysisTask(cfgc)}; + strangenessBuilderTask}; }