1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#include <pbdata/Types.h>
#include <hdf/HDFZMWReader.hpp>
HDFZMWReader::HDFZMWReader()
{
closeFileOnExit = false;
readHoleNumber = false;
readHoleXY = false;
readNumEvent = false;
readHoleStatus = false;
nZMWEntries = curZMW = 0;
parentGroupPtr = NULL;
}
int HDFZMWReader::Initialize(HDFGroup *parentGroupP)
{
parentGroupPtr = parentGroupP;
closeFileOnExit = false;
return Initialize();
}
int HDFZMWReader::Initialize()
{
//
// Make sure we can open the component containing the zmw information.
//
if (parentGroupPtr->ContainsObject("ZMW") == 0 or
zmwGroup.Initialize(parentGroupPtr->group, "ZMW") == 0) {
return 0;
}
//
// Now open all the important datasets in the zmw group. Some of
// these are optional, so flags must be set if they do not exist.
//
if (zmwGroup.ContainsObject("HoleNumber")) {
if (holeNumberArray.Initialize(zmwGroup, "HoleNumber") == 0) {
return 0;
}
readHoleNumber = true;
} else {
readHoleNumber = false;
}
if (zmwGroup.ContainsObject("HoleStatus")) {
if (holeStatusArray.Initialize(zmwGroup, "HoleStatus") == 0) {
return 0;
}
readHoleStatus = true;
} else {
readHoleStatus = false;
}
if (zmwGroup.ContainsObject("HoleXY")) {
if (xyArray.Initialize(zmwGroup, "HoleXY") == 0) {
return 0;
}
readHoleXY = true;
} else {
readHoleXY = false;
}
if (numEventArray.Initialize(zmwGroup, "NumEvent") == 0) {
return 0;
}
nZMWEntries = numEventArray.arrayLength;
readNumEvent = true;
curZMW = 0;
return 1;
}
int HDFZMWReader::Advance(UInt nSteps)
{
if (curZMW >= nZMWEntries) {
return 0;
} else {
curZMW += nSteps;
return 1;
}
}
bool HDFZMWReader::GetNext(ZMWGroupEntry &groupEntry)
{
if (curZMW == nZMWEntries) {
return false;
}
if (readHoleNumber) {
holeNumberArray.Read(curZMW, curZMW + 1, &groupEntry.holeNumber);
}
if (readHoleStatus) {
holeStatusArray.Read(curZMW, curZMW + 1, &groupEntry.holeStatus);
}
if (readHoleXY) {
int16_t holeXY[2];
xyArray.Read(curZMW, curZMW + 1, holeXY);
groupEntry.x = holeXY[0];
groupEntry.y = holeXY[1];
}
numEventArray.Read(curZMW, curZMW + 1, &groupEntry.numEvents);
curZMW++;
return true;
}
void HDFZMWReader::Close()
{
if (readHoleNumber) {
holeNumberArray.Close();
}
if (readHoleStatus) {
holeStatusArray.Close();
}
if (readHoleXY) {
xyArray.Close();
}
if (readNumEvent) {
numEventArray.Close();
}
if (closeFileOnExit == true) {
//
// This instance is owner of it's reader. Close the reader file.
//
hdfPlsFile.close();
}
zmwGroup.Close();
}
bool HDFZMWReader::GetHoleNumberAt(UInt index, UInt &holeNumber)
{
if (index >= nZMWEntries) {
return false;
}
holeNumberArray.Read(index, index + 1, &holeNumber);
return true;
}
HDFZMWReader::~HDFZMWReader() { Close(); }
|