18 : m_LogLevel(ps.
get<
int>(
"LogLevel")),
19 m_OutFile(ps.
get<
Name>(
"OutFile")),
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;
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);
35 float* pmd = &tdat.
mdata[0];
37 ptre->Branch(mnam.c_str(), pmd++);
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();
54 cout << myname <<
" MetadataFields: [";
57 if ( first ) first =
false;
68 const string myname =
"AdcRoiToTree::dtor: ";
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;
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;
79 cout << myname <<
"Tree entry count is " << ptre->GetEntries() <<
endl;
89 const string myname =
"AdcRoiToTree::viewMap: ";
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;
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;
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);
114 float* pmd = &tdat.
mdata[0];
116 ptre->SetBranchAddress(mnam.c_str(), pmd++);
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]);
125 for (
const auto& iacd : acds ) {
132 for (
Name mnam : m_MetadataFields ) {
134 cout << myname <<
"WARNING: Run/event/channel " 136 <<
" does not have metadata field " << mnam <<
endl;
142 for (
Index iroi=0; iroi<nroi; ++iroi ) {
149 bool haveSamples =
false;
150 if ( acd.
samples.size() > isam2 ) {
151 for (
Index isam=isam1; isam<=isam2; ++isam ) {
152 float qsam = acd.
samples[isam];
155 if ( qsam < hmin ) hmin = qsam;
156 if ( qsam > hmax ) hmax = qsam;
164 cout << myname <<
"WARNING: Ignoring missing samples for run " << acd.
run()
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;
174 cout << myname <<
"Filling run " << tdat.
run <<
", event " << tdat.
event 177 string spre = myname +
" nsam: [";
178 for (
Index iroi=0; iroi<nroi; ++iroi ) {
180 cout << tdat.
nsam[iroi];
184 spre = myname +
" isam: [";
185 for (
Index iroi=0; iroi<nroi; ++iroi ) {
187 cout << tdat.
isam[iroi];
191 spre = myname +
" qroi: [";
192 for (
Index iroi=0; iroi<nroi; ++iroi ) {
194 cout << tdat.
qroi[iroi];
202 ptre->ResetBranchAddresses();
207 ret.
setInt(
"art_nfill", nfill);
DataMap & setStatus(int stat)
NameVector m_MetadataFields
bool hasMetadata(Name mname) const
float getMetadata(Name mname, float def=0.0) const
void setInt(Name name, int val)
static constexpr double ps
Index channelStatus() const
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
auto const & get(AssnsNode< L, R, D > const &r)
DataMap viewMap(const AdcChannelDataMap &acds) const override
QTextStream & endl(QTextStream &s)
std::vector< Name > NameVector
AdcRoiToTree(fhicl::ParameterSet const &ps)