TpcData.h
Go to the documentation of this file.
1 // TpcData.h
2 //
3 // David Adams
4 // January 2021
5 //
6 // Class to hold TPC data in two formats:
7 // AdcData: Vector of shared pointers to maps of AdcChannelData.
8 // TPC 2D ROIs: Tpc2dRoi objects held in a vector.
9 // Other may be added later.
10 //
11 // The object may also hold named objects of the same type so that data can
12 // can be split by detector region (e.g. TPC plane) or processing stage.
13 // Branches below the first level, are referenced in slash-separated path format
14 // e.g. "apa3/z" refers to TPC data "z" in TPC data "apa3".
15 
16 #ifndef TpcData_H
17 #define TpcData_H
18 
21 #include <string>
22 #include <map>
23 #include <set>
24 
25 class TpcData {
26 
27 public:
28 
29  using Index = unsigned int;
30  using Name = std::string;
31  using Tpc2dRoiVector = std::vector<Tpc2dRoi>;
32  using TpcDataMap = std::map<Name, TpcData>;
33  using TpcDataVector = std::vector<TpcData*>;
35  using AdcDataPtr = std::shared_ptr<AdcChannelDataMap>;
36  using AdcDataVector = std::vector<AdcDataPtr>;
37 
38  // Default ctor.
39  TpcData();
40 
41  // Ctor to create npla AdcChannelData maps.
42  TpcData(Index npla);
43 
44  // Ctor from ADC data.
45  TpcData(const AdcDataVector& adcs);
46 
47  // Copy ctor.
48  TpcData(const TpcData& rhs) =delete;
49 
50  // Accessors.
51  TpcData* getParent() { return m_parent; }
52  const TpcData* getParent() const { return m_parent; }
53  TpcDataMap& getData() { return m_dat; }
54  const TpcDataMap& getData() const { return m_dat; }
56  const AdcDataVector& getAdcData() const { return m_adcs; }
58  const Tpc2dRoiVector& get2dRois() const { return m_2drois; }
59 
60  // Add a named TPC data constituent and return its pointer.
61  // If the name is target/subname, constituent subname is inserted
62  // in constituent target.
63  // Fails and returns null if the name is already used or the
64  // target does not already exist.
65  // If copyAdcData is true, the new object copies the AdcData (pointers).
66  TpcData* addTpcData(Name nam, bool copyAdcData =true);
67 
68  // Return a constituent TPC data object by name.
69  // The name "" or "." returns this object.
70  // If the name is target/subname, constituent subname from
71  // constituent target is returned.
72  TpcData* getTpcData(Name nam);
73  const TpcData* getTpcData(Name nam) const;
74 
75  // Appends named constituent TPC data objects to a vector.
76  // The name "" or "." appends this object.
77  // If the name is a/b/.../z all matching constituents are returned
78  // with "*" used to select all at any level.
79  // Returns non-zero if any errors arise.
81 
82  // Add ADC data.
83  // If updateParent is true, the same object is added to all ancestors.
84  AdcDataPtr createAdcData(bool updateParent =true);
85  AdcDataPtr addAdcData(AdcDataPtr padc, bool updateParent =true);
86 
87  // Delete the ADC data. References in acestor and descendants are not affected.
88  void clearAdcData();
89 
90  // Print a brief description of thid object:
91  // # ADC maps and channels for each.
92  // # 2D ROIS
93  // # constituents
94  // Same for each constituent to the indicated depth.
95  std::ostream& print(Name prefix, Index depth =10) const;
96 
97 private:
98 
103 
104 };
105 
106 #endif
AdcDataVector m_adcs
Definition: TpcData.h:101
const TpcData * getParent() const
Definition: TpcData.h:52
TpcData * m_parent
Definition: TpcData.h:99
AdcDataPtr addAdcData(AdcDataPtr padc, bool updateParent=true)
Definition: TpcData.cxx:105
std::string string
Definition: nybbler.cc:12
std::ostream & print(Name prefix, Index depth=10) const
Definition: TpcData.cxx:119
std::shared_ptr< AdcChannelDataMap > AdcDataPtr
Definition: TpcData.h:35
TpcData * addTpcData(Name nam, bool copyAdcData=true)
Definition: TpcData.cxx:24
TpcData * getParent()
Definition: TpcData.h:51
std::vector< TpcData * > TpcDataVector
Definition: TpcData.h:33
TpcDataMap & getData()
Definition: TpcData.h:53
AdcDataVector & getAdcData()
Definition: TpcData.h:55
AdcChannelDataMap AdcData
Definition: TpcData.h:34
std::string Name
Definition: TpcData.h:30
TpcDataMap m_dat
Definition: TpcData.h:100
const TpcDataMap & getData() const
Definition: TpcData.h:54
void clearAdcData()
Definition: TpcData.cxx:113
TpcData * getTpcData(Name nam)
Definition: TpcData.cxx:42
std::vector< AdcDataPtr > AdcDataVector
Definition: TpcData.h:36
std::vector< Tpc2dRoi > Tpc2dRoiVector
Definition: TpcData.h:31
const AdcDataVector & getAdcData() const
Definition: TpcData.h:56
TpcData()
Definition: TpcData.cxx:10
unsigned int Index
Definition: TpcData.h:29
AdcDataPtr createAdcData(bool updateParent=true)
Definition: TpcData.cxx:99
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
Tpc2dRoiVector m_2drois
Definition: TpcData.h:102
std::map< Name, TpcData > TpcDataMap
Definition: TpcData.h:32
Tpc2dRoiVector & get2dRois()
Definition: TpcData.h:57
const Tpc2dRoiVector & get2dRois() const
Definition: TpcData.h:58