Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:02:12

0001 #include "RecoTBCalo/HcalTBObjectUnpacker/interface/HcalTBSlowDataUnpacker.h"
0002 #include "TBDataFormats/HcalTBObjects/interface/HcalTBRunData.h"
0003 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0004 #include <iostream>
0005 #include <string>
0006 #include <map>
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 
0009 using namespace std;
0010 
0011 // structure for Slow Data
0012 struct xdaqSlowDataFormat {
0013   uint32_t cdfHeader[4];
0014   uint16_t n_doubles;
0015   uint16_t n_strings;
0016   uint16_t key_length;
0017   uint16_t string_value_length;
0018   char start_of_data;  // see below
0019   // char[n_doubles*key_length] doubles names
0020   // double[n_doubles] doubles values
0021   // char[n_strings*key_length] strings names
0022   // char[n_strings*string_value_length] strings values
0023   // xdaqCommonDataFormatTrailer
0024 };
0025 
0026 namespace hcaltb {
0027 
0028   void HcalTBSlowDataUnpacker::unpackMaps(const FEDRawData &raw,
0029                                           std::map<std::string, std::string> &strings,
0030                                           std::map<std::string, double> &numerics) const {
0031     if (raw.size() < 3 * 8) {
0032       throw cms::Exception("Missing Data") << "No data in the slow data block";
0033     }
0034 
0035     const struct xdaqSlowDataFormat *sd = (const struct xdaqSlowDataFormat *)(raw.data());
0036 
0037 #ifdef DEBUG
0038     cout << "#doubles = " << sd->n_doubles << endl;
0039     ;
0040     cout << "#strings = " << sd->n_strings << endl;
0041     cout << "key_length = " << sd->key_length << endl;
0042     cout << "string_value_length = " << sd->string_value_length << endl;
0043 #endif
0044 
0045     // List of doubles:
0046 
0047     const char *keyptr = &sd->start_of_data;
0048     const double *valptr = (const double *)(&sd->start_of_data + sd->n_doubles * sd->key_length);
0049 
0050     for (int i = 0; i < sd->n_doubles; i++) {
0051 #ifdef DEBUG
0052       cout << keyptr << " = " << *valptr << endl;
0053 #endif
0054       numerics[keyptr] = *valptr;
0055       keyptr += sd->key_length;
0056       valptr++;
0057     }
0058 
0059     // List of strings:
0060 
0061     keyptr = (const char *)valptr;
0062     const char *strptr = (keyptr + sd->n_strings * sd->key_length);
0063 
0064     for (int i = 0; i < sd->n_strings; i++) {
0065 #ifdef DEBUG
0066       cout << keyptr << " = " << strptr << endl;
0067 #endif
0068       strings[keyptr] = strptr;
0069       keyptr += sd->key_length;
0070       strptr += sd->string_value_length;
0071     }
0072   }
0073 
0074   void HcalTBSlowDataUnpacker::unpack(const FEDRawData &raw, HcalTBRunData &htbrd, HcalTBEventPosition &htbep) const {
0075     map<string, double> sd_dblmap;
0076     map<string, string> sd_strmap;
0077 
0078     unpackMaps(raw, sd_strmap, sd_dblmap);
0079 
0080     // Now fill the input objects:
0081     htbrd.setRunData(sd_strmap["RunType"].c_str(), sd_strmap["Beam.Mode"].c_str(), sd_dblmap["Beam.Energy"]);
0082 
0083     htbep.setHFtableCoords(sd_dblmap["HFTable.X"], sd_dblmap["HFTable.Y"], sd_dblmap["HFTable.V"]);
0084 
0085     htbep.setHBHEtableCoords(sd_dblmap["Table.Eta"], sd_dblmap["Table.Phi"]);
0086   }
0087 }  // namespace hcaltb