CMS 3D CMS Logo

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