Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEPICSstore.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DEPICSStore.cc
4 // Created: Tue Nov 18 15:44:17 EST 2014
5 // Creator: sdobbs (on Linux ifarm1102 2.6.32-220.7.1.el6.x86_64 x86_64)
6 //
7 
8 #include <DEPICSstore.h>
9 
10 //----------------
11 // GetValue
12 // get last read EPICS value, if we have come across it
13 //----------------
15 {
16  map<string, DEPICSvalue_data_t>::iterator result_itr = stored_values.find(name);
17  if(result_itr == stored_values.end())
18  return NULL;
19  else
20  return result_itr->second.value;
21 }
22 
23 const double DEPICSstore::GetAverage(string name)
24 {
25  map<string, DEPICSvalue_data_t>::iterator result_itr = stored_values.find(name);
26  if(result_itr == stored_values.end())
27  return -1.;
28  else
29  return result_itr->second.cumulative_average;
30 }
31 
32 void DEPICSstore::AddValue(const DEPICSvalue *new_value)
33 {
34  map<string, DEPICSvalue_data_t>::iterator result_itr = stored_values.find(new_value->name);
35  if(result_itr == stored_values.end()) {
36  stored_values[new_value->name] = DEPICSvalue_data_t();
37  stored_values[new_value->name].value = new DEPICSvalue(*new_value);
38  stored_values[new_value->name].first_time = new_value->timestamp;
39  } else {
40  // float values aren't working for now in DEPICSvalue objects?
41  // just use string values, which seem to be okay
42  //stored_values[new_value->name].cumulative_average += stored_values[new_value->name].value->fval / static_cast<double>( new_value->timestamp - stored_values[new_value->name].value->timestamp );
43  stored_values[new_value->name].cumulative_average += atof(stored_values[new_value->name].value->sval.c_str()) / static_cast<double>( new_value->timestamp - stored_values[new_value->name].value->timestamp );
44  if(stored_values[new_value->name].value != NULL)
45  delete stored_values[new_value->name].value;
46  stored_values[new_value->name].value = new DEPICSvalue(*new_value);
47  }
48 }
49 
51 {
52  for(map<string, DEPICSvalue_data_t>::iterator val_itr = stored_values.begin();
53  val_itr != stored_values.end(); val_itr++) {
54  val_itr->second.cumulative_average = 0.;
55  }
56 }
57 
58 
59 void DEPICSstore::ResetStartTimes(time_t new_start_time)
60 {
61  for(map<string, DEPICSvalue_data_t>::iterator val_itr = stored_values.begin();
62  val_itr != stored_values.end(); val_itr++) {
63  val_itr->second.first_time = new_start_time;
64  }
65 }
66 
67 
68 vector<string> DEPICSstore::GetNames()
69 {
70  vector<string> names;
71  for(map<string, DEPICSvalue_data_t>::iterator val_itr = stored_values.begin();
72  val_itr != stored_values.end(); val_itr++) {
73  names.push_back(val_itr->first);
74  }
75  return names;
76 }
void AddValue(const DEPICSvalue *new_value)
Definition: DEPICSstore.cc:32
void ResetStartTimes(time_t new_start_time)
Definition: DEPICSstore.cc:59
const double GetAverage(string name)
Definition: DEPICSstore.cc:23
string name
Definition: DEPICSvalue.h:64
void ClearAverages()
Definition: DEPICSstore.cc:50
struct DEPICSvalue_data DEPICSvalue_data_t
Definition: DEPICSstore.h:35
time_t timestamp
Definition: DEPICSvalue.h:62
const DEPICSvalue * GetValue(string key)
Definition: DEPICSstore.cc:14
vector< string > GetNames()
Definition: DEPICSstore.cc:68
map< string, DEPICSvalue_data_t > stored_values
Definition: DEPICSstore.h:55
A DEPICSvalue object holds information for a single EPICS value read from the data stream...
Definition: DEPICSvalue.h:37