All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbndPDMapAlg_tool.cc
Go to the documentation of this file.
2 #include "art/Utilities/ToolMacros.h"
3 #include "art/Utilities/make_tool.h"
4 
5 
6 //------------------------------------------------------------------------------
7 //--- opdet::sbndPDMapAlg implementation
8 //------------------------------------------------------------------------------
9 
10 namespace opdet {
11 
12  sbndPDMapAlg::sbndPDMapAlg(const fhicl::ParameterSet&)
13  {
14  std::string fname;
15  cet::search_path sp("FW_SEARCH_PATH");
16  sp.find_file("sbnd_pds_mapping.json", fname);
17  std::ifstream i(fname, std::ifstream::in);
18  i >> PDmap;
19  i.close();
20  }
21 
23  { }
24 
25  bool sbndPDMapAlg::isPDType(size_t ch, std::string pdname) const
26  {
27  if(PDmap.at(ch)["pd_type"] == std::string(pdname)) return true;
28  return false;
29  }
30 
31  bool sbndPDMapAlg::isElectronics(size_t ch, std::string pdname) const
32  {
33  if(PDmap.at(ch)["electronics"] == std::string(pdname)) return true; // TODO: add number of electronics, daphne01, daphne02, .... ~rodrigoa
34  return false;
35  }
36 
37  std::string sbndPDMapAlg::pdType(size_t ch) const
38  {
39  return PDmap.at(ch)["pd_type"];
40  }
41 
42  std::string sbndPDMapAlg::electronicsType(size_t ch) const
43  {
44  return PDmap.at(ch)["electronics"];
45  }
46 
47  std::vector<int> sbndPDMapAlg::getChannelsOfType(std::string pdname) const
48  {
49  std::vector<int> out_ch_v;
50  for (size_t ch = 0; ch < PDmap.size(); ch++) {
51  if (PDmap.at(ch)["pd_type"] == pdname) out_ch_v.push_back(ch);
52  }
53  return out_ch_v;
54  }
55 
56  std::vector<int> sbndPDMapAlg::getChannelsOfType(std::string pdname,std::string elname) const
57  {//overload to select channels by pdtype AND electronics type ~rodrigoa
58  std::vector<int> out_ch_v;
59  for (size_t ch = 0; ch < PDmap.size(); ch++) {
60  if ((PDmap.at(ch)["pd_type"] == pdname) && (PDmap.at(ch)["electronics"] == elname))out_ch_v.push_back(ch);
61  }
62  return out_ch_v;
63  }
64 
65  size_t sbndPDMapAlg::size() const
66  {
67  return PDmap.size();
68  }
69 
70  auto sbndPDMapAlg::getChannelEntry(size_t ch) const
71  {
72  return PDmap.at(ch);
73  }
74 
75  // template<>
77  {
78  nlohmann::json subSetPDmap;
79  std::copy_if (PDmap.begin(), PDmap.end(), std::back_inserter(subSetPDmap),
80  [property](const nlohmann::json e)->bool
81  {return e[property];} );
82  return subSetPDmap;
83  }
84 
85  // Look in the header for the implementation:
86  // template<typename T>
87  // nlohmann::json sbndPDMapAlg::getCollectionWithProperty(std::string property, T property_value)
88 
89 DEFINE_ART_CLASS_TOOL(sbndPDMapAlg)
90 }
size_t size() const
string fname
Definition: demo.py:5
a class to store JSON values
Definition: json.hpp:2421
iterator end() noexcept
returns an iterator to one past the last element
Definition: json.hpp:18745
iterator begin() noexcept
returns an iterator to the first element
Definition: json.hpp:18674
bool isPDType(size_t ch, std::string pdname) const override
nlohmann::json PDmap
Definition: sbndPDMapAlg.hh:70
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:17519
size_type size() const noexcept
returns the number of elements
Definition: json.hpp:19195
std::vector< int > getChannelsOfType(std::string pdname) const
bool isElectronics(size_t ch, std::string pdname) const
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
std::string electronicsType(size_t ch) const
do i e
auto getChannelEntry(size_t ch) const
nlohmann::json getCollectionWithProperty(std::string property)
std::string pdType(size_t ch) const override