CMS 3D CMS Logo

DaqFakeReader.cc
Go to the documentation of this file.
1 
6 #include "DaqFakeReader.h"
11 
13 
15 
17 
18 #include "CLHEP/Random/RandGauss.h"
19 
20 #include <cmath>
21 #include <sys/time.h>
22 #include <cstring>
23 #include <cstdlib>
24 #include <chrono>
25 
26 using namespace std;
27 using namespace edm;
28 
30 // construction/destruction
32 
33 //______________________________________________________________________________
35  : runNum(1),
36  eventNum(1),
37  empty_events(pset.getUntrackedParameter<bool>("emptyEvents", false)),
38  fillRandom_(pset.getUntrackedParameter<bool>("fillRandom", 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  tcdsFEDID_(pset.getUntrackedParameter<unsigned int>("tcdsFEDID", 1024)),
43  modulo_error_events(injected_errors_per_million_events ? 1000000 / injected_errors_per_million_events
44  : 0xffffffff) {
45  // mean = pset.getParameter<float>("mean");
47  throw cms::Exception("DaqFakeReader::DaqFakeReader")
48  << " TCDS FED ID lower than " << FEDNumbering::MINTCDSuTCAFEDID;
49  if (fillRandom_) {
50  //intialize random seed
51  auto time_count =
52  static_cast<long unsigned int>(std::chrono::high_resolution_clock::now().time_since_epoch().count());
53  srand(time_count & 0xffffffff);
54  }
55  produces<FEDRawDataCollection>();
56 }
57 
58 //______________________________________________________________________________
60 
62 // implementation of member functions
64 
65 //______________________________________________________________________________
67  // a null pointer is passed, need to allocate the fed collection
68  data = new FEDRawDataCollection();
69  EventID eID = e.id();
70  auto ls = e.luminosityBlock();
71 
72  if (!empty_events) {
73  // Fill the EventID
74  eventNum++;
75  // FIXME:
76 
84 
85  timeval now;
86  gettimeofday(&now, nullptr);
87  fillTCDSFED(eID, *data, ls, &now);
88  }
89  return 1;
90 }
91 
94  FEDRawDataCollection* fedcoll = nullptr;
95  fillRawData(e, fedcoll);
96  std::unique_ptr<FEDRawDataCollection> bare_product(fedcoll);
97  e.put(std::move(bare_product));
98 }
99 
100 //______________________________________________________________________________
102  const int fedmin, const int fedmax, EventID& eID, FEDRawDataCollection& data, float meansize, float width) {
103  // FIXME: last ID included?
104  for (int fedId = fedmin; fedId <= fedmax; ++fedId) {
105  // Generate size...
106  float logsiz = CLHEP::RandGauss::shoot(std::log(meansize), std::log(meansize) - std::log(width / 2.));
107  size_t size = int(std::exp(logsiz));
108  size -= size % 8; // all blocks aligned to 64 bit words
109 
110  FEDRawData& feddata = data.FEDData(fedId);
111  // Allocate space for header+trailer+payload
112  feddata.resize(size + 16);
113 
114  if (fillRandom_) {
115  //fill FED with random values
116  size_t size_ui = size - size % sizeof(unsigned int);
117  for (size_t i = 0; i < size_ui; i += sizeof(unsigned int)) {
118  *((unsigned int*)(feddata.data() + i)) = (unsigned int)rand();
119  }
120  //remainder
121  for (size_t i = size_ui; i < size; i++) {
122  *(feddata.data() + i) = rand() & 0xff;
123  }
124  }
125 
126  // Generate header
127  FEDHeader::set(feddata.data(),
128  1, // Trigger type
129  eID.event(), // LV1_id (24 bits)
130  0, // BX_id
131  fedId); // source_id
132 
133  // Payload = all 0s...
134 
135  // Generate trailer
136  int crc = 0; // FIXME : get CRC
137  FEDTrailer::set(feddata.data() + 8 + size,
138  size / 8 + 2, // in 64 bit words!!!
139  crc,
140  0, // Evt_stat
141  0); // TTS bits
142  }
143 }
144 
146  uint32_t fedId = tcdsFEDID_;
147  FEDRawData& feddata = data.FEDData(fedId);
148  uint32_t size = sizeof(tcds::Raw_v1);
149  feddata.resize(size + 16);
150 
151  uint64_t orbitnr = 0;
152  uint16_t bxid = 0;
153 
154  FEDHeader::set(feddata.data(),
155  1, // Trigger type
156  eID.event(), // LV1_id (24 bits)
157  bxid, // BX_id
158  fedId); // source_id
159 
160  tcds::Raw_v1* tcds = reinterpret_cast<tcds::Raw_v1*>(feddata.data() + FEDHeader::length);
161  tcds::BST_v1* bst = const_cast<tcds::BST_v1*>(&tcds->bst);
162  tcds::Header_v1* header = const_cast<tcds::Header_v1*>(&tcds->header);
163 
164  const_cast<uint32_t&>(bst->gpstimehigh) = now->tv_sec;
165  const_cast<uint32_t&>(bst->gpstimelow) = now->tv_usec;
166  const_cast<uint16_t&>(bst->lhcFillHigh) = 0;
167  const_cast<uint16_t&>(bst->lhcFillLow) = 0;
168 
169  const_cast<uint32_t&>(header->orbitHigh) = orbitnr & 0xffff00;
170  const_cast<uint16_t&>(header->orbitLow) = orbitnr & 0xff;
171  const_cast<uint16_t&>(header->bxid) = bxid;
172 
173  const_cast<uint64_t&>(header->eventNumber) = eID.event();
174  const_cast<uint32_t&>(header->lumiSection) = ls;
175 
176  int crc = 0; // only full event crc32c checked in HLT, not FED CRC16
177  FEDTrailer::set(feddata.data() + 8 + size,
178  size / 8 + 2, // in 64 bit words!!!
179  crc,
180  0, // Evt_stat
181  0); // TTS bits
182 }
183 
185  std::cout << "DaqFakeReader begin Lumi " << iL.luminosityBlock() << std::endl;
186  fakeLs_ = iL.luminosityBlock();
187 }
188 
191  desc.setComment("Injector of generated raw FED data for DAQ testing");
192  desc.addUntracked<bool>("emptyEvents", false);
193  desc.addUntracked<bool>("fillRandom", false);
194  desc.addUntracked<unsigned int>("meanSize", 1024);
195  desc.addUntracked<unsigned int>("width", 1024);
196  desc.addUntracked<unsigned int>("injectErrPpm", 1024);
197  desc.addUntracked<unsigned int>("tcdsFEDID", 1024);
198  descriptions.add("DaqFakeReader", desc);
199 }
DeadROC_duringRun.runNum
runNum
Definition: DeadROC_duringRun.py:21
FEDNumbering.h
eostools.ls
def ls(path, rec=False)
Definition: eostools.py:349
ApeEstimator_cff.width
width
Definition: ApeEstimator_cff.py:24
FEDNumbering::MINCSCFEDID
Definition: FEDNumbering.h:51
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
DaqFakeReader::produce
void produce(edm::Event &, edm::EventSetup const &) override
Definition: DaqFakeReader.cc:92
DaqFakeReader::fillTCDSFED
void fillTCDSFED(edm::EventID &eID, FEDRawDataCollection &data, uint32_t ls, timeval *now)
Definition: DaqFakeReader.cc:145
funct::false
false
Definition: Factorize.h:29
DaqFakeReader::empty_events
bool empty_events
Definition: DaqFakeReader.h:53
FEDNumbering::MINSiPixelFEDID
Definition: FEDNumbering.h:27
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
submitPVValidationJobs.now
now
Definition: submitPVValidationJobs.py:639
FEDNumbering::MAXSiPixelFEDID
Definition: FEDNumbering.h:28
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
edm
HLT enums.
Definition: AlignableModifier.h:19
DaqFakeReader::fillRawData
virtual int fillRawData(edm::Event &e, FEDRawDataCollection *&data)
Definition: DaqFakeReader.cc:66
gather_cfg.cout
cout
Definition: gather_cfg.py:144
DaqFakeReader::DaqFakeReader
DaqFakeReader(const edm::ParameterSet &pset)
Definition: DaqFakeReader.cc:34
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
DaqFakeReader::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: DaqFakeReader.cc:189
FEDNumbering::MAXECALFEDID
Definition: FEDNumbering.h:44
FEDNumbering::MAXDTFEDID
Definition: FEDNumbering.h:56
FEDRawData.h
edm::Handle< FEDRawDataCollection >
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
FEDRawData
Definition: FEDRawData.h:19
FEDNumbering::MAXHCALFEDID
Definition: FEDNumbering.h:48
DaqFakeReader::meansize
unsigned int meansize
Definition: DaqFakeReader.h:55
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::LuminosityBlockBase::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: LuminosityBlockBase.h:40
TCDSRaw.h
FEDNumbering::MINSiStripFEDID
Definition: FEDNumbering.h:29
FEDNumbering::MINRPCFEDID
Definition: FEDNumbering.h:59
tcds::Raw_v1
Definition: TCDSRaw.h:106
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
FEDNumbering::MINTCDSuTCAFEDID
Definition: FEDNumbering.h:101
EcalFEDMonitor_cfi.FEDRawDataCollection
FEDRawDataCollection
Definition: EcalFEDMonitor_cfi.py:6
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
DaqFakeReader::eventNum
edm::EventNumber_t eventNum
Definition: DaqFakeReader.h:52
tcds::Header_v1
Definition: TCDSRaw.h:29
edm::ParameterSet
Definition: ParameterSet.h:47
DaqFakeReader::fillRandom_
bool fillRandom_
Definition: DaqFakeReader.h:54
DaqFakeReader.h
FEDNumbering::MINHCALFEDID
Definition: FEDNumbering.h:47
edm::EventID::event
EventNumber_t event() const
Definition: EventID.h:40
createfilelist.int
int
Definition: createfilelist.py:10
FEDHeader::length
static const uint32_t length
Definition: FEDHeader.h:54
edm::EventSetup
Definition: EventSetup.h:58
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:89
FEDTrailer::set
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:31
tcds
Definition: TCDSRaw.h:16
DaqFakeReader::width
unsigned int width
Definition: DaqFakeReader.h:56
DaqFakeReader::fillFEDs
void fillFEDs(const int, const int, edm::EventID &eID, FEDRawDataCollection &data, float meansize, float width)
Definition: DaqFakeReader.cc:101
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DaqFakeReader::fakeLs_
unsigned int fakeLs_
Definition: DaqFakeReader.h:60
GlobalEventNumber.h
FEDNumbering::MAXCSCFEDID
Definition: FEDNumbering.h:52
Exception
Definition: hltDiff.cc:245
FEDHeader::set
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:25
FEDRawData::resize
void resize(size_t newsize)
Definition: FEDRawData.cc:28
FEDNumbering::MINECALFEDID
Definition: FEDNumbering.h:43
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
FEDNumbering::MAXSiStripFEDID
Definition: FEDNumbering.h:30
DaqFakeReader::tcdsFEDID_
unsigned int tcdsFEDID_
Definition: DaqFakeReader.h:58
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:291
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
tcds::BST_v1
Definition: TCDSRaw.h:71
DaqFakeReader::~DaqFakeReader
~DaqFakeReader() override
Definition: DaqFakeReader.cc:59
ParameterSet.h
FEDNumbering::MINDTFEDID
Definition: FEDNumbering.h:55
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
edm::EventID
Definition: EventID.h:31
edm::Event
Definition: Event.h:73
FEDHeader.h
FEDNumbering::MAXRPCFEDID
Definition: FEDNumbering.h:60
DaqFakeReader::beginLuminosityBlock
virtual void beginLuminosityBlock(edm::LuminosityBlock const &iL, edm::EventSetup const &iE)
Definition: DaqFakeReader.cc:184
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
FEDTrailer.h