CMS 3D CMS Logo

DaqFakeReader.cc
Go to the documentation of this file.
1 
6 #include "DaqFakeReader.h"
10 
12 
14 
16 
17 #include "CLHEP/Random/RandGauss.h"
18 
19 #include <cmath>
20 #include <sys/time.h>
21 #include <cstring>
22 
23 
24 using namespace std;
25 using namespace edm;
26 
27 
29 // construction/destruction
31 
32 //______________________________________________________________________________
34  : runNum(1)
35  , eventNum(1)
36  , empty_events(pset.getUntrackedParameter<bool>("emptyEvents",false))
37  , meansize(pset.getUntrackedParameter<unsigned int>("meanSize",1024))
38  , width(pset.getUntrackedParameter<unsigned int>("width",1024))
39  , injected_errors_per_million_events(pset.getUntrackedParameter<unsigned int>("injectErrPpm",0))
40  , modulo_error_events(injected_errors_per_million_events ? 1000000/injected_errors_per_million_events : 0xffffffff)
41 {
42  // mean = pset.getParameter<float>("mean");
43  produces<FEDRawDataCollection>();
44 }
45 
46 //______________________________________________________________________________
48 {
49 
50 }
51 
52 
54 // implementation of member functions
56 
57 //______________________________________________________________________________
60 {
61  // a null pointer is passed, need to allocate the fed collection
62  data=new FEDRawDataCollection();
63  EventID eID = e.id();
64 
65  if(!empty_events)
66  {
67 
68  // Fill the EventID
69  eventNum++;
70  // FIXME:
71 
74  eID, *data, meansize, width);
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);
93 
94  timeval now;
95  gettimeofday(&now,nullptr);
96  fillGTPFED(eID, *data,&now);
97  //TODO: write fake TCDS FED filler
98  }
99  return 1;
100 }
101 
103 
105  FEDRawDataCollection *fedcoll = nullptr;
106  fillRawData(e,fedcoll);
107  std::unique_ptr<FEDRawDataCollection> bare_product(fedcoll);
108  e.put(std::move(bare_product));
109 }
110 
111 
112 //______________________________________________________________________________
113 void DaqFakeReader::fillFEDs(const int fedmin, const int fedmax,
114  EventID& eID,
116  float meansize,
117  float width)
118 {
119 
120  // FIXME: last ID included?
121  for (int fedId = fedmin; fedId <= fedmax; ++fedId ) {
122 
123  // Generate size...
124  float logsiz = CLHEP::RandGauss::shoot(std::log(meansize),
125  std::log(meansize)-std::log(width/2.));
126  size_t size = int(std::exp(logsiz));
127  size -= size % 8; // all blocks aligned to 64 bit words
128 
129  FEDRawData& feddata = data.FEDData(fedId);
130  // Allocate space for header+trailer+payload
131  feddata.resize(size+16);
132 
133  // Generate header
134  FEDHeader::set(feddata.data(),
135  1, // Trigger type
136  eID.event(), // LV1_id (24 bits)
137  0, // BX_id
138  fedId); // source_id
139 
140  // Payload = all 0s...
141 
142  // Generate trailer
143  int crc = 0; // FIXME : get CRC
144  FEDTrailer::set(feddata.data()+8+size,
145  size/8+2, // in 64 bit words!!!
146  crc,
147  0, // Evt_stat
148  0); // TTS bits
149  }
150 }
151 
153  FEDRawDataCollection& data, timeval *now)
154 {
156  FEDRawData& feddata = data.FEDData(fedId);
157  uint32_t size = evf::evtn::SLINK_WORD_SIZE*37-16;//BST52_3BX
158  feddata.resize(size+16);
159 
160  FEDHeader::set(feddata.data(),
161  1, // Trigger type
162  eID.event(), // LV1_id (24 bits)
163  0, // BX_id
164  fedId); // source_id
165 
166  int crc = 0; // FIXME : get CRC
167  FEDTrailer::set(feddata.data()+8+size,
168  size/8+2, // in 64 bit words!!!
169  crc,
170  0, // Evt_stat
171  0); // TTS bits
172 
173  unsigned char * pOffset = feddata.data() + FEDHeader::length;
174  //fill in event ID
176  *( (uint32_t*)(pOffset + FEDHeader::length + (9*2 + evf::evtn::EVM_TCS_TRIGNR_OFFSET) * evf::evtn::SLINK_WORD_SIZE / 2)) = eID.event();
177  //fill in timestamp
178  *( (uint32_t*) (pOffset + evf::evtn::EVM_GTFE_BSTGPS_OFFSET * evf::evtn::SLINK_WORD_SIZE / 2)) = now->tv_sec;
180 
181  //*( (uint16_t*) (pOffset + (evtn::EVM_GTFE_BLOCK*2 + evtn::EVM_TCS_LSBLNR_OFFSET)*evtn::SLINK_HALFWORD_SIZE)) = (unsigned short)fakeLs_-1;
182 
183  //we could also generate lumiblock, bcr, orbit,... but they are not currently used by the FRD input source
184 
185 }
186 
187 
189 {
190  std::cout << "DaqFakeReader begin Lumi " << iL.luminosityBlock() << std::endl;
192 }
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:125
const unsigned int EVM_TCS_TRIGNR_OFFSET
static const uint32_t length
Definition: FEDHeader.h:54
const unsigned int EVM_BOARDID_VALUE
void fillFEDs(const int, const int, edm::EventID &eID, FEDRawDataCollection &data, float meansize, float width)
void fillGTPFED(edm::EventID &eID, FEDRawDataCollection &data, timeval *now)
const unsigned int SLINK_HALFWORD_SIZE
LuminosityBlockNumber_t luminosityBlock() const
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
static void set(unsigned char *trailer, uint32_t lenght, uint16_t crc, uint8_t evt_stat, uint8_t tts, bool moreTrailers=false)
Set all fields in the trailer.
Definition: FEDTrailer.cc:60
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)
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
~DaqFakeReader() override
edm::EventID id() const
Definition: EventBase.h:59
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
static void set(unsigned char *header, uint8_t triggerType, uint32_t lvl1ID, uint16_t bxID, uint16_t sourceID, uint8_t version=0, bool moreHeaders=false)
Set all fields in the header.
Definition: FEDHeader.cc:47
def move(src, dest)
Definition: eostools.py:511