CMS 3D CMS Logo

Phase2TrackerDigiProducer.cc
Go to the documentation of this file.
16 #include <iostream>
17 #include <sstream>
18 #include <iomanip>
19 #include <ext/algorithm>
20 
21 using namespace std;
22 
23 namespace Phase2Tracker {
24 
26  : runNumber_(0), cabling_(nullptr), cacheId_(0) {
27  // define product
28  produces<edm::DetSetVector<Phase2TrackerDigi>>("ProcessedRaw");
29  token_ = consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("ProductLabel"));
30  }
31 
33 
35 
37  // fetch cabling from event setup
40  cabling_ = c.product();
41  }
42 
44 
46  // empty vectors for the next event
47  proc_work_registry_.clear();
48  proc_work_digis_.clear();
49 
50  // Retrieve FEDRawData collection
52  event.getByToken(token_, buffers);
53 
54  // Analyze strip tracker FED buffers in data
55  size_t fedIndex;
56  for (fedIndex = Phase2Tracker::FED_ID_MIN; fedIndex < Phase2Tracker::CMS_FED_ID_MAX; ++fedIndex) {
57  const FEDRawData& fed = buffers->FEDData(fedIndex);
58  if (fed.size() != 0) {
59  // construct buffer
62 
63 #ifdef EDM_ML_DEBUG
64  std::ostringstream ss;
65  ss << " -------------------------------------------- " << endl;
66  ss << " buffer debug ------------------------------- " << endl;
67  ss << " -------------------------------------------- " << endl;
68  ss << " buffer size : " << buffer->bufferSize() << endl;
69  ss << " fed id : " << fedIndex << endl;
70  ss << " -------------------------------------------- " << endl;
71  ss << " tracker header debug ------------------------" << endl;
72  ss << " -------------------------------------------- " << endl;
73  LogTrace("Phase2TrackerDigiProducer") << ss.str();
74  ss.clear();
75  ss.str("");
76 
77  Phase2TrackerFEDHeader tr_header = buffer->trackerHeader();
78  ss << " Version : " << hex << setw(2) << (int)tr_header.getDataFormatVersion() << endl;
79  ss << " Mode : " << hex << setw(2) << tr_header.getDebugMode() << endl;
80  ss << " Type : " << hex << setw(2) << (int)tr_header.getEventType() << endl;
81  ss << " Readout : " << hex << setw(2) << tr_header.getReadoutMode() << endl;
82  ss << " Condition Data : " << (tr_header.getConditionData() ? "Present" : "Absent") << "\n";
83  ss << " Data Type : " << (tr_header.getDataType() ? "Real" : "Fake") << "\n";
84  ss << " Status : " << hex << setw(16) << (int)tr_header.getGlibStatusCode() << endl;
85  ss << " FE stat : ";
86  for (int i = 15; i >= 0; i--) {
87  if ((tr_header.frontendStatus())[i]) {
88  ss << "1";
89  } else {
90  ss << "0";
91  }
92  }
93  ss << endl;
94  ss << " Nr CBC : " << hex << setw(16) << (int)tr_header.getNumberOfCBC() << endl;
95  ss << " CBC stat : ";
96  for (int i = 0; i < tr_header.getNumberOfCBC(); i++) {
97  ss << hex << setw(2) << (int)tr_header.CBCStatus()[i] << " ";
98  }
99  ss << endl;
100  LogTrace("Phase2TrackerDigiProducer") << ss.str();
101  ss.clear();
102  ss.str("");
103  ss << " -------------------------------------------- " << endl;
104  ss << " Payload ----------------------------------- " << endl;
105  ss << " -------------------------------------------- " << endl;
106 #endif
107 
108  // loop channels
109  int ichan = 0;
110  for (int ife = 0; ife < MAX_FE_PER_FED; ife++) {
111  for (int icbc = 0; icbc < MAX_CBC_PER_FE; icbc++) {
112  const Phase2TrackerFEDChannel& channel = buffer->channel(ichan);
113  if (channel.length() > 0) {
114  // get fedid from cabling
115  const Phase2TrackerModule mod = cabling_->findFedCh(std::make_pair(fedIndex, ife));
116  uint32_t detid = mod.getDetid();
117 #ifdef EDM_ML_DEBUG
118  ss << dec << " id from cabling : " << detid << endl;
119  ss << dec << " reading channel : " << icbc << " on FE " << ife;
120  ss << dec << " with length : " << (int)channel.length() << endl;
121 #endif
122 
123  // container for this channel's digis
124  std::vector<Phase2TrackerDigi> stripsTop;
125  std::vector<Phase2TrackerDigi> stripsBottom;
126 
127  // unpacking data
129  while (unpacker.hasData()) {
130  if (unpacker.stripOn()) {
131  if (unpacker.stripIndex() % 2) {
132  stripsTop.push_back(Phase2TrackerDigi((int)(STRIPS_PER_CBC * icbc + unpacker.stripIndex()) / 2, 0));
133 #ifdef EDM_ML_DEBUG
134  ss << "t";
135 #endif
136  } else {
137  stripsBottom.push_back(
138  Phase2TrackerDigi((int)(STRIPS_PER_CBC * icbc + unpacker.stripIndex()) / 2, 0));
139 #ifdef EDM_ML_DEBUG
140  ss << "b";
141 #endif
142  }
143  } else {
144 #ifdef EDM_ML_DEBUG
145  ss << "_";
146 #endif
147  }
148  unpacker++;
149  }
150 #ifdef EDM_ML_DEBUG
151  ss << endl;
152  LogTrace("Phase2TrackerDigiProducer") << ss.str();
153  ss.clear();
154  ss.str("");
155 #endif
156 
157  // store beginning and end of this digis for this detid and add this registry to the list
158  // and store data
159  Registry regItemTop(detid + 1, STRIPS_PER_CBC * icbc / 2, proc_work_digis_.size(), stripsTop.size());
160  proc_work_registry_.push_back(regItemTop);
161  proc_work_digis_.insert(proc_work_digis_.end(), stripsTop.begin(), stripsTop.end());
162  Registry regItemBottom(
163  detid + 2, STRIPS_PER_CBC * icbc / 2, proc_work_digis_.size(), stripsBottom.size());
164  proc_work_registry_.push_back(regItemBottom);
165  proc_work_digis_.insert(proc_work_digis_.end(), stripsBottom.begin(), stripsBottom.end());
166  }
167  ichan++;
168  }
169  } // end loop on channels
170  // store digis in edm collections
171  std::sort(proc_work_registry_.begin(), proc_work_registry_.end());
172  std::vector<edm::DetSet<Phase2TrackerDigi>> sorted_and_merged;
173 
175 
176  std::vector<Registry>::iterator it = proc_work_registry_.begin(), it2 = it + 1, end = proc_work_registry_.end();
177  while (it < end) {
178  sorted_and_merged.push_back(edm::DetSet<Phase2TrackerDigi>(it->detid));
179  std::vector<Phase2TrackerDigi>& digis = sorted_and_merged.back().data;
180  // first count how many digis we have
181  size_t len = it->length;
182  for (it2 = it + 1; (it2 != end) && (it2->detid == it->detid); ++it2) {
183  len += it2->length;
184  }
185  // reserve memory
186  digis.reserve(len);
187  // push them in
188  for (it2 = it + 0; (it2 != end) && (it2->detid == it->detid); ++it2) {
189  digis.insert(digis.end(), &proc_work_digis_[it2->index], &proc_work_digis_[it2->index + it2->length]);
190  }
191  it = it2;
192  }
193 
194  edm::DetSetVector<Phase2TrackerDigi> proc_raw_dsv(sorted_and_merged, true);
195  pr->swap(proc_raw_dsv);
196  event.put(std::unique_ptr<edm::DetSetVector<Phase2TrackerDigi>>(pr), "ProcessedRaw");
197  delete buffer;
198  }
199  }
200  }
201 } // namespace Phase2Tracker
FEDNumbering.h
edm::DetSetVector
Definition: DetSetVector.h:61
fed_trailer.h
Phase2Tracker::Phase2TrackerFEDChannel
Definition: Phase2TrackerFEDChannel.h:12
Phase2Tracker::Phase2TrackerFEDHeader::CBCStatus
std::vector< uint8_t > CBCStatus() const
Definition: Phase2TrackerFEDHeader.cc:127
mps_fire.i
i
Definition: mps_fire.py:355
Phase2TrackerFEDRawChannelUnpacker.h
MessageLogger.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
edm::DetSet
Definition: DetSet.h:23
Phase2Tracker::Phase2TrackerDigiProducer::proc_work_digis_
std::vector< Phase2TrackerDigi > proc_work_digis_
Definition: Phase2TrackerDigiProducer.h:57
fed_header.h
edm::Run
Definition: Run.h:45
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::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: Phase2TrackerDigiProducer.cc:36
Phase2Tracker::Phase2TrackerDigiProducer::Phase2TrackerDigiProducer
Phase2TrackerDigiProducer(const edm::ParameterSet &pset)
constructor
Definition: Phase2TrackerDigiProducer.cc:25
Phase2Tracker::Phase2TrackerFEDHeader::getEventType
uint8_t getEventType() const
Definition: Phase2TrackerFEDHeader.h:22
utils.h
edm::Handle
Definition: AssociativeIterator.h:50
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
end
#define end
Definition: vmac.h:39
FEDRawData
Definition: FEDRawData.h:19
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
Phase2Tracker::Phase2TrackerDigiProducer::endJob
void endJob() override
Definition: Phase2TrackerDigiProducer.cc:43
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:73
Phase2TrackerCablingRcd.h
Phase2TrackerFEDChannel.h
edm::ESHandle
Definition: DTSurvey.h:22
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:34
Phase2Tracker::Phase2TrackerDigiProducer::Registry
Definition: Phase2TrackerDigiProducer.h:41
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.h:37
edm::ParameterSet
Definition: ParameterSet.h:36
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:38
Phase2Tracker::Phase2TrackerFEDChannel::length
uint16_t length() const
Definition: Phase2TrackerFEDChannel.h:22
Phase2Tracker::Phase2TrackerFEDBuffer
Definition: Phase2TrackerFEDBuffer.h:14
Phase2Tracker::Phase2TrackerFEDRawChannelUnpacker::stripIndex
uint8_t stripIndex() const
Definition: Phase2TrackerFEDRawChannelUnpacker.h:16
Phase2TrackerDigiProducer.h
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:57
Phase2Tracker::Phase2TrackerFEDHeader::getConditionData
uint8_t getConditionData() const
Definition: Phase2TrackerFEDHeader.h:24
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
get
#define get
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:45
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.h:56
Phase2TrackerCablingRcd
Definition: SiStripCondDataRecords.h:63
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
Phase2Tracker::Phase2TrackerDigiProducer::cabling_
const Phase2TrackerCabling * cabling_
Definition: Phase2TrackerDigiProducer.h:38
Phase2Tracker::MAX_FE_PER_FED
static const int MAX_FE_PER_FED
Definition: utils.h:24
Phase2TrackerFEDHeader.h
Exception.h
Phase2Tracker::Phase2TrackerFEDHeader::getGlibStatusCode
uint64_t getGlibStatusCode() const
Definition: Phase2TrackerFEDHeader.h:27
DetSet.h
Phase2Tracker::Phase2TrackerFEDHeader::frontendStatus
std::vector< bool > frontendStatus() const
Definition: Phase2TrackerFEDHeader.cc:109
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
Phase2Tracker::STRIPS_PER_CBC
static const int STRIPS_PER_CBC
Definition: utils.h:26
Phase2Tracker::FED_ID_MIN
static const uint16_t FED_ID_MIN
Definition: utils.h:17
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
Phase2Tracker::Phase2TrackerDigiProducer::~Phase2TrackerDigiProducer
~Phase2TrackerDigiProducer() override
default constructor
Definition: Phase2TrackerDigiProducer.cc:32
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
Phase2TrackerFEDBuffer.h
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
Phase2Tracker::Phase2TrackerFEDHeader::getDebugMode
READ_MODE getDebugMode() const
Definition: Phase2TrackerFEDHeader.h:20