35 using namespace KKLSC;
180 fileName.MemoryConsumedEstimated () +
181 frameOffsets.size () *
sizeof(kkint64) +
182 indexFileName.MemoryConsumedEstimated () +
183 startStopPoints.MemoryConsumedEstimated ();
185 if (
file) mem += 2000;
281 indexFile =
new ofstream (indexFileName.Str ());
282 *indexFile <<
"IndexFile" << endl
283 <<
"ScannerFile" <<
"\t" << _fileName << endl
284 <<
"DateTime" <<
"\t" << osGetLocalDateTime () << endl;
286 *indexFile <<
"IndexEntryFields" <<
"\t" <<
"FrameNum" 287 <<
"\t" <<
"ScanLineNum" 288 <<
"\t" <<
"ByteOffset" 299 log.Level (-1) << endl << endl <<
"ScannerFile::Open ***ERROR*** Opening File[" << fileName <<
"]" << endl << endl;
324 bool clearToUpdate =
false;
325 while (!clearToUpdate)
335 clearToUpdate =
true;
339 indexFile =
new ofstream (indexFileName.Str (), ios_base::app);
342 *indexFile <<
"DeleteStartStopPoint" <<
"\t" << scanLineNum << endl;
344 *indexFile <<
"StartStopPoint" <<
"\t" << scanLineNum <<
"\t" << StartStopPoint::StartStopTypeToStr (type) << endl;
357 startStopPoints.AddEntry (_scanLineNum, StartStopPoint::StartStopType::StartPoint);
365 startStopPoints.AddEntry (_scanLineNum, StartStopPoint::StartStopType::StopPoint);
373 startStopPoints.DeleteEntry (_scanLineNum);
382 return startStopPoints.NearestEntry (_scanLineNum);
389 return startStopPoints.PrevEntry (_scanLineNum);
396 return startStopPoints.SuccEntry (_scanLineNum);
404 float secsPerFrame = 1.0f;
410 float totalTime = (
float)(frameOffsets.size ()) * secsPerFrame;
411 int totalNumIntervals = (
int)(0.5f + totalTime / (
float)intervalSecs);
413 VectorFloatPtr recordRates =
new VectorFloat (totalNumIntervals, 0.0f);
417 kkint64 bytesThisFrame = frameOffsets[frameOffsetsIdx];
418 float frameOffsetsStartTime = 0;
419 float frameOffsetsEndTime = secsPerFrame;
420 float frameOffsetsRecRate = (
float)bytesThisFrame / secsPerFrame;
422 while (idx < totalNumIntervals)
424 float timeIntervalStartTime = (
float)(idx * intervalSecs);
425 float timeIntervalEndTime = timeIntervalStartTime + (
float)intervalSecs;
427 float timeIntervalCurTime = timeIntervalStartTime;
428 while (timeIntervalCurTime < timeIntervalEndTime)
430 float nextMark = Min (timeIntervalEndTime, frameOffsetsEndTime);
431 float deltaTime = nextMark - timeIntervalCurTime;
432 (*recordRates)[idx] += frameOffsetsRecRate * (deltaTime / secsPerFrame);
433 timeIntervalCurTime = nextMark;
436 frameOffsetsStartTime = frameOffsetsIdx * secsPerFrame;
437 frameOffsetsEndTime = frameOffsetsStartTime + (
float)secsPerFrame;
438 if (frameOffsetsIdx < frameOffsets.size ())
439 bytesThisFrame = frameOffsets[frameOffsetsIdx] - frameOffsets[frameOffsetsIdx - 1];
442 frameOffsetsRecRate = (
float)bytesThisFrame / secsPerFrame;
464 if (frameNum == frameOffsets.size ())
466 frameOffsets.push_back (byteOffset);
468 else if (frameNum < frameOffsets.size ())
470 frameOffsets[frameNum] = byteOffset;
474 while (frameOffsets.size () < frameNum)
475 frameOffsets.push_back (-1);
476 frameOffsets.push_back (byteOffset);
480 *indexFile <<
"IndexEntry" <<
"\t" << frameNum <<
"\t" << scanLineNum <<
"\t" << byteOffset << endl;
491 if (frameNum < frameOffsets.size ())
492 offset = frameOffsets[frameNum];
504 if (frameNum >= frameOffsets.size ())
511 FSeek (frameOffsets[frameNum]);
516 frameBufferLastReadEof = (feof (file) != 0);
533 cerr << endl <<
"ScannerFile::FrameRead ***ERROR*** No scan lines were loaded." << endl << endl;
565 frameBufferLastReadEof = (feof (file) != 0);
585 cerr << endl <<
"ScannerFile::GetNextLine ***ERROR*** No scan lines loaded." << endl << endl;
593 kkuint32 bytesToCopy = Min (lineBuffSize, pixelsPerScanLine);
594 for (
kkuint32 x = 0; x < bytesToCopy; ++x)
633 frameBufferLastReadEof = (feof (file) != 0);
645 cerr << endl <<
"ScannerFile::SkipNextLine ***ERROR*** No scan lines were loaded." << endl << endl;
672 kkuint32 bytesToCopy = Min (bufferLen, pixelsPerScanLine);
673 memcpy (frameBuffer + byteOffset, buffer, bytesToCopy);
685 if (frameNum >= frameOffsets.size ())
686 frameNum = frameOffsets.size () - 1;
703 cerr << endl << endl <<
"ScannerFile::SkipToScanLine ***ERROR*** FrameBufer is short scan lines." << endl << endl;
721 s <<
"InstrumentDataWord" <<
"\t" << (
int)idNum <<
"\t" << scanLineNum <<
"\t" << dataWord
.unsigned32BitInt;
739 bool endOfText =
false;
756 Format& _scannerFileFormat,
768 _log.Level (-1) <<
"Could not determine scanner file format." << endl;
772 delete _headerFields;
795 if (format == Format::sfSimple)
796 return new ScannerFileSimple (_fileName, _log);
798 if (format == Format::sf2BitEncoded)
799 return new ScannerFile2BitEncoded (_fileName, _log);
801 if (format == Format::sf3BitEncoded)
802 return new ScannerFile3BitEncoded (_fileName, _log);
804 if (format == Format::sf4BitEncoded)
805 return new ScannerFile4BitEncoded (_fileName, _log);
807 if (format == Format::sfZlib3BitEncoded)
808 return new ScannerFileZLib3BitEncoded (_fileName, _log);
818 const uchar* result = NULL;
859 errMsg <<
"ScannerFile::CreateScannerFileForOutput ***ERROR*** ScannerFile[" << _fileName <<
"] already exists.";
860 _log.Level (-1) << endl << endl << errMsg << endl << endl;
866 case Format::sfSimple:
867 scannerFile =
new ScannerFileSimple (_fileName, _pixelsPerScanLine, _frameHeight, _log);
870 case Format::sf2BitEncoded:
871 scannerFile =
new ScannerFile2BitEncoded (_fileName, _pixelsPerScanLine, _frameHeight, _log);
874 case Format::sf3BitEncoded:
875 scannerFile =
new ScannerFile3BitEncoded (_fileName, _pixelsPerScanLine, _frameHeight, _log);
878 case Format::sf4BitEncoded:
879 scannerFile =
new ScannerFile4BitEncoded (_fileName, _pixelsPerScanLine, _frameHeight, _log);
882 case Format::sfZlib3BitEncoded:
883 scannerFile =
new ScannerFileZLib3BitEncoded (_fileName, _pixelsPerScanLine, _frameHeight, _log);
895 errMsg <<
"ScannerFile::CreateScannerFileForOutput ***ERROR*** Invalid ScannerFile Format specified.";
896 _log.Level (-1) << endl << endl << errMsg << endl << endl;
907 const KKStr& _formatStr,
918 _log.Level (-1) << endl << endl <<
"ScannerFile::CreateScannerFileForOutput ***ERROR*** Invalid Format[" << _formatStr <<
"]" << endl << endl;
923 (_fileName
, (
Format)format
, _pixelsPerScanLine
, _frameHeight
, _log
);
997 fwrite (ln.Str (), 1, ln.Len (), file);
999 ScannerHeaderFields::const_iterator idx;
1000 for (idx = headerFields->begin (); idx != headerFields->end (); ++idx)
1003 ln << idx->first <<
"\t" << idx->second <<
"\n";
1004 fwrite (ln.Str (), 1, ln.Len (), file);
1009 fwrite (&ch, 1, 1, file);
1024 kkint32 bytesReturned = fread (&ch, 1, 1, f);
1025 while ((ch != 0) && (ch !=
'\n') && (bytesReturned > 0))
1028 bytesReturned = fread (&ch, 1, 1, f);
1031 if ((ch == 0) || (bytesReturned == 0))
1041 bool endOfText =
false;
1059 const KKStr& fieldValue
1065 if ((fieldValueUint > 0) && (fieldValueUint < (1024 * 1024)))
1083 const KKStr& _fieldValue
1098 ScannerHeaderFields::const_iterator idx;
1099 for (idx = _headerFields->begin (); idx != _headerFields->end (); ++idx)
1100 AddHeaderField (idx->first, idx->second);
1130 KKStr s
(textBuff
, 0
, numTextBytes - 1
);
1180 if ((frameNum < 1) || (frameNum >= frameOffsets.size ()))
1186 FSeek (frameOffsets[frameNum - 1]);
1188 frameOffsets[frameNum] = SkipToNextFrame ();
1204 bool changesMadeToIndexFile =
false;
1205 bool loadSuccessful =
false;
1207 if (!loadSuccessful)
1208 changesMadeToIndexFile =
true;
1211 if (frameOffsets.size () < 1)
1212 frameOffsets.push_back (byteOffsetScanLineZero);
1215 for (
kkuint32 frameNum = 0; frameNum < frameOffsets.size (); ++frameNum)
1217 if (frameOffsets[frameNum] < 0)
1219 if (goalie->NumBlockedThreads () > 0)
1223 FSeek (origFilePos);
1224 goalie->EndBlock ();
1225 osSleepMiliSecs (10);
1226 goalie->StartBlock ();
1227 origFilePos = osFTELL (file);
1229 changesMadeToIndexFile =
true;
1230 DetermineFrameOffsetForFrame (frameNum);
1234 bool readToEOF =
false;
1235 while ((!readToEOF) && (!cancelFlag))
1253 kkuint32 lastFrameNum = frameOffsets.size () - 1;
1256 FSeek (frameOffsets[lastFrameNum]);
1264 frameOffsets.push_back (nextFrameByteOffset);
1266 changesMadeToIndexFile =
true;
1270 if (nextFrameByteOffset < 0)
1274 if ((!cancelFlag) && changesMadeToIndexFile)
1275 SaveIndexFile (frameOffsets);
1295 ofstream f (indexFileName.Str ());
1296 f <<
"IndexFile" << endl
1297 <<
"ScannerFile" <<
"\t" << fileName << endl
1298 <<
"DateTime" <<
"\t" << osGetLocalDateTime () << endl;
1300 f <<
"IndexEntryFields" <<
"\t" <<
"FrameNum" 1301 <<
"\t" <<
"ScanLineNum" 1302 <<
"\t" <<
"ByteOffset" 1305 for (
kkuint32 frameNum = 0; frameNum < frameOffsets.size (); ++frameNum)
1307 f <<
"IndexEntry" <<
"\t" << frameNum <<
"\t" << (frameNum * frameHeight) <<
"\t" << frameOffsets[frameNum] << endl;
1310 StartStopPointList::const_iterator idx;
1311 for (idx = startStopPoints.begin (); idx != startStopPoints.end (); ++idx)
1313 StartStopPointPtr ssp = *idx;
1314 f <<
"StartStopPoint" <<
"\t" << ssp->ToTabDelStr () << endl;
1336 log.Level (-1) <<
"LoadIndexFile IndexFile[" << indexFileName <<
"] does not exist." << endl;
1365 startStopPoints.Clear ();
1378 startStopPoints.AddEntry (entry);
1385 startStopPoints.DeleteEntry (scanLineNum);
1400 kkint32 returnCd = osFSEEK (file, numBytes, SEEK_CUR);
1403 log.Level (-1) <<
"ScannerFile::SkipBytesForward ReturnCd = " << returnCd << endl;
1414 returnCd = osFSEEK (file, filePos, SEEK_SET);
void ScanRate(float _scanRate)
void FullName(const KKStr &_fullName)
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for 'size' characters.
static ScannerFilePtr CreateScannerFileForOutput(const KKStr &_fileName, const KKStr &_formatStr, kkuint32 _pixelsPerScanLine, kkuint32 _frameHeight, RunLog &_log)
kkint64 frameBufferFileOffsetLast
virtual void WriteTextBlock(const uchar *txtBlock, kkuint32 txtBlockLen)=0
kkint64 frameBufferFileOffsetNext
void SaveIndexFile(std::vector< kkint64 > &frameOffsets)
bool EqualIgnoreCase(const char *s2) const
StartStopPointPtr StartStopPointPrevEntry(kkint32 _scanLineNum)
void LoadIndexFile(bool &successful)
Call this method to Load the FrameOffsets and StartStop points from the index file.
static const KKStr & ScannerFileFormatToStr(Format fileFormat)
KKStr osRemoveExtension(const KKStr &_fullFileName)
kkint64 osFTELL(FILE *f)
Calls the appropriate 64 bit function for operating system.
ScannerFile * ScannerFilePtr
kkuint32 ExtractTokenUint(const char *delStr)
ScannerHeaderFields * ScannerHeaderFieldsPtr
virtual void WriteInstrumentDataWord(uchar idNum, kkuint32 scanLineNum, WordFormat32Bits dataWord)
Writes a 32 bit number into the Scanner File Stream at current location.
KKStr ExtractToken2(const char *delStr="\n\t\r ")
Extract first Token from the string.
void Open(const KKStr &_fileName)
static const uchar * CompensationTable()
void WriteHeader()
This method is called before any scanner data is added to the file. It will write the header informat...
KKStr & operator=(const char *src)
Implements a 2 bit Encoded format.
static void Destroy(volatile GoalKeeperPtr &_goalKeeperInstance)
Destroys an existing instance of GoalKeeper.
void AddStartPoint(kkint32 _scanLineNum)
Adds a Start-Point to the 'StartStopPoints' list.
void ReportInstrumentDataWord(uchar idNum, kkuint32 scanLineNum, WordFormat32Bits dataWord)
static const uchar * CompensationTable()
VectorFloatPtr RecordRateByTimeIntervals(int intervalSecs)
Returns an array indication the record rate in bytes/sec for specified time-intervals.
void SkipBytesForward(kkuint32 numBytes)
void AddStopPoint(kkint32 _scanLineNum)
Adds a Stop-Point to the 'StartStopPoints' list.
void ReportTextMsg(const char *textBuff, kkint32 numTextBytes)
Text messages that are embedded in a scanner file can be reported here.
kkuint32 frameBufferNumScanLines
virtual kkuint32 ReadBufferFrame()=0
Read in one Scanner File Frame return number of actual scan-lines read.
void FrameRead(kkuint32 frameNum, bool &found)
Read into frame buffer 'frameNum' and reposition so that next scan-line will be the 1st line in the f...
void AddHeaderFields(const ScannerHeaderFieldsPtr _headerFields)
static void Create(const KKStr &_name, volatile GoalKeeperPtr &_newGoalKeeper)
Create a GoalKeeper object and avoid a race condition doing it.
KKStr operator+(const char *right) const
bool EqualIgnoreCase(const KKStr &s2) const
StartStopPointPtr StartStopPointSuccEntry(kkint32 _scanLineNum)
unsigned __int32 kkuint32
const KKStr & GetValue(const KKStr &fieldName)
static ScannerFileEntryPtr GetOrCreateScannerFileEntry(const KKStr &rootName)
KKStr & operator=(KKStr &&src)
kkuint32 Len() const
Returns the number of characters in the string.
kkuint32 flowMeterCounterScanLine
void ExtractHeaderField(const KKStr &fieldName, const KKStr &fieldValue)
Class that keeps track of parameter details of a single scanner file.
ScannerHeaderFieldsPtr headerFields
KKStr operator+(const char *left, const KKStr &right)
void AddStartStopEntryToIndexFile(kkint32 scanLineNum, StartStopPoint::StartStopType type, bool deleteEntry)
kkint32 MemoryConsumedEstimated()
void DetermineFrameOffsetForFrame(kkuint32 frameNum)
Updates the byte offset for specified entry in 'frameOffsets' that is currently flagged with "-1"...
KKStr(const KKStr &str)
Copy Constructor.
static ScannerFilePtr CreateScannerFile(KKStr _fileName, RunLog &_log)
void StartBlock()
Initiates a Block as long as another thread has not already locked this object.
void AllocateFrameBuffer()
std::ofstream * indexFile
static const KKStr fileFormatOptions[]
bool frameBufferLastReadEof
KKStr FileFormatStr() const
void EndBlock()
Ends the block and allows other threads to pass through StatBlock.
void PixelsPerScanLine(kkuint32 _pixelsPerScanLine)
unsigned char uchar
Unsigned character.
static Format ScannerFileFormatFromStr(const KKStr &fileFormatStr)
virtual Format FileFormat() const
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
void UpdateFrameOffset(kkuint32 frameNum, kkuint32 scanLineNum, kkint64 byteOffset)
void osSleepMiliSecs(kkuint32 numMiliSecs)
KKStr(const char *src, kkuint32 startPos, kkuint32 endPos)
Constructs a KKStr instance from a sub-string of 'src'.
Contains Classes that are specific to Cameras physical characteristics.
static const KKStr & EmptyStr()
Static method that returns an Empty String.
virtual void WriteScanLine(const uchar *buffer, kkuint32 bufferLen)
kkint64 GetFrameOffset(kkuint32 frameNum)
ScannerHeaderFieldsPtr HeaderFields() const
virtual void WriteBufferFrame()=0
Write the contents of 'frameBuffer' to he end of the scanner file.
StartStopType Type() const
void StartStopPointDelete(kkint32 _scanLineNum)
unsigned __int64 kkuint64
bool StartsWith(const char *value, bool ignoreCase) const
KKStr StrFormatInt(kkint32 val, const char *mask)
bool frameOffsetsBuildRunning
static const uchar * CompensationTable()
kkint32 ExtractTokenInt(const char *delStr)
void BuildFrameOffsets(const volatile bool &cancelFlag)
Will update the 'frameOffsets' table by scanning the file from the last known entry until the end of ...
kkuint64 ExtractTokenUint64(const char *delStr)
StartStopPoint(const KKStr &s)
float GetValueFloat(const KKStr &fieldName)
kkuint32 frameNumCurLoaded
static const uchar * ConpensationTable(Format format)
const char * Str() const
Returns a pointer to a ascii string.
KKStr StrFormatDouble(double val, const char *mask)
Implements a 3 bit Encoded format.
bool osFileExists(const KKStr &_fileName)
FILE * osFOPEN(const char *fileName, const char *mode)
static const uchar * CompensationTable()
kkuint32 frameBufferNextLine
kkint32 FSeek(kkint64 filePos)
static void ReadHeaderOneLine(FILE *f, bool &endOfText, KKStr &line)
Implements a 4 bit Encoded format.
KKStr & operator=(const KKStr &src)
virtual void GetNextLine(uchar *lineBuff, kkuint32 lineBuffSize, kkuint32 &lineSize, kkuint32 colCount[], kkuint32 &pixelsInRow)
kkuint32 pixelsPerScanLine
void AddHeaderField(const KKStr &_fieldName, const KKStr &_fieldValue)
Used for logging messages.
static void GetScannerFileParameters(const KKStr &_scannerFileName, ScannerHeaderFieldsPtr &_headerFields, Format &_scannerFileFormat, kkint32 &_frameHeight, kkint32 &_frameWidth, float &_scanRate, bool &_successful, RunLog &_log)
Retrieves statistics for a specified Scanner File.
kkint32 NumBlockedThreads()
Returns the number of threads that are waiting to establish a lock on this instance.
virtual void ScanRate(float _scanRate)
virtual kkint64 SkipToNextFrame()=0
Skip to start of next frame returning back byte offset of that frame.
kkuint32 PixelsPerScanLine() const
kkint32 FrameHeight() const
void SkipToScanLine(kkint32 scanLine)
Repositions the file such that the next call to 'GetNextLine' returns the 'scanLine' scan-line...
bool ToBool() const
Returns the bool equivalent of the string, ex 'Yes' = true, 'No' = false, 'True' = true...
ScannerFile(const KKStr &_fileName, kkuint32 _pixelsPerScanLine, kkuint32 _frameHeight, RunLog &_log)
kkint32 largestKnownScanLine
static ScannerFilePtr CreateScannerFileForOutput(const KKStr &_fileName, Format _format, kkuint32 _pixelsPerScanLine, kkuint32 _frameHeight, RunLog &_log)
kkint64 byteOffsetScanLineZero
Class that keeps track of parameter details of a single scanner file.
ScannerFile(const KKStr &_fileName, RunLog &_log)
StartStopPointPtr StartStopPointNearestEntry(kkint32 _scanLineNum)
static Format GuessFormatOfFile(const KKStr &_fileName, RunLog &_log)
ScannerFileEntryPtr scannerFileEntry
kkint64 osGetFileSize(const KKStr &fileName)
kkuint32 flowMeterCounter
KKB::KKStrPtr osReadRestOfLine(FILE *in, bool &eof)
KKStr osGetRootName(const KKStr &fullFileName)
virtual kkint32 MemoryConsumedEstimated() const
VectorFloat * VectorFloatPtr