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, std::map<std::string,std::string>& strings, std::map<std::string,double>& numerics) const {
29 
30  if (raw.size()<3*8) {
31  throw cms::Exception("Missing Data") << "No data in the slow data block";
32  }
33 
34  const struct xdaqSlowDataFormat *sd =
35  (const struct xdaqSlowDataFormat *)(raw.data());
36 
37 #ifdef DEBUG
38  cout << "#doubles = " << sd->n_doubles << endl;;
39  cout << "#strings = " << sd->n_strings << endl;
40  cout << "key_length = " << sd->key_length << endl;
41  cout << "string_value_length = " << sd->string_value_length << endl;
42 #endif
43 
44  // List of doubles:
45 
46  const char *keyptr = &sd->start_of_data;
47  const double *valptr =
48  (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  HcalTBRunData& htbrd,
76  HcalTBEventPosition& htbep) const {
77 
78  map<string,double> sd_dblmap;
79  map<string,string> sd_strmap;
80 
81  unpackMaps(raw,sd_strmap,sd_dblmap);
82 
83  // Now fill the input objects:
84  htbrd.setRunData(sd_strmap["RunType"].c_str(),
85  sd_strmap["Beam.Mode"].c_str(),
86  sd_dblmap["Beam.Energy"]);
87 
88  htbep.setHFtableCoords(sd_dblmap["HFTable.X"],
89  sd_dblmap["HFTable.Y"],
90  sd_dblmap["HFTable.V"]);
91 
92  htbep.setHBHEtableCoords(sd_dblmap["Table.Eta"],
93  sd_dblmap["Table.Phi"]);
94  }
95 }
96 
void setRunData(const char *run_type, const char *beam_mode, double beam_energy_gev)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
void setHBHEtableCoords(double eta, double phi)
double sd
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
void setHFtableCoords(double x, double y, double v)