CMS 3D CMS Logo

HcalTBSlowDataUnpacker.cc
Go to the documentation of this file.
4 #include <iostream>
5 #include <string>
6 #include <map>
8 
9 using namespace std;
10 
11 // structure for Slow Data
13  uint32_t cdfHeader[4];
14  uint16_t n_doubles;
15  uint16_t n_strings;
16  uint16_t key_length;
18  char start_of_data; // see below
19  // char[n_doubles*key_length] doubles names
20  // double[n_doubles] doubles values
21  // char[n_strings*key_length] strings names
22  // char[n_strings*string_value_length] strings values
23  // xdaqCommonDataFormatTrailer
24 };
25 
26 namespace hcaltb {
27 
28  void HcalTBSlowDataUnpacker::unpackMaps(const FEDRawData &raw,
29  std::map<std::string, std::string> &strings,
30  std::map<std::string, double> &numerics) const {
31  if (raw.size() < 3 * 8) {
32  throw cms::Exception("Missing Data") << "No data in the slow data block";
33  }
34 
35  const struct xdaqSlowDataFormat *sd = (const struct xdaqSlowDataFormat *)(raw.data());
36 
37 #ifdef DEBUG
38  cout << "#doubles = " << sd->n_doubles << endl;
39  ;
40  cout << "#strings = " << sd->n_strings << endl;
41  cout << "key_length = " << sd->key_length << endl;
42  cout << "string_value_length = " << sd->string_value_length << endl;
43 #endif
44 
45  // List of doubles:
46 
47  const char *keyptr = &sd->start_of_data;
48  const double *valptr = (const double *)(&sd->start_of_data + sd->n_doubles * sd->key_length);
49 
50  for (int i = 0; i < sd->n_doubles; i++) {
51 #ifdef DEBUG
52  cout << keyptr << " = " << *valptr << endl;
53 #endif
54  numerics[keyptr] = *valptr;
55  keyptr += sd->key_length;
56  valptr++;
57  }
58 
59  // List of strings:
60 
61  keyptr = (const char *)valptr;
62  const char *strptr = (keyptr + sd->n_strings * sd->key_length);
63 
64  for (int i = 0; i < sd->n_strings; i++) {
65 #ifdef DEBUG
66  cout << keyptr << " = " << strptr << endl;
67 #endif
68  strings[keyptr] = strptr;
69  keyptr += sd->key_length;
70  strptr += sd->string_value_length;
71  }
72  }
73 
75  map<string, double> sd_dblmap;
76  map<string, string> sd_strmap;
77 
78  unpackMaps(raw, sd_strmap, sd_dblmap);
79 
80  // Now fill the input objects:
81  htbrd.setRunData(sd_strmap["RunType"].c_str(), sd_strmap["Beam.Mode"].c_str(), sd_dblmap["Beam.Energy"]);
82 
83  htbep.setHFtableCoords(sd_dblmap["HFTable.X"], sd_dblmap["HFTable.Y"], sd_dblmap["HFTable.V"]);
84 
85  htbep.setHBHEtableCoords(sd_dblmap["Table.Eta"], sd_dblmap["Table.Phi"]);
86  }
87 } // namespace hcaltb
void setRunData(const char *run_type, const char *beam_mode, double beam_energy_gev)
Definition: HcalTBRunData.cc:7
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:48
void setHBHEtableCoords(double eta, double phi)
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
void setHFtableCoords(double x, double y, double v)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24