9 #include "application.hh" 17 using std::stringstream;
19 LOGGER(
mlog,
"M3Info" );
21 template<
typename XDataType >
24 template<
typename XDataType >
27 int main(
const int argc,
const char** argv )
29 scarab::main_app theMain(
false );
32 std::string tFilename;
34 theMain.add_flag(
"-H,--header-only", tHeaderOnly,
"Only look at header information; does not check number of records" );
35 theMain.add_option(
"Filename", tFilename,
"File to read" )->required();
37 CLI11_PARSE( theMain, argc, argv );
41 LPROG(
mlog,
"Opening file <" << tFilename <<
">" );
44 LPROG(
mlog,
"Reading header" );
45 tReadTest->ReadHeader();
47 const M3Header* tReadHeader = tReadTest->GetHeader();
48 LPROG(
mlog, *tReadHeader );
52 tReadTest->FinishReading();
53 return RETURN_SUCCESS;
56 LPROG(
mlog,
"Reading data" );
58 unsigned tNStreams = tReadHeader->GetNStreams();
59 for(
unsigned iStream = 0; iStream < tNStreams; ++iStream )
61 const M3StreamHeader& tStrHeader = tReadHeader->StreamHeaders().at( iStream );
62 unsigned tNChannels = tStrHeader.GetNChannels();
64 LPROG(
mlog,
"Stream " << iStream <<
" has " << tNChannels <<
" channel(s) stored in format mode " << tStrHeader.GetChannelFormat() );
66 const M3Stream* tStream = tReadTest->GetStream( iStream );
68 if( tStream->GetNAcquisitions() == 0 )
70 LPROG(
mlog,
"\tThis stream has no acquisitions" );
74 const unsigned tMaxRecords = 2;
75 for(
unsigned iRec = 0; iRec < tMaxRecords; ++iRec )
77 if( ! tStream->ReadRecord() )
79 throw M3Exception() <<
"There was a problem reading a record from this stream";
81 switch( tStrHeader.GetDataFormat() )
84 if( ! PrintChannelsReal< uint64_t >( tStream,
sDigitizedUS ) )
86 throw M3Exception() <<
"Problem printing channels (int)";
90 if( ! PrintChannelsReal< int64_t >( tStream,
sDigitizedS ) )
92 throw M3Exception() <<
"Problem printing channels (int)";
96 switch( tStream->GetSampleSize() )
99 if( ! PrintChannelsReal< double >( tStream,
sAnalog ) )
101 throw M3Exception() <<
"Problem printing channels (float)" ;
105 switch( tStream->GetDataTypeSize() )
108 if( ! PrintChannelsComplex< f4_complex >( tStream,
sAnalog ) )
110 throw M3Exception() <<
"Problem printing channels (float-complex)" ;
114 if( ! PrintChannelsComplex< f8_complex >( tStream,
sAnalog ) )
116 throw M3Exception() <<
"Problem printing channels (float-complex)";
120 throw M3Exception() <<
"Invalid data type size: " << tStream->GetDataTypeSize();
124 throw M3Exception() <<
"Invalid sample size: " << tStream->GetSampleSize();
128 throw M3Exception() <<
"Invalid data format: "<<tStrHeader.GetDataFormat();
134 tReadTest->FinishReading();
138 LERROR(
mlog,
"Exception thrown during file reading:\n" << e.
what() );
142 return RETURN_SUCCESS;
145 template<
typename XDataType >
148 const unsigned tMaxSamples = 30;
150 for(
unsigned iChan = 0; iChan < aStream->
GetNChannels(); ++iChan )
154 stringstream tDataOut;
155 for(
unsigned iSample = 0; iSample < std::min( tMaxSamples, tRecSize ); ++iSample )
157 tDataOut << tDataInterface.
at( iSample );
158 if( iSample != tRecSize - 1 ) tDataOut <<
", ";
160 if( tRecSize > tMaxSamples ) tDataOut <<
" . . .";
161 LPROG(
mlog,
"\tChannel " << iChan <<
": " << tDataOut.str() );
166 template<
typename XDataType >
169 const unsigned tMaxSamples = 30;
171 for(
unsigned iChan = 0; iChan < aStream->
GetNChannels(); ++iChan )
175 stringstream tDataOut;
176 for(
unsigned iSample = 0; iSample < std::min( tMaxSamples, tRecSize ); ++iSample )
178 tDataOut << tDataInterface.
at( iSample );
179 if( iSample != tRecSize - 1 ) tDataOut <<
", ";
181 if( tRecSize > tMaxSamples ) tDataOut <<
" . . .";
182 LPROG(
mlog,
"\tChannel " << iChan <<
": " << tDataOut.str() );
const ReturnType & at(unsigned index) const
static const Monarch3 * OpenForReading(const std::string &filename)
static const uint32_t sDigitizedUS
bool PrintChannelsComplex(const M3Stream *aStream, uint32_t aDataFormat)
unsigned GetSampleSize() const
unsigned GetChannelRecordSize() const
unsigned GetNChannels() const
virtual const char * what() const
ReturnType at(unsigned index) const
static const uint32_t sDigitizedS
Read/write access for a data stream.
const byte_type * GetData() const
Specialized exception class for Monarch3.
bool PrintChannelsReal(const M3Stream *aStream, uint32_t aDataFormat)
static scarab::logger mlog("M3Header")
const M3Record * GetChannelRecord(unsigned aChannel) const
Get the pointer to a particular channel record.
Interface class for complex data types.
int main(const int argc, const char **argv)
Interface class for a variety of data types.
static const uint32_t sAnalog
unsigned GetDataTypeSize() const