CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
26 namespace hcaltb {
27 
29  HcalSourcePositionData& hspd) const {
30 
31  if (raw.size()<3*8) {
32  throw cms::Exception("Missing Data") << "No data in the source position data block";
33  }
34 
35  const struct xdaqSourcePositionDataFormat* sp =
36  (const struct xdaqSourcePositionDataFormat*)(raw.data());
37 
38  if (raw.size()<sizeof(xdaqSourcePositionDataFormat)) {
39  throw cms::Exception("DataFormatError","Fragment too small");
40  }
41 
42  map<string,double> sp_dblmap;
43  map<string,string> sp_strmap;
44 
45  #ifdef DEBUG
46  cout << "#doubles = " << sp->n_doubles << endl;;
47  cout << "#strings = " << sp->n_strings << endl;
48  cout << "key_length = " << sp->key_length << endl;
49  cout << "string_value_length = " << sp->string_value_length << endl;
50  #endif
51 
52  // List of doubles:
53  const char *keyptr = &sp->start_of_data;
54  const double *valptr =
55  (const double *)(&sp->start_of_data + sp->n_doubles*sp->key_length);
56 
57  for (int i=0; i<sp->n_doubles; i++) {
58  #ifdef DEBUG
59  cout << keyptr << " = " << *valptr << endl;
60  #endif
61  sp_dblmap[keyptr] = *valptr;
62  keyptr += sp->key_length;
63  valptr++;
64  }
65 
66  // List of strings:
67  keyptr = (const char *)valptr;
68  const char *strptr = (keyptr + sp->n_strings*sp->key_length);
69 
70  for (int i=0; i<sp->n_strings; i++) {
71  #ifdef DEBUG
72  cout << keyptr << " = " << strptr << endl;
73  #endif
74  sp_strmap[keyptr] = strptr;
75  keyptr += sp->key_length;
76  strptr += sp->string_value_length;
77  }
78 
79  // Now fill the input objects:
80  hspd.set(sp_dblmap["MESSAGE"], //double message_counter
81  sp_dblmap["TIME_STAMP1"],//double timestamp1_sec
82  sp_dblmap["TIME_STAMP2"],//double timestamp1_usec
83  -1,//double timestamp2_sec
84  -1,//double timestamp2_usec
85  sp_dblmap["STATUS"],//double status
86  sp_dblmap["INDEX"],//double index_counter
87  sp_dblmap["REEL"],//double reel_counter
88  sp_dblmap["MOTOR_CURRENT"],//double motor_current
89  sp_dblmap["MOTOR_VOLTAGE"],//double motor_voltage
90  -1,//double driver_id
91  -1,//double source_id
92  sp_strmap["CURRENT_TUBENAME_FROM_COORD"],
93  sp_strmap["INDEX_DESCRIPTION"],
94  sp_strmap["LAST_COMMAND"],
95  sp_strmap["MESSAGE"]
96  );
97  }
98 }
99 
int i
Definition: DBlmapReader.cc:9
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:47
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
Structure for Source Position Data.
tuple cout
Definition: gather_cfg.py:121