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 beginRun(edm::Run const&, edm::EventSetup const&) override;
32  void produce(edm::Event&, const edm::EventSetup&) override;
33 
34  private:
36 
37  unsigned int runNumber_;
40  uint32_t cacheId_;
42  class Registry {
43  public:
45  Registry(uint32_t aDetid, uint16_t firstStrip, size_t indexInVector, uint16_t numberOfDigis)
46  : detid(aDetid), first(firstStrip), index(indexInVector), length(numberOfDigis) {}
48  bool operator<(const Registry& other) const {
49  return (detid != other.detid ? detid < other.detid : first < other.first);
50  }
52  uint32_t detid;
53  uint16_t first;
54  size_t index;
55  uint16_t length;
56  };
57  std::vector<Registry> proc_work_registry_;
58  std::vector<Phase2TrackerDigi> proc_work_digis_;
59  };
60 } // namespace Phase2Tracker
61 
65 
66 using namespace std;
67 
68 namespace Phase2Tracker {
69 
71  : ph2CablingESToken_(esConsumes<edm::Transition::BeginRun>()), runNumber_(0), cabling_(nullptr), cacheId_(0) {
72  // define product
73  produces<edm::DetSetVector<Phase2TrackerDigi>>("ProcessedRaw");
74  token_ = consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("ProductLabel"));
75  }
76 
78  // fetch cabling from event setup
80  }
81 
83  // empty vectors for the next event
84  proc_work_registry_.clear();
85  proc_work_digis_.clear();
86 
87  // Retrieve FEDRawData collection
89  event.getByToken(token_, buffers);
90 
91  // Analyze strip tracker FED buffers in data
92  size_t fedIndex;
94  const FEDRawData& fed = buffers->FEDData(fedIndex);
95  if (fed.size() != 0) {
96  // construct buffer
99 
100 #ifdef EDM_ML_DEBUG
101  std::ostringstream ss;
102  ss << " -------------------------------------------- " << endl;
103  ss << " buffer debug ------------------------------- " << endl;
104  ss << " -------------------------------------------- " << endl;
105  ss << " buffer size : " << buffer->bufferSize() << endl;
106  ss << " fed id : " << fedIndex << endl;
107  ss << " -------------------------------------------- " << endl;
108  ss << " tracker header debug ------------------------" << endl;
109  ss << " -------------------------------------------- " << endl;
110  LogTrace("Phase2TrackerDigiProducer") << ss.str();
111  ss.clear();
112  ss.str("");
113 
114  Phase2TrackerFEDHeader tr_header = buffer->trackerHeader();
115  ss << " Version : " << hex << setw(2) << (int)tr_header.getDataFormatVersion() << endl;
116  ss << " Mode : " << hex << setw(2) << tr_header.getDebugMode() << endl;
117  ss << " Type : " << hex << setw(2) << (int)tr_header.getEventType() << endl;
118  ss << " Readout : " << hex << setw(2) << tr_header.getReadoutMode() << endl;
119  ss << " Condition Data : " << (tr_header.getConditionData() ? "Present" : "Absent") << "\n";
120  ss << " Data Type : " << (tr_header.getDataType() ? "Real" : "Fake") << "\n";
121  ss << " Status : " << hex << setw(16) << (int)tr_header.getGlibStatusCode() << endl;
122  ss << " FE stat : ";
123  for (int i = 15; i >= 0; i--) {
124  if ((tr_header.frontendStatus())[i]) {
125  ss << "1";
126  } else {
127  ss << "0";
128  }
129  }
130  ss << endl;
131  ss << " Nr CBC : " << hex << setw(16) << (int)tr_header.getNumberOfCBC() << endl;
132  ss << " CBC stat : ";
133  for (int i = 0; i < tr_header.getNumberOfCBC(); i++) {
134  ss << hex << setw(2) << (int)tr_header.CBCStatus()[i] << " ";
135  }
136  ss << endl;
137  LogTrace("Phase2TrackerDigiProducer") << ss.str();
138  ss.clear();
139  ss.str("");
140  ss << " -------------------------------------------- " << endl;
141  ss << " Payload ----------------------------------- " << endl;
142  ss << " -------------------------------------------- " << endl;
143 #endif
144 
145  // loop channels
146  int ichan = 0;
147  for (int ife = 0; ife < MAX_FE_PER_FED; ife++) {
148  for (int icbc = 0; icbc < MAX_CBC_PER_FE; icbc++) {
149  const Phase2TrackerFEDChannel& channel = buffer->channel(ichan);
150  if (channel.length() > 0) {
151  // get fedid from cabling
152  const Phase2TrackerModule mod = cabling_->findFedCh(std::make_pair(fedIndex, ife));
153  uint32_t detid = mod.getDetid();
154 #ifdef EDM_ML_DEBUG
155  ss << dec << " id from cabling : " << detid << endl;
156  ss << dec << " reading channel : " << icbc << " on FE " << ife;
157  ss << dec << " with length : " << (int)channel.length() << endl;
158 #endif
159 
160  // container for this channel's digis
161  std::vector<Phase2TrackerDigi> stripsTop;
162  std::vector<Phase2TrackerDigi> stripsBottom;
163 
164  // unpacking data
166  while (unpacker.hasData()) {
167  if (unpacker.stripOn()) {
168  if (unpacker.stripIndex() % 2) {
169  stripsTop.push_back(Phase2TrackerDigi((int)(STRIPS_PER_CBC * icbc + unpacker.stripIndex()) / 2, 0));
170 #ifdef EDM_ML_DEBUG
171  ss << "t";
172 #endif
173  } else {
174  stripsBottom.push_back(
175  Phase2TrackerDigi((int)(STRIPS_PER_CBC * icbc + unpacker.stripIndex()) / 2, 0));
176 #ifdef EDM_ML_DEBUG
177  ss << "b";
178 #endif
179  }
180  } else {
181 #ifdef EDM_ML_DEBUG
182  ss << "_";
183 #endif
184  }
185  unpacker++;
186  }
187 #ifdef EDM_ML_DEBUG
188  ss << endl;
189  LogTrace("Phase2TrackerDigiProducer") << ss.str();
190  ss.clear();
191  ss.str("");
192 #endif
193 
194  // store beginning and end of this digis for this detid and add this registry to the list
195  // and store data
196  Registry regItemTop(detid + 1, STRIPS_PER_CBC * icbc / 2, proc_work_digis_.size(), stripsTop.size());
197  proc_work_registry_.push_back(regItemTop);
198  proc_work_digis_.insert(proc_work_digis_.end(), stripsTop.begin(), stripsTop.end());
199  Registry regItemBottom(
200  detid + 2, STRIPS_PER_CBC * icbc / 2, proc_work_digis_.size(), stripsBottom.size());
201  proc_work_registry_.push_back(regItemBottom);
202  proc_work_digis_.insert(proc_work_digis_.end(), stripsBottom.begin(), stripsBottom.end());
203  }
204  ichan++;
205  }
206  } // end loop on channels
207  // store digis in edm collections
209  std::vector<edm::DetSet<Phase2TrackerDigi>> sorted_and_merged;
210 
212 
213  std::vector<Registry>::iterator it = proc_work_registry_.begin(), it2 = it + 1, end = proc_work_registry_.end();
214  while (it < end) {
215  sorted_and_merged.push_back(edm::DetSet<Phase2TrackerDigi>(it->detid));
216  std::vector<Phase2TrackerDigi>& digis = sorted_and_merged.back().data;
217  // first count how many digis we have
218  size_t len = it->length;
219  for (it2 = it + 1; (it2 != end) && (it2->detid == it->detid); ++it2) {
220  len += it2->length;
221  }
222  // reserve memory
223  digis.reserve(len);
224  // push them in
225  for (it2 = it + 0; (it2 != end) && (it2->detid == it->detid); ++it2) {
226  digis.insert(digis.end(), &proc_work_digis_[it2->index], &proc_work_digis_[it2->index + it2->length]);
227  }
228  it = it2;
229  }
230 
231  edm::DetSetVector<Phase2TrackerDigi> proc_raw_dsv(sorted_and_merged, true);
232  pr->swap(proc_raw_dsv);
233  event.put(std::unique_ptr<edm::DetSetVector<Phase2TrackerDigi>>(pr), "ProcessedRaw");
234  delete buffer;
235  }
236  }
237  }
238 } // namespace Phase2Tracker
static const char runNumber_[]
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
void reserve(size_t s)
Definition: DetSetVector.h:147
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
static const uint16_t CMS_FED_ID_MAX
Definition: utils.h:19
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
edm::EDGetTokenT< FEDRawDataCollection > token_
Phase2Tracker::Phase2TrackerDigiProducer Phase2TrackerDigiProducer
#define LogTrace(id)
void produce(edm::Event &, const edm::EventSetup &) override
static const int MAX_CBC_PER_FE
Definition: utils.h:25
std::vector< Phase2TrackerDigi > proc_work_digis_
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const Phase2TrackerModule & findFedCh(std::pair< unsigned int, unsigned int > fedch) const
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Phase2TrackerDigiProducer(const edm::ParameterSet &pset)
constructor
void beginRun(edm::Run const &, edm::EventSetup const &) override
~Phase2TrackerDigiProducer() override=default
default constructor
HLT enums.
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:26
const edm::ESGetToken< Phase2TrackerCabling, Phase2TrackerCablingRcd > ph2CablingESToken_
static const uint16_t FED_ID_MIN
Definition: utils.h:17
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
static const int MAX_FE_PER_FED
Definition: utils.h:24
__host__ __device__ fedId_t fedIndex(fedId_t fed)
bool operator<(const Registry &other) const
< operator to sort registries
Registry(uint32_t aDetid, uint16_t firstStrip, size_t indexInVector, uint16_t numberOfDigis)
constructor
Definition: event.py:1
Definition: Run.h:45