Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEPICSvalue.h
Go to the documentation of this file.
1 // $Id$
2 // $HeadURL$
3 //
4 // File: DEPICSvalue.h
5 // Created: Tue Nov 11 21:40:17 EST 2014
6 // Creator: davidl (on Linux gluon104.jlab.org 2.6.32-358.23.2.el6.x86_64 x86_64)
7 //
8 
9 #ifndef _DEPICSvalue_
10 #define _DEPICSvalue_
11 
12 #include <string>
13 #include <time.h>
14 #include <stdint.h>
15 using std::string;
16 
17 #include <JANA/jerror.h>
18 #include <JANA/JObject.h>
19 
20 /// A DEPICSvalue object holds information for a single
21 /// EPICS value read from the data stream. Values are
22 /// stored in the data stream as strings of the form:
23 /// key=value. This string is available in the "nameval"
24 /// field. It is parsed however so that one may access the
25 /// name via "name" and the value as a sting via "sval".
26 /// The "ival", "uval", and "fval" hold the value converted
27 /// into a an "int", "uint32_t", and "double" respectively.
28 /// This is done using the stringstream class an is done
29 /// for convience. The EPICS values are inserted into the
30 /// EVIO file during data taking by the epics2et program
31 /// which should be started automatically by the DAQ system.
32 /// Source for that can be found here:
33 ///
34 /// https://halldsvn.jlab.org/repos/trunk/online/packages/etUtils/src/epics2et
35 
36 
37 class DEPICSvalue:public jana::JObject{
38  public:
40  DEPICSvalue(time_t timestamp, string &nameval){
41  this->timestamp = timestamp;
42  this->nameval = nameval;
43  size_t pos = nameval.find("=");
44  if(pos != nameval.npos){
45  name = nameval.substr(0, pos);
46  sval = nameval.substr(pos+1);
47 
48  stringstream ss(sval);
49  ss >> ival;
50  ss.str(sval);
51  ss >> uval;
52  ss.str(sval);
53  ss >> fval;
54 
55  // stringstream will set fval to 0.0 if no decimal
56  // point is in the string. Use ival in these cases
57  if( (fval==0.0) && (ival!=0.0) ) fval = (double)ival;
58  }
59  }
60  virtual ~DEPICSvalue(){}
61 
62  time_t timestamp;
63  string nameval;
64  string name;
65  string sval;
66  int ival;
67  uint32_t uval;
68  double fval;
69 
70  // This method is used primarily for pretty printing
71  // the second argument to AddString is printf style format
72  void toStrings(vector<pair<string,string> > &items)const{
73  string timestr = ctime(&timestamp);
74  timestr[timestr.length()-1] = 0;
75  AddString(items, "timestamp", "%d", timestamp);
76  AddString(items, "name", "%s", name.c_str());
77  AddString(items, "sval", "%s", sval.substr(0, 255).c_str());
78  AddString(items, "ival", "%d", ival);
79  AddString(items, "fval", "%f", (float)fval);
80  AddString(items, "t", "%s", timestr.c_str());
81  }
82 };
83 
84 #endif // _DEPICSvalue_
85 
DEPICSvalue(time_t timestamp, string &nameval)
Definition: DEPICSvalue.h:40
double fval
Definition: DEPICSvalue.h:68
char string[256]
string sval
Definition: DEPICSvalue.h:65
JOBJECT_PUBLIC(DEPICSvalue)
uint32_t uval
Definition: DEPICSvalue.h:67
string nameval
Definition: DEPICSvalue.h:63
void toStrings(vector< pair< string, string > > &items) const
Definition: DEPICSvalue.h:72
virtual ~DEPICSvalue()
Definition: DEPICSvalue.h:60
string name
Definition: DEPICSvalue.h:64
time_t timestamp
Definition: DEPICSvalue.h:62
A DEPICSvalue object holds information for a single EPICS value read from the data stream...
Definition: DEPICSvalue.h:37