7 #include "application.hh" 16 using std::stringstream;
18 LOGGER(
mlog,
"M3ReadTest" );
26 int main(
const int argc,
const char** argv )
28 scarab::main_app theMain(
false );
31 std::string tFilename;
32 theMain.add_flag(
"-H,--header-only", tHeaderOnly,
"Only look at header information; does not check number of records" );
33 theMain.add_option(
"Filename", tFilename,
"File to read" )->required();
35 CLI11_PARSE( theMain, argc, argv );
39 LINFO(
mlog,
"Opening file <" << tFilename );
42 LINFO(
mlog,
"Reading header" );
43 tReadTest->ReadHeader();
45 const M3Header* tReadHeader = tReadTest->GetHeader();
46 LINFO(
mlog, *tReadHeader );
50 tReadTest->FinishReading();
51 return RETURN_SUCCESS;
54 LINFO(
mlog,
"Reading data" );
56 LINFO(
mlog,
"Test 1: reading 2 sequential 1-channel records from stream 0");
57 LINFO(
mlog,
"\tRecord 0 has values '1'" );
58 LINFO(
mlog,
"\tRecord 1 has values '10'" );
60 const M3Stream* tStream0 = tReadTest->GetStream( 0 );
63 LINFO(
mlog,
"Stream 0 has " << tNAcquisitions0 <<
" acquisitions and " << tNRecords0 <<
" records" );
64 const M3StreamHeader& tStrHeader0 = tReadHeader->StreamHeaders().at( 0 );
65 unsigned tNChannels0 = tStrHeader0.GetNChannels();
67 LINFO(
mlog,
"Stream 0 has " << tNChannels0 <<
" channel(s) stored in format mode " << tStrHeader0.GetChannelFormat() );
68 if( tNAcquisitions0 != 1 || tNChannels0 != 1 || tNRecords0 != 2 )
70 LERROR(
mlog,
"Invalid number of acquisitions (1 expected), channels (1 expected), or records (2 expected)" );
74 for(
unsigned iRec = 0; iRec < tNRecords0; ++iRec )
76 LINFO(
mlog,
"Checking record " << iRec );
79 LERROR(
mlog,
"Failed read record check" );
84 LINFO(
mlog,
"Test 1 complete\n" );
88 LINFO(
mlog,
"Test 2: using non-zero reading offsets");
89 LINFO(
mlog,
"\tRecord 0 has values '1' and '2'" );
90 LINFO(
mlog,
"\tRecord 1 has values '1000' and '2000'" );
91 LINFO(
mlog,
"\tRecord 2 has values '10000' and '20000'" );
93 const M3Stream* tStream1 = tReadTest->GetStream( 1 );
96 LINFO(
mlog,
"Stream 1 has " << tNAcquisitions1 <<
" acquisitions and " << tNRecords1 <<
" records" );
97 const M3StreamHeader& tStrHeader1 = tReadHeader->StreamHeaders().at( 1 );
98 unsigned tNChannels1 = tStrHeader1.GetNChannels();
100 LINFO(
mlog,
"Stream 1 has " << tNChannels1 <<
" channel(s) stored in format mode " << tStrHeader1.GetChannelFormat() );
101 if( tNAcquisitions1 != 2 || tNChannels1 != 2 || tNRecords1 != 3 )
103 LERROR(
mlog,
"Invalid number of acquisitions (2 expected), channels (2 expected), or records (3 expected)" );
107 LINFO(
mlog,
"Read the first record (record 0)" );
110 LERROR(
mlog,
"Failed read record check" );
114 LINFO(
mlog,
"Skip to the third record, crossing to the next acquisition (record 2; acquisition 1)" );
117 LERROR(
mlog,
"Failed read record check" );
121 LINFO(
mlog,
"Reread the third record (record 2; acquisition 1)" );
124 LERROR(
mlog,
"Failed read record check" );
128 LINFO(
mlog,
"Go backwards to the second record (record 1; acquisition 1)" );
131 LERROR(
mlog,
"Failed read record check" );
135 LINFO(
mlog,
"Go backwards to the first record (record 1; acquisition 0)" );
138 LERROR(
mlog,
"Failed read record check" );
142 LINFO(
mlog,
"Reread the first record (record 1; acquisition 0)" );
145 LERROR(
mlog,
"Failed read record check" );
149 LINFO(
mlog,
"Request record beyond the end of the file" );
152 LERROR(
mlog,
"Record read did not fail" );
156 LINFO(
mlog,
"Test 2 complete\n" );
160 LINFO(
mlog,
"Test 3: using non-zero reading offset to skip the first record");
161 LINFO(
mlog,
"\tRecord 0 has values '1', '2', and '3'" );
162 LINFO(
mlog,
"\tRecord 1 has values '10', '20', and '30'" );
164 const M3Stream* tStream2 = tReadTest->GetStream( 2 );
167 LINFO(
mlog,
"Stream 2 has " << tNAcquisitions2 <<
" acquisitions and " << tNRecords2 <<
" records" );
168 const M3StreamHeader& tStrHeader2 = tReadHeader->StreamHeaders().at( 2 );
169 unsigned tNChannels2 = tStrHeader2.GetNChannels();
171 LINFO(
mlog,
"Stream 2 has " << tNChannels2 <<
" channel(s) stored in format mode " << tStrHeader2.GetChannelFormat() );
172 if( tNAcquisitions2 != 1 || tNChannels2 != 3 || tNRecords2 != 2 )
174 LERROR(
mlog,
"Invalid number of acquisitions (1 expected), channels (3 expected), or records (2 expected)" );
178 LINFO(
mlog,
"Skipping immediately to the second record (record 1)" );
181 LERROR(
mlog,
"Failed read record check" );
185 LINFO(
mlog,
"Request record before the beginning of the file" );
188 LERROR(
mlog,
"Record read did not fail" );
192 LINFO(
mlog,
"Test 3 complete\n" );
195 LINFO(
mlog,
"Test 4: reading 2 sequential 1-channel floating-point records from stream 3");
196 LINFO(
mlog,
"\tRecord 0 has values '3.1415926535898'" );
197 LINFO(
mlog,
"\tRecord 1 has values '2.71828182846'" );
199 const M3Stream* tStream3 = tReadTest->GetStream( 3 );
202 LINFO(
mlog,
"Stream 3 has " << tNAcquisitions3 <<
" acquisitions and " << tNRecords3 <<
" records" );
203 const M3StreamHeader& tStrHeader3 = tReadHeader->StreamHeaders().at( 3 );
204 unsigned tNChannels3 = tStrHeader3.GetNChannels();
206 LINFO(
mlog,
"Stream 3 has " << tNChannels3 <<
" channel(s) stored in format mode " << tStrHeader3.GetChannelFormat() );
207 if( tNAcquisitions3 != 2 || tNChannels3 != 1 || tNRecords3 != 2 )
209 LERROR(
mlog,
"Invalid number of acquisitions (2 expected), channels (1 expected), or records (2 expected)" );
213 for(
unsigned iRec = 0; iRec < tNRecords3; ++iRec )
215 LINFO(
mlog,
"Checking record " << iRec );
218 LERROR(
mlog,
"Failed read record check" );
223 LINFO(
mlog,
"Test 4 complete\n" );
262 tReadTest->FinishReading();
266 LERROR(
mlog,
"Exception thrown during file reading:\n" << e.
what() );
270 return RETURN_SUCCESS;
277 LERROR(
mlog,
"Failed to read record" );
281 switch( aDataFormat )
286 LERROR(
mlog,
"Failed to print channels (digitized)" );
293 LERROR(
mlog,
"Failed to print channels (digitized)" );
303 LERROR(
mlog,
"Problem printing channels (float)" );
310 LERROR(
mlog,
"Problem printing channels (float-complex)" );
317 LERROR(
mlog,
"Invalid data format" );
327 const unsigned tMaxSamples = 30;
328 for(
unsigned iChan = 0; iChan < aStream->
GetNChannels(); ++iChan )
332 stringstream tDataOut;
333 for(
unsigned iSample = 0; iSample < std::min( tMaxSamples, tRecSize ); ++iSample )
335 tDataOut << tDataInterface.
at( iSample );
336 if( iSample != tRecSize - 1 ) tDataOut <<
", ";
338 if( tRecSize > tMaxSamples ) tDataOut <<
" . . .";
339 LINFO(
mlog,
"\tChannel " << iChan <<
": " << tDataOut.str() );
347 const unsigned tMaxSamples = 30;
348 for(
unsigned iChan = 0; iChan < aStream->
GetNChannels(); ++iChan )
352 stringstream tDataOut;
353 for(
unsigned iSample = 0; iSample < std::min( tMaxSamples, tRecSize ); ++iSample )
355 tDataOut << tDataInterface.
at( iSample );
356 if( iSample != tRecSize - 1 ) tDataOut <<
", ";
358 if( tRecSize > tMaxSamples ) tDataOut <<
" . . .";
359 LINFO(
mlog,
"\tChannel " << iChan <<
": " << tDataOut.str() );
367 const unsigned tMaxSamples = 30;
368 for(
unsigned iChan = 0; iChan < aStream->
GetNChannels(); ++iChan )
372 stringstream tDataOut;
373 for(
unsigned iSample = 0; iSample < std::min( tMaxSamples, tRecSize ); ++iSample )
375 tDataOut << tDataInterface.
at( iSample );
376 if( iSample != tRecSize - 1 ) tDataOut <<
", ";
378 if( tRecSize > tMaxSamples ) tDataOut <<
" . . .";
379 LINFO(
mlog,
"\tChannel " << iChan <<
": " << tDataOut.str() );
387 const unsigned tMaxSamples = 30;
392 for(
unsigned iChan = 0; iChan < aStream->
GetNChannels(); ++iChan )
396 stringstream tDataOut;
397 for(
unsigned iSample = 0; iSample < std::min( tMaxSamples, tRecSize ); ++iSample )
399 tDataOut <<
"(" << tDataInterface.
at( iSample )[ 0 ] <<
", " << tDataInterface.at( iSample )[ 1 ] <<
")";
400 if( iSample != tRecSize - 1 ) tDataOut <<
", ";
402 if( tRecSize > tMaxSamples ) tDataOut <<
" . . .";
403 LINFO(
mlog,
"\tChannel " << iChan <<
": " << tDataOut.str() );
407 for(
unsigned iChan = 0; iChan < aStream->
GetNChannels(); ++iChan )
411 stringstream tDataOut;
412 for(
unsigned iSample = 0; iSample < std::min( tMaxSamples, tRecSize ); ++iSample )
414 tDataOut <<
"(" << tDataInterface.
at( iSample )[ 0 ] <<
", " << tDataInterface.at( iSample )[ 1 ] <<
")";
415 if( iSample != tRecSize - 1 ) tDataOut <<
", ";
417 if( tRecSize > tMaxSamples ) tDataOut <<
" . . .";
418 LINFO(
mlog,
"\tChannel " << iChan <<
": " << tDataOut.str() );
422 LERROR(
mlog,
"Cannot print channels for complex floating-point data with type size " << aStream->
GetDataTypeSize() );
const ReturnType & at(unsigned index) const
unsigned GetNRecordsInFile() const
static const Monarch3 * OpenForReading(const std::string &filename)
static const uint32_t sDigitizedUS
unsigned GetSampleSize() const
unsigned GetChannelRecordSize() const
unsigned GetNChannels() const
virtual const char * what() const
int main(const int argc, const char **argv)
ReturnType at(unsigned index) const
bool PrintChannelsUInt(const M3Stream *aStream)
bool PrintChannelsFloatComplex(const M3Stream *aStream)
bool ReadRecord(int anOffset=0, bool aIfNewAcqStartAtFirstRec=true) const
Read the next record from the file.
unsigned GetNAcquisitions() const
static const uint32_t sDigitizedS
Read/write access for a data stream.
bool PrintChannelsInt(const M3Stream *aStream)
const byte_type * GetData() const
Specialized exception class for Monarch3.
static scarab::logger mlog("M3Header")
const M3Record * GetChannelRecord(unsigned aChannel) const
Get the pointer to a particular channel record.
bool ReadRecordCheck(const M3Stream *aStream, int aOffset, unsigned aDataFormat)
Interface class for complex data types.
Interface class for a variety of data types.
static const uint32_t sAnalog
bool PrintChannelsFloat(const M3Stream *aStream)
unsigned GetDataTypeSize() const