TpcData.cxx
Go to the documentation of this file.
1 // TpcData.cxx
2 
4 
5 using std::cout;
6 using std::endl;
7 
8 //**********************************************************************
9 
10 TpcData::TpcData() : m_parent(nullptr) { }
11 
12 //**********************************************************************
13 
14 TpcData::TpcData(Index npla) : m_parent(nullptr), m_adcs(npla) {
15  for ( Index ipla=0; ipla<npla; ++ipla ) m_adcs[ipla].reset(new AdcChannelDataMap);
16 }
17 
18 //**********************************************************************
19 
20 TpcData::TpcData(const AdcDataVector& adcs) : m_parent(nullptr), m_adcs(adcs) { }
21 
22 //**********************************************************************
23 
24 TpcData* TpcData::addTpcData(Name nam, bool copyAdcData) {
25  if ( nam == "" || nam == "." ) return nullptr;
26  Name::size_type ipos = nam.rfind("/");
27  if ( ipos != Name::npos ) {
28  TpcData* pdat = getTpcData(nam.substr(0, ipos));
29  if ( pdat == nullptr ) return nullptr;
30  return pdat->addTpcData(nam.substr(ipos+1), copyAdcData);
31  }
32 
33  if ( m_dat.count(nam) ) return nullptr;
34  TpcData& tpc = m_dat[nam];
35  if ( copyAdcData ) tpc.m_adcs = m_adcs;
36  tpc.m_parent = this;
37  return &tpc;
38 }
39 
40 //**********************************************************************
41 
43  if ( nam == "" || nam == "." ) return this;
44  Name::size_type ipos = nam.find("/");
45  if ( ipos == Name::npos ) return m_dat.count(nam) ? &m_dat[nam] : nullptr;
46  TpcData* pdat = getTpcData(nam.substr(0,ipos));
47  if ( pdat == nullptr ) return nullptr;
48  return pdat->getTpcData(nam.substr(ipos+1));
49 }
50 
51 
52 //**********************************************************************
53 
55  Index nerr = 0;
56  if ( nam == "" || nam == "." ) {
57  out.push_back(this);
58  return 0;
59  }
60  if ( nam == "*" ) {
61  for ( TpcDataMap::value_type& idat : m_dat ) {
62  out.push_back(&idat.second);
63  }
64  return 0;
65  }
66  // Split nam --> dnam/rnam
67  Name::size_type ipos = nam.find("/");
68  if ( ipos == Name::npos ) {
69  TpcData* pdat = getTpcData(nam);
70  if ( pdat == nullptr ) ++nerr;
71  else out.push_back(pdat);
72  } else {
73  Name dnam = nam.substr(0,ipos);
74  Name rnam = ipos == Name::npos ? "" : nam.substr(ipos+1);
75  TpcDataVector dirs;
76  nerr += getTpcData(dnam, dirs);
77  for ( TpcData* pdat : dirs ) nerr += pdat->getTpcData(rnam, out);
78  }
79  return nerr;
80 }
81 
82 //**********************************************************************
83 
84 const TpcData* TpcData::getTpcData(Name nam) const {
85  if ( nam == "" || nam == "." ) return this;
86  Name::size_type ipos = nam.find("/");
87  if ( ipos == Name::npos ) {
88  TpcDataMap::const_iterator idat = m_dat.find(nam);
89  if ( idat == m_dat.end() ) return nullptr;
90  return &idat->second;
91  }
92  const TpcData* pdat = getTpcData(nam.substr(0,ipos));
93  if ( pdat == nullptr ) return nullptr;
94  return pdat->getTpcData(nam.substr(ipos+1));
95 }
96 
97 //**********************************************************************
98 
100  return addAdcData(AdcDataPtr(new AdcChannelDataMap), updateParent);
101 }
102 
103 //**********************************************************************
104 
106  m_adcs.push_back(padc);
107  if ( updateParent && m_parent != nullptr ) m_parent->addAdcData(padc, true);
108  return padc;
109 }
110 
111 //**********************************************************************
112 
114  m_adcs.clear();
115 }
116 
117 //**********************************************************************
118 
119 std::ostream& TpcData::print(Name prefix, Index depth) const {
120  Index nmap = getAdcData().size();
121  cout << prefix << "ADC Channel map count is " << nmap;
122  if ( nmap ) cout << ":";
123  cout << endl;
124  for ( const AdcDataPtr& pacm : getAdcData() ) {
125  if ( ! pacm ) cout << "NULL" << endl;
126  else {
127  cout << prefix << " " << "Channel count " << pacm->size();
128  if ( pacm->size() ) {
129  cout << " in range [" << pacm->begin()->first << ", " << pacm->rbegin()->first << "]";
130  }
131  cout << endl;
132  }
133  }
134  cout << prefix << "2D ROI count is " << get2dRois().size() << endl;
135  cout << prefix << "TPC data count is " << getData().size();
136  if ( getData().size() ) cout << ":";
137  cout << endl;
138  if ( depth > 0 ) {
139  for ( const TpcDataMap::value_type& itpd : getData() ) {
140  cout << prefix << itpd.first << ":" << endl;
141  itpd.second.print(prefix + " ", depth - 1);
142  }
143  }
144  return cout;
145 }
146 
147 //**********************************************************************
AdcDataVector m_adcs
Definition: TpcData.h:101
TpcData * m_parent
Definition: TpcData.h:99
AdcDataPtr addAdcData(AdcDataPtr padc, bool updateParent=true)
Definition: TpcData.cxx:105
std::ostream & print(Name prefix, Index depth=10) const
Definition: TpcData.cxx:119
std::shared_ptr< AdcChannelDataMap > AdcDataPtr
Definition: TpcData.h:35
intermediate_table::const_iterator const_iterator
TpcData * addTpcData(Name nam, bool copyAdcData=true)
Definition: TpcData.cxx:24
std::vector< TpcData * > TpcDataVector
Definition: TpcData.h:33
TpcDataMap & getData()
Definition: TpcData.h:53
AdcDataVector & getAdcData()
Definition: TpcData.h:55
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
QTextStream & reset(QTextStream &s)
std::string Name
Definition: TpcData.h:30
TpcDataMap m_dat
Definition: TpcData.h:100
void clearAdcData()
Definition: TpcData.cxx:113
TpcData * getTpcData(Name nam)
Definition: TpcData.cxx:42
std::vector< AdcDataPtr > AdcDataVector
Definition: TpcData.h:36
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 & get2dRois()
Definition: TpcData.h:57
QTextStream & endl(QTextStream &s)