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
00028 namespace evf{
00029
00030 class EvffedFillerRB{
00031
00032 public:
00033 EvffedFillerRB(FUResourceBroker *rb){
00034 for(unsigned int i = 0; i < fedinterface::EVFFED_LENGTH; i++){
00035 *(payload_.asWords + i) = 0;
00036 }
00037 char hostname[32];
00038 int retval = gethostname(hostname, 32);
00039 if(retval != 0){
00040 hostid_ = 0xdead;
00041 }
00042 else{
00043 if(strtok(hostname,"-") == 0) hostid_ = 0xdead;
00044 char *p = strtok(0,"-");
00045 long hostid = 0xdead;
00046 if(p!=0) hostid = strtol(p,0,16) << 8;
00047 p = strtok(0,"-");
00048 if(p==0) hostid += 0xdead;
00049 else hostid += strtol(p,0,16);
00050 hostid_ = hostid;
00051 }
00052 *(uint32_t*)(payload_.asBytes+fedinterface::EVFFED_RBIDENT_OFFSET) =
00053 ((hostid_ & fedinterface::EVFFED_RBPCIDE_MASK) << fedinterface::EVFFED_RBPCIDE_SHIFT) +
00054 ((rb->instanceNumber() & fedinterface::EVFFED_RBINSTA_MASK) << fedinterface::EVFFED_RBINSTA_SHIFT);
00055 }
00056 unsigned char * const getPayload(){return payload_.asBytes;}
00057 uint32_t getSize(){return fedinterface::EVFFED_TOTALSIZE;}
00058
00059 void putHeader(unsigned int l1id, unsigned int bxid){
00060 *(payload_.asHWords)
00061 = FED_SOID_INSERT(fedinterface::EVFFED_ID) + FED_VERSION_INSERT(fedinterface::EVFFED_VERSION);
00062 *(uint32_t*)(payload_.asBytes + evtn::SLINK_HALFWORD_SIZE)
00063 = FED_HCTRLID_INSERT + FED_EVTY_INSERT(0x1) + FED_LVL1_INSERT(l1id) + FED_BXID_INSERT(bxid);
00064
00065 }
00066
00067 void putTrailer(){
00068 unsigned char *fedtr_p = payload_.asBytes + fedinterface::EVFFED_TOTALSIZE - evtn::FED_TRAILER_SIZE;
00069 *(uint32_t*)(fedtr_p+evtn::SLINK_HALFWORD_SIZE)
00070 = FED_TCTRLID_INSERT + FED_EVSZ_INSERT(fedinterface::EVFFED_LENGTH);
00071 *(uint32_t*)(fedtr_p)
00072 = FED_CRCS_INSERT(compute_crc(payload_.asBytes,fedinterface::EVFFED_TOTALSIZE));
00073 }
00074 void setRBTimeStamp(uint64_t ts){
00075 *(uint64_t*) (payload_.asBytes + fedinterface::EVFFED_RBWCTIM_OFFSET) = ts;
00076 }
00077 void setRBEventCount(uint32_t evtcnt){
00078 *(uint32_t*) (payload_.asBytes + fedinterface::EVFFED_RBEVCNT_OFFSET) = evtcnt;
00079 }
00080
00081 void setEPProcessId(pid_t pid){
00082 *(uint32_t*)(payload_.asBytes+fedinterface::EVFFED_EPIDENT_OFFSET) =
00083 (pid & fedinterface::EVFFED_EPPCIDE_MASK) << fedinterface::EVFFED_EPPCIDE_SHIFT;
00084 }
00085 unsigned int fedId() const { return fedinterface::EVFFED_ID;}
00086 unsigned int size() const { return fedinterface::EVFFED_TOTALSIZE;}
00087 private:
00088 union Payload {
00089 unsigned char asBytes[fedinterface::EVFFED_TOTALSIZE];
00090 uint32_t asHWords[fedinterface::EVFFED_TOTALSIZE/sizeof(uint32_t)];
00091 uint64_t asWords[fedinterface::EVFFED_TOTALSIZE/sizeof(uint64_t)];
00092 };
00093 Payload payload_;
00094 unsigned int hostid_;
00095 };
00096 }
00097
00098
00099 #endif