Skip to content

Commit

Permalink
Merge pull request #594 from sethcooper/UpdateSourceDataFormatAndUnpa…
Browse files Browse the repository at this point in the history
…ckers700pre2

HcalSourcePosition dataformat and unpacker changes
  • Loading branch information
ktf committed Aug 23, 2013
2 parents 1bd9d74 + 5a554c6 commit 8e06a45
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 57 deletions.
26 changes: 21 additions & 5 deletions DataFormats/HcalRecHit/interface/HcalSourcePositionData.h
@@ -1,6 +1,8 @@
#ifndef DATAFORMATS_HCALRECHIT_HCALSOURCEPOSITIONDATA_H
#define DATAFORMATS_HCALRECHIT_HCALSOURCEPOSITIONDATA_H 1

#include <string>

#include "DataFormats/CaloRecHit/interface/CaloRecHit.h"

class HcalSourcePositionData {
Expand All @@ -14,15 +16,20 @@ class HcalSourcePositionData {
inline int indexCounter() const { return indexCounter_; }
inline int reelCounter() const { return reelCounter_; }
inline int motorCurrent() const { return motorCurrent_; }
inline int speed() const { return speed_; }
inline int speed() const { return -1; } // no longer implemented
inline int motorVoltage() const { return motorVoltage_; }
inline int tubeId() const { return tubeId_; }
inline int driverId() const { return driverId_; }
inline int sourceId() const { return sourceId_; }
inline std::string tubeNameFromCoord() const { return tubeNameFromCoord_; }
inline std::string tubeNameFromSD() const { return tubeNameFromSD_; }
inline std::string lastCommand() const { return lastCommand_; }
inline std::string message() const { return message_; }

void getDriverTimestamp(int& seconds, int& useconds) const;
void getDAQTimestamp(int& seconds, int& useconds) const;

void set( int message_counter,
void set(int message_counter,
int timestamp1_sec,
int timestamp1_usec,
int timestamp2_sec,
Expand All @@ -31,10 +38,15 @@ class HcalSourcePositionData {
int index_counter,
int reel_counter,
int motor_current,
int speed,
int motor_voltage,
int tube_id,
int driver_id,
int source_id);
int source_id,
std::string tubeNameFromCoord,
std::string tubeNameFromSD,
std::string lastCommand,
std::string message);

private:
int messageCounter_;
int indexCounter_;
Expand All @@ -45,10 +57,14 @@ class HcalSourcePositionData {
int timestamp2_usec_;
int status_;
int motorCurrent_;
int speed_;
int motorVoltage_;
int tubeId_;
int driverId_;
int sourceId_;
std::string tubeNameFromCoord_;
std::string tubeNameFromSD_;
std::string lastCommand_;
std::string message_;
};

std::ostream& operator<<(std::ostream& s, const HcalSourcePositionData& hspd);
Expand Down
39 changes: 26 additions & 13 deletions DataFormats/HcalRecHit/src/HcalSourcePositionData.cc
Expand Up @@ -13,7 +13,7 @@ HcalSourcePositionData::HcalSourcePositionData(){
timestamp2_usec_=0;
status_=0;
motorCurrent_=0;
speed_=0;
motorVoltage_=0;
tubeId_=-1;
driverId_=-1;
sourceId_=-1;
Expand All @@ -28,10 +28,15 @@ void HcalSourcePositionData::set(int message_counter,
int index_counter,
int reel_counter,
int motor_current,
int speed,
int motor_voltage,
int tube_id,
int driver_id,
int source_id){
int source_id,
std::string tubeNameFromCoord,
std::string tubeNameFromSD,
std::string lastCommand,
std::string message)
{

messageCounter_=message_counter;
indexCounter_=index_counter;
Expand All @@ -42,10 +47,14 @@ void HcalSourcePositionData::set(int message_counter,
timestamp2_usec_=timestamp2_usec;
status_=status;
motorCurrent_=motor_current;
speed_=speed;
motorVoltage_=motor_voltage;
tubeId_=tube_id;
driverId_=driver_id;
sourceId_=source_id;
tubeNameFromCoord_=tubeNameFromCoord;
tubeNameFromSD_=tubeNameFromSD;
lastCommand_=lastCommand;
message_=message;
}

void HcalSourcePositionData::getDriverTimestamp(int& seconds, int& useconds) const{
Expand All @@ -60,15 +69,19 @@ void HcalSourcePositionData::getDAQTimestamp(int& seconds, int& useconds) const{

ostream& operator<<(ostream& s, const HcalSourcePositionData& hspd) {

s << " Message Counter =" << hspd.messageCounter() << endl;
s << " Index Counter =" << hspd.indexCounter() << endl;
s << " Reel Counter =" << hspd.reelCounter() << endl;
s << " Status =" << hex << hspd.status() << dec << endl;
s << " Motor Current =" << hspd.motorCurrent() << endl;
s << " Speed =" << hspd.speed() << endl;
s << " Tube Id =" << hspd.tubeId() << endl;
s << " Driver Id =" << hspd.driverId() << endl;
s << " Source Id =" << hspd.sourceId() << endl;
s << " Message Counter =" << hspd.messageCounter() << endl;
s << " Index Counter =" << hspd.indexCounter() << endl;
s << " Reel Counter =" << hspd.reelCounter() << endl;
s << " Status =" << hex << hspd.status() << dec << endl;
s << " Motor Current =" << hspd.motorCurrent() << endl;
s << " Motor Voltage =" << hspd.motorVoltage() << endl;
s << " Tube Id =" << hspd.tubeId() << endl;
s << " Driver Id =" << hspd.driverId() << endl;
s << " Source Id =" << hspd.sourceId() << endl;
s << " TubeNameFromCoord =" << hspd.tubeNameFromCoord() << endl;
s << " TubeNameFromSD =" << hspd.tubeNameFromSD() << endl;
s << " Last Command =" << hspd.lastCommand() << endl;
s << " Message =" << hspd.message() << endl;

int timebase =0; int timeusec=0;
hspd.getDriverTimestamp(timebase,timeusec);
Expand Down
4 changes: 2 additions & 2 deletions DataFormats/HcalRecHit/src/classes_def.xml
Expand Up @@ -17,8 +17,8 @@
<class name="HcalCalibRecHit" ClassVersion="10">
<version ClassVersion="10" checksum="1085028533"/>
</class>
<class name="HcalSourcePositionData" ClassVersion="10">
<version ClassVersion="10" checksum="741265236"/>
<class name="HcalSourcePositionData" ClassVersion="11">
<version ClassVersion="11" checksum="913740682"/>
</class>
<class name="std::vector<HBHERecHit>"/>
<class name="std::vector<HORecHit>"/>
Expand Down
Expand Up @@ -81,7 +81,7 @@ using namespace std;
if (doTiming_) produces<HcalTBTiming>();
// if (doBeamADC_) produces<HcalTBBeamCounters>();
if (doBeamADC_) {produces<HcalTBBeamCounters>();qadcUnpacker_.setCalib(calibLines_);}
// if (doSourcePos_) produces<HcalSourcePositionData>();
if (doSourcePos_) produces<HcalSourcePositionData>();
if(doTiming_||doEventPosition_)tdcUnpacker_.setCalib(calibLines_);
}

Expand Down
Expand Up @@ -7,56 +7,94 @@
using namespace std;

/// Structure for Source Position Data
struct xdaqSourcePositionDriverData {
int message_counter;
int timestamp1_sec;
int timestamp1_usec;
int status;
int index_counter;
int reel_counter;
int motor_current;
int speed;
int timestamp2_sec;
int timestamp2_usec;
};

// same as slow data format
struct xdaqSourcePositionDataFormat {
int cdfHeader[4];
int maxDrivers;
unsigned int globalStatus;
xdaqSourcePositionDriverData driverInfo[4];
unsigned int word1_low;
unsigned int word1_high;
uint32_t cdfHeader[4];
uint16_t n_doubles;
uint16_t n_strings;
uint16_t key_length;
uint16_t string_value_length;
char start_of_data; // see below
// char[n_doubles*key_length] doubles names
// double[n_doubles] doubles values
// char[n_strings*key_length] strings names
// char[n_strings*string_value_length] strings values
// xdaqCommonDataFormatTrailer
};


namespace hcaltb {

void HcalTBSourcePositionDataUnpacker::unpack(const FEDRawData& raw,
HcalSourcePositionData& hspd) const {

if (raw.size()<3*8) {
throw cms::Exception("Missing Data") << "No data in the source position data block";
}

const struct xdaqSourcePositionDataFormat* sp =
(const struct xdaqSourcePositionDataFormat*)(raw.data());

if (raw.size()<sizeof(xdaqSourcePositionDataFormat)) {
throw cms::Exception("DataFormatError","Fragment too small");
}


hspd.set(sp->driverInfo[0].message_counter,//int message_counter,
sp->driverInfo[0].timestamp1_sec,//int timestamp1_sec,
sp->driverInfo[0].timestamp1_usec,//int timestamp1_usec,
sp->driverInfo[0].timestamp2_sec,//int timestamp2_sec,
sp->driverInfo[0].timestamp2_usec,//int timestamp2_usec,
sp->driverInfo[0].status,//int status,
sp->driverInfo[0].index_counter, // int index_counter,
sp->driverInfo[0].reel_counter,//int reel_counter,
sp->driverInfo[0].motor_current,//int motor_current,
sp->driverInfo[0].speed,//int speed,
-1,//int tube_number,
-1,// int driver_id
-1); //int source_id);

return;

map<string,double> sp_dblmap;
map<string,string> sp_strmap;

#ifdef DEBUG
cout << "#doubles = " << sp->n_doubles << endl;;
cout << "#strings = " << sp->n_strings << endl;
cout << "key_length = " << sp->key_length << endl;
cout << "string_value_length = " << sp->string_value_length << endl;
#endif

// List of doubles:
const char *keyptr = &sp->start_of_data;
const double *valptr =
(const double *)(&sp->start_of_data + sp->n_doubles*sp->key_length);

for (int i=0; i<sp->n_doubles; i++) {
#ifdef DEBUG
cout << keyptr << " = " << *valptr << endl;
#endif
sp_dblmap[keyptr] = *valptr;
keyptr += sp->key_length;
valptr++;
}

// List of strings:
keyptr = (const char *)valptr;
const char *strptr = (keyptr + sp->n_strings*sp->key_length);

for (int i=0; i<sp->n_strings; i++) {
#ifdef DEBUG
cout << keyptr << " = " << strptr << endl;
#endif
sp_strmap[keyptr] = strptr;
keyptr += sp->key_length;
strptr += sp->string_value_length;
}

// Now fill the input objects:
hspd.set(sp_dblmap["MESSAGE"], //double message_counter
sp_dblmap["TIME_STAMP1"],//double timestamp1_sec
sp_dblmap["TIME_STAMP2"],//double timestamp1_usec
-1,//double timestamp2_sec
-1,//double timestamp2_usec
-1,//double status
sp_dblmap["INDEX"],//double index_counter
sp_dblmap["REEL"],//double reel_counter
sp_dblmap["MOTOR_CURRENT"],//double motor_current
sp_dblmap["MOTOR_VOLTAGE"],//double motor_voltage
-1,//double tube_id
-1,//double driver_id
-1,//double source_id
sp_strmap["CURRENT_TUBENAME_FROM_COORD"],
"", // current tubeName from SD
sp_strmap["LAST_COMMAND"],
sp_strmap["MESSAGE"]
);
}
}

0 comments on commit 8e06a45

Please sign in to comment.