Monarch  v3.8.2
Project 8 Data File Format Library
Monarch2Info.cc
Go to the documentation of this file.
1 #include "M2Monarch.hh"
2 
3 #include "application.hh"
4 #include "logger.hh"
5 
6 #include <cstring>
7 #include <memory>
8 
9 using namespace monarch2;
10 
11 LOGGER( mlog, "Monarch2Info" );
12 
13 int main( const int argc, const char** argv )
14 {
15  scarab::main_app theMain( false );
16 
17  bool tHeaderOnly;
18  std::string tFilename;
19 
20  theMain.add_flag( "-H,--header-only", tHeaderOnly, "Only look at header information; does not check number of records" );
21  theMain.add_option( "Filename", tFilename, "Input egg file" )->required();
22 
23  CLI11_PARSE( theMain, argc, argv );
24 
25  std::shared_ptr< const Monarch2 > tReadTest( Monarch2::OpenForReading( tFilename ) );
26  tReadTest->ReadHeader();
27 
28  const M2Header* tReadHeader = tReadTest->GetHeader();
29  LINFO( mlog, *tReadHeader );
30 
31  if( tHeaderOnly )
32  {
33  tReadTest->Close();
34  return RETURN_SUCCESS;
35  }
36 
37  unsigned int tRecordCount = 0;
38  unsigned int tAcquisiontCount = 0;
39  const M2RecordBytes* tReadRecord;
40  if( tReadHeader->GetAcquisitionMode() == 1 /* the FormatMode is ignored for single-channel data */ )
41  {
42  tReadRecord = tReadTest->GetRecordSeparateOne();
43  }
44  else if( tReadHeader->GetAcquisitionMode() == 2 && tReadHeader->GetFormatMode() == sFormatMultiSeparate )
45  {
46  tReadRecord = tReadTest->GetRecordSeparateOne();
47  }
48  else if( tReadHeader->GetAcquisitionMode() == 2 && tReadHeader->GetFormatMode() == sFormatMultiInterleaved )
49  {
50  tReadRecord = tReadTest->GetRecordInterleaved();
51  }
52  else
53  {
54  LERROR( mlog, "Unable to read a header with acquisition mode <" << tReadHeader->GetAcquisitionMode() << "> and format mode <" << tReadHeader->GetFormatMode() << ">" );
55  return RETURN_ERROR;
56  }
57  try
58  {
59  while( tReadTest->ReadRecord() != false )
60  {
61  tRecordCount = tRecordCount + 1;
62  if( tReadRecord->fAcquisitionId == tAcquisiontCount )
63  {
64  tAcquisiontCount = tAcquisiontCount + 1;
65  }
66  //cout << " record " << tRecordCount << ": time offset: " << tReadRecord->fTime << " ns" << endl;
67  }
68  }
69  catch (M2Exception& e)
70  {
71  LWARN( mlog, "Something went wrong during the reading of records!" << "\n\t" << e.what() );
72  return RETURN_ERROR;
73  }
74  LINFO( mlog, "record count <" << tRecordCount << ">" );
75  LINFO( mlog, "acquisition count <" << tAcquisiontCount << ">" );
76 
77  tReadTest->Close();
78 
79  return RETURN_SUCCESS;
80 }
virtual const char * what() const
Definition: M2Exception.cc:20
FormatModeType GetFormatMode() const
Definition: M2Header.cc:175
static scarab::logger mlog("Monarch2Info")
static const FormatModeType sFormatMultiSeparate
Definition: M2Types.hh:53
AcquisitionIdType fAcquisitionId
Definition: M2Record.hh:12
int main(const int argc, const char **argv)
Definition: Monarch2Info.cc:13
static const FormatModeType sFormatMultiInterleaved
Definition: M2Types.hh:54
static const Monarch2 * OpenForReading(const std::string &filename)
Definition: M2Monarch.cc:62
AcquisitionModeType GetAcquisitionMode() const
Definition: M2Header.cc:196