CMS 3D CMS Logo

Phase2TrackerDigiProducer.cc
Go to the documentation of this file.
22 
23 namespace Phase2Tracker {
24 
26  public:
30  ~Phase2TrackerDigiProducer() override = default;
31  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
32 
33  private:
35 
38  class Registry {
39  public:
41  Registry(uint32_t aDetid, uint16_t firstStrip, size_t indexInVector, uint16_t numberOfDigis)
42  : detid(aDetid), first(firstStrip), index(indexInVector), length(numberOfDigis) {}
44  bool operator<(const Registry& other) const {
45  return (detid != other.detid ? detid < other.detid : first < other.first);
46  }
48  uint32_t detid;
49  uint16_t first;
50  size_t index;
51  uint16_t length;
52  };
53  };
54 } // namespace Phase2Tracker
55 
59 
60 using namespace std;
61 
62 namespace Phase2Tracker {
63 
65  : ph2CablingESToken_(esConsumes()),
66  token_(consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("ProductLabel"))),
67  putToken_(produces<edm::DetSetVector<Phase2TrackerDigi>>("ProcessedRaw")) {}
68 
70  // fetch cabling from event setup
71  auto const& cabling = es.getData(ph2CablingESToken_);
72 
73  // Retrieve FEDRawData collection
75  event.getByToken(token_, buffers);
76 
77  //reserve enough working memory
78  std::vector<Registry> proc_work_registry;
79  std::vector<Phase2TrackerDigi> proc_work_digis;
80  {
81  size_t reserve_count = 0;
82  size_t reserve_digis = 0;
84  const FEDRawData& fed = buffers->FEDData(fedIndex);
85  if (fed.size() != 0) {
86  // construct buffer
88  int ichan = 0;
89  for (int ife = 0; ife < MAX_FE_PER_FED; ife++) {
90  for (int icbc = 0; icbc < MAX_CBC_PER_FE; icbc++) {
91  if (buffer.channel(ichan).length() > 0) {
92  ++reserve_count;
93  //calculation from Phase2TrackerFEDRawChannelUnpacker.h
94  reserve_digis += buffer.channel(ichan).length() * 8 - STRIPS_PADDING;
95  ++ichan;
96  }
97  }
98  }
99  }
100  }
101  proc_work_registry.reserve(2 * reserve_count);
102  proc_work_digis.reserve(reserve_digis);
103  }
104  // Analyze strip tracker FED buffers in data
106  const FEDRawData& fed = buffers->FEDData(fedIndex);
107  if (fed.size() != 0) {
108  // construct buffer
110 
111 #ifdef EDM_ML_DEBUG
112  std::ostringstream ss;
113  ss << " -------------------------------------------- " << endl;
114  ss << " buffer debug ------------------------------- " << endl;
115  ss << " -------------------------------------------- " << endl;
116  ss << " buffer size : " << buffer.bufferSize() << endl;
117  ss << " fed id : " << fedIndex << endl;
118  ss << " -------------------------------------------- " << endl;
119  ss << " tracker header debug ------------------------" << endl;
120  ss << " -------------------------------------------- " << endl;
121  LogTrace("Phase2TrackerDigiProducer") << ss.str();
122  ss.clear();
123  ss.str("");
124 
125  Phase2TrackerFEDHeader tr_header = buffer.trackerHeader();
126  ss << " Version : " << hex << setw(2) << (int)tr_header.getDataFormatVersion() << endl;
127  ss << " Mode : " << hex << setw(2) << tr_header.getDebugMode() << endl;
128  ss << " Type : " << hex << setw(2) << (int)tr_header.getEventType() << endl;
129  ss << " Readout : " << hex << setw(2) << tr_header.getReadoutMode() << endl;
130  ss << " Condition Data : " << (tr_header.getConditionData() ? "Present" : "Absent") << "\n";
131  ss << " Data Type : " << (tr_header.getDataType() ? "Real" : "Fake") << "\n";
132  ss << " Status : " << hex << setw(16) << (int)tr_header.getGlibStatusCode() << endl;
133  ss << " FE stat : ";
134  for (int i = 15; i >= 0; i--) {
135  if ((tr_header.frontendStatus())[i]) {
136  ss << "1";
137  } else {
138  ss << "0";
139  }
140  }
141  ss << endl;
142  ss << " Nr CBC : " << hex << setw(16) << (int)tr_header.getNumberOfCBC() << endl;
143  ss << " CBC stat : ";
144  for (int i = 0; i < tr_header.getNumberOfCBC(); i++) {
145  ss << hex << setw(2) << (int)tr_header.CBCStatus()[i] << " ";
146  }
147  ss << endl;
148  LogTrace("Phase2TrackerDigiProducer") << ss.str();
149  ss.clear();
150  ss.str("");
151  ss << " -------------------------------------------- " << endl;
152  ss << " Payload ----------------------------------- " << endl;
153  ss << " -------------------------------------------- " << endl;
154 #endif
155 
156  // loop channels
157  int ichan = 0;
158  for (int ife = 0; ife < MAX_FE_PER_FED; ife++) {
159  for (int icbc = 0; icbc < MAX_CBC_PER_FE; icbc++) {
160  const Phase2TrackerFEDChannel& channel = buffer.channel(ichan);
161  if (channel.length() > 0) {
162  // get fedid from cabling
163  const Phase2TrackerModule mod = cabling.findFedCh(std::make_pair(fedIndex, ife));
164  uint32_t detid = mod.getDetid();
165 #ifdef EDM_ML_DEBUG
166  ss << dec << " id from cabling : " << detid << endl;
167  ss << dec << " reading channel : " << icbc << " on FE " << ife;
168  ss << dec << " with length : " << (int)channel.length() << endl;
169 #endif
170 
171  // container for this channel's digis
172  std::vector<Phase2TrackerDigi> stripsTop;
173  std::vector<Phase2TrackerDigi> stripsBottom;
174 
175  // unpacking data
177  while (unpacker.hasData()) {
178  if (unpacker.stripOn()) {
179  if (unpacker.stripIndex() % 2) {
180  stripsTop.push_back(Phase2TrackerDigi((int)(STRIPS_PER_CBC * icbc + unpacker.stripIndex()) / 2, 0));
181 #ifdef EDM_ML_DEBUG
182  ss << "t";
183 #endif
184  } else {
185  stripsBottom.push_back(
186  Phase2TrackerDigi((int)(STRIPS_PER_CBC * icbc + unpacker.stripIndex()) / 2, 0));
187 #ifdef EDM_ML_DEBUG
188  ss << "b";
189 #endif
190  }
191  } else {
192 #ifdef EDM_ML_DEBUG
193  ss << "_";
194 #endif
195  }
196  unpacker++;
197  }
198 #ifdef EDM_ML_DEBUG
199  ss << endl;
200  LogTrace("Phase2TrackerDigiProducer") << ss.str();
201  ss.clear();
202  ss.str("");
203 #endif
204 
205  // store beginning and end of this digis for this detid and add this registry to the list
206  // and store data
207  proc_work_registry.emplace_back(
208  detid + 1, STRIPS_PER_CBC * icbc / 2, proc_work_digis.size(), stripsTop.size());
209  proc_work_digis.insert(proc_work_digis.end(), stripsTop.begin(), stripsTop.end());
210  proc_work_registry.emplace_back(
211  detid + 2, STRIPS_PER_CBC * icbc / 2, proc_work_digis.size(), stripsBottom.size());
212  proc_work_digis.insert(proc_work_digis.end(), stripsBottom.begin(), stripsBottom.end());
213  }
214  ichan++;
215  }
216  } // end loop on channels
217  }
218  }
219 
220  // store digis in edm collections
221  std::sort(proc_work_registry.begin(), proc_work_registry.end());
222  std::vector<edm::DetSet<Phase2TrackerDigi>> sorted_and_merged;
223 
224  std::vector<Registry>::iterator it = proc_work_registry.begin(), it2 = it + 1, end = proc_work_registry.end();
225  while (it < end) {
226  sorted_and_merged.push_back(edm::DetSet<Phase2TrackerDigi>(it->detid));
227  std::vector<Phase2TrackerDigi>& digis = sorted_and_merged.back().data;
228  // first count how many digis we have
229  size_t len = it->length;
230  for (it2 = it + 1; (it2 != end) && (it2->detid == it->detid); ++it2) {
231  len += it2->length;
232  }
233  // reserve memory
234  digis.reserve(len);
235  // push them in
236  for (it2 = it + 0; (it2 != end) && (it2->detid == it->detid); ++it2) {
237  digis.insert(digis.end(), &proc_work_digis[it2->index], &proc_work_digis[it2->index + it2->length]);
238  }
239  it = it2;
240  }
241  event.emplace(putToken_, sorted_and_merged, true);
242  }
243 } // namespace Phase2Tracker
std::vector< uint8_t > CBCStatus() const
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:48
static const uint16_t CMS_FED_ID_MAX
Definition: utils.h:20
Phase2Tracker::Phase2TrackerDigiProducer Phase2TrackerDigiProducer
#define LogTrace(id)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
static const int MAX_CBC_PER_FE
Definition: utils.h:26
const edm::EDGetTokenT< FEDRawDataCollection > token_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Phase2TrackerDigiProducer(const edm::ParameterSet &pset)
constructor
~Phase2TrackerDigiProducer() override=default
default constructor
HLT enums.
const edm::EDPutTokenT< edm::DetSetVector< Phase2TrackerDigi > > putToken_
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
static const int STRIPS_PER_CBC
Definition: utils.h:27
const edm::ESGetToken< Phase2TrackerCabling, Phase2TrackerCablingRcd > ph2CablingESToken_
static const uint16_t FED_ID_MIN
Definition: utils.h:18
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
static const int MAX_FE_PER_FED
Definition: utils.h:25
__host__ __device__ fedId_t fedIndex(fedId_t fed)
bool operator<(const Registry &other) const
< operator to sort registries
static const int STRIPS_PADDING
Definition: utils.h:28
Registry(uint32_t aDetid, uint16_t firstStrip, size_t indexInVector, uint16_t numberOfDigis)
constructor
Definition: event.py:1