Back to home page

Project CMSSW displayed by LXR

 
 

    


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 /// Structure for Source Position Data
0010 // same as slow data format
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;  // see below
0018   // char[n_doubles*key_length] doubles names
0019   // double[n_doubles] doubles values
0020   // char[n_strings*key_length] strings names
0021   // char[n_strings*string_value_length] strings values
0022   // xdaqCommonDataFormatTrailer
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     // List of doubles:
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     // List of strings:
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     // Now fill the input objects:
0076     hspd.set(sp_dblmap["MESSAGE"],        //double message_counter
0077              sp_dblmap["TIME_STAMP1"],    //double timestamp1_sec
0078              sp_dblmap["TIME_STAMP2"],    //double timestamp1_usec
0079              -1,                          //double timestamp2_sec
0080              -1,                          //double timestamp2_usec
0081              sp_dblmap["STATUS"],         //double status
0082              sp_dblmap["INDEX"],          //double index_counter
0083              sp_dblmap["REEL"],           //double reel_counter
0084              sp_dblmap["MOTOR_CURRENT"],  //double motor_current
0085              sp_dblmap["MOTOR_VOLTAGE"],  //double motor_voltage
0086              -1,                          //double driver_id
0087              -1,                          //double source_id
0088              sp_strmap["CURRENT_TUBENAME_FROM_COORD"],
0089              sp_strmap["INDEX_DESCRIPTION"],
0090              sp_strmap["LAST_COMMAND"],
0091              sp_strmap["MESSAGE"]);
0092   }
0093 }  // namespace hcaltb