EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
packet_idcdevdescr.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file packet_idcdevdescr.cc
1 #include "packet_idcdevdescr.h"
2 #include <stdio.h>
3 #include <vector>
4 #include <sstream>
5 #include <string.h>
6 
7 
9  : Packet_w1 (data)
10 {
11 
12  is_decoded = 0;
13 }
14 
15 
16 
17 double Packet_idcdevdescr::dValue(const int ich, const char *what)
18 {
19 
20  if ( ! is_decoded )
21  {
22 
23  decode();
24 
25  }
26 
27  static namedVector search;
28  strcpy ( search.name, what );
29 
30  packetidcdevdescrSetiter it = nvset.find(&search);
31 
32  if ( it != nvset.end())
33  {
34  namedVector *x = *it;
35  // std::cout << what << " x " << x->values.size() << std::endl;
36  if ( ich < 0 || (unsigned int) ich >= x->values.size()) return 0;
37  return (x->values)[ich];
38 
39  }
40 
41  return 0;
42 
43 
44 }
45 
46 
47 
49 {
50 
52  for (it = nvset.begin(); it != nvset.end(); it++)
53  {
54  delete (*it);
55  // nvset.erase(it); // commented out by K.Aoki
56  }
57  nvset.clear(); // added by K.Aoki
58 
59 }
60 
62 {
63  is_decoded = 1;
64 
66 
67  char* from = ( char *) &x[1];
68 
69  int dlength = 4 * getDataLength() - 4;
70 
71  char *t = new char[dlength+1];
72  strncpy ( t, from, dlength);
73 
74  char *token = strtok(t, ";");
75  while (token)
76  {
77  struct namedVector *xx = new struct namedVector;
78  double value;
79  char * start = strstr( token, "=");
80  if ( start)
81  {
82  *start = '\0';
83  // std::cout << "---" << token << std::endl;
84  strcpy ( xx->name, token);
85 
86  start++;
87  char *copy = NULL;
88  copy = new char[strlen(start)+1];
89  strcpy ( copy, start);
90 
91  {
92  char *c;
93 
94  for ( c= copy; *c;)
95  {
96  if ( *c == ',') *c = ' ';
97  c++;
98  }
99  }
100 
101  {
102  std::stringstream iss(copy);
103  while ( iss >> value )
104  {
105  // std::cout << " " << value << " ";
106  xx->values.push_back(value);
107  }
108  // os << copy << std::endl;
109  if ( nvset.find(xx) != nvset.end() ) // added by K.Aoki
110  {
111  std::cout << "multiple entries\n"
112  << " " << xx->name << std::endl;
113  delete xx;
114  }
115  else
116  {
117  nvset.insert ( xx);
118  }
119  //std::cout << "Token " << token << " vector length = " << xx->values.size() << std::endl;
120  }
121  delete[] copy;
122  }else{
123  delete xx;
124  }
125 
126  token = strtok(0, ";");
127  }
128  delete []t; // added by K.Aoki
129 
130  return 0;
131 }
132 
134 {
135 
137 
138  char* from = ( char *) &x[1];
139 
140  int dlength = 4 * getDataLength() - 4;
141 
142  os << "Length = " << *x << std::endl;
143 
144  char *t = new char[dlength+1];
145  strncpy ( t, from, dlength);
146 
147  char *token = strtok(t, ";");
148  while (token)
149  {
150  os << token << std::endl;
151  token = strtok(0, ";");
152  }
153 
154  /*
155  os << std::endl;
156  os << dValue(0, "bi8-rot3-2.3") << std::endl;
157  os << dValue(0, "rbpm.bi8-bh1avgOrbTimeStamp") << std::endl;
158  os << dValue(0, "pol_countUpRightY") << std::endl;
159  os << dValue(0, "pol_downCountsY") << std::endl;
160  os << dValue(0, "pol_maxTimeB") << std::endl;
161  */
162 
163 }