Classes | Public Types | Public Member Functions | Private Attributes | List of all members
AdcRoiToTree Class Reference

#include <AdcRoiToTree.h>

Inheritance diagram for AdcRoiToTree:
TpcDataTool

Classes

struct  TreeData
 

Public Types

using Name = std::string
 
using NameVector = std::vector< Name >
 
using Index = unsigned int
 
using IndexVector = std::vector< Index >
 
using FloatVector = std::vector< float >
 

Public Member Functions

 AdcRoiToTree (fhicl::ParameterSet const &ps)
 
 ~AdcRoiToTree () override
 
DataMap viewMap (const AdcChannelDataMap &acds) const override
 
bool updateWithView () const override
 
Name treeName () const
 

Private Attributes

int m_LogLevel
 
Name m_OutFile
 
NameVector m_MetadataFields
 

Additional Inherited Members

- Private Types inherited from AdcChannelTool
using Index = unsigned int
 
- Private Member Functions inherited from TpcDataTool
virtual DataMap updateTpcData (TpcData &) const
 
virtual DataMap viewTpcData (const TpcData &) const
 
virtual int forwardTpcData () const
 
- Private Member Functions inherited from AdcChannelTool
virtual ~AdcChannelTool ()=default
 
virtual DataMap update (AdcChannelData &) const
 
virtual DataMap view (const AdcChannelData &acd) const
 
virtual DataMap updateMap (AdcChannelDataMap &acds) const
 
virtual bool viewWithUpdate () const
 
virtual DataMap beginEvent (const DuneEventInfo &) const
 
virtual DataMap endEvent (const DuneEventInfo &) const
 
virtual DataMap close (const DataMap *dmin=nullptr)
 
- Static Private Member Functions inherited from AdcChannelTool
static int interfaceNotImplemented ()
 

Detailed Description

Definition at line 22 of file AdcRoiToTree.h.

Member Typedef Documentation

Definition at line 30 of file AdcRoiToTree.h.

using AdcRoiToTree::Index = unsigned int

Definition at line 28 of file AdcRoiToTree.h.

Definition at line 29 of file AdcRoiToTree.h.

Definition at line 26 of file AdcRoiToTree.h.

Definition at line 27 of file AdcRoiToTree.h.

Constructor & Destructor Documentation

AdcRoiToTree::AdcRoiToTree ( fhicl::ParameterSet const &  ps)

Definition at line 17 of file AdcRoiToTree_tool.cc.

18 : m_LogLevel(ps.get<int>("LogLevel")),
19  m_OutFile(ps.get<Name>("OutFile")),
20  m_MetadataFields(ps.get<NameVector>("MetadataFields"))
21 {
22  const string myname = "AdcRoiToTree::ctor: ";
23  if ( m_LogLevel >=2 ) cout << myname << "Creating output file." << endl;
24  TFile* pfil = TFile::Open(m_OutFile.c_str(), "RECREATE");
25  if ( pfil == nullptr || ! pfil->IsOpen() ) {
26  cout << myname << "ERROR: Unable to create output file " << m_OutFile << endl;
27  } else {
28  TreeData tdat;
29  TTree* ptre = new TTree(treeName().c_str(), "ADC ROIs");
30  ptre->Branch("run", &tdat.run);
31  ptre->Branch("event", &tdat.event);
32  ptre->Branch("channel", &tdat.channel);
33  ptre->Branch("status", &tdat.status);
34  tdat.mdata.resize(m_MetadataFields.size());
35  float* pmd = &tdat.mdata[0];
36  for ( Name mnam : m_MetadataFields ) {
37  ptre->Branch(mnam.c_str(), pmd++);
38  }
39  ptre->Branch("nroi", &tdat.nroi);
40  ptre->Branch("nsam", &tdat.nsam[0], "nsam[nroi]/i");
41  ptre->Branch("isam", &tdat.isam[0], "isam[nroi]/i");
42  ptre->Branch("qroi", &tdat.qroi[0], "qroi[nroi]/F");
43  ptre->Branch("hmin", &tdat.hmin[0], "hmin[nroi]/F");
44  ptre->Branch("hmax", &tdat.hmax[0], "hmax[nroi]/F");
45  ptre->ResetBranchAddresses();
46  ptre->Write();
47  pfil->Close();
48  }
49  delete pfil;
50  // Display the configuration.
51  if ( m_LogLevel>= 1 ) {
52  cout << myname << " LogLevel: " << m_LogLevel << endl;
53  cout << myname << " OutFile: " << m_OutFile << endl;
54  cout << myname << " MetadataFields: [";
55  bool first = true;
56  for ( Name mnam : m_MetadataFields ) {
57  if ( first ) first = false;
58  else cout << ", ";
59  cout << mnam;
60  }
61  cout << "]" << endl;
62  }
63 }
ChannelGroupService::Name Name
Name treeName() const
Definition: AdcRoiToTree.h:58
NameVector m_MetadataFields
Definition: AdcRoiToTree.h:65
static constexpr double ps
Definition: Units.h:99
std::vector< string > NameVector
QTextStream & endl(QTextStream &s)
AdcRoiToTree::~AdcRoiToTree ( )
override

Definition at line 67 of file AdcRoiToTree_tool.cc.

67  {
68  const string myname = "AdcRoiToTree::dtor: ";
69  if ( m_LogLevel >= 1 ) {
70  cout << myname << "Exiting." << endl;
71  TFile* pfil = TFile::Open(m_OutFile.c_str(), "READ");
72  if ( pfil == nullptr || ! pfil->IsOpen() ) {
73  cout << myname << "ERROR: Unable to open output file " << m_OutFile << endl;
74  } else {
75  TTree* ptre = dynamic_cast<TTree*>(pfil->Get(treeName().c_str()));
76  if ( ptre == nullptr ) {
77  cout << myname << "ERROR: Unable to open tree " << treeName() << endl;
78  } else {
79  cout << myname << "Tree entry count is " << ptre->GetEntries() << endl;
80  }
81  }
82  delete pfil;
83  }
84 }
Name treeName() const
Definition: AdcRoiToTree.h:58
QTextStream & endl(QTextStream &s)

Member Function Documentation

Name AdcRoiToTree::treeName ( ) const
inline

Definition at line 58 of file AdcRoiToTree.h.

58 { return "adcrois"; }
bool AdcRoiToTree::updateWithView ( ) const
inlineoverridevirtual

Reimplemented from AdcChannelTool.

Definition at line 55 of file AdcRoiToTree.h.

55 { return true; }
DataMap AdcRoiToTree::viewMap ( const AdcChannelDataMap acds) const
overridevirtual

Reimplemented from AdcChannelTool.

Definition at line 88 of file AdcRoiToTree_tool.cc.

88  {
89  const string myname = "AdcRoiToTree::viewMap: ";
90  DataMap ret;
91  TFile* pfil = TFile::Open(m_OutFile.c_str(), "UPDATE");
92  if ( pfil == nullptr || ! pfil->IsOpen() ) {
93  cout << myname << "ERROR: Unable to open output file " << m_OutFile << endl;
94  return ret.setStatus(1);
95  }
96  TTree* ptre = dynamic_cast<TTree*>(pfil->Get(treeName().c_str()));
97  if ( ptre == nullptr ) {
98  cout << myname << "ERROR: Unable to open tree " << treeName() << endl;
99  return ret.setStatus(2);
100  }
101  Index nfill = 0;
102  Index maxroi = 1000;
103  TreeData tdat;
104  tdat.nsam.resize(maxroi);
105  tdat.isam.resize(maxroi);
106  tdat.qroi.resize(maxroi);
107  tdat.hmin.resize(maxroi);
108  tdat.hmax.resize(maxroi);
109  ptre->SetBranchAddress("run", &tdat.run);
110  ptre->SetBranchAddress("event", &tdat.event);
111  ptre->SetBranchAddress("channel", &tdat.channel);
112  ptre->SetBranchAddress("status", &tdat.status);
113  tdat.mdata.resize(m_MetadataFields.size());
114  float* pmd = &tdat.mdata[0];
115  for ( Name mnam : m_MetadataFields ) {
116  ptre->SetBranchAddress(mnam.c_str(), pmd++);
117  }
118  ptre->SetBranchAddress("nroi", &tdat.nroi);
119  ptre->SetBranchAddress("nsam", &tdat.nsam[0]);
120  ptre->SetBranchAddress("isam", &tdat.isam[0]);
121  ptre->SetBranchAddress("qroi", &tdat.qroi[0]);
122  ptre->SetBranchAddress("hmin", &tdat.hmin[0]);
123  ptre->SetBranchAddress("hmax", &tdat.hmax[0]);
124  //ptre->SetBranchAddress("nsample", pflt, "nsample[nroi]/F");
125  for ( const auto& iacd : acds ) {
126  const AdcChannelData& acd = iacd.second;
127  tdat.run = acd.run();
128  tdat.event = acd.event();
129  tdat.channel = acd.channel();
130  tdat.status = acd.channelStatus();
131  Index idat = 0;
132  for ( Name mnam : m_MetadataFields ) {
133  if ( ! acd.hasMetadata(mnam) ) {
134  cout << myname << "WARNING: Run/event/channel "
135  << acd.run() << "/" << acd.event() << "/" << acd.channel()
136  << " does not have metadata field " << mnam << endl;
137  }
138  tdat.mdata[idat++] = acd.getMetadata(mnam, 0.0);
139  }
140  tdat.nroi = acd.rois.size();
141  Index nroi = std::min(tdat.nroi, maxroi);
142  for ( Index iroi=0; iroi<nroi; ++iroi ) {
143 
144  Index isam1 = acd.rois[iroi].first;
145  Index isam2 = acd.rois[iroi].second;
146  float qroi = 0.0;
147  float hmin = 0.0;
148  float hmax = 0.0;
149  bool haveSamples = false;
150  if ( acd.samples.size() > isam2 ) {
151  for ( Index isam=isam1; isam<=isam2; ++isam ) {
152  float qsam = acd.samples[isam];
153  qroi += qsam;
154  if ( haveSamples ) {
155  if ( qsam < hmin ) hmin = qsam;
156  if ( qsam > hmax ) hmax = qsam;
157  } else {
158  hmin = qsam;
159  hmax = qsam;
160  haveSamples = true;
161  }
162  }
163  } else {
164  cout << myname << "WARNING: Ignoring missing samples for run " << acd.run()
165  << ", event " << acd.event() << ", channel " << acd.channel() << endl;
166  }
167  tdat.nsam[iroi] = 1 + isam2 - isam1;
168  tdat.isam[iroi] = isam1;
169  tdat.qroi[iroi] = qroi;
170  tdat.hmin[iroi] = hmin;
171  tdat.hmax[iroi] = hmax;
172  }
173  if ( m_LogLevel >= 3 ) {
174  cout << myname << "Filling run " << tdat.run << ", event " << tdat.event
175  << ", channel " << tdat.channel << ", nroi " << tdat.nroi << endl;
176  if ( m_LogLevel >= 4 ) {
177  string spre = myname + " nsam: [";
178  for ( Index iroi=0; iroi<nroi; ++iroi ) {
179  cout << spre;
180  cout << tdat.nsam[iroi];
181  spre = ", ";
182  }
183  cout << "]" << endl;
184  spre = myname + " isam: [";
185  for ( Index iroi=0; iroi<nroi; ++iroi ) {
186  cout << spre;
187  cout << tdat.isam[iroi];
188  spre = ", ";
189  }
190  cout << "]" << endl;
191  spre = myname + " qroi: [";
192  for ( Index iroi=0; iroi<nroi; ++iroi ) {
193  cout << spre;
194  cout << tdat.qroi[iroi];
195  spre = ", ";
196  }
197  cout << "]" << endl;
198  }
199  }
200  ptre->Fill();
201  }
202  ptre->ResetBranchAddresses();
203  ptre->Write();
204  gDirectory->Purge();
205  pfil->Close();
206  delete pfil;
207  ret.setInt("art_nfill", nfill);
208  return ret;
209 }
DataMap & setStatus(int stat)
Definition: DataMap.h:130
ChannelGroupService::Name Name
unsigned int Index
Name treeName() const
Definition: AdcRoiToTree.h:58
NameVector m_MetadataFields
Definition: AdcRoiToTree.h:65
AdcRoiVector rois
bool hasMetadata(Name mname) const
AdcIndex run() const
float getMetadata(Name mname, float def=0.0) const
void setInt(Name name, int val)
Definition: DataMap.h:131
AdcIndex event() const
Index channelStatus() const
Channel channel() const
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
AdcSignalVector samples
QTextStream & endl(QTextStream &s)

Member Data Documentation

int AdcRoiToTree::m_LogLevel
private

Definition at line 63 of file AdcRoiToTree.h.

NameVector AdcRoiToTree::m_MetadataFields
private

Definition at line 65 of file AdcRoiToTree.h.

Name AdcRoiToTree::m_OutFile
private

Definition at line 64 of file AdcRoiToTree.h.


The documentation for this class was generated from the following files: