Monarch  v3.8.2
Project 8 Data File Format Library
Monarch3Dump.cpp
Go to the documentation of this file.
1 #include "Monarch.hpp"
2 #include "MonarchLogger.hpp"
3 
4 #include <cstdlib>
5 
6 #include <fstream>
7 using std::ofstream;
8 
9 using namespace monarch;
10 
11 MLOGGER( mlog, "MonarchDump" );
12 
13 int main( const int argc, const char** argv )
14 {
15  if( argc < 3 )
16  {
17  MLINFO( mlog, "usage:\n"
18  << " MonarchDump <input egg file> <output text file> <# of records per channel [optional]>\n"
19  << "# of records is optional; the default is 1; use 0 to dump the whole file" );
20  return -1;
21  }
22 
23  unsigned int nRecords = 1;
24  if( argc >= 4 )
25  {
26  nRecords = atoi( argv[3] );
27  }
28 
29  const Monarch* tReadTest = Monarch::OpenForReading( argv[ 1 ] );
30  tReadTest->ReadHeader();
31  tReadTest->SetInterface( sInterfaceSeparate );
32 
33  const MonarchHeader* tReadHeader = tReadTest->GetHeader();
34  MLINFO( mlog, *tReadHeader );
35 
36  unsigned int tRecordCount = 0;
37  unsigned int tAcquisitionCount = 0;
38 
39  if( tReadHeader->GetFormatMode() == sFormatSingle )
40  {
41  ofstream tOutputOne( (string( argv[ 2 ] ) + string( "_ch1.txt" )).c_str() );
42  if( tOutputOne.is_open() == false )
43  {
44  MERROR( mlog, "could not open channel one output file!" );
45  tReadTest->Close();
46  delete tReadTest;
47  return -1;
48  }
49 
50  const unsigned tDataTypeSize = tReadHeader->GetDataTypeSize();
51  const MonarchRecordBytes* tReadRecord = tReadTest->GetRecordSeparateOne();
52  const MonarchRecordDataInterface< uint64_t > tData( tReadRecord->fData, tDataTypeSize );
53  unsigned int tRecordsPerChannel = 0;
54  while( tReadTest->ReadRecord() != false )
55  {
56  tRecordCount++;
57  tRecordsPerChannel++;
58  if( tReadRecord->fAcquisitionId == tAcquisitionCount )
59  {
60  tAcquisitionCount = tAcquisitionCount + 1;
61  tOutputOne << "\n\n";
62  }
63  for( unsigned int tIndex = 0; tIndex < tReadHeader->GetRecordSize(); tIndex++ )
64  {
65  tOutputOne << tIndex << " " << tData.at( tIndex ) << "\n";
66  }
67  if (nRecords != 0 && tRecordsPerChannel >= nRecords)
68  break;
69  }
70 
71  tOutputOne.close();
72  }
73  if( (tReadHeader->GetFormatMode() == sFormatMultiInterleaved) || (tReadHeader->GetFormatMode() == sFormatMultiSeparate) )
74  {
75  ofstream tOutputOne( (string( argv[ 2 ] ) + string( "_ch1.txt" )).c_str() );
76  ofstream tOutputTwo( (string( argv[ 2 ] ) + string( "_ch2.txt" )).c_str() );
77  if( tOutputOne.is_open() == false )
78  {
79  MERROR( mlog, "could not open channel one output file!" );
80  tReadTest->Close();
81  delete tReadTest;
82  return -1;
83  }
84  if( tOutputTwo.is_open() == false )
85  {
86  MERROR( mlog, "could not open channel two output file!" );
87  tReadTest->Close();
88  delete tReadTest;
89  return -1;
90  }
91 
92  const unsigned tDataTypeSize = tReadHeader->GetDataTypeSize();
93  const MonarchRecordBytes* tReadRecordOne = tReadTest->GetRecordSeparateOne();
94  const MonarchRecordDataInterface< uint64_t > tDataOne( tReadRecordOne->fData, tDataTypeSize );
95  const MonarchRecordBytes* tReadRecordTwo = tReadTest->GetRecordSeparateTwo();
96  const MonarchRecordDataInterface< uint64_t > tDataTwo( tReadRecordTwo->fData , tDataTypeSize);
97  unsigned int tRecordsPerChannel = 0;
98  while( tReadTest->ReadRecord() != false )
99  {
100  tRecordCount = tRecordCount + 1;
101  tRecordsPerChannel++;
102  if( tReadRecordOne->fAcquisitionId == tAcquisitionCount )
103  {
104  tAcquisitionCount = tAcquisitionCount + 1;
105  tOutputOne << "\n\n";
106  tOutputTwo << "\n\n";
107  }
108  for( unsigned int tIndex = 0; tIndex < tReadHeader->GetRecordSize(); tIndex++ )
109  {
110  tOutputOne << tIndex << " " << tDataOne.at( tIndex ) << "\n";
111  tOutputTwo << tIndex << " " << tDataTwo.at( tIndex ) << "\n";
112  }
113  if (nRecords != 0 && tRecordsPerChannel >= nRecords)
114  break;
115  }
116 
117  tOutputOne.close();
118  tOutputTwo.close();
119  }
120 
121  MLINFO( mlog, "record count <" << tRecordCount << ">" );
122  MLINFO( mlog, "acquisition count <" << tAcquisitionCount << ">" );
123 
124  tReadTest->Close();
125  delete tReadTest;
126 
127  return 0;
128 }
129 
static const FormatModeType sFormatSingle
Definition: M2Types.hh:52
MLOGGER(mlog, "MonarchDump")
static scarab::logger mlog("M3Info")
static const FormatModeType sFormatMultiSeparate
Definition: M2Types.hh:53
static const FormatModeType sFormatMultiInterleaved
Definition: M2Types.hh:54
static const AccessModeType sInterfaceSeparate
Definition: M2Types.hh:36
int main(const int argc, const char **argv)