1 #include "M3DataInterface.hh" 16 int main(
const int argc,
const char** argv )
18 if( argc < 2 || strcmp( argv[1],
"-h" ) == 0 )
20 LINFO(
plog,
"usage:\n" 21 <<
" test_monarch3_write [-h] <output egg file>\n" 22 <<
" -h: print this usage information" );
33 t_hwp->header().SetFilename( argv[1] );
34 t_hwp->header().SetRunDuration( 8675309 );
35 t_hwp->header().SetTimestamp(
"Stardate 33515" );
36 t_hwp->header().SetDescription(
"Bigger on the inside" );
39 unsigned tSSSamples = 10;
40 unsigned tDSSamples = 5;
41 unsigned tTSSamples = 5;
42 unsigned tFlSSamples = 10;
45 LINFO(
plog,
"Adding streams" );
46 unsigned tSingleStreamNum = t_hwp->header().AddStream(
"1-channel device", 500, tSSSamples, 1, 1, sDigitizedUS, 8, sBitsAlignedLeft );
47 unsigned tDoubleStreamNum = t_hwp->header().AddStream(
"2-channel device", 2, sInterleaved, 250, tDSSamples, 1, 2, sDigitizedUS, 16, sBitsAlignedLeft );
48 unsigned tTripleStreamNum = t_hwp->header().AddStream(
"3-channel device", 3, sSeparate, 100, tTSSamples, 1, 1, sDigitizedUS, 8, sBitsAlignedLeft );
49 unsigned tFloatStreamNum = t_hwp->header().AddStream(
"Floating-point device", 100, tFlSSamples, 1, 4, sAnalog, 8, sBitsAlignedLeft );
55 LINFO(
plog,
"Wrote header:\n" << t_hwp->header() );
57 LINFO(
plog,
"Writing data" );
62 byte_type* tSSData = t_swp0->get_stream_record()->GetData();
63 for(
unsigned iSample = 0; iSample < tSSSamples; ++iSample )
65 tSSData[ iSample ] = 1;
67 if( ! t_swp0->write_record(
true ) )
69 LERROR(
plog,
"Unable to write the record!" );
74 for(
unsigned iSample = 0; iSample < tSSSamples; ++iSample )
76 tSSData[ iSample ] = 10;
78 if( ! t_swp0->write_record(
false ) )
80 LERROR(
plog,
"Unable to write the record!" );
85 t_mwp->finish_stream( tSingleStreamNum );
91 M3DataWriter< uint16_t > tDSData0( t_swp1->get_channel_record( 0 )->GetData(), 2, sDigitizedUS );
92 M3DataWriter< uint16_t > tDSData1( t_swp1->get_channel_record( 1 )->GetData(), 2, sDigitizedUS );
93 for(
unsigned iSample = 0; iSample < tDSSamples; ++iSample )
95 tDSData0.set_at( 1, iSample );
96 tDSData1.set_at( 2, iSample );
98 if( ! t_swp1->write_record(
true ) )
100 LERROR(
plog,
"Unable to write the record!" );
105 for(
unsigned iSample = 0; iSample < tDSSamples; ++iSample )
107 tDSData0.set_at( 1000, iSample );
108 tDSData1.set_at( 2000, iSample );
110 if( ! t_swp1->write_record(
true ) )
112 LERROR(
plog,
"Unable to write the record!" );
117 for(
unsigned iSample = 0; iSample < tDSSamples; ++iSample )
119 tDSData0.set_at( 10000, iSample );
120 tDSData1.set_at( 20000, iSample );
122 if( ! t_swp1->write_record(
false ) )
124 LERROR(
plog,
"Unable to write the record!" );
129 t_mwp->finish_stream( tDoubleStreamNum );
135 byte_type* tTSData0 = t_swp2->get_channel_record( 0 )->GetData();
136 byte_type* tTSData1 = t_swp2->get_channel_record( 1 )->GetData();
137 byte_type* tTSData2 = t_swp2->get_channel_record( 2 )->GetData();
138 for(
unsigned iSample = 0; iSample < tTSSamples; ++iSample )
140 tTSData0[ iSample ] = 1;
141 tTSData1[ iSample ] = 2;
142 tTSData2[ iSample ] = 3;
144 if( ! t_swp2->write_record(
true ) )
146 LERROR(
plog,
"Unable to write the record!" );
151 for(
unsigned iSample = 0; iSample < tTSSamples; ++iSample )
153 tTSData0[ iSample ] = 10;
154 tTSData1[ iSample ] = 20;
155 tTSData2[ iSample ] = 30;
157 if( ! t_swp2->write_record(
false ) )
159 LERROR(
plog,
"Unable to write the record!" );
164 t_mwp->finish_stream( tTripleStreamNum );
170 M3DataWriter< float > tFlSData( t_swp3->get_channel_record( 0 )->GetData(), 4, sAnalog );
171 for(
unsigned iSample = 0; iSample < tFlSSamples; ++iSample )
173 tFlSData.set_at( 3.1415926535898, iSample );
175 if( ! t_swp3->write_record(
true ) )
177 LERROR(
plog,
"Unable to write the record!" );
182 for(
unsigned iSample = 0; iSample < tFlSSamples; ++iSample )
184 tFlSData.set_at( 2.71828182846, iSample );
186 if( ! t_swp3->write_record(
true ) )
188 LERROR(
plog,
"Unable to write the record!" );
193 t_mwp->finish_stream( tFloatStreamNum );
249 t_mwp->finish_file();
250 LINFO(
plog,
"File closed" );
257 LERROR(
plog,
"Exception thrown during write test:\n" << e.
what() );
std::shared_ptr< header_wrapper > header_wrap_ptr
const char * what() const
std::shared_ptr< stream_wrapper > stream_wrap_ptr
int main(const int argc, const char **argv)
static scarab::logger plog("test_monarch3_write")
std::shared_ptr< monarch_wrapper > monarch_wrap_ptr
LOGGER(plog, "egg_writer")
Wrapper class for a monarch3::M3Monarch object.