14 #include "art_root_io/TFileService.h"
15 #include "art/Framework/Principal/Event.h"
16 #include "art/Framework/Core/EDAnalyzer.h"
17 #include "art/Framework/Core/ModuleMacros.h"
18 #include "canvas/Persistency/Provenance/ProcessHistory.h"
20 #include "messagefacility/MessageLogger/MessageLogger.h"
21 #include "fhiclcpp/types/Atom.h"
22 #include "fhiclcpp/ParameterSetRegistry.h"
71 Name(
"includePreviousProcesses"),
72 Comment(
"Also save configuration of all previous processes in the input file"),
87 virtual void analyze(art::Event
const& event)
override;
100 (std::string
const& procName, fhicl::ParameterSet
const& config);
109 (art::Event
const& event, std::string
const& procName);
116 (std::string
const& procName);
123 (fhicl::ParameterSet
const& pset, std::string
const& procName);
134 bool has_table(fhicl::ParameterSet
const& pset, std::string
const&
name)
135 {
return pset.has_key(name) && pset.is_key_to_table(name); }
137 bool has_sequence(fhicl::ParameterSet
const& pset, std::string
const& name)
138 {
return pset.has_key(name) && pset.is_key_to_sequence(name); }
140 bool has_atom(fhicl::ParameterSet
const& pset, std::string
const& name)
141 {
return pset.has_key(name) && pset.is_key_to_atom(name); }
148 : art::EDAnalyzer(config)
149 , fIncludePreviousProcesses(config().includePreviousProcesses())
156 std::string
const procName = processName();
162 MF_LOG_DEBUG(
"SaveConfigurationIntoTFile")
163 <<
"This process: '" << procName <<
"':\n"
164 << std::string(80,
'=') <<
'\n'
165 << pset.to_indented_string()
166 <<
'\n' << std::string(80,
'=');
170 mf::LogInfo(
"SaveConfigurationIntoTFile")
171 <<
"Configuration of current process ('" << procName
172 <<
"') stored via TFileService.";
184 for (
auto const& procConfigInfo: event.processHistory()) {
185 std::string
const& procName = procConfigInfo.processName();
190 mf::LogInfo(
"SaveConfigurationIntoTFile")
191 <<
"Configuration of process '" << procName
192 <<
"' from input file stored via TFileService.";
202 std::string
const& procName, fhicl::ParameterSet
const& config
207 storeString(procName, config.to_indented_string());
216 (art::Event
const& event, std::string
const& procName)
218 fhicl::ParameterSet pset;
219 event.getProcessParameterSet(procName, pset);
226 (std::string
const& key, std::string
const&
value)
240 auto const& fs = *(art::ServiceHandle<art::TFileService>());
241 fs.makeAndRegister<TNamed>(key.c_str(), value.c_str());
248 (std::string
const& procName)
266 static std::string
const rootKey {
"process_name" };
268 fhicl::ParameterSet
const* rootConfig =
nullptr;
270 auto const& pset = idAndSet.second;
271 if (isProcessConfiguration(pset, procName)) {
273 throw art::Exception(art::errors::LogicError)
274 <<
"Found two candidate process parameter sets: with " << rootKey
275 <<
" '" << rootConfig->get<std::string>(rootKey) <<
"' and '"
276 << pset.get<std::string>(rootKey) <<
"'!\n";
282 throw art::Exception(art::errors::LogicError)
283 <<
"No parameter set with 'process_name' atom found!\n";
292 (fhicl::ParameterSet
const& pset)
309 if (!::has_table (pset,
"services" ))
return false;
310 if (!::has_table (pset,
"physics" ))
return false;
311 if (!::has_table (pset,
"source" ))
return false;
312 if (!::has_atom (pset,
"process_name"))
return false;
313 if (!::has_sequence(pset,
"physics.trigger_paths"))
return false;
314 if (!::has_sequence(pset,
"physics.end_paths"))
return false;
322 (fhicl::ParameterSet
const& pset, std::string
const& procName)
324 if (!isProcessConfiguration(pset))
return false;
325 return pset.get<std::string>(
"process_name") == procName;
art::EDAnalyzer::Table< Config > Parameters
std::set< std::string > fProcessedProcesses
Process names already saved.
bool isProcessConfigurationSaved(std::string const &procName) const
Returns whether we have already saved configuration for procName.
static fhicl::ParameterSet currentProcessConfiguration(std::string const &procName)
Returns the configuration of the current art process.
virtual void beginJob() override
Writes the configuration information of the current process.
static void storeString(std::string const &key, std::string const &value)
Saves a string via TFileService (as TNamed).
void saveProcessConfiguration(std::string const &procName, fhicl::ParameterSet const &config)
Writes the specified configuration into a ROOT directory.
BEGIN_PROLOG vertical distance to the surface Name
SaveConfigurationIntoTFile(Parameters const &config)
Standard art analyzer moduel constructor.
static bool isProcessConfiguration(fhicl::ParameterSet const &pset)
Returns whether the specified one is a process configuration.
fhicl::Atom< bool > includePreviousProcesses
virtual void analyze(art::Event const &event) override
Writes the configuration information of the input processes.
Writes the art configuration into the TFileService file.
static fhicl::ParameterSet processConfiguration(art::Event const &event, std::string const &procName)
Extracts the configuration of the specified process from event.
bool fIncludePreviousProcesses
Whether to save the configuration of the input file.