CTlib
Classes | Public Member Functions | Protected Member Functions | List of all members
CTlib.CTwriter Class Reference

Write CloudTurbine-formatted data. While not a full one-to-one implementation of the Java CTwriter API, this C# version provides basic functionality for storing different types of data. Data can optionally be packed and/or ZIP'ed at the block level. Timestamps can either be represented as milliseconds or seconds since epoch. Timestamps can be auto-generated or manually set. More...

Inheritance diagram for CTlib.CTwriter:
CTlib.CThttp_base CTlib.CThttp CTlib.CThttp_HttpClient

Public Member Functions

 CTwriter (String baseCTOutputFolderI, int numBlocksPerSegmentI, int numSegmentsToKeepI, bool bOutputTimesAreMillisI, bool bPackI, bool bZipI, bool bDeleteOldDataAtStartupI, bool bVerifyOutputFolderI=true)
 Constructor. More...
 
String getBaseCTOutputFolder ()
 Get baseCTOutputFolder. More...
 
void UseTmpFileForZipData (bool bUseTmpZipFilesI)
 If writing output ZIP files, should we write data first to a temporary file (".tmp") and then rename this to the final ".zip" file? If false, we write directly to the output ZIP file using (what is intended to be) a quick stream operation; this has the possible advantage that an extra intermediary ".tmp" file isn't created temporarily. More...
 
void putData (string[] channamesI, double[] dataI)
 Store an additional double data point in each of the specified channels. More...
 
void putData (string[] channamesI, float[] dataI)
 Store an additional single-precision float data point in each of the specified channels. More...
 
void putData (string channameI, String dataI)
 Store a new string in the given channel. More...
 
void putData (string channameI, double dataI)
 Store a double-precision float data value for the given channel. More...
 
void putData (string channameI, float dataI)
 Store a single-precision float data value for the given channel. More...
 
void putData (string channameI, long dataI)
 Store a long integer data value for the given channel. More...
 
void putData (string channameI, int dataI)
 Store an integer data value for the given channel. More...
 
void putData (string channameI, short dataI)
 Store a short integer data value for the given channel. More...
 
void putData (string channameI, char dataI)
 Store a character data value for the given channel. More...
 
void putData (string channameI, byte[] dataI)
 Store binary data array for the given channel. More...
 
long setTime ()
 Set time for subsequent putData(). This method simply calls setTime(<current_time_millis>). More...
 
void setTime (long timeI)
 Set time for subsequent putData(). To switch back to automatic timestamp mode, call this method with the argument equal to -1. More...
 
void setTime (double timeI)
 Set time for subsequent putData(). To switch back to automatic timestamp mode, call this method with the argument equal to -1.0. More...
 
void setAsync (bool bAsyncI)
 Specify whether flushes should be executed asynchronously. More...
 
void flush ()
 Write out all data that has been queued up for this block.
 
virtual void close ()
 Close the source. Flush any remaining data to the output source.
 

Protected Member Functions

virtual void writeToStream (String outputDirI, String chanNameI, byte[] dataI)
 Low-level method to write data to the channel. More...
 

Detailed Description

Write CloudTurbine-formatted data. While not a full one-to-one implementation of the Java CTwriter API, this C# version provides basic functionality for storing different types of data. Data can optionally be packed and/or ZIP'ed at the block level. Timestamps can either be represented as milliseconds or seconds since epoch. Timestamps can be auto-generated or manually set.

CTwriter

2019-03-22 JPW

  Notes on referencing the standard Microsoft ZIP library from
  the CTrollaball Unity application:

  How to reference a standard Microsoft library which isn't by
  default included in Unity is described in the post "Using .NET
  4.x in Unity" found at:
  https://docs.microsoft.com/en-us/visualstudio/cross-platform/unity-scripting-upgrade?view=vs-2017

  For CTrollaball, we needed Unity to be able to access the
  System.IO.Compression library. This was accomplished as follows:
  1. In Player Settings, set Scripting Runtime Version to ".NET 4.x Equivalent"
  2. In Player Settings, set Api Compatibility Level to ".NET 4.x"
  3. Include a "csc.rsp" file in the CTrollaball "Assets" folder
     which includes the following single line (w/o the quotation
     marks): "-r:System.IO.Compression.dll"

  Since we no longer need to use the "DotNetZip"/Ionic.Zip.Unity.dll
  library (from https://github.com/r2d2rigo/dotnetzip-for-unity), the 
  "UNITY_5_3_OR_NEWER" sections in CTlib.cs have been removed.

Constructor & Destructor Documentation

◆ CTwriter()

CTlib.CTwriter.CTwriter ( String  baseCTOutputFolderI,
int  numBlocksPerSegmentI,
int  numSegmentsToKeepI,
bool  bOutputTimesAreMillisI,
bool  bPackI,
bool  bZipI,
bool  bDeleteOldDataAtStartupI,
bool  bVerifyOutputFolderI = true 
)
inline

Constructor.

Parameters
baseCTOutputFolderIThe root folder where the output source is to be written. This must be at the same level as the application working directory or a sub-directory under it.
numBlocksPerSegmentINumber of blocks per segment in the source folder hierarchy. Use 0 to not include a segment layer.
numSegmentsToKeepIWhen using a segment layer, this specifies the number of full segments to keep. Older segments will be trimmed. Set to 0 to keep all segments.
bOutputTimesAreMillisIOutput times should be in milliseconds? Needed if blocks are written (i.e., flush() is called) at a rate greater than 1Hz.
bPackIPack data at the block folder level? Packed data times are linearly interpolated from the block start time to the time of the final datapoint in the packed channel.
bZipIZIP data at the block folder level?
bDeleteOldDataAtStartupIDelete old data from this source at startup?
bVerifyOutputFolderIAn optional argument, default value is true; if true, verify that baseCTOutputFolderI is at the same level as the application working directory or a sub-directory under it. Should be set false for HTTP or FTP output types.

Member Function Documentation

◆ getBaseCTOutputFolder()

String CTlib.CTwriter.getBaseCTOutputFolder ( )
inline

Get baseCTOutputFolder.

Returns
the base output folder, baseCTOutputFolder

◆ putData() [1/10]

void CTlib.CTwriter.putData ( string []  channamesI,
double []  dataI 
)
inline

Store an additional double data point in each of the specified channels.

Parameters
channamesIThe names of the channels to which new data will be added.
dataIArray containing one new data point per channel.
Exceptions
System.ArgumentExceptionThrown if the channel or data arrays are empty of their sizes don't match.
See also
putData(string[] channamesI, float[] dataI)

◆ putData() [2/10]

void CTlib.CTwriter.putData ( string []  channamesI,
float []  dataI 
)
inline

Store an additional single-precision float data point in each of the specified channels.

Parameters
channamesIThe names of the channels to which new data will be added.
dataIArray containing one new data point per channel.
Exceptions
System.ArgumentExceptionThrown if the channel or data arrays are empty of their sizes don't match.
See also
putData(string[] channamesI, double[] dataI)

◆ putData() [3/10]

void CTlib.CTwriter.putData ( string  channameI,
String  dataI 
)
inline

Store a new string in the given channel.

Parameters
channameIChannel to store the given data in.
dataIThe data to store.
Exceptions
System.ArgumentExceptionRe-throws any exception that is thrown by the underlying putData(string,byte[]) call.

◆ putData() [4/10]

void CTlib.CTwriter.putData ( string  channameI,
double  dataI 
)
inline

Store a double-precision float data value for the given channel.

Parameters
channameIChannel to store the given data in.
dataIThe data to store.
Exceptions
System.ArgumentExceptionRe-throws any exception that is thrown by the underlying putData(string,byte[]) call.

◆ putData() [5/10]

void CTlib.CTwriter.putData ( string  channameI,
float  dataI 
)
inline

Store a single-precision float data value for the given channel.

Parameters
channameIChannel to store the given data in.
dataIThe data to store.
Exceptions
System.ArgumentExceptionRe-throws any exception that is thrown by the underlying putData(string,byte[]) call.

◆ putData() [6/10]

void CTlib.CTwriter.putData ( string  channameI,
long  dataI 
)
inline

Store a long integer data value for the given channel.

Parameters
channameIChannel to store the given data in.
dataIThe data to store.
Exceptions
System.ArgumentExceptionRe-throws any exception that is thrown by the underlying putData(string,byte[]) call.

◆ putData() [7/10]

void CTlib.CTwriter.putData ( string  channameI,
int  dataI 
)
inline

Store an integer data value for the given channel.

Parameters
channameIChannel to store the given data in.
dataIThe data to store.
Exceptions
System.ArgumentExceptionRe-throws any exception that is thrown by the underlying putData(string,byte[]) call.

◆ putData() [8/10]

void CTlib.CTwriter.putData ( string  channameI,
short  dataI 
)
inline

Store a short integer data value for the given channel.

Parameters
channameIChannel to store the given data in.
dataIThe data to store.
Exceptions
System.ArgumentExceptionRe-throws any exception that is thrown by the underlying putData(string,byte[]) call.

◆ putData() [9/10]

void CTlib.CTwriter.putData ( string  channameI,
char  dataI 
)
inline

Store a character data value for the given channel.

Parameters
channameIChannel to store the given data in.
dataIThe data to store.
Exceptions
System.ArgumentExceptionRe-throws any exception that is thrown by the underlying putData(string,byte[]) call.

◆ putData() [10/10]

void CTlib.CTwriter.putData ( string  channameI,
byte []  dataI 
)
inline

Store binary data array for the given channel.

Parameters
channameIChannel to store the given data in.
dataIThe data to store.
Exceptions
System.ArgumentExceptionThrown if the specified channel name or data array is empty.

◆ setAsync()

void CTlib.CTwriter.setAsync ( bool  bAsyncI)
inline

Specify whether flushes should be executed asynchronously.

Parameters
bAsyncIShould flush calls be asynchronous?

◆ setTime() [1/3]

long CTlib.CTwriter.setTime ( )
inline

Set time for subsequent putData(). This method simply calls setTime(<current_time_millis>).

Returns
The next timestamp.

◆ setTime() [2/3]

void CTlib.CTwriter.setTime ( long  timeI)
inline

Set time for subsequent putData(). To switch back to automatic timestamp mode, call this method with the argument equal to -1.

Parameters
timeITimestamp in msec

◆ setTime() [3/3]

void CTlib.CTwriter.setTime ( double  timeI)
inline

Set time for subsequent putData(). To switch back to automatic timestamp mode, call this method with the argument equal to -1.0.

Parameters
timeITimestamp in sec

◆ UseTmpFileForZipData()

void CTlib.CTwriter.UseTmpFileForZipData ( bool  bUseTmpZipFilesI)
inline

If writing output ZIP files, should we write data first to a temporary file (".tmp") and then rename this to the final ".zip" file? If false, we write directly to the output ZIP file using (what is intended to be) a quick stream operation; this has the possible advantage that an extra intermediary ".tmp" file isn't created temporarily.

Parameters
bUseTmpZipFilesIWrite ZIP data first to a temporary file?

◆ writeToStream()

virtual void CTlib.CTwriter.writeToStream ( String  outputDirI,
String  chanNameI,
byte []  dataI 
)
inlineprotectedvirtual

Low-level method to write data to the channel.

Parameters
outputDirI
chanNameI
dataI

Reimplemented in CTlib.CThttp_base, CTlib.CThttp_HttpClient, and CTlib.CThttp.


The documentation for this class was generated from the following file: