WirePlaneId.h
Go to the documentation of this file.
1 #ifndef WIRECELL_WIREPLANEID
2 #define WIRECELL_WIREPLANEID
3 
4 // fixme: should move into WirePlaneIdCfg.h or similar. (more below)
6 #include <ostream>
7 #include <functional>
8 
9 namespace WireCell {
10 
11 
12  /// Enumerate layer IDs. These are not indices!
15 
16  class WirePlaneId {
17  public:
18  explicit WirePlaneId(WirePlaneLayer_t layer, int face = 0, int apa = 0);
19  explicit WirePlaneId(int packed);
20 
21  /// Unit ID as integer
22  int ident() const;
23 
24  /// Layer as enum
25  WirePlaneLayer_t layer() const;
26 
27  /// Layer as integer (not index!)
28  int ilayer() const;
29 
30  /// Layer as index number (0,1 or 2). -1 if unknown
31  int index() const;
32 
33  /// APA face number
34  int face() const;
35 
36  /// APA number
37  int apa() const;
38 
39  /// return true if valid
40  //operator bool() const;
41  bool valid() const;
42 
43  bool operator==(const WirePlaneId& rhs);
44 
45  bool operator!=(const WirePlaneId& rhs);
46 
47  bool operator<(const WirePlaneId& rhs);
48 
49 
50  private:
51  int m_pack;
52  };
53 
54  std::ostream& operator<<(std::ostream& os, const WireCell::WirePlaneId& wpid);
55  std::ostream& operator<<(std::ostream& o, const WireCell::WirePlaneLayer_t& layer);
56 
57  // fixme: should move into WirePlaneIdCfg.h or similar.
58  template<>
59  inline
60  WireCell::WirePlaneId convert< WireCell::WirePlaneId>(const Configuration& cfg, const WireCell::WirePlaneId& def) {
61  return WireCell::WirePlaneId(iplane2layer[convert<int>(cfg[0])],
62  convert<int>(cfg[1],0), convert<int>(cfg[2], 0));
63  }
64 
65 }
66 
67 // implement hash() so WirePlaneId an be used as a key in unordered STL containers.
68 namespace std {
69  template<>
70  struct hash<WireCell::WirePlaneId> {
71  std::size_t operator()(const WireCell::WirePlaneId& wpid) const {
72  return std::hash<int>()(wpid.ident());
73  }
74  };
75 }
76 
77 #endif
WirePlaneLayer_t layer() const
Layer as enum.
Definition: WirePlaneId.cxx:25
int ident() const
Unit ID as integer.
Definition: WirePlaneId.cxx:21
std::size_t operator()(const WireCell::WirePlaneId &wpid) const
Definition: WirePlaneId.h:71
STL namespace.
cfg
Definition: dbjson.py:29
const WirePlaneLayer_t iplane2layer[3]
Definition: WirePlaneId.h:14
bool operator==(const WirePlaneId &rhs)
Definition: WirePlaneId.cxx:59
int ilayer() const
Layer as integer (not index!)
Definition: WirePlaneId.cxx:29
bool valid() const
return true if valid
Definition: WirePlaneId.cxx:53
Definition: Main.h:22
std::ostream & operator<<(std::ostream &os, const WireCell::WirePlaneId &wpid)
Definition: WirePlaneId.cxx:83
int apa() const
APA number.
Definition: WirePlaneId.cxx:48
bool operator<(const WirePlaneId &rhs)
Definition: WirePlaneId.cxx:69
Json::Value Configuration
Definition: Configuration.h:50
WirePlaneLayer_t
Enumerate layer IDs. These are not indices!
Definition: WirePlaneId.h:13
bool operator!=(const WirePlaneId &rhs)
Definition: WirePlaneId.cxx:64
int convert< int >(const Configuration &cfg, const int &def)
Definition: Configuration.h:74
WirePlaneId(WirePlaneLayer_t layer, int face=0, int apa=0)
Definition: WirePlaneId.cxx:9
int index() const
Layer as index number (0,1 or 2). -1 if unknown.
Definition: WirePlaneId.cxx:34
int face() const
APA face number.
Definition: WirePlaneId.cxx:44