CMS 3D CMS Logo

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 <cstring>
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 }
47 
48 //______________________________________________________________________________
50 {
51 
52 }
53 
54 
56 // implementation of member functions
58 
59 //______________________________________________________________________________
62 {
63  // a null pointer is passed, need to allocate the fed collection
64  data=new FEDRawDataCollection();
65  EventID eID = e.id();
66 
67  if(!empty_events)
68  {
69 
70  // Fill the EventID
71  eventNum++;
72  // FIXME:
73 
76  eID, *data, meansize, width);
79  eID, *data, meansize, width);
82  eID, *data, meansize, width);
85  eID, *data, meansize, width);
88  eID, *data, meansize, width);
91  eID, *data, meansize, width);
94  eID, *data, meansize, width);
95 
96  timeval now;
97  gettimeofday(&now,nullptr);
98  fillGTPFED(eID, *data,&now);
99  //TODO: write fake TCDS FED filler
100  }
101  return 1;
102 }
103 
105 
107  FEDRawDataCollection *fedcoll = nullptr;
108  fillRawData(e,fedcoll);
109  std::unique_ptr<FEDRawDataCollection> bare_product(fedcoll);
110  e.put(std::move(bare_product));
111 }
112 
113 
114 //______________________________________________________________________________
115 void DaqFakeReader::fillFEDs(const int fedmin, const int fedmax,
116  EventID& eID,
118  float meansize,
119  float width)
120 {
121 
122  // FIXME: last ID included?
123  for (int fedId = fedmin; fedId <= fedmax; ++fedId ) {
124 
125  // Generate size...
126  float logsiz = CLHEP::RandGauss::shoot(std::log(meansize),
127  std::log(meansize)-std::log(width/2.));
128  size_t size = int(std::exp(logsiz));
129  size -= size % 8; // all blocks aligned to 64 bit words
130 
131  FEDRawData& feddata = data.FEDData(fedId);
132  // Allocate space for header+trailer+payload
133  feddata.resize(size+16);
134 
135  // Generate header
136  FEDHeader::set(feddata.data(),
137  1, // Trigger type
138  eID.event(), // LV1_id (24 bits)
139  0, // BX_id
140  fedId); // source_id
141 
142  // Payload = all 0s...
143 
144  // Generate trailer
145  int crc = 0; // FIXME : get CRC
146  FEDTrailer::set(feddata.data()+8+size,
147  size/8+2, // in 64 bit words!!!
148  crc,
149  0, // Evt_stat
150  0); // TTS bits
151  }
152 }
153 
155  FEDRawDataCollection& data, timeval *now)
156 {
158  FEDRawData& feddata = data.FEDData(fedId);
159  uint32_t size = evf::evtn::SLINK_WORD_SIZE*37-16;//BST52_3BX
160  feddata.resize(size+16);
161 
162  FEDHeader::set(feddata.data(),
163  1, // Trigger type
164  eID.event(), // LV1_id (24 bits)
165  0, // BX_id
166  fedId); // source_id
167 
168  int crc = 0; // FIXME : get CRC
169  FEDTrailer::set(feddata.data()+8+size,
170  size/8+2, // in 64 bit words!!!
171  crc,
172  0, // Evt_stat
173  0); // TTS bits
174 
175  unsigned char * pOffset = feddata.data() + sizeof(fedh_t);
176  //fill in event ID
178  *( (uint32_t*)(pOffset + sizeof(fedh_t) + (9*2 + evf::evtn::EVM_TCS_TRIGNR_OFFSET) * evf::evtn::SLINK_WORD_SIZE / 2)) = eID.event();
179  //fill in timestamp
180  *( (uint32_t*) (pOffset + evf::evtn::EVM_GTFE_BSTGPS_OFFSET * evf::evtn::SLINK_WORD_SIZE / 2)) = now->tv_sec;
181  *( (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;
182 
183  //*( (uint16_t*) (pOffset + (evtn::EVM_GTFE_BLOCK*2 + evtn::EVM_TCS_LSBLNR_OFFSET)*evtn::SLINK_HALFWORD_SIZE)) = (unsigned short)fakeLs_-1;
184 
185  //we could also generate lumiblock, bcr, orbit,... but they are not currently used by the FRD input source
186 
187 }
188 
189 
191 {
192  std::cout << "DaqFakeReader begin Lumi " << iL.luminosityBlock() << std::endl;
194 }
unsigned int width
Definition: DaqFakeReader.h:61
size
Write out results.
EventNumber_t event() const
Definition: EventID.h:41
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
const unsigned int EVM_TCS_TRIGNR_OFFSET
struct fedh_struct fedh_t
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
void fillGTPFED(edm::EventID &eID, FEDRawDataCollection &data, timeval *now)
const unsigned int SLINK_HALFWORD_SIZE
Definition: FEDConstants.h:7
LuminosityBlockNumber_t luminosityBlock() const
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
virtual void beginLuminosityBlock(edm::LuminosityBlock const &iL, edm::EventSetup const &iE)
void resize(size_t newsize)
Definition: FEDRawData.cc:32
unsigned int fakeLs_
Definition: DaqFakeReader.h:64
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:60
DaqFakeReader(const edm::ParameterSet &pset)
void produce(edm::Event &, edm::EventSetup const &) override
const unsigned int SLINK_WORD_SIZE
Definition: FEDConstants.h:6
~DaqFakeReader() override
edm::EventID id() const
Definition: EventBase.h:60
const unsigned int EVM_BOARDID_OFFSET
HLT enums.
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:58
const unsigned int EVM_BOARDID_SHIFT
def move(src, dest)
Definition: eostools.py:510