Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
DaqIOLib
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
NADS-Public
DaqIOLib
Commits
4bab8971
Commit
4bab8971
authored
Nov 12, 2004
by
yiannis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new library skeleton
parents
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
440 additions
and
0 deletions
+440
-0
DaqFileIO.cxx
DaqFileIO.cxx
+244
-0
DaqIOLib.vcproj
DaqIOLib.vcproj
+126
-0
DaqIo.h
DaqIo.h
+65
-0
daqio.cxx
daqio.cxx
+5
-0
No files found.
DaqFileIO.cxx
0 → 100644
View file @
4bab8971
/////////////////////////////////////////////////////////////////////////////
//
// DAQ low level IO Library
//
//
#include "DaqIo.h"
CDaqLowLevelIo
::
CDaqLowLevelIo
()
{
}
CDaqLowLevelIo
::~
CDaqLowLevelIo
()
{
}
void
NearDump
(
FILE
*
p
)
{
printf
(
"
\n
Data dump near error
\n
"
);
fseek
(
p
,
-
8
,
SEEK_CUR
);
int
d
;
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
size_t
n
=
fread
(
&
d
,
sizeof
(
d
),
1
,
p
);
printf
(
"%-d: %d (code=%d)
\n
"
,
ftell
(
p
)
-
sizeof
(
d
),
d
,
n
);
}
}
int
DataSize
(
CDaqChannelInfo
&
ch
)
{
int
size
;
switch
(
ch
.
m_Type
)
{
case
'f'
:
case
'i'
:
size
=
4
;
break
;
case
'd'
:
size
=
8
;
break
;
case
's'
:
size
=
2
;
break
;
case
'c'
:
size
=
1
;
break
;
default
:
return
-
1
;
}
return
size
*
ch
.
m_Items
;
}
/////////////////////////////////////////////////////////////////////////////
///
/// Reads the header of the DAQ file, independent of its version, and
/// stores the information in variables local to the class instance.
/// Values that are not provided in the specific file version are set
/// to some default
///
bool
CDaqLowLevelIo
::
ReadHeader
(
FILE
*
p
)
{
unsigned
magic
;
if
(
fread
(
&
magic
,
sizeof
(
magic
),
1
,
p
)
!=
1
)
{
return
false
;
}
rewind
(
p
);
bool
supported
=
false
;
if
(
magic
==
DAQ_MAGIC_NUM_VER_2_0
)
{
printf
(
"Version 2.0
\n
"
);
}
else
if
(
magic
==
DAQ_MAGIC_NUM_VER_2_1
)
{
printf
(
"Version 2.1
\n
"
);
}
else
if
(
magic
==
DAQ_MAGIC_NUM_VER_2_2
)
{
printf
(
"Version 2.2
\n
"
);
struct
Hdr
{
unsigned
Magic
;
char
Title
[
120
];
char
Date
[
27
];
char
Subj
[
128
];
char
Run
[
128
];
char
RunInst
[
128
];
int
NumEntries
;
unsigned
DAQFrequency
;
}
header
=
{
0
};
if
(
fread
(
&
header
,
sizeof
(
header
),
1
,
p
)
!=
1
)
{
return
false
;
}
m_Title
=
header
.
Title
;
m_Date
=
header
.
Date
;
m_Subj
=
header
.
Subj
;
m_Run
=
header
.
Run
;
m_RunInst
=
header
.
RunInst
;
m_NumEntries
=
header
.
NumEntries
;
m_Frequency
=
header
.
DAQFrequency
;
supported
=
true
;
}
if
(
!
supported
)
{
fprintf
(
stderr
,
"Unsuppored version, magic=0x%X
\n
"
,
magic
);
return
false
;
}
return
true
;
}
/////////////////////////////////////////////////////////////////////////////
///
/// Reads the information about all channels stored in the DAQ file.
/// Dagta is stored in the m_Channels instance variable
///
bool
CDaqLowLevelIo
::
ReadChannelInfo
(
FILE
*
p
)
{
int
ch
;
struct
ChInfo
{
int
ItemCount
;
char
Name
[
36
];
char
Units
[
16
];
short
CaptureRate
;
int
DataType
;
char
VarLenFlag
;
}
chan
;
for
(
ch
=
0
;
ch
<
m_NumEntries
;
ch
++
)
{
CDaqChannelInfo
chInfo
;
if
(
fread
(
&
chan
,
sizeof
(
chan
),
1
,
p
)
!=
1
)
{
return
false
;
}
chInfo
.
m_Id
=
ch
;
chInfo
.
m_Items
=
chan
.
ItemCount
;
chInfo
.
m_Name
=
chan
.
Name
;
chInfo
.
m_Type
=
chan
.
DataType
;
chInfo
.
m_CapRate
=
chan
.
CaptureRate
;
chInfo
.
m_VarLen
=
chan
.
VarLenFlag
?
true
:
false
;
m_Channels
.
push_back
(
chInfo
);
}
return
true
;
}
bool
CDaqLowLevelIo
::
Open
(
const
string
&
fname
)
{
//
// Open the file
//
FILE
*
p
=
fopen
(
fname
.
c_str
(),
"rb"
);
if
(
p
==
0
)
{
return
false
;
}
//
// Read the header and print, if needed
//
if
(
!
ReadHeader
(
p
)
)
{
return
false
;
}
printf
(
"Title = %s
\n
"
,
m_Title
.
c_str
());
printf
(
"Date = %s"
,
m_Date
.
c_str
());
printf
(
"Subj = %s
\n
"
,
m_Subj
.
c_str
());
printf
(
"Run = %s
\n
"
,
m_Run
.
c_str
());
printf
(
"RunInst = %s
\n
"
,
m_RunInst
.
c_str
());
printf
(
"Channels = %d
\n
"
,
m_NumEntries
);
printf
(
"Frequency = %d
\n
"
,
m_Frequency
);
//
// Read channel information and print, if needed
//
if
(
!
ReadChannelInfo
(
p
)
)
{
return
false
;
}
int
ch
;
printf
(
"Channels:
\n
"
);
printf
(
" Id Name Items Type Rate VarLen
\n
"
);
for
(
ch
=
0
;
ch
<
m_NumEntries
;
ch
++
)
{
printf
(
"%4d %-36s %5d %c %d %d
\n
"
,
m_Channels
[
ch
].
m_Id
,
m_Channels
[
ch
].
m_Name
.
c_str
(),
m_Channels
[
ch
].
m_Items
,
m_Channels
[
ch
].
m_Type
,
m_Channels
[
ch
].
m_CapRate
,
m_Channels
[
ch
].
m_VarLen
?
1
:
0
);
}
m_DataOffset
=
ftell
(
p
);
//
// Go through the file and build the TOC
//
while
(
1
)
{
int
three
[
3
];
// (Code, Frame, Count)
if
(
fread
(
three
,
sizeof
(
int
),
3
,
p
)
!=
3
)
{
fprintf
(
stderr
,
"Couldn't read file, premature end or messed up file
\n
"
);
return
false
;
}
if
(
three
[
0
]
<
0
)
{
// some marker
if
(
three
[
0
]
==
-
1
)
{
// frame
m_Toc
[
three
[
1
]]
=
ftell
(
p
);
// add to TOC
printf
(
"F=%d "
,
three
[
1
]);
}
else
if
(
three
[
0
]
==
-
2
)
{
// end marker
if
(
three
[
2
]
==
DAQ_END_MARK
)
{
break
;
/// <----------- END
}
}
else
{
fprintf
(
stderr
,
"Unexpected code %d at line %d
\n
"
,
three
[
0
],
__LINE__
);
return
false
;
}
}
else
{
int
chId
=
three
[
0
];
if
(
chId
>=
m_NumEntries
)
{
fprintf
(
stderr
,
"Invalid channel %d
\n
"
,
chId
);
NearDump
(
p
);
return
false
;
}
CDaqChannelInfo
&
ch
=
m_Channels
[
chId
];
int
skip
=
DataSize
(
ch
);
printf
(
"Channel %d found, %d bytes
\n
"
,
three
[
0
],
skip
);
fseek
(
p
,
skip
,
SEEK_CUR
);
}
}
return
true
;
}
DaqIOLib.vcproj
0 → 100644
View file @
4bab8971
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType=
"Visual C++"
Version=
"7.10"
Name=
"DaqIOLib"
ProjectGUID=
"{9BFCBD6F-7458-4944-902E-5CB41854BCC9}"
Keyword=
"Win32Proj"
>
<Platforms>
<Platform
Name=
"Win32"
/>
</Platforms>
<Configurations>
<Configuration
Name=
"Debug|Win32"
OutputDirectory=
"Debug"
IntermediateDirectory=
"Debug"
ConfigurationType=
"4"
CharacterSet=
"2"
>
<Tool
Name=
"VCCLCompilerTool"
Optimization=
"0"
PreprocessorDefinitions=
"WIN32;_DEBUG;_LIB"
MinimalRebuild=
"TRUE"
BasicRuntimeChecks=
"3"
RuntimeLibrary=
"3"
UsePrecompiledHeader=
"0"
WarningLevel=
"3"
Detect64BitPortabilityProblems=
"TRUE"
DebugInformationFormat=
"4"
/>
<Tool
Name=
"VCCustomBuildTool"
/>
<Tool
Name=
"VCLibrarianTool"
OutputFile=
"$(OutDir)/DaqIOLib.lib"
/>
<Tool
Name=
"VCMIDLTool"
/>
<Tool
Name=
"VCPostBuildEventTool"
/>
<Tool
Name=
"VCPreBuildEventTool"
/>
<Tool
Name=
"VCPreLinkEventTool"
/>
<Tool
Name=
"VCResourceCompilerTool"
/>
<Tool
Name=
"VCWebServiceProxyGeneratorTool"
/>
<Tool
Name=
"VCXMLDataGeneratorTool"
/>
<Tool
Name=
"VCManagedWrapperGeneratorTool"
/>
<Tool
Name=
"VCAuxiliaryManagedWrapperGeneratorTool"
/>
</Configuration>
<Configuration
Name=
"Release|Win32"
OutputDirectory=
"Release"
IntermediateDirectory=
"Release"
ConfigurationType=
"4"
CharacterSet=
"2"
>
<Tool
Name=
"VCCLCompilerTool"
PreprocessorDefinitions=
"WIN32;NDEBUG;_LIB"
RuntimeLibrary=
"4"
UsePrecompiledHeader=
"0"
WarningLevel=
"3"
Detect64BitPortabilityProblems=
"TRUE"
DebugInformationFormat=
"3"
/>
<Tool
Name=
"VCCustomBuildTool"
/>
<Tool
Name=
"VCLibrarianTool"
OutputFile=
"$(OutDir)/DaqIOLib.lib"
/>
<Tool
Name=
"VCMIDLTool"
/>
<Tool
Name=
"VCPostBuildEventTool"
/>
<Tool
Name=
"VCPreBuildEventTool"
/>
<Tool
Name=
"VCPreLinkEventTool"
/>
<Tool
Name=
"VCResourceCompilerTool"
/>
<Tool
Name=
"VCWebServiceProxyGeneratorTool"
/>
<Tool
Name=
"VCXMLDataGeneratorTool"
/>
<Tool
Name=
"VCManagedWrapperGeneratorTool"
/>
<Tool
Name=
"VCAuxiliaryManagedWrapperGeneratorTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name=
"Source Files"
Filter=
"cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier=
"{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=
".\DaqFileIo.cxx"
>
</File>
<File
RelativePath=
".\DaqIo.cxx"
>
</File>
</Filter>
<Filter
Name=
"Header Files"
Filter=
"h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier=
"{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=
".\DaqIo.h"
>
</File>
</Filter>
<Filter
Name=
"Resource Files"
Filter=
"rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier=
"{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<File
RelativePath=
".\ReadMe.txt"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
DaqIo.h
0 → 100644
View file @
4bab8971
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
using
namespace
std
;
#define DAQ_MAGIC_NUM_VER_2_0 0x2C3D4E5F
#define DAQ_MAGIC_NUM_VER_2_1 0x2C3D4E6F
#define DAQ_MAGIC_NUM_VER_2_2 0x2C3D4E7F
#define DAQ_END_MARK 0x1A2B2C3D
//
// This class represents all information about a channel stored in the DAQ
// file.
//
class
CDaqChannelInfo
{
public
:
CDaqChannelInfo
()
{
m_Id
=
m_Items
=
m_CapRate
=
m_Type
=
-
1
;
m_VarLen
=
false
;
m_Name
=
""
;
}
~
CDaqChannelInfo
()
{};
int
m_Id
;
int
m_Items
;
string
m_Name
;
int
m_CapRate
;
int
m_Type
;
bool
m_VarLen
;
};
/////////////////////////////////////////////////////////////////////////////
//
// This class provides an API that does low level reading from a DAQ file
//
//
class
CDaqLowLevelIo
{
public
:
CDaqLowLevelIo
();
~
CDaqLowLevelIo
();
bool
Open
(
const
string
&
);
private
:
bool
ReadHeader
(
FILE
*
);
bool
ReadChannelInfo
(
FILE
*
);
string
m_Title
;
// As stored in DAQ file
string
m_Date
;
// As stored in DAQ file
string
m_Subj
;
// As stored in DAQ file
string
m_Run
;
// As stored in DAQ file
string
m_RunInst
;
// As stored in DAQ file
int
m_NumEntries
;
// As stored in DAQ file
int
m_Frequency
;
// As stored in DAQ file
vector
<
CDaqChannelInfo
>
m_Channels
;
// Channel information
long
m_DataOffset
;
// where data starts in the file
map
<
int
,
int
>
m_Toc
;
// given a sim frame, gives the offset in the file
};
daqio.cxx
0 → 100644
View file @
4bab8971
/////////////////////////////////////////////////////////////////////////////
//
// DAQ IO Library
//
//
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment