Go to the documentation of this file.00001 #ifndef EVENTFILTER_RESOURCEBROKER_EVFFEDFILLERRB
00002 #define EVENTFILTER_RESOURCEBROKER_EVFFEDFILLERRB
00003
00004 #include <unistd.h>
00005
00006 #include "interface/shared/fed_header.h"
00007
00008 #define FED_HCTRLID_INSERT ( ( (FED_SLINK_START_MARKER) & FED_HCTRLID_WIDTH )<< FED_HCTRLID_SHIFT)
00009 #define FED_EVTY_INSERT(a) ( ( (a) & FED_EVTY_WIDTH ) << FED_EVTY_SHIFT )
00010 #define FED_LVL1_INSERT(a) ( ( (a) & FED_LVL1_WIDTH ) << FED_LVL1_SHIFT )
00011 #define FED_BXID_INSERT(a) ( ( (a) & FED_BXID_WIDTH ) << FED_BXID_SHIFT )
00012 #define FED_SOID_INSERT(a) ( ( (a) & FED_SOID_WIDTH ) << FED_SOID_SHIFT )
00013 #define FED_VERSION_INSERT(a) ( ( (a) & FED_VERSION_WIDTH ) << FED_VERSION_SHIFT )
00014 #define FED_MORE_HEADERS_INSERT(a) ( ( (a) & FED_MORE_HEADERS_WIDTH ) << FED_MORE_HEADERS_SHIFT )
00015
00016 #include "interface/shared/fed_trailer.h"
00017 #define FED_TCTRLID_INSERT ( ( (FED_SLINK_END_MARKER) & FED_TCTRLID_WIDTH ) << FED_TCTRLID_SHIFT )
00018 #define FED_EVSZ_INSERT(a) ( ( (a) & FED_EVSZ_WIDTH ) << FED_EVSZ_SHIFT )
00019 #define FED_CRCS_INSERT(a) ( ( (a) & FED_CRCS_WIDTH ) << FED_CRCS_SHIFT )
00020 #define FED_STAT_INSERT(a) ( ( (a) & FED_STAT_WIDTH ) << FED_STAT_SHIFT )
00021 #define FED_TTSI_INSERT(a) ( ( (a) & FED_TTSI_WIDTH ) << FED_TTSI_SHIFT )
00022 #define FED_MORE_TRAILERS_INSERT(a) ( ( (a) & FED_MORE_TRAILERS_WIDTH ) << FED_MORE_TRAILERS_SHIFT )
00023
00024 #include "EventFilter/FEDInterface/interface/FED1023.h"
00025 #include "EventFilter/ResourceBroker/interface/FUResourceBroker.h"
00026
00027 namespace evf {
00028
00029 class EvffedFillerRB {
00030
00031 public:
00032 EvffedFillerRB(FUResourceBroker *rb) {
00033 for (unsigned int i = 0; i < fedinterface::EVFFED_LENGTH; i++) {
00034 *(payload_.asWords + i) = 0;
00035 }
00036 char hostname[32];
00037 int retval = gethostname(hostname, 32);
00038 if (retval != 0) {
00039 hostid_ = 0xdead;
00040 } else {
00041 if (strtok(hostname, "-") == 0)
00042 hostid_ = 0xdead;
00043 char *p = strtok(0, "-");
00044 long hostid = 0xdead;
00045 if (p != 0)
00046 hostid = strtol(p, 0, 16) << 8;
00047 p = strtok(0, "-");
00048 if (p == 0)
00049 hostid += 0xdead;
00050 else
00051 hostid += strtol(p, 0, 16);
00052 hostid_ = hostid;
00053 }
00054 *(uint32_t*) (payload_.asBytes + fedinterface::EVFFED_RBIDENT_OFFSET)
00055 = ((hostid_ & fedinterface::EVFFED_RBPCIDE_MASK)
00056 << fedinterface::EVFFED_RBPCIDE_SHIFT)
00057 + ((rb->instanceNumber()
00058 & fedinterface::EVFFED_RBINSTA_MASK)
00059 << fedinterface::EVFFED_RBINSTA_SHIFT);
00060 }
00061 unsigned char * const getPayload() {
00062 return payload_.asBytes;
00063 }
00064 uint32_t getSize() {
00065 return fedinterface::EVFFED_TOTALSIZE;
00066 }
00067
00068 void putHeader(unsigned int l1id, unsigned int bxid) {
00069 *(payload_.asHWords) = FED_SOID_INSERT(fedinterface::EVFFED_ID)
00070 + FED_VERSION_INSERT(fedinterface::EVFFED_VERSION);
00071 *(uint32_t*) (payload_.asBytes + evtn::SLINK_HALFWORD_SIZE)
00072 = FED_HCTRLID_INSERT + FED_EVTY_INSERT(0x1)
00073 + FED_LVL1_INSERT(l1id) + FED_BXID_INSERT(bxid);
00074
00075 }
00076
00077 void putTrailer() {
00078 unsigned char *fedtr_p = payload_.asBytes
00079 + fedinterface::EVFFED_TOTALSIZE - evtn::FED_TRAILER_SIZE;
00080 *(uint32_t*) (fedtr_p + evtn::SLINK_HALFWORD_SIZE) = FED_TCTRLID_INSERT
00081 + FED_EVSZ_INSERT(fedinterface::EVFFED_LENGTH);
00082 *(uint32_t*) (fedtr_p)
00083 = FED_CRCS_INSERT(compute_crc(payload_.asBytes,fedinterface::EVFFED_TOTALSIZE));
00084 }
00085 void setRBTimeStamp(uint64_t ts) {
00086 *(uint64_t*) (payload_.asBytes + fedinterface::EVFFED_RBWCTIM_OFFSET)
00087 = ts;
00088 }
00089 void setRBEventCount(uint32_t evtcnt) {
00090 *(uint32_t*) (payload_.asBytes + fedinterface::EVFFED_RBEVCNT_OFFSET)
00091 = evtcnt;
00092 }
00093
00094 void setEPProcessId(pid_t pid) {
00095 *(uint32_t*) (payload_.asBytes + fedinterface::EVFFED_EPIDENT_OFFSET)
00096 = (pid & fedinterface::EVFFED_EPPCIDE_MASK)
00097 << fedinterface::EVFFED_EPPCIDE_SHIFT;
00098 }
00099 unsigned int fedId() const {
00100 return fedinterface::EVFFED_ID;
00101 }
00102 unsigned int size() const {
00103 return fedinterface::EVFFED_TOTALSIZE;
00104 }
00105 private:
00106 union Payload {
00107 unsigned char asBytes[fedinterface::EVFFED_TOTALSIZE];
00108 uint32_t asHWords[fedinterface::EVFFED_TOTALSIZE / sizeof(uint32_t)];
00109 uint64_t asWords[fedinterface::EVFFED_TOTALSIZE / sizeof(uint64_t)];
00110 };
00111 Payload payload_;
00112 unsigned int hostid_;
00113 };
00114 }
00115
00116 #endif