CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/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 
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         unsigned int offset = i * evtn::SLINK_WORD_SIZE;
00036         *(uint64_t*)(payload_ + offset ) = 0;
00037       }
00038       char hostname[32];
00039       int retval = gethostname(hostname, 32);
00040       if(retval != 0){
00041         hostid_ = 0xdead;
00042       }
00043       else{
00044         if(strtok(hostname,"-") == 0) hostid_ = 0xdead;
00045         char *p = strtok(0,"-"); // rack id
00046         long hostid = 0xdead;
00047         if(p!=0) hostid = strtol(p,0,16) << 8;
00048         p = strtok(0,"-"); // node id
00049         if(p==0) hostid += 0xdead;
00050         else hostid += strtol(p,0,16);
00051         hostid_ = hostid;
00052       }
00053       *(uint32_t*)(payload_+fedinterface::EVFFED_RBIDENT_OFFSET) = 
00054         ((hostid_ & fedinterface::EVFFED_RBPCIDE_MASK) << fedinterface::EVFFED_RBPCIDE_SHIFT) +
00055         ((rb->instanceNumber() & fedinterface::EVFFED_RBINSTA_MASK) <<  fedinterface::EVFFED_RBINSTA_SHIFT);
00056     }
00057     unsigned char * const getPayload(){return payload_;}
00058     uint32_t getSize(){return fedinterface::EVFFED_TOTALSIZE;}
00059 
00060     void putHeader(unsigned int l1id, unsigned int bxid){
00061       *(uint32_t*)(payload_ )
00062         = FED_SOID_INSERT(fedinterface::EVFFED_ID) + FED_VERSION_INSERT(fedinterface::EVFFED_VERSION);
00063       *(uint32_t*)(payload_+ evtn::SLINK_HALFWORD_SIZE) 
00064         = FED_HCTRLID_INSERT + FED_EVTY_INSERT(0x1) + FED_LVL1_INSERT(l1id) + FED_BXID_INSERT(bxid);
00065 
00066     }
00067     // this function MUST be called again after filling is complete (hence again in EP!!!)
00068     void putTrailer(){
00069       unsigned char *fedtr_p = payload_ + fedinterface::EVFFED_TOTALSIZE - evtn::FED_TRAILER_SIZE; 
00070       *(uint32_t*)(fedtr_p+evtn::SLINK_HALFWORD_SIZE) 
00071         = FED_TCTRLID_INSERT + FED_EVSZ_INSERT(fedinterface::EVFFED_LENGTH);
00072       *(uint32_t*)(fedtr_p) 
00073         = FED_CRCS_INSERT(compute_crc(payload_,fedinterface::EVFFED_TOTALSIZE));
00074     }
00075     void setRBTimeStamp(uint64_t ts){
00076       *(uint64_t*) (payload_ + fedinterface::EVFFED_RBWCTIM_OFFSET) = ts;
00077     }
00078     void setRBEventCount(uint32_t evtcnt){
00079       *(uint32_t*) (payload_ + fedinterface::EVFFED_RBEVCNT_OFFSET) = evtcnt;
00080     }
00081 
00082     void setEPProcessId(pid_t pid){
00083       *(uint32_t*)(payload_+fedinterface::EVFFED_EPIDENT_OFFSET) = 
00084         (pid & fedinterface::EVFFED_EPPCIDE_MASK) << fedinterface::EVFFED_EPPCIDE_SHIFT;
00085     }
00086     unsigned int fedId() const { return fedinterface::EVFFED_ID;}
00087     unsigned int size() const { return fedinterface::EVFFED_TOTALSIZE;}
00088   private:
00089     unsigned char payload_[fedinterface::EVFFED_TOTALSIZE];
00090     unsigned int hostid_;
00091   };
00092 }
00093 
00094 
00095 #endif