CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/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::unpackMaps(const FEDRawData&    raw, std::map<std::string,std::string>& strings, std::map<std::string,double>& numerics) const {
00029     
00030     if (raw.size()<3*8) {
00031       throw cms::Exception("Missing Data") << "No data in the slow data block";
00032     }
00033     
00034     const struct xdaqSlowDataFormat *sd =
00035       (const struct xdaqSlowDataFormat *)(raw.data());
00036     
00037 #ifdef DEBUG
00038     cout << "#doubles = "   << sd->n_doubles << endl;;
00039     cout << "#strings = "   << sd->n_strings << endl;
00040     cout << "key_length = " << sd->key_length << endl;
00041     cout << "string_value_length = " << sd->string_value_length << endl;
00042 #endif
00043     
00044     // List of doubles:
00045     
00046     const char   *keyptr = &sd->start_of_data;
00047     const double *valptr =
00048       (const double *)(&sd->start_of_data + sd->n_doubles*sd->key_length);
00049     
00050     for (int i=0; i<sd->n_doubles; i++) {
00051 #ifdef DEBUG
00052       cout << keyptr << " = " << *valptr << endl;
00053 #endif
00054       numerics[keyptr] = *valptr;
00055       keyptr += sd->key_length;
00056       valptr++;
00057     }
00058     
00059     // List of strings:
00060     
00061     keyptr = (const char *)valptr;
00062     const char *strptr = (keyptr + sd->n_strings*sd->key_length);
00063     
00064     for (int i=0; i<sd->n_strings; i++) {
00065 #ifdef DEBUG
00066       cout << keyptr << " = " << strptr << endl;
00067 #endif
00068       strings[keyptr] = strptr;
00069       keyptr += sd->key_length;
00070       strptr += sd->string_value_length;
00071     }
00072   }
00073    
00074   void HcalTBSlowDataUnpacker::unpack(const FEDRawData&  raw,
00075                                         HcalTBRunData&          htbrd,
00076                                         HcalTBEventPosition&    htbep) const {
00077     
00078     map<string,double> sd_dblmap;
00079     map<string,string> sd_strmap;
00080     
00081     unpackMaps(raw,sd_strmap,sd_dblmap);
00082     
00083     // Now fill the input objects:
00084     htbrd.setRunData(sd_strmap["RunType"].c_str(),
00085                      sd_strmap["Beam.Mode"].c_str(),
00086                      sd_dblmap["Beam.Energy"]);
00087     
00088     htbep.setHFtableCoords(sd_dblmap["HFTable.X"],
00089                            sd_dblmap["HFTable.Y"],
00090                            sd_dblmap["HFTable.V"]);
00091     
00092     htbep.setHBHEtableCoords(sd_dblmap["Table.Eta"],
00093                              sd_dblmap["Table.Phi"]);
00094   }
00095 }
00096