All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PMTconfigurationExtractor.cxx
Go to the documentation of this file.
1 /**
2  * @file icaruscode/Decode/DecoderTools/PMTconfigurationExtractor.cxx
3  * @brief Utility to extract PMT readout configuration from data.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date February 18, 2021
6  * @see icaruscode/Decode/DecoderTools/PMTconfigurationExtractor.h
7  */
8 
9 
10 // ICARUS libraries
12 
13 // C/C++ standard libraries
14 #include <algorithm> // std::find_if()
15 #include <memory> // std::unique_ptr<>
16 
17 
18 
19 // -----------------------------------------------------------------------------
20 // --- icarus::PMTconfigurationExtractorBase
21 // -----------------------------------------------------------------------------
22 fhicl::ParameterSet
24  fhicl::ParameterSet const& container,
25  std::string const& configListKey,
26  std::initializer_list<std::regex const> components // TODO template with matcher functor
27 ) {
28 
29  fhicl::ParameterSet const sourceConfig
30  = container.get<fhicl::ParameterSet>(configListKey);
31 
32  fhicl::ParameterSet configDocs;
33  for (auto const& key: sourceConfig.get_names()) {
34  if (!sourceConfig.is_key_to_atom(key)) continue;
35 
36  if (!matchKey(key, components.begin(), components.end())) continue;
37 
38  std::string const psetStr = sourceConfig.get<std::string>(key);
39 
40  fhicl::ParameterSet pset;
41  try {
42  pset = fhicl::ParameterSet::make(psetStr);
43  }
44  catch (cet::exception& e) {
45  throw cet::exception{ "convertConfigurationDocuments", "", e }
46  << "Error parsing the content of key '" << configListKey << "." << key
47  << "'; content was:\n" << psetStr << "\n";
48  }
49 
50  configDocs.put(key, pset);
51 
52  } // for all main keys
53 
54  return configDocs;
55 } // convertConfigurationDocuments()
56 
57 
58 
59 // -----------------------------------------------------------------------------
60 // --- icarus::PMTconfigurationExtractor
61 // -----------------------------------------------------------------------------
62 std::vector<std::regex> const
64  { std::regex{ "icaruspmt.*" } }
65  ;
66 
67 // -----------------------------------------------------------------------------
69  (fhicl::ParameterSet const& pset, std::string const& key)
70 {
71  return matchKey(key, ConfigurationNames.begin(), ConfigurationNames.end());
72 } // icarus::PMTconfigurationExtractor::isGoodConfiguration()
73 
74 
75 // -----------------------------------------------------------------------------
77  (fhicl::ParameterSet const& pset) const
78 {
79 
80  sbn::PMTconfiguration config;
81 
82  for (std::string const& key: pset.get_names()) {
83 
84  std::optional<fhicl::ParameterSet> boardConfig
85  = readBoardConfig(pset, key);
86 
87  if (!boardConfig) continue;
88 
89  config.boards.push_back(extractV1730configuration(*boardConfig, key));
90 
91  } // for
92 
93  return config;
94 } // icarus::PMTconfigurationExtractor::extract()
95 
96 
97 // -----------------------------------------------------------------------------
99  (fhicl::ParameterSet const& pset, std::string const& boardName) const
101 {
102 
103  auto const& boardParams
104  = pset.get<fhicl::ParameterSet>("daq.fragment_receiver");
105 
106  sbn::V1730Configuration rc; // readout config, for friends
107  rc.boardName = boardName;
108 
109  rc.boardID = boardParams.get<unsigned int>("board_id");
110  rc.fragmentID = boardParams.get<unsigned int>("fragment_id");
111 
112  rc.bufferLength = boardParams.get<int>("recordLength");
113  rc.postTriggerFrac = boardParams.get<float>("postPercent") / 100.0f;
114 
115  rc.nChannels = boardParams.get<unsigned int>("nChannels");
116 
117  rc.useTimeTagForTimeStamp = boardParams.get("UseTimeTagForTimeStamp", false);
118 
119  for (unsigned short int channelNo = 0; channelNo < 16; ++channelNo)
120  rc.channels.push_back(extractChannelConfiguration(boardParams, channelNo));
121 
122  return rc;
123 } // icarus::PMTconfigurationExtractor::extractV1730configuration()
124 
125 
126 // -----------------------------------------------------------------------------
129  (fhicl::ParameterSet const& boardPSet, unsigned short int channelNo) const
130 {
131  std::string const ChannelStr = std::to_string(channelNo);
132 
134 
135  channel.channelNo = channelNo;
136 
137  channel.baseline = boardPSet.get<short signed int>
138  ("BaselineCh" + std::to_string(channelNo + 1));
139  channel.threshold = boardPSet.get<short signed int>
140  ("triggerThreshold" + ChannelStr);
141  channel.enabled = boardPSet.get<bool>("channelEnable" + ChannelStr);
142 
143  return channel;
144 } // icarus::PMTconfigurationExtractor::extractChannelConfiguration()
145 
146 
147 // ---------------------------------------------------------------------------
149  (sbn::PMTconfiguration config) const
150 {
151 
152  for (sbn::V1730Configuration& readoutBoardConfig: config.boards) {
153  auto const fragmentID = readoutBoardDBfragmentID(readoutBoardConfig);
154  if (!fChannelMap->hasPMTDigitizerID(fragmentID)) {
155  mf::LogWarning("PMTconfigurationExtractor")
156  << "No entry found in PMT channel mapping database for board '"
157  << readoutBoardConfig.boardName << "' (fragment ID: "
158  << readoutBoardConfig.fragmentID << " => " << std::hex << fragmentID
159  << ")\n";
160  continue;
161  }
162 
163  icarusDB::DigitizerChannelChannelIDPairVec const& digitizerChannelVec
164  = fChannelMap->getChannelIDPairVec(fragmentID);
165 
166  // finds the channel ID matching the specified channel number of this board
167  auto const toChannelID = [&channelIDs=digitizerChannelVec]
168  (short unsigned int channelNo)
169  {
170  auto const it = std::find_if(channelIDs.begin(), channelIDs.end(),
171  [channelNo](auto const& p){ return p.first == channelNo; });
172  return (it != channelIDs.end())
173  ? it->second
175  ;
176  };
177 
178  for (auto& channelInfo: readoutBoardConfig.channels)
179  channelInfo.channelID = toChannelID(channelInfo.channelNo);
180 
181  } // for boards
182 
183  return config;
184 } // icarus::PMTconfigurationExtractor::finalize()
185 
186 
187 // -----------------------------------------------------------------------------
188 std::optional<fhicl::ParameterSet>
190  (fhicl::ParameterSet const& pset, std::string const& key) const
191 {
192  static std::string const ExpectedFragmentType = "CAENV1730";
193 
194  std::optional<fhicl::ParameterSet> config;
195 
196  do { // fake loop for fast exit
197 
198  // it must be a parameter set
199  if (!pset.has_key(key) || !pset.is_key_to_table(key)) break;
200 
201  auto boardPSet = pset.get<fhicl::ParameterSet>(key);
202 
203  // its "fragment_type" must be the expected one
204  std::string fragmentType;
205  if (!boardPSet.get_if_present("daq.fragment_receiver.fragment_type", fragmentType))
206  break;
207  if (fragmentType != ExpectedFragmentType) break;
208 
209  config.emplace(std::move(boardPSet)); // success
210  } while (false);
211  return config;
212 } // icarus::PMTconfigurationExtractor::readBoardConfig()
213 
214 
215 // -----------------------------------------------------------------------------
216 // --- free functions implementation
217 // -----------------------------------------------------------------------------
219  (std::string const& srcFileName, icarus::PMTconfigurationExtractor extractor)
220 {
221  //
222  // TFile::Open() call is needed to support non-local URL
223  // (e.g. XRootD URL are not supported by TFile constructor).
224  //
226  std::unique_ptr<TFile>{ TFile::Open(srcFileName.c_str(), "READ") }
227  ),
228  std::move(extractor)
229  );
230 } // icarus::extractPMTreadoutConfiguration(string)
231 
232 
233 // -----------------------------------------------------------------------------
235  (TFile& srcFile, icarus::PMTconfigurationExtractor extractor)
236 {
237 
239  (util::readConfigurationFromArtFile(srcFile), std::move(extractor));
240 
241 } // icarus::extractPMTreadoutConfiguration(TFile)
242 
243 
244 // ---------------------------------------------------------------------------
246  (sbn::V1730Configuration const& boardConfig)
247 {
248  return boardConfig.fragmentID & 0xFF; // secret recipe
249 } // icarus::PMTconfigurationExtractor::readoutBoardDBfragmentID()
250 
251 
252 // -----------------------------------------------------------------------------
253 
std::string boardName
Name (mnemonic) of the board.
std::vector< DigitizerChannelChannelIDPair > DigitizerChannelChannelIDPairVec
static unsigned int readoutBoardDBfragmentID(sbn::V1730Configuration const &boardConfig)
Returns the fragment ID of the specified board as known by the database.
short signed int threshold
Threshold (triggerThreshold&lt;N&gt;).
pdgs p
Definition: selectors.fcl:22
sbn::V1730channelConfiguration extractChannelConfiguration(fhicl::ParameterSet const &boardPSet, unsigned short int channelNo) const
Returns the specified V1730 readout channel configuration.
static std::vector< std::regex > const ConfigurationNames
Regular expressions matching all names of supported PMT configurations.
static fhicl::ParameterSet convertConfigurationDocuments(fhicl::ParameterSet const &container, std::string const &configListKey, std::initializer_list< std::regex const > components)
Returns a parameter set with the content of configuration_documents key from container.
sbn::PMTconfiguration extractPMTreadoutConfiguration(std::string const &srcFileName, icarus::PMTconfigurationExtractor extractor)
std::map< fhicl::ParameterSetID, fhicl::ParameterSet > readConfigurationFromArtFile(TFile &file)
Reads and returns the art configuration stored in sourceDir.
sbn::PMTconfiguration finalize(sbn::PMTconfiguration config) const
Assigns unique channel IDs to the channel information.
unsigned int fragmentID
DAQ fragment ID.
static bool matchKey(std::string const &key, RBegin rbegin, REnd rend)
short unsigned int channelNo
Number of the channel on the board (0-15).
sbn::V1730Configuration extractV1730configuration(fhicl::ParameterSet const &pset, std::string const &boardName) const
Extracts PMT readout board configuration from pset.
static bool isGoodConfiguration(fhicl::ParameterSet const &pset, std::string const &key)
Returns whether the specified key of pset is a good configuration.
std::optional< fhicl::ParameterSet > readBoardConfig(fhicl::ParameterSet const &pset, std::string const &key) const
Returns the specified PMT readout board configuration.
Class to extract PMT readout board configuration.
std::string to_string(WindowPattern const &pattern)
short signed int baseline
Baseline (BaselineCh&lt;N+1&gt;).
Utility to extract PMT readout configuration from data.
do i e
sbn::PMTconfiguration extract(fhicl::ParameterSet const &config) const
Extracts all supported PMT configuration from config.
bool enabled
Channel is enabled (enable).
static constexpr auto NoChannelID
Special value for unassigned channel ID.
std::vector< sbn::V1730channelConfiguration > channels
Configuration of each channel.
Class containing configuration for a V1730 channel.
Class containing configuration for PMT readout.
sbn::PMTconfiguration extractPMTreadoutConfigurationImpl(ConfigMap const &configMap, icarus::PMTconfigurationExtractor extractor)
std::vector< sbn::V1730Configuration > boards
Configuration of all PMT readout boards.
Class containing configuration for a V1730 board.