CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/RecoTBCalo/HcalTBObjectUnpacker/src/HcalTBSlowDataUnpacker.cc

Go to the documentation of this file.
00001 #include "RecoTBCalo/HcalTBObjectUnpacker/interface/HcalTBSlowDataUnpacker.h"
00002 #include "TBDataFormats/HcalTBObjects/interface/HcalTBRunData.h"
00003 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00004 #include <iostream>
00005 #include <string>
00006 #include <map>
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 
00009 using namespace std;
00010 
00011 // structure for Slow Data
00012 struct xdaqSlowDataFormat {
00013   uint32_t cdfHeader[4];
00014   uint16_t n_doubles;
00015   uint16_t n_strings;
00016   uint16_t key_length;
00017   uint16_t string_value_length;
00018   char     start_of_data; // see below
00019   // char[n_doubles*key_length] doubles names
00020   // double[n_doubles] doubles values
00021   // char[n_strings*key_length] strings names
00022   // char[n_strings*string_value_length] strings values
00023   // xdaqCommonDataFormatTrailer
00024 };
00025 
00026 namespace hcaltb {
00027 
00028   void HcalTBSlowDataUnpacker::unpack(const FEDRawData&  raw,
00029                                       HcalTBRunData&          htbrd,
00030                                       HcalTBEventPosition&    htbep) {
00031 
00032   if (raw.size()<3*8) {
00033     throw cms::Exception("Missing Data") << "No data in the slow data block";
00034   }
00035 
00036     const struct xdaqSlowDataFormat *sd =
00037       (const struct xdaqSlowDataFormat *)(raw.data());
00038 
00039     map<string,double> sd_dblmap;
00040     map<string,string> sd_strmap;
00041 
00042 #ifdef DEBUG
00043     cout << "#doubles = "   << sd->n_doubles << endl;;
00044     cout << "#strings = "   << sd->n_strings << endl;
00045     cout << "key_length = " << sd->key_length << endl;
00046     cout << "string_value_length = " << sd->string_value_length << endl;
00047 #endif
00048 
00049     // List of doubles:
00050 
00051     const char   *keyptr = &sd->start_of_data;
00052     const double *valptr =
00053       (const double *)(&sd->start_of_data + sd->n_doubles*sd->key_length);
00054 
00055     for (int i=0; i<sd->n_doubles; i++) {
00056 #ifdef DEBUG
00057       cout << keyptr << " = " << *valptr << endl;
00058 #endif
00059       sd_dblmap[keyptr] = *valptr;
00060       keyptr += sd->key_length;
00061       valptr++;
00062     }
00063 
00064     // List of strings:
00065 
00066     keyptr = (const char *)valptr;
00067     const char *strptr = (keyptr + sd->n_strings*sd->key_length);
00068 
00069     for (int i=0; i<sd->n_strings; i++) {
00070 #ifdef DEBUG
00071       cout << keyptr << " = " << strptr << endl;
00072 #endif
00073       sd_strmap[keyptr] = strptr;
00074       keyptr += sd->key_length;
00075       strptr += sd->string_value_length;
00076     }
00077 
00078     // Now fill the input objects:
00079     htbrd.setRunData(sd_strmap["RunType"].c_str(),
00080                      sd_strmap["Beam.Mode"].c_str(),
00081                      sd_dblmap["Beam.Energy"]);
00082 
00083     htbep.setHFtableCoords(sd_dblmap["HFTable.X"],
00084                            sd_dblmap["HFTable.Y"],
00085                            sd_dblmap["HFTable.V"]);
00086 
00087     htbep.setHBHEtableCoords(sd_dblmap["Table.Eta"],
00088                              sd_dblmap["Table.Phi"]);
00089   }
00090 }
00091