31 cout << myname <<
" chan toff samples" <<
endl;
32 for (
auto& iacd : acm ) {
36 if ( dochk && pacmchk->count(icha) == 0 ) {
40 const AdcChannelData* pacdchk = dochk ? &pacmchk->find(icha)->second :
nullptr;
48 if ( first ) first =
false;
51 if ( pacdchk->
samples.size() <= isam ||
52 fabs(pacdchk->
samples[isam] - sam ) > 1.e-5 ) ++nerr;
58 for (
bool sig : acd.
signal ) cout << (sig ?
"X" :
".");
62 cout << myname <<
" chan nROI ROIs" <<
endl;
63 for (
auto& iacd : acm ) {
66 cout << myname <<
setw(6) << icha <<
setw(6) << acd.
rois.size() <<
":";
69 if ( first ) first =
false;
71 cout <<
" " << roi.first <<
"-" << roi.second;
83 cout << myname <<
setw(6) << icha <<
":";
86 if ( first ) first =
false;
89 cout <<
setw(6) << roi.
value(icha, isam, 8888);
99 const string myname =
"test_Roi2dToAdc: ";
101 cout << myname <<
"NDEBUG must be off." <<
endl;
104 string line =
"-----------------------------";
106 cout << myname << line <<
endl;
107 string fclfile =
"test_Roi2dToAdc.fcl";
108 if ( ! useExistingFcl ) {
109 cout << myname <<
"Creating top-level FCL." <<
endl;
110 ofstream
fout(fclfile.c_str());
111 fout <<
"#include \"dataprep_tools.fcl\"" <<
endl;
113 fout <<
" tool_type: Roi2dToAdc" <<
endl;
118 cout << myname <<
"Using existing top-level FCL." <<
endl;
121 cout << myname << line <<
endl;
122 cout << myname <<
"Fetching tool manager." <<
endl;
124 assert ( ptm !=
nullptr );
129 cout << myname << line <<
endl;
130 cout << myname <<
"Create test data." <<
endl;
143 tpd.
get2dRois().emplace_back(ncha, ntckroi, icha0, itck0+tckoff);
151 for (
Index kcha=0; kcha<ncha; ++kcha, ++dtck ) {
152 Index icha = icha0 + kcha;
158 float val = 10*(kcha + 1);
165 acdchk.
samples.resize(ntck, 0.0);
166 for (
Index ktck=tckoff; ktck<tckoff+3; ++ktck, ++idxs[1] ) {
167 roi.data().setValue(idxs, val);
169 if ( acdchk.
rois.size() == 0 ) {
170 acdchk.
rois.push_back({ktck, ktck});
172 acdchk.
rois.back().second = ktck;
175 acdchk.
signal.resize(ntck,
false);
176 Index isig1 = tckoff > kcha ? tckoff - kcha : 0;
178 for (
Index ktck=isig1; ktck<isig2; ++ktck ) {
179 acdchk.
signal[ktck] =
true;
184 assert( tpd.
getAdcData()[0]->size() == ncha );
187 assert( acd.
samples.size() == ntck );
189 assert( roi.channelSize() == ncha );
190 assert( roi.channelOffset() == icha0 );
191 assert( roi.sampleSize() == ntckroi );
192 assert( roi.sampleOffset() == itck0 + tckoff );
194 cout << myname << line <<
endl;
195 cout << myname <<
"Check ROI data." <<
endl;
197 assert( &tpd.
get2dRois().front() == &roi );
199 cout << myname << line <<
endl;
201 cout << myname << line <<
endl;
202 cout << myname <<
"Check ADC data before tool:" <<
endl;
208 cout << myname << line <<
endl;
209 cout << myname <<
"Expected data after tool:" <<
endl;
212 cout << myname << line <<
endl;
213 cout << myname <<
"Fetching tool." <<
endl;
215 assert( ptoo !=
nullptr );
217 cout << myname << line <<
endl;
218 cout << myname <<
"Call tool." <<
endl;
219 DataMap res = ptoo->updateTpcData(tpd);
221 assert( res.
status() == 0 );
223 cout << myname << line <<
endl;
224 cout << myname <<
"Check ADC data after tool." <<
endl;
227 assert(
showAdcMap(acm, myname, &acmchk) == 0 );
228 assert( res.
getInt(
"r2a_nchaZeroed") ==
int(ncha) );
229 assert( res.
getInt(
"r2a_nchaFilled") ==
int(ncha) );
230 assert( res.
getInt(
"r2a_nsamZeroed") ==
int(ncha*ntck) );
231 assert( res.
getInt(
"r2a_nsamFilled") ==
int(nsig) );
233 cout << myname << line <<
endl;
234 cout << myname <<
"Done." <<
endl;
241 bool useExistingFcl =
false;
243 string sarg(argv[1]);
244 if ( sarg ==
"-h" ) {
245 cout <<
"Usage: " << argv[0] <<
" [ARG]" <<
endl;
246 cout <<
" If ARG = true, existing FCL file is used." <<
endl;
249 useExistingFcl = sarg ==
"true" || sarg ==
"1";
int main(int argc, char *argv[])
std::pair< AdcIndex, AdcIndex > AdcRoi
std::shared_ptr< AdcChannelDataMap > AdcDataPtr
void print(std::ostream *pout) const
std::shared_ptr< const EventInfo > EventInfoPtr
int showRoi(const Tpc2dRoi &roi, string myname)
AdcDataVector & getAdcData()
float value(Index icha, LongIndex itck, float valdef=0.0) const
void setChannelInfo(ChannelInfoPtr pchi)
std::array< Index, 2 > IndexArray
AdcLongIndex tickOffset() const
void setEventInfo(EventInfoPtr pevi)
Index channelOffset() const
Q_EXPORT QTSManip setw(int w)
int showAdcMap(const AdcChannelDataMap &acm, string myname, const AdcChannelDataMap *pacmchk=0)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
int getInt(Name name, int def=0) const
void line(double t, double *p, double &x, double &y, double &z)
Index channelSize() const
AdcDataPtr createAdcData(bool updateParent=true)
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
LongIndex sampleOffset() const
int test_Roi2dToAdc(bool useExistingFcl=false)
Tpc2dRoiVector & get2dRois()
QTextStream & endl(QTextStream &s)