File indexing completed on 2024-04-06 12:27:58
0001 #include "RecoTBCalo/HcalTBObjectUnpacker/interface/HcalTBSourcePositionDataUnpacker.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include <iostream>
0004 #include <string>
0005 #include <map>
0006
0007 using namespace std;
0008
0009
0010
0011 struct xdaqSourcePositionDataFormat {
0012 uint32_t cdfHeader[4];
0013 uint16_t n_doubles;
0014 uint16_t n_strings;
0015 uint16_t key_length;
0016 uint16_t string_value_length;
0017 char start_of_data;
0018
0019
0020
0021
0022
0023 };
0024
0025 namespace hcaltb {
0026
0027 void HcalTBSourcePositionDataUnpacker::unpack(const FEDRawData &raw, HcalSourcePositionData &hspd) const {
0028 if (raw.size() < 3 * 8) {
0029 throw cms::Exception("Missing Data") << "No data in the source position data block";
0030 }
0031
0032 const struct xdaqSourcePositionDataFormat *sp = (const struct xdaqSourcePositionDataFormat *)(raw.data());
0033
0034 if (raw.size() < sizeof(xdaqSourcePositionDataFormat)) {
0035 throw cms::Exception("DataFormatError", "Fragment too small");
0036 }
0037
0038 map<string, double> sp_dblmap;
0039 map<string, string> sp_strmap;
0040
0041 #ifdef DEBUG
0042 cout << "#doubles = " << sp->n_doubles << endl;
0043 ;
0044 cout << "#strings = " << sp->n_strings << endl;
0045 cout << "key_length = " << sp->key_length << endl;
0046 cout << "string_value_length = " << sp->string_value_length << endl;
0047 #endif
0048
0049
0050 const char *keyptr = &sp->start_of_data;
0051 const double *valptr = (const double *)(&sp->start_of_data + sp->n_doubles * sp->key_length);
0052
0053 for (int i = 0; i < sp->n_doubles; i++) {
0054 #ifdef DEBUG
0055 cout << keyptr << " = " << *valptr << endl;
0056 #endif
0057 sp_dblmap[keyptr] = *valptr;
0058 keyptr += sp->key_length;
0059 valptr++;
0060 }
0061
0062
0063 keyptr = (const char *)valptr;
0064 const char *strptr = (keyptr + sp->n_strings * sp->key_length);
0065
0066 for (int i = 0; i < sp->n_strings; i++) {
0067 #ifdef DEBUG
0068 cout << keyptr << " = " << strptr << endl;
0069 #endif
0070 sp_strmap[keyptr] = strptr;
0071 keyptr += sp->key_length;
0072 strptr += sp->string_value_length;
0073 }
0074
0075
0076 hspd.set(sp_dblmap["MESSAGE"],
0077 sp_dblmap["TIME_STAMP1"],
0078 sp_dblmap["TIME_STAMP2"],
0079 -1,
0080 -1,
0081 sp_dblmap["STATUS"],
0082 sp_dblmap["INDEX"],
0083 sp_dblmap["REEL"],
0084 sp_dblmap["MOTOR_CURRENT"],
0085 sp_dblmap["MOTOR_VOLTAGE"],
0086 -1,
0087 -1,
0088 sp_strmap["CURRENT_TUBENAME_FROM_COORD"],
0089 sp_strmap["INDEX_DESCRIPTION"],
0090 sp_strmap["LAST_COMMAND"],
0091 sp_strmap["MESSAGE"]);
0092 }
0093 }