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 
12 
14 
15 #include "CLHEP/Random/RandGauss.h"
16 
17 #include <cmath>
18 #include <sys/time.h>
19 #include <string.h>
20 
21 
22 using namespace std;
23 using namespace edm;
24 
25 
27 // construction/destruction
29 
30 //______________________________________________________________________________
32  : runNum(1)
33  , eventNum(1)
34  , empty_events(pset.getUntrackedParameter<bool>("emptyEvents",false))
35  , meansize(pset.getUntrackedParameter<unsigned int>("meanSize",1024))
36  , width(pset.getUntrackedParameter<unsigned int>("width",1024))
37  , injected_errors_per_million_events(pset.getUntrackedParameter<unsigned int>("injectErrPpm",0))
38  , modulo_error_events(injected_errors_per_million_events ? 1000000/injected_errors_per_million_events : 0xffffffff)
39 {
40  // mean = pset.getParameter<float>("mean");
41  produces<FEDRawDataCollection>();
42  frb.setEPProcessId(getpid());
43 }
44 
45 //______________________________________________________________________________
47 {
48 
49 }
50 
51 
53 // implementation of member functions
55 
56 //______________________________________________________________________________
59 {
60  // a null pointer is passed, need to allocate the fed collection
61  data=new FEDRawDataCollection();
62  EventID eID = e.id();
63 
64  if(!empty_events)
65  {
66 
67  // Fill the EventID
68  eventNum++;
69  // FIXME:
70 
73  eID, *data, meansize, width);
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);
92  fillFED1023(eID,*data);
93  }
94  return 1;
95 }
96 
98 
100  FEDRawDataCollection *fedcoll = 0;
101  fillRawData(e,fedcoll);
102  std::auto_ptr<FEDRawDataCollection> bare_product(fedcoll);
103  e.put(bare_product);
104 }
105 
106 
107 //______________________________________________________________________________
108 void DaqFakeReader::fillFEDs(const int fedmin, const int fedmax,
109  EventID& eID,
111  float meansize,
112  float width)
113 {
114 
115  // FIXME: last ID included?
116  for (int fedId = fedmin; fedId <= fedmax; ++fedId ) {
117 
118  // Generate size...
119  float logsiz = CLHEP::RandGauss::shoot(std::log(meansize),
120  std::log(meansize)-std::log(width/2.));
121  size_t size = int(std::exp(logsiz));
122  size -= size % 8; // all blocks aligned to 64 bit words
123 
124  FEDRawData& feddata = data.FEDData(fedId);
125  // Allocate space for header+trailer+payload
126  feddata.resize(size+16);
127 
128  // Generate header
129  FEDHeader::set(feddata.data(),
130  1, // Trigger type
131  eID.event(), // LV1_id (24 bits)
132  0, // BX_id
133  fedId); // source_id
134 
135  // Payload = all 0s...
136 
137  // Generate trailer
138  int crc = 0; // FIXME : get CRC
139  FEDTrailer::set(feddata.data()+8+size,
140  size/8+2, // in 64 bit words!!!
141  crc,
142  0, // Evt_stat
143  0); // TTS bits
144  }
145 }
146 
149 {
150  FEDRawData& feddata = data.FEDData(frb.fedId());
151  // Allocate space for header+trailer+payload
152  feddata.resize(frb.size());
153  frb.putHeader(eID.event(),0);
154  if(eID.event()%modulo_error_events==0) frb.setDAQDiaWord1(1ll); else frb.setDAQDiaWord1(0ll);
155  timeval now;
156  gettimeofday(&now, 0);
157  frb.setRBTimeStamp(((uint64_t) (now.tv_sec) << 32) + (uint64_t) (now.tv_usec));
158  frb.putTrailer();
159  memcpy(feddata.data(),frb.getPayload(),frb.size());
160 }
161 
163 {
164  std::cout << "DaqFakeReader begin Lumi " << iL.luminosityBlock() << std::endl;}
unsigned int width
Definition: DaqFakeReader.h:62
EventNumber_t event() const
Definition: EventID.h:44
unsigned int modulo_error_events
Definition: DaqFakeReader.h:64
unsigned int size() const
evf::EvffedFillerRB frb
Definition: DaqFakeReader.h:65
void fillFED1023(edm::EventID &eID, FEDRawDataCollection &data)
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
LuminosityBlockNumber_t luminosityBlock() const
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:116
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:61
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
edm::EventID id() const
Definition: EventBase.h:56
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
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:59
void setRBTimeStamp(uint64_t ts)
tuple cout
Definition: gather_cfg.py:121
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)