CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DaqFakeReader.cc
Go to the documentation of this file.
1 
6 #include "DaqFakeReader.h"
10 
14 
16 
18 
19 #include "CLHEP/Random/RandGauss.h"
20 
21 #include <cmath>
22 #include <sys/time.h>
23 #include <string.h>
24 
25 
26 using namespace std;
27 using namespace edm;
28 
29 
31 // construction/destruction
33 
34 //______________________________________________________________________________
36  : runNum(1)
37  , eventNum(1)
38  , empty_events(pset.getUntrackedParameter<bool>("emptyEvents",false))
39  , meansize(pset.getUntrackedParameter<unsigned int>("meanSize",1024))
40  , width(pset.getUntrackedParameter<unsigned int>("width",1024))
41  , injected_errors_per_million_events(pset.getUntrackedParameter<unsigned int>("injectErrPpm",0))
42  , modulo_error_events(injected_errors_per_million_events ? 1000000/injected_errors_per_million_events : 0xffffffff)
43 {
44  // mean = pset.getParameter<float>("mean");
45  produces<FEDRawDataCollection>();
46  frb.setEPProcessId(getpid());
47 }
48 
49 //______________________________________________________________________________
51 {
52 
53 }
54 
55 
57 // implementation of member functions
59 
60 //______________________________________________________________________________
63 {
64  // a null pointer is passed, need to allocate the fed collection
65  data=new FEDRawDataCollection();
66  EventID eID = e.id();
67 
68  if(!empty_events)
69  {
70 
71  // Fill the EventID
72  eventNum++;
73  // FIXME:
74 
77  eID, *data, meansize, width);
80  eID, *data, meansize, width);
83  eID, *data, meansize, width);
86  eID, *data, meansize, width);
89  eID, *data, meansize, width);
92  eID, *data, meansize, width);
95  eID, *data, meansize, width);
96 
97  timeval now;
98  gettimeofday(&now,0);
99  fillGTPFED(eID, *data,&now);
100  fillFED1023(eID,*data,&now);
101  }
102  return 1;
103 }
104 
106 
108  FEDRawDataCollection *fedcoll = 0;
109  fillRawData(e,fedcoll);
110  std::auto_ptr<FEDRawDataCollection> bare_product(fedcoll);
111  e.put(bare_product);
112 }
113 
114 
115 //______________________________________________________________________________
116 void DaqFakeReader::fillFEDs(const int fedmin, const int fedmax,
117  EventID& eID,
119  float meansize,
120  float width)
121 {
122 
123  // FIXME: last ID included?
124  for (int fedId = fedmin; fedId <= fedmax; ++fedId ) {
125 
126  // Generate size...
127  float logsiz = CLHEP::RandGauss::shoot(std::log(meansize),
128  std::log(meansize)-std::log(width/2.));
129  size_t size = int(std::exp(logsiz));
130  size -= size % 8; // all blocks aligned to 64 bit words
131 
132  FEDRawData& feddata = data.FEDData(fedId);
133  // Allocate space for header+trailer+payload
134  feddata.resize(size+16);
135 
136  // Generate header
137  FEDHeader::set(feddata.data(),
138  1, // Trigger type
139  eID.event(), // LV1_id (24 bits)
140  0, // BX_id
141  fedId); // source_id
142 
143  // Payload = all 0s...
144 
145  // Generate trailer
146  int crc = 0; // FIXME : get CRC
147  FEDTrailer::set(feddata.data()+8+size,
148  size/8+2, // in 64 bit words!!!
149  crc,
150  0, // Evt_stat
151  0); // TTS bits
152  }
153 }
154 
156  FEDRawDataCollection& data, timeval *now)
157 {
158  uint32_t fedId = FEDNumbering::MINTriggerGTPFEDID;
159  FEDRawData& feddata = data.FEDData(fedId);
160  uint32_t size = evf::evtn::SLINK_WORD_SIZE*37-16;//BST52_3BX
161  feddata.resize(size+16);
162 
163  FEDHeader::set(feddata.data(),
164  1, // Trigger type
165  eID.event(), // LV1_id (24 bits)
166  0, // BX_id
167  fedId); // source_id
168 
169  int crc = 0; // FIXME : get CRC
170  FEDTrailer::set(feddata.data()+8+size,
171  size/8+2, // in 64 bit words!!!
172  crc,
173  0, // Evt_stat
174  0); // TTS bits
175 
176  unsigned char * pOffset = feddata.data() + sizeof(fedh_t);
177  //fill in event ID
179  *( (uint32_t*)(pOffset + sizeof(fedh_t) + (9*2 + evf::evtn::EVM_TCS_TRIGNR_OFFSET) * evf::evtn::SLINK_WORD_SIZE / 2)) = eID.event();
180  //fill in timestamp
181  *( (uint32_t*) (pOffset + evf::evtn::EVM_GTFE_BSTGPS_OFFSET * evf::evtn::SLINK_WORD_SIZE / 2)) = now->tv_sec;
182  *( (uint32_t*) (pOffset + sizeof(fedh_t) + evf::evtn::EVM_GTFE_BSTGPS_OFFSET * evf::evtn::SLINK_WORD_SIZE / 2 + evf::evtn::SLINK_HALFWORD_SIZE)) = now->tv_usec;
183 
184  //*( (uint16_t*) (pOffset + (evtn::EVM_GTFE_BLOCK*2 + evtn::EVM_TCS_LSBLNR_OFFSET)*evtn::SLINK_HALFWORD_SIZE)) = (unsigned short)fakeLs_-1;
185 
186  //we could also generate lumiblock, bcr, orbit,... but they are not currently used by the FRD input source
187 
188 }
189 
190 
192  FEDRawDataCollection& data,timeval *now)
193 {
194  FEDRawData& feddata = data.FEDData(frb.fedId());
195  // Allocate space for header+trailer+payload
196  feddata.resize(frb.size());
197  frb.putHeader(eID.event(),0);
198  if(eID.event()%modulo_error_events==0) frb.setDAQDiaWord1(1ll); else frb.setDAQDiaWord1(0ll);
199  frb.setRBTimeStamp(((uint64_t) (now->tv_sec) << 32) + (uint64_t) (now->tv_usec));
200  frb.putTrailer();
201  memcpy(feddata.data(),frb.getPayload(),frb.size());
202 }
203 
205 {
206  std::cout << "DaqFakeReader begin Lumi " << iL.luminosityBlock() << std::endl;
208 }
unsigned int width
Definition: DaqFakeReader.h:64
EventNumber_t event() const
Definition: EventID.h:41
unsigned int modulo_error_events
Definition: DaqFakeReader.h:66
unsigned int size() const
const unsigned int EVM_TCS_TRIGNR_OFFSET
struct fedh_struct fedh_t
evf::EvffedFillerRB frb
Definition: DaqFakeReader.h:68
const unsigned int EVM_BOARDID_VALUE
void fillFEDs(const int, const int, edm::EventID &eID, FEDRawDataCollection &data, float meansize, float width)
static void set(unsigned char *trailer, int evt_lgth, int crc, int evt_stat, int tts, bool T=false)
Set all fields in the trailer.
Definition: FEDTrailer.cc:42
unsigned int fedId() const
void fillGTPFED(edm::EventID &eID, FEDRawDataCollection &data, timeval *now)
const unsigned int SLINK_HALFWORD_SIZE
Definition: FEDConstants.h:7
LuminosityBlockNumber_t luminosityBlock() const
void fillFED1023(edm::EventID &eID, FEDRawDataCollection &data, timeval *now)
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
virtual ~DaqFakeReader()
void setEPProcessId(pid_t pid)
virtual void beginLuminosityBlock(edm::LuminosityBlock const &iL, edm::EventSetup const &iE)
void resize(size_t newsize)
Definition: FEDRawData.cc:32
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
unsigned int fakeLs_
Definition: DaqFakeReader.h:67
virtual int fillRawData(edm::Event &e, FEDRawDataCollection *&data)
static void set(unsigned char *header, int evt_ty, int lvl1_ID, int bx_ID, int source_ID, int version=0, bool H=false)
Set all fields in the header.
Definition: FEDHeader.cc:40
unsigned int meansize
Definition: DaqFakeReader.h:63
virtual void produce(edm::Event &, edm::EventSetup const &)
unsigned char *const getPayload()
DaqFakeReader(const edm::ParameterSet &pset)
unsigned long long uint64_t
Definition: Time.h:15
const unsigned int SLINK_WORD_SIZE
Definition: FEDConstants.h:6
edm::EventID id() const
Definition: EventBase.h:56
const unsigned int EVM_BOARDID_OFFSET
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const unsigned int EVM_GTFE_BSTGPS_OFFSET
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
edm::EventNumber_t eventNum
Definition: DaqFakeReader.h:61
void setRBTimeStamp(uint64_t ts)
tuple cout
Definition: gather_cfg.py:121
const unsigned int EVM_BOARDID_SHIFT
dictionary rawdata
Definition: lumiPlot.py:393
volatile std::atomic< bool > shutdown_flag false
tuple size
Write out results.
void setDAQDiaWord1(uint64_t word)
void putHeader(unsigned int l1id, unsigned int bxid)