CMS 3D CMS Logo

Phase2TrackerDigiProducer.cc
Go to the documentation of this file.
25 
26 namespace Phase2Tracker {
27 
29  public:
33  ~Phase2TrackerDigiProducer() override;
34  void beginJob() override;
35  void beginRun(edm::Run const&, edm::EventSetup const&) override;
36  void produce(edm::Event&, const edm::EventSetup&) override;
37  void endJob() override;
38 
39  private:
40  unsigned int runNumber_;
43  uint32_t cacheId_;
45  class Registry {
46  public:
48  Registry(uint32_t aDetid, uint16_t firstStrip, size_t indexInVector, uint16_t numberOfDigis)
49  : detid(aDetid), first(firstStrip), index(indexInVector), length(numberOfDigis) {}
51  bool operator<(const Registry& other) const {
52  return (detid != other.detid ? detid < other.detid : first < other.first);
53  }
55  uint32_t detid;
56  uint16_t first;
57  size_t index;
58  uint16_t length;
59  };
60  std::vector<Registry> proc_work_registry_;
61  std::vector<Phase2TrackerDigi> proc_work_digis_;
62  };
63 } // namespace Phase2Tracker
64 
68 
69 using namespace std;
70 
71 namespace Phase2Tracker {
72 
74  : runNumber_(0), cabling_(nullptr), cacheId_(0) {
75  // define product
76  produces<edm::DetSetVector<Phase2TrackerDigi>>("ProcessedRaw");
77  token_ = consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("ProductLabel"));
78  }
79 
81 
83 
85  // fetch cabling from event setup
88  cabling_ = c.product();
89  }
90 
92 
94  // empty vectors for the next event
95  proc_work_registry_.clear();
96  proc_work_digis_.clear();
97 
98  // Retrieve FEDRawData collection
100  event.getByToken(token_, buffers);
101 
102  // Analyze strip tracker FED buffers in data
103  size_t fedIndex;
105  const FEDRawData& fed = buffers->FEDData(fedIndex);
106  if (fed.size() != 0) {
107  // 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  Registry regItemTop(detid + 1, STRIPS_PER_CBC * icbc / 2, proc_work_digis_.size(), stripsTop.size());
208  proc_work_registry_.push_back(regItemTop);
209  proc_work_digis_.insert(proc_work_digis_.end(), stripsTop.begin(), stripsTop.end());
210  Registry regItemBottom(
211  detid + 2, STRIPS_PER_CBC * icbc / 2, proc_work_digis_.size(), stripsBottom.size());
212  proc_work_registry_.push_back(regItemBottom);
213  proc_work_digis_.insert(proc_work_digis_.end(), stripsBottom.begin(), stripsBottom.end());
214  }
215  ichan++;
216  }
217  } // end loop on channels
218  // store digis in edm collections
220  std::vector<edm::DetSet<Phase2TrackerDigi>> sorted_and_merged;
221 
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 
242  edm::DetSetVector<Phase2TrackerDigi> proc_raw_dsv(sorted_and_merged, true);
243  pr->swap(proc_raw_dsv);
244  event.put(std::unique_ptr<edm::DetSetVector<Phase2TrackerDigi>>(pr), "ProcessedRaw");
245  delete buffer;
246  }
247  }
248  }
249 } // namespace Phase2Tracker
FEDNumbering.h
edm::DetSetVector
Definition: DetSetVector.h:61
fed_trailer.h
Phase2Tracker::Phase2TrackerFEDChannel
Definition: Phase2TrackerFEDChannel.h:12
Handle.h
Phase2Tracker::Phase2TrackerFEDHeader::CBCStatus
std::vector< uint8_t > CBCStatus() const
Definition: Phase2TrackerFEDHeader.cc:127
mps_fire.i
i
Definition: mps_fire.py:428
Phase2TrackerFEDRawChannelUnpacker.h
MessageLogger.h
sistrip::SpyUtilities::fedIndex
void fedIndex(uint32_t aFedIndex, uint16_t &aFedId, uint16_t &aFedChannel)
Definition: SiStripSpyUtilities.cc:300
EDProducer.h
Phase2Tracker::Phase2TrackerFEDHeader::getReadoutMode
FEDReadoutMode getReadoutMode() const
Definition: Phase2TrackerFEDHeader.h:23
Phase2Tracker::CMS_FED_ID_MAX
static const uint16_t CMS_FED_ID_MAX
Definition: utils.h:19
ESHandle.h
Phase2TrackerCabling
Definition: Phase2TrackerCabling.h:9
edm::DetSet
Definition: DetSet.h:23
Phase2Tracker::Phase2TrackerDigiProducer::proc_work_digis_
std::vector< Phase2TrackerDigi > proc_work_digis_
Definition: Phase2TrackerDigiProducer.cc:61
fed_header.h
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< FEDRawDataCollection >
Phase2Tracker::Phase2TrackerFEDRawChannelUnpacker::stripOn
bool stripOn() const
Definition: Phase2TrackerFEDRawChannelUnpacker.h:17
mod
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
Phase2Tracker::Phase2TrackerDigiProducer::Registry::first
uint16_t first
Definition: Phase2TrackerDigiProducer.cc:56
Phase2Tracker::Phase2TrackerDigiProducer::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: Phase2TrackerDigiProducer.cc:84
Phase2Tracker::Phase2TrackerDigiProducer::Phase2TrackerDigiProducer
Phase2TrackerDigiProducer(const edm::ParameterSet &pset)
constructor
Definition: Phase2TrackerDigiProducer.cc:73
Phase2Tracker::Phase2TrackerFEDHeader::getEventType
uint8_t getEventType() const
Definition: Phase2TrackerFEDHeader.h:22
utils.h
Phase2Tracker::Phase2TrackerDigiProducer::Registry::operator<
bool operator<(const Registry &other) const
< operator to sort registries
Definition: Phase2TrackerDigiProducer.cc:51
edm::Handle< FEDRawDataCollection >
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
FEDRawData
Definition: FEDRawData.h:19
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
MakerMacros.h
Phase2Tracker::Phase2TrackerDigiProducer::endJob
void endJob() override
Definition: Phase2TrackerDigiProducer.cc:91
Phase2Tracker::MAX_CBC_PER_FE
static const int MAX_CBC_PER_FE
Definition: utils.h:25
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Phase2Tracker::Phase2TrackerDigiProducer::Registry::Registry
Registry(uint32_t aDetid, uint16_t firstStrip, size_t indexInVector, uint16_t numberOfDigis)
constructor
Definition: Phase2TrackerDigiProducer.cc:48
Phase2TrackerCablingRcd.h
Phase2TrackerFEDChannel.h
mps_fire.end
end
Definition: mps_fire.py:242
edm::ESHandle
Definition: DTSurvey.h:22
Phase2Tracker::Phase2TrackerDigiProducer::detids_
DetIdCollection detids_
Definition: Phase2TrackerDigiProducer.cc:44
trackingPlots.other
other
Definition: trackingPlots.py:1460
Phase2TrackerCabling::findFedCh
const Phase2TrackerModule & findFedCh(std::pair< unsigned int, unsigned int > fedch) const
Definition: Phase2TrackerCabling.cc:84
Phase2Tracker::Phase2TrackerFEDHeader::getNumberOfCBC
uint16_t getNumberOfCBC() const
Definition: Phase2TrackerFEDHeader.h:28
Phase2Tracker::Phase2TrackerDigiProducer::beginJob
void beginJob() override
Definition: Phase2TrackerDigiProducer.cc:82
Phase2Tracker::Phase2TrackerDigiProducer::Registry
Definition: Phase2TrackerDigiProducer.cc:45
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
Phase2Tracker::Phase2TrackerDigiProducer::token_
edm::EDGetTokenT< FEDRawDataCollection > token_
Definition: Phase2TrackerDigiProducer.cc:41
Phase2TrackerDigi.h
Phase2TrackerDigiProducer
Phase2Tracker::Phase2TrackerDigiProducer Phase2TrackerDigiProducer
Definition: Phase2TrackerDigiProducer.cc:66
edm::ParameterSet
Definition: ParameterSet.h:47
Phase2Tracker::Phase2TrackerFEDHeader::getDataType
uint8_t getDataType() const
Definition: Phase2TrackerFEDHeader.h:25
Phase2TrackerFEDZSChannelUnpacker.h
Phase2Tracker::Phase2TrackerFEDRawChannelUnpacker::hasData
bool hasData() const
Definition: Phase2TrackerFEDRawChannelUnpacker.h:18
sipixeldigitoraw
Definition: SiPixelDigiToRaw.cc:39
Event.h
Phase2Tracker::Phase2TrackerFEDChannel::length
uint16_t length() const
Definition: Phase2TrackerFEDChannel.h:22
Phase2Tracker::Phase2TrackerFEDBuffer
Definition: Phase2TrackerFEDBuffer.h:14
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
Phase2Tracker::Phase2TrackerFEDRawChannelUnpacker::stripIndex
uint8_t stripIndex() const
Definition: Phase2TrackerFEDRawChannelUnpacker.h:16
createfilelist.int
int
Definition: createfilelist.py:10
Phase2TrackerModule
Definition: Phase2TrackerModule.h:9
FEDRawDataCollection.h
Phase2Tracker::Phase2TrackerFEDRawChannelUnpacker
Definition: Phase2TrackerFEDRawChannelUnpacker.h:13
edm::EventSetup
Definition: EventSetup.h:58
Phase2Tracker::Phase2TrackerFEDHeader::getConditionData
uint8_t getConditionData() const
Definition: Phase2TrackerFEDHeader.h:24
DetSetVector.h
Phase2TrackerCabling.h
Phase2Tracker::Phase2TrackerDigiProducer::runNumber_
unsigned int runNumber_
Definition: Phase2TrackerDigiProducer.cc:40
get
#define get
Phase2Tracker::Phase2TrackerDigiProducer::Registry::index
size_t index
Definition: Phase2TrackerDigiProducer.cc:57
edm::EDCollection< DetId >
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
Phase2Tracker::Phase2TrackerDigiProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: Phase2TrackerDigiProducer.cc:93
Phase2Tracker::Phase2TrackerFEDHeader
Definition: Phase2TrackerFEDHeader.h:12
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
Phase2TrackerDigi
Definition: Phase2TrackerDigi.h:12
Phase2Tracker::Phase2TrackerDigiProducer::proc_work_registry_
std::vector< Registry > proc_work_registry_
Definition: Phase2TrackerDigiProducer.cc:60
Phase2TrackerCablingRcd
Definition: SiStripCondDataRecords.h:62
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
Phase2Tracker::Phase2TrackerDigiProducer::cabling_
const Phase2TrackerCabling * cabling_
Definition: Phase2TrackerDigiProducer.cc:42
Phase2Tracker::Phase2TrackerDigiProducer
Definition: Phase2TrackerDigiProducer.cc:28
Phase2Tracker::MAX_FE_PER_FED
static const int MAX_FE_PER_FED
Definition: utils.h:24
Phase2TrackerFEDHeader.h
Phase2Tracker::Phase2TrackerDigiProducer::cacheId_
uint32_t cacheId_
Definition: Phase2TrackerDigiProducer.cc:43
EventSetup.h
edm::EDProducer
Definition: EDProducer.h:35
Exception.h
Phase2Tracker::Phase2TrackerFEDHeader::getGlibStatusCode
uint64_t getGlibStatusCode() const
Definition: Phase2TrackerFEDHeader.h:27
Phase2Tracker::Phase2TrackerDigiProducer::Registry::length
uint16_t length
Definition: Phase2TrackerDigiProducer.cc:58
DetSet.h
Phase2Tracker::Phase2TrackerFEDHeader::frontendStatus
std::vector< bool > frontendStatus() const
Definition: Phase2TrackerFEDHeader.cc:109
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
ParameterSet.h
Phase2Tracker::STRIPS_PER_CBC
static const int STRIPS_PER_CBC
Definition: utils.h:26
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
Phase2Tracker::FED_ID_MIN
static const uint16_t FED_ID_MIN
Definition: utils.h:17
Phase2Tracker::Phase2TrackerDigiProducer::Registry::detid
uint32_t detid
public data members
Definition: Phase2TrackerDigiProducer.cc:55
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
Phase2Tracker::Phase2TrackerDigiProducer::~Phase2TrackerDigiProducer
~Phase2TrackerDigiProducer() override
default constructor
Definition: Phase2TrackerDigiProducer.cc:80
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
edm::InputTag
Definition: InputTag.h:15
sistrip::runNumber_
static const char runNumber_[]
Definition: ConstantsForDqm.h:33
Phase2Tracker
Definition: Phase2TrackerFEDBuffer.h:12
Phase2Tracker::Phase2TrackerFEDHeader::getDataFormatVersion
uint8_t getDataFormatVersion() const
Definition: Phase2TrackerFEDHeader.h:19
DetIdCollection.h
Phase2TrackerFEDBuffer.h
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
Phase2Tracker::Phase2TrackerFEDHeader::getDebugMode
READ_MODE getDebugMode() const
Definition: Phase2TrackerFEDHeader.h:20