CMS 3D CMS Logo

TotemTriggerRawToDigi.cc
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * This is a part of TOTEM offline software.
4 * Authors:
5 * Jan Kašpar (jan.kaspar@gmail.com)
6 *
7 ****************************************************************************/
8 
15 
19 
21 
22 #include <string>
23 #include <iostream>
24 
25 //----------------------------------------------------------------------------------------------------
26 
28 {
29  public:
31  ~TotemTriggerRawToDigi() override;
32 
33  void produce(edm::Event&, const edm::EventSetup&) override;
34 
35  private:
36  unsigned int fedId;
37 
39 
41  int ProcessLoneGFrame(uint64_t *oBuf, unsigned long size, TotemTriggerCounters &data);
42 };
43 
44 //----------------------------------------------------------------------------------------------------
45 
46 using namespace edm;
47 using namespace std;
48 
49 //----------------------------------------------------------------------------------------------------
50 
52  fedId(conf.getParameter<unsigned int>("fedId"))
53 {
54  fedDataToken = consumes<FEDRawDataCollection>(conf.getParameter<edm::InputTag>("rawDataTag"));
55 
56  if (fedId == 0)
58 
59  produces<TotemTriggerCounters>();
60 }
61 
62 //----------------------------------------------------------------------------------------------------
63 
65 {
66 }
67 
68 //----------------------------------------------------------------------------------------------------
69 
71 {
72  // raw data handle
74  event.getByToken(fedDataToken, rawData);
75 
76  // book output products
77  TotemTriggerCounters totemTriggerCounters;
78 
79  // unpack trigger data
80  const FEDRawData &data = rawData->FEDData(fedId);
81  uint64_t *buf = (uint64_t *) data.data();
82  unsigned int sizeInWords = data.size() / 8; // bytes -> words
83  if (data.size() > 0)
84  ProcessLoneGFrame(buf + 2, sizeInWords - 4, totemTriggerCounters);
85 
86  // commit products to event
87  event.put(make_unique<TotemTriggerCounters>(totemTriggerCounters));
88 }
89 
90 //----------------------------------------------------------------------------------------------------
91 
93 {
94  if (size != 20)
95  {
96  LogError("Totem") << "Error in TotemTriggerRawToDigi::ProcessLoneGFrame > " <<
97  "Wrong LoneG frame size: " << size << " (shall be 20)." << endl;
98  return 1;
99  }
100 
101  // buffer mapping: OptoRx buffer --> LoneG buffer
102  uint64_t buf[5];
103  for (unsigned int i = 0; i < 5; i++)
104  buf[i] = 0;
105 
106  for (unsigned int i = 0; i < 20; i++)
107  {
108  int row = i / 4;
109  int col = i % 4;
110  buf[row] |= (oBuf[i] & 0xFFFF) << (col * 16);
111  }
112 
113  td.type = (buf[0] >> 56) & 0xF;
114  td.event_num = (buf[0] >> 32) & 0xFFFFFF;
115  td.bunch_num = (buf[0] >> 20) & 0xFFF;
116  td.src_id = (buf[0] >> 8) & 0xFFF;
117 
118  td.orbit_num = (buf[1] >> 32) & 0xFFFFFFFF;
119  td.revision_num = (buf[1] >> 24) & 0xFF;
120 
121  td.run_num = (buf[2] >> 32) & 0xFFFFFFFF;
122  td.trigger_num = (buf[2] >> 0) & 0xFFFFFFFF;
123 
124  td.inhibited_triggers_num = (buf[3] >> 32) & 0xFFFFFFFF;
125  td.input_status_bits = (buf[3] >> 0) & 0xFFFFFFFF;
126 
127 #ifdef DEBUG
128  printf(">> RawDataUnpacker::ProcessLoneGFrame > size = %li\n", size);
129  printf("\ttype = %x, event number = %x, bunch number = %x, id = %x\n",
130  td.type, td.event_num, td.bunch_num, td.src_id);
131  printf("\torbit number = %x, revision = %x\n",
132  td.orbit_num, td.revision_num);
133  printf("\trun number = %x, trigger number = %x\n",
134  td.run_num, td.trigger_num);
135  printf("\tinhibited triggers = %x, input status bits = %x\n",
137 #endif
138 
139  return 0;
140 }
141 
142 //----------------------------------------------------------------------------------------------------
143 
size
Write out results.
T getParameter(std::string const &) const
int ProcessLoneGFrame(uint64_t *oBuf, unsigned long size, TotemTriggerCounters &data)
Process one LoneG frame.
TotemTriggerRawToDigi(const edm::ParameterSet &)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
unsigned long long uint64_t
Definition: Time.h:15
unsigned int inhibited_triggers_num
HLT enums.
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
col
Definition: cuy.py:1010
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< FEDRawDataCollection > fedDataToken
Definition: event.py:1