CMS 3D CMS Logo

HcalTBSourcePositionDataUnpacker.cc
Go to the documentation of this file.
3 #include <iostream>
4 #include <string>
5 #include <map>
6 
7 using namespace std;
8 
10 // same as slow data format
12  uint32_t cdfHeader[4];
13  uint16_t n_doubles;
14  uint16_t n_strings;
15  uint16_t key_length;
17  char start_of_data; // see below
18  // char[n_doubles*key_length] doubles names
19  // double[n_doubles] doubles values
20  // char[n_strings*key_length] strings names
21  // char[n_strings*string_value_length] strings values
22  // xdaqCommonDataFormatTrailer
23 };
24 
25 namespace hcaltb {
26 
28  if (raw.size() < 3 * 8) {
29  throw cms::Exception("Missing Data") << "No data in the source position data block";
30  }
31 
32  const struct xdaqSourcePositionDataFormat *sp = (const struct xdaqSourcePositionDataFormat *)(raw.data());
33 
34  if (raw.size() < sizeof(xdaqSourcePositionDataFormat)) {
35  throw cms::Exception("DataFormatError", "Fragment too small");
36  }
37 
38  map<string, double> sp_dblmap;
39  map<string, string> sp_strmap;
40 
41 #ifdef DEBUG
42  cout << "#doubles = " << sp->n_doubles << endl;
43  ;
44  cout << "#strings = " << sp->n_strings << endl;
45  cout << "key_length = " << sp->key_length << endl;
46  cout << "string_value_length = " << sp->string_value_length << endl;
47 #endif
48 
49  // List of doubles:
50  const char *keyptr = &sp->start_of_data;
51  const double *valptr = (const double *)(&sp->start_of_data + sp->n_doubles * sp->key_length);
52 
53  for (int i = 0; i < sp->n_doubles; i++) {
54 #ifdef DEBUG
55  cout << keyptr << " = " << *valptr << endl;
56 #endif
57  sp_dblmap[keyptr] = *valptr;
58  keyptr += sp->key_length;
59  valptr++;
60  }
61 
62  // List of strings:
63  keyptr = (const char *)valptr;
64  const char *strptr = (keyptr + sp->n_strings * sp->key_length);
65 
66  for (int i = 0; i < sp->n_strings; i++) {
67 #ifdef DEBUG
68  cout << keyptr << " = " << strptr << endl;
69 #endif
70  sp_strmap[keyptr] = strptr;
71  keyptr += sp->key_length;
72  strptr += sp->string_value_length;
73  }
74 
75  // Now fill the input objects:
76  hspd.set(sp_dblmap["MESSAGE"], //double message_counter
77  sp_dblmap["TIME_STAMP1"], //double timestamp1_sec
78  sp_dblmap["TIME_STAMP2"], //double timestamp1_usec
79  -1, //double timestamp2_sec
80  -1, //double timestamp2_usec
81  sp_dblmap["STATUS"], //double status
82  sp_dblmap["INDEX"], //double index_counter
83  sp_dblmap["REEL"], //double reel_counter
84  sp_dblmap["MOTOR_CURRENT"], //double motor_current
85  sp_dblmap["MOTOR_VOLTAGE"], //double motor_voltage
86  -1, //double driver_id
87  -1, //double source_id
88  sp_strmap["CURRENT_TUBENAME_FROM_COORD"],
89  sp_strmap["INDEX_DESCRIPTION"],
90  sp_strmap["LAST_COMMAND"],
91  sp_strmap["MESSAGE"]);
92  }
93 } // namespace hcaltb
void set(int message_counter, int timestamp1_sec, int timestamp1_usec, int timestamp2_sec, int timestamp2_usec, int status, int index_counter, int reel_counter, int motor_current, int motor_voltage, int driver_id, int source_id, std::string tubeNameFromCoord, std::string tubeDescFromSD, std::string lastCommand, std::string message)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:48
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
Structure for Source Position Data.
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24