LDMX Software
tracking::reco::TrackerPedestalProvider Class Reference

Conditions provider for the per-channel tracker pedestals/noise. More...

Public Member Functions

 TrackerPedestalProvider (const std::string &name, const std::string &tagname, const framework::config::Parameters &parameters, framework::Process &process)
 
std::pair< const framework::ConditionsObject *, framework::ConditionsIOVgetCondition (const ldmx::EventHeader &) override
 Pure virtual getCondition function.
 
- Public Member Functions inherited from framework::ConditionsObjectProvider
 DECLARE_FACTORY (ConditionsObjectProvider, std::shared_ptr< ConditionsObjectProvider >, const std::string &, const std::string &, const framework::config::Parameters &, Process &)
 declare that we have a factory for these types of classes
 
 ConditionsObjectProvider (const std::string &objname, const std::string &tagname, const framework::config::Parameters &parameters, Process &process)
 Class constructor.
 
virtual ~ConditionsObjectProvider ()=default
 Class destructor.
 
virtual void releaseConditionsObject (const ConditionsObject *co)
 Called by conditions system when done with a conditions object, appropriate point for cleanup.
 
virtual void onProcessStart ()
 Callback for the ConditionsObjectProvider to take any necessary action when the processing of events starts.
 
virtual void onProcessEnd ()
 Callback for the ConditionsObjectProvider to take any necessary action when the processing of events finishes, such as closing database connections.
 
virtual void onNewRun (ldmx::RunHeader &)
 Callback for the ConditionsObjectProvider to take any necessary action when the processing of events starts for a given run.
 
const std::string & getConditionObjectName () const
 Get the list of conditions objects available from this provider.
 
const std::string & getTagName () const
 Access the tag name.
 

Private Member Functions

void loadJson (TrackerPedestals &peds) const
 

Private Attributes

std::string pedestal_file_
 
std::string pedestal_format_ {"json"}
 

Additional Inherited Members

- Protected Member Functions inherited from framework::ConditionsObjectProvider
std::pair< const ConditionsObject *, ConditionsIOVrequestParentCondition (const std::string &name, const ldmx::EventHeader &context)
 Request another condition needed to construct this condition.
 
const Processprocess () const
 Get the process handle.
 
- Protected Attributes inherited from framework::ConditionsObjectProvider
logging::logger the_log_
 The logger for this ConditionsObjectProvider.
 

Detailed Description

Conditions provider for the per-channel tracker pedestals/noise.

Reads the pedestal file written by PedestalCalculator and serves it as a TrackerPedestals conditions object. The storage backend ("json"; future: "sqlite", ...) is selected by the pedestal_format parameter, so the choice of source lives entirely here rather than in any consuming processor.

Definition at line 23 of file TrackerPedestalProvider.cxx.

Constructor & Destructor Documentation

◆ TrackerPedestalProvider()

tracking::reco::TrackerPedestalProvider::TrackerPedestalProvider ( const std::string & name,
const std::string & tagname,
const framework::config::Parameters & parameters,
framework::Process & process )
inline

Definition at line 25 of file TrackerPedestalProvider.cxx.

29 tagname, parameters, process) {
31 EXCEPTION_RAISE("BadConfig",
32 "The name provided to TrackerPedestalProvider '" + name +
33 "' is not the expected '" +
35 }
36 pedestal_file_ = parameters.get<std::string>("pedestal_file");
37 pedestal_format_ =
38 parameters.get<std::string>("pedestal_format", pedestal_format_);
39 }
Base class for all providers of conditions objects.
const Process & process() const
Get the process handle.
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
static const std::string CONDITIONS_NAME
Name of the conditions object (must match the python registration).

Member Function Documentation

◆ getCondition()

std::pair< const framework::ConditionsObject *, framework::ConditionsIOV > tracking::reco::TrackerPedestalProvider::getCondition ( const ldmx::EventHeader & context)
inlineoverridevirtual

Pure virtual getCondition function.

Must be implemented by any Conditions providers.

Implements framework::ConditionsObjectProvider.

Definition at line 42 of file TrackerPedestalProvider.cxx.

42 {
43 auto* peds = new TrackerPedestals();
44
45 // Dispatch on the configured storage backend. Only JSON is supported
46 // today; additional backends (e.g. SQLite) can be added as new load*().
47 if (pedestal_format_ == "json") {
48 loadJson(*peds);
49 } else {
50 EXCEPTION_RAISE("BadConfiguration",
51 "TrackerPedestalProvider unknown pedestal_format '" +
52 pedestal_format_ + "' (supported: 'json').");
53 }
54
55 std::cout << "[TrackerPedestalProvider] Loaded " << peds->size()
56 << " channel pedestals from '" << pedestal_file_ << "'"
57 << std::endl;
58
59 // Pedestals are valid for all runs (data and MC) for now.
60 return {peds, framework::ConditionsIOV(true, true)};
61 }
Class which defines the run/event/type range for which a given condition is valid,...

◆ loadJson()

void tracking::reco::TrackerPedestalProvider::loadJson ( TrackerPedestals & peds) const
inlineprivate

Definition at line 64 of file TrackerPedestalProvider.cxx.

64 {
65 std::ifstream in(pedestal_file_);
66 if (!in) {
67 EXCEPTION_RAISE("FileNotFound",
68 "TrackerPedestalProvider could not open pedestal file '" +
69 pedestal_file_ + "'.");
70 }
71
72 nlohmann::json doc;
73 try {
74 in >> doc;
75 } catch (const nlohmann::json::parse_error& e) {
76 EXCEPTION_RAISE(
77 "BadFormat",
78 "TrackerPedestalProvider failed to parse pedestal file '" +
79 pedestal_file_ + "': " + e.what());
80 }
81
82 // Each channel is keyed "feb:hyb:apv:ch" -> {"mean":[...], "noise":[...]}.
83 for (const auto& [key, ch] : doc.at("channels").items()) {
84 uint8_t feb, hybrid, apv, channel;
85 if (!channelmap::parseChannelKey(key, feb, hybrid, apv, channel))
86 continue;
87 TrackerPedestals::Channel ped;
88 ped.mean_ = ch.at("mean").get<decltype(ped.mean_)>();
89 ped.noise_ = ch.at("noise").get<decltype(ped.noise_)>();
90 peds.add(feb, hybrid, apv, channel, ped);
91 }
92 }
bool parseChannelKey(const std::string &key, uint8_t &feb, uint8_t &hybrid, uint8_t &apv, uint8_t &channel)
Parse a "feb:hybrid:apv:channel" key (as produced by channelKey()) back into its electronics fields.

Member Data Documentation

◆ pedestal_file_

std::string tracking::reco::TrackerPedestalProvider::pedestal_file_
private

Definition at line 94 of file TrackerPedestalProvider.cxx.

◆ pedestal_format_

std::string tracking::reco::TrackerPedestalProvider::pedestal_format_ {"json"}
private

Definition at line 95 of file TrackerPedestalProvider.cxx.

95{"json"};

The documentation for this class was generated from the following file: