3using System.Collections.Generic;
10using System.Threading.Tasks;
25 ManualResetEvent m_evtEnabled =
new ManualResetEvent(
false);
26 ManualResetEvent m_evtPaused =
new ManualResetEvent(
false);
27 Task m_taskConsolidate;
28 int m_nQueryCount = 0;
30 int m_nFieldCount = 0;
55 public MgrQueryTime(
int nQueryCount, DateTime dtStart,
int nTimeSpanInMs,
int nSegmentSize,
int nMaxCount,
string strSchema, List<IXCustomQuery> rgCustomQueries)
57 m_colCustomQuery.
Load();
59 m_nQueryCount = nQueryCount;
60 m_nSegmentSize = nSegmentSize;
66 m_colCustomQuery.
Add(icustomquery);
70 for (
int i = 0; i < nConnections; i++)
72 string strConTag =
"Connection" + i.ToString();
73 string strCustomQuery = m_schema.
GetProperty(strConTag +
"_CustomQueryName");
74 string strCustomQueryParam = m_schema.
GetProperty(strConTag +
"_CustomQueryParam");
78 throw new Exception(
"Could not find the custom query '" + strCustomQuery +
"'!");
81 throw new Exception(
"The custom query '" + iqry.
Name +
"' does not support the 'CUSTOM_QUERY_TYPE.TIME'!");
83 DataQuery dq =
new DataQuery(iqry.
Clone(strCustomQueryParam), dtStart, TimeSpan.FromMilliseconds(nTimeSpanInMs), nSegmentSize, nMaxCount);
84 m_colDataQuery.
Add(dq);
90 m_colDataQuery.
Start();
93 m_taskConsolidate = Task.Factory.StartNew(
new Action(consolidateThread));
102 private void consolidateThread()
104 int nAllDataReady = ((int)Math.Pow(2, m_colDataQuery.
Count)) - 1;
107 while (!m_evtCancel.
WaitOne(nWait))
109 if (!m_evtEnabled.WaitOne(0))
122 for (
int i = 0; i < m_colDataQuery.
Count; i++)
124 DataQuery dq = m_colDataQuery[i];
126 nDataReady |= (0x0001 << i);
129 nDataDone |= (0x0001 << i);
135 if (nDataReady != nAllDataReady)
138 DataItem di =
new DataItem(m_nFieldCount);
139 int nLocalFieldCount = m_colDataQuery[0].FieldCount;
140 double[] rg = m_colDataQuery[0].GetNextData();
148 for (
int i = 0; i < m_nSegmentSize; i++)
150 int nFieldIdx = di.Add(0, i, rg, nLocalFieldCount);
152 for (
int j = 1; j < m_colDataQuery.
Count; j++)
154 double[] rg1 = m_colDataQuery[j].GetNextData();
163 while (dtSync1 < dtSync)
165 rg1 = m_colDataQuery[j].GetNextData();
178 nLocalFieldCount = m_colDataQuery[j].FieldCount;
179 nFieldIdx = di.
Add(nFieldIdx, i, rg1, nLocalFieldCount);
204 m_colCustomQuery.
Add(iqry);
213 m_evtEnabled.Reset();
214 m_evtPaused.WaitOne();
218 dq.
Reset(nStartOffset);
245 List<int> rg =
new List<int>();
247 if (m_colDataQuery.
Count == 0)
251 rg.Add(m_nFieldCount);
252 rg.Add(m_nQueryCount);
267 int nCount = m_nQueryCount * m_nFieldCount;
269 double[] rgLast =
null;
271 for (
int i = 0; i < m_nQueryCount; i++)
275 throw new Exception(
"The data item should not be null!");
277 double[] rgItem = di.
GetData();
279 for (
int j = 0; j < rgItem.Length; j++)
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
void Reset()
Resets the event clearing any signaled state.
bool WaitOne(int nMs=int.MaxValue)
Waits for the signal state to occur.
void Set()
Sets the event to the signaled state.
int Count
Returns the number of items in the list.
virtual void Add(T item)
Add a new item to the list.
Specifies a key-value pair of properties.
string GetProperty(string strName, bool bThrowExceptions=true)
Returns a property as a string value.
int GetPropertyAsInt(string strName, int nDefault=0)
Returns a property as an integer value.
The SimpleDatum class holds a data input within host memory.
DateTime TimeStamp
Get/set the Timestamp.
The Utility class provides general utility funtions.
static DateTime ConvertTimeFromMinutes(double dfMin)
Convert a number of minutes into the date time equivalent to 1/1/1980 + the minutes.
The Realmap operates similar to a bitmap but is actually just an array of doubles.
void SetPixel(int nX, int nY, double clr)
Set a given pixel to a given color.
The CustomQueryCollection manages the external Custom Queries placed in the
void Load()
Loads all custom query DLL's (if found).
IXCustomQuery Find(string strName)
Locates a custom query by name and returns it.
void Add(IXCustomQuery iqry)
Directly adds a custom query to the list.
The DataItemCollection contains the collection of synchronized data items collected from all custom q...
DataItem GetData(int nWait)
Returns the next data item from the back of the queue.
CancelEvent Cancel
Cancels the internal WaitForCount.
ManualResetEvent QueryEnd
The QueryEnd is set when the data reaches the data end.
bool WaitForCount(int nWait)
The WaitForCount function waits for the data queue to either fill to a given number of items (e....
void Add(DataItem di)
Add a new data item to the queue.
void Clear()
The Clear method removes all data from the data queue.
bool WaitData(int nWait)
The WaitData function waits a given amount of time for data to be ready.
The DataItem manages one synchronized data item where the first element is the sync field.
double[] GetData()
Returns the synchronized data fields.
The DataQueryCollection manages all active data queries.
void Shutdown()
Shutdown all data queries, stopping their internal query threads.
void Start()
Enable all data queries allowing each to actively query data, filling their internal queues.
The DataQuery manages a custom query interface and queues data from the custom query via an internal ...
int FieldCount
Returns the number of fields (including the sync field) that this query manages.
void Reset(int nStartOffset)
Reset the data query to and offset from the start date.
The MgrQueryTime class manages the collection of data queries, and the internal data queue that conta...
List< int > GetQuerySize()
Returns the query size of the data in the form: [0] = channels [1] = height [2] = width.
MgrQueryTime(int nQueryCount, DateTime dtStart, int nTimeSpanInMs, int nSegmentSize, int nMaxCount, string strSchema, List< IXCustomQuery > rgCustomQueries)
The constructor.
void Reset(int nStartOffset)
Reset the query to the start date used in Initialize, optionally with an offset from the start.
byte[] ConvertOutput(float[] rg, out string type)
Converts the output values into the native type used by the CustomQuery.
Dictionary< string, float > QueryInfo()
The Query information returns information about the data queried such as header information.
void Shutdown()
Shutdown the data queries and consolidation thread.
void AddDirectQuery(IXCustomQuery iqry)
Add a custom query directly to the streaming database.
SimpleDatum Query(int nWait)
Query the next data in the streaming database.
The custom query interface defines the functions implemented by each Custom Query object used to spec...
CUSTOM_QUERY_TYPE QueryType
Returns the custom query type supported by the custom query.
IXCustomQuery Clone(string strParam)
Return a new instance of the custom query.
string Name
Returns the name of the Custom Query.
Dictionary< string, float > QueryInfo()
The Query information returns information about the data queried such as header information.
byte[] ConvertOutput(float[] rg, out string strType)
Converts the output values into the native type used by the CustomQuery.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.db.stream namespace contains all data streaming related classes.
CUSTOM_QUERY_TYPE
Defines the custom query type to use.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...