CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/EventFilter/ResourceBroker/src/EvffedFillerRB.h

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, "-"); // rack id
00044                         long hostid = 0xdead;
00045                         if (p != 0)
00046                                 hostid = strtol(p, 0, 16) << 8;
00047                         p = strtok(0, "-"); // node id
00048                         if (p == 0)
00049                                 hostid += 0xdead;
00050                         else
00051                                 hostid += strtol(p, 0, 16);
00052                         hostid_ = hostid;
00053                 }
00054                 *(payload_.asHWords + (fedinterface::EVFFED_RBIDENT_OFFSET/sizeof(uint32_t)))
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                 *(payload_.asHWords + (evtn::SLINK_HALFWORD_SIZE/sizeof(uint32_t)))
00072                                 = FED_HCTRLID_INSERT + FED_EVTY_INSERT(0x1)
00073                                                 + FED_LVL1_INSERT(l1id) + FED_BXID_INSERT(bxid);
00074 
00075         }
00076         // this function MUST be called again after filling is complete (hence again in EP!!!)
00077         void putTrailer() {
00078                 uint32_t *fedtr_p = payload_.asHWords
00079                                 + ((fedinterface::EVFFED_TOTALSIZE - evtn::FED_TRAILER_SIZE)/sizeof(uint32_t));
00080                 *(fedtr_p + (evtn::SLINK_HALFWORD_SIZE/sizeof(uint32_t))) = FED_TCTRLID_INSERT
00081                                 + FED_EVSZ_INSERT(fedinterface::EVFFED_LENGTH);
00082                 *(fedtr_p) = FED_CRCS_INSERT(compute_crc(payload_.asBytes,fedinterface::EVFFED_TOTALSIZE));
00083         }
00084         void setRBTimeStamp(uint64_t ts) {
00085                 *(payload_.asWords + (fedinterface::EVFFED_RBWCTIM_OFFSET/sizeof(uint64_t)))
00086                                 = ts;
00087         }
00088         void setRBEventCount(uint32_t evtcnt) {
00089                 *(payload_.asHWords + (fedinterface::EVFFED_RBEVCNT_OFFSET/sizeof(uint32_t)))
00090                                 = evtcnt;
00091         }
00092 
00093         void setEPProcessId(pid_t pid) {
00094                 *(payload_.asHWords + (fedinterface::EVFFED_EPIDENT_OFFSET/sizeof(uint32_t)))
00095                                 = (pid & fedinterface::EVFFED_EPPCIDE_MASK)
00096                                                 << fedinterface::EVFFED_EPPCIDE_SHIFT;
00097         }
00098         unsigned int fedId() const {
00099                 return fedinterface::EVFFED_ID;
00100         }
00101         unsigned int size() const {
00102                 return fedinterface::EVFFED_TOTALSIZE;
00103         }
00104 private:
00105         union Payload {
00106                 unsigned char asBytes[fedinterface::EVFFED_TOTALSIZE];
00107                 uint32_t asHWords[fedinterface::EVFFED_TOTALSIZE / sizeof(uint32_t)];
00108                 uint64_t asWords[fedinterface::EVFFED_TOTALSIZE / sizeof(uint64_t)];
00109         };
00110         Payload payload_;
00111         unsigned int hostid_;
00112 };
00113 }
00114 
00115 #endif