CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Static Private Member Functions
sistrip::SpyDigiConverter Class Reference

Converts scope mode like digis into virgin raw like digis by: -extracting the frame payload, -reordering to physical order and -merging the DetSets indexed by FedKey to DetSets indexed by DetId. More...

#include <SiStripSpyDigiConverter.h>

Public Types

typedef edm::DetSetVector< SiStripRawDigiDSVRawDigis
 

Public Member Functions

 SpyDigiConverter ()
 
 ~SpyDigiConverter ()
 

Static Public Member Functions

static std::unique_ptr< DSVRawDigisextractPayloadDigis (const DSVRawDigis *inputScopeDigis, std::vector< uint32_t > *pAPVAddresses, const bool discardDigisWithAPVAddrErr, const sistrip::SpyUtilities::FrameQuality &aQuality, const uint16_t expectedPos)
 Extract frames from the scope digis. More...
 
static std::unique_ptr< DSVRawDigismergeModuleChannels (const DSVRawDigis *inputPhysicalOrderChannelDigis, const SiStripFedCabling &cabling)
 
static std::unique_ptr< DSVRawDigisreorderDigis (const DSVRawDigis *inputPayloadDigis)
 

Private Types

typedef DSVRawDigis::detset DetSetRawDigis
 

Static Private Member Functions

static void processFED (const uint16_t aPreviousFedId, const bool discardDigisWithAPVAddrErr, std::vector< uint32_t > *pAPVAddresses, std::vector< DetSetRawDigis > &outputData, std::vector< uint16_t > &aAddrVec, std::vector< uint16_t > &aHeaderBitVec, std::vector< uint16_t > &aTrailBitVec, std::vector< DSVRawDigis::const_iterator > &aFedScopeDigis)
 

Detailed Description

Converts scope mode like digis into virgin raw like digis by: -extracting the frame payload, -reordering to physical order and -merging the DetSets indexed by FedKey to DetSets indexed by DetId.

Definition at line 25 of file SiStripSpyDigiConverter.h.

Member Typedef Documentation

◆ DetSetRawDigis

Definition at line 52 of file SiStripSpyDigiConverter.h.

◆ DSVRawDigis

Definition at line 27 of file SiStripSpyDigiConverter.h.

Constructor & Destructor Documentation

◆ SpyDigiConverter()

sistrip::SpyDigiConverter::SpyDigiConverter ( )
inline

Definition at line 30 of file SiStripSpyDigiConverter.h.

30 {}

◆ ~SpyDigiConverter()

sistrip::SpyDigiConverter::~SpyDigiConverter ( )
inline

Definition at line 31 of file SiStripSpyDigiConverter.h.

31 {}

Member Function Documentation

◆ extractPayloadDigis()

std::unique_ptr< SpyDigiConverter::DSVRawDigis > sistrip::SpyDigiConverter::extractPayloadDigis ( const DSVRawDigis inputScopeDigis,
std::vector< uint32_t > *  pAPVAddresses,
const bool  discardDigisWithAPVAddrErr,
const sistrip::SpyUtilities::FrameQuality aQuality,
const uint16_t  expectedPos 
)
static

Extract frames from the scope digis.

If pAPVAddress is set, the map is filled with a map from FedKey to APVAddress. minAllowedRange is the min allowed range of digis when determine the threshold.

Definition at line 23 of file SiStripSpyDigiConverter.cc.

28  {
29  // Data is already sorted so push back fast into vector to avoid sorts and create DSV later
30  std::vector<DetSetRawDigis> outputData;
31  outputData.reserve(inputScopeDigis->size());
32 
33  //APV address vector indexed by fedid, majority value written.
34  pAPVAddresses->resize(sistrip::FED_ID_MAX + 1, 0);
35  std::vector<uint16_t> lAddrVec;
36  lAddrVec.reserve(2 * sistrip::FEDCH_PER_FED);
37  uint16_t lPreviousFedId = 0;
38  std::vector<uint16_t> lHeaderBitVec;
39  lHeaderBitVec.reserve(sistrip::FEDCH_PER_FED);
40  std::vector<uint16_t> lTrailBitVec;
41  lTrailBitVec.reserve(sistrip::FEDCH_PER_FED);
42 
43  //local DSVRawDigis per FED
44  std::vector<DSVRawDigis::const_iterator> lFedScopeDigis;
45  lFedScopeDigis.reserve(sistrip::FEDCH_PER_FED);
46 
47  // Loop over channels in input collection
48  DSVRawDigis::const_iterator inputChannel = inputScopeDigis->begin();
49  const DSVRawDigis::const_iterator endChannels = inputScopeDigis->end();
50  bool hasBeenProcessed = false;
51 
52  for (; inputChannel != endChannels; ++inputChannel) {
53  const uint32_t lFedIndex = inputChannel->detId();
54  const uint16_t fedId = static_cast<uint16_t>((lFedIndex >> 16) & 0xFFFF);
55 
56  // Fill frame parameters. Second parameter is to print debug info (if logDebug enabled....)
57  const sistrip::SpyUtilities::Frame lFrame = sistrip::SpyUtilities::extractFrameInfo(*inputChannel, false);
58 
59  if (lPreviousFedId == 0) {
60  lPreviousFedId = fedId;
61  }
62 
63  //print out warning only for non-empty frames....
64  if (!sistrip::SpyUtilities::isValid(lFrame, aQuality, expectedPos)) {
66  // edm::LogWarning("SiStripSpyDigiConverter") << " FED ID: " << fedId << ", channel: " << fedCh << std::endl
67  // << sistrip::SpyUtilities::print(lFrame,
68  // std::string(" -- Invalid Frame ")
69  // );
70  }
71  continue;
72  }
73 
74  //fill local vectors per FED
75  if (fedId == lPreviousFedId) {
76  if (hasBeenProcessed)
77  hasBeenProcessed = false;
78  }
79  if (fedId != lPreviousFedId) {
80  SpyDigiConverter::processFED(lPreviousFedId,
81  discardDigisWithAPVAddrErr,
82  pAPVAddresses,
83  outputData,
84  lAddrVec,
85  lHeaderBitVec,
86  lTrailBitVec,
87  lFedScopeDigis);
88  lPreviousFedId = fedId;
89  hasBeenProcessed = true;
90  }
91  // add digis
92  lFedScopeDigis.push_back(inputChannel);
93  lAddrVec.push_back(lFrame.apvAddress.first);
94  lAddrVec.push_back(lFrame.apvAddress.second);
95  lHeaderBitVec.push_back(lFrame.firstHeaderBit);
96  lTrailBitVec.push_back(lFrame.firstTrailerBit);
97 
98  } // end of loop over channels.
99 
100  //process the last one if not already done.
101  if (!hasBeenProcessed) {
102  SpyDigiConverter::processFED(lPreviousFedId,
103  discardDigisWithAPVAddrErr,
104  pAPVAddresses,
105  outputData,
106  lAddrVec,
107  lHeaderBitVec,
108  lTrailBitVec,
109  lFedScopeDigis);
110  }
111 
112  //return DSV of output
113  return std::unique_ptr<DSVRawDigis>(new DSVRawDigis(outputData, true));
114 
115  } // end of SpyDigiConverter::extractPayloadDigis method

References sistrip::SpyUtilities::Frame::apvAddress, edm::DetSetVector< T >::begin(), edm::DetSetVector< T >::end(), sistrip::SpyUtilities::extractFrameInfo(), sistrip::FED_ID_MAX, sistrip::FEDCH_PER_FED, l1tstage2_dqm_sourceclient-live_cfg::fedId, sistrip::SpyUtilities::Frame::firstHeaderBit, sistrip::SpyUtilities::Frame::firstTrailerBit, sistrip::SpyUtilities::isValid(), processFED(), edm::DetSetVector< T >::size(), and sistrip::SPY_SAMPLES_PER_CHANNEL.

Referenced by sistrip::SpyDigiConverterModule::produce().

◆ mergeModuleChannels()

std::unique_ptr< SpyDigiConverter::DSVRawDigis > sistrip::SpyDigiConverter::mergeModuleChannels ( const DSVRawDigis inputPhysicalOrderChannelDigis,
const SiStripFedCabling cabling 
)
static

Definition at line 201 of file SiStripSpyDigiConverter.cc.

202  {
203  // Create filler for detSetVector to create output (with maximum number of DetSets and digis)
204  uint16_t nFeds = static_cast<uint16_t>(FED_ID_MAX - FED_ID_MIN + 1);
205 
206  RawDigiDetSetVectorFiller dsvFiller(nFeds * FEDCH_PER_FED / 2, nFeds * FEDCH_PER_FED * STRIPS_PER_FEDCH);
207  // Loop over FEDs in cabling
208  auto iFed = cabling.fedIds().begin();
209  auto endFeds = cabling.fedIds().end();
210  for (; iFed != endFeds; ++iFed) {
211  // Loop over cabled channels
212  auto conns = cabling.fedConnections(*iFed);
213  auto iConn = conns.begin();
214  auto endConns = conns.end();
215  for (; iConn != endConns; ++iConn) {
216  // Skip channels not connected to a detector.
217  if (!iConn->isConnected())
218  continue;
219  if (iConn->detId() == sistrip::invalid32_)
220  continue;
221 
222  // Find the data from the input collection
223  const uint32_t fedIndex = ((iConn->fedId() & sistrip::invalid_) << 16) | (iConn->fedCh() & sistrip::invalid_);
224  const DSVRawDigis::const_iterator iDetSet = inputPhysicalOrderChannelDigis->find(fedIndex);
225  if (iDetSet == inputPhysicalOrderChannelDigis->end()) {
226  // NOTE: It will display this warning if channel hasn't been unpacked...
227  // Will comment out for now.
228  //edm::LogWarning("SiStripSpyDigiConverter") << "No data found for FED ID: " << iConn->fedId() << " channel: " << iConn->fedCh();
229  continue;
230  }
231 
232  // Start a new channel indexed by the detId in the filler
233  dsvFiller.newChannel(iConn->detId(), iConn->apvPairNumber() * STRIPS_PER_FEDCH);
234 
235  // Add the data
236  DetSetRawDigis::const_iterator iDigi = iDetSet->begin();
237  const DetSetRawDigis::const_iterator endDetSetDigis = iDetSet->end();
238  for (; iDigi != endDetSetDigis; ++iDigi) {
239  dsvFiller.addItem(*iDigi);
240  } // end of loop over the digis.
241  } // end of loop over channels.
242  } // end of loop over FEDs
243 
244  return dsvFiller.createDetSetVector();
245  } // end of SpyDigiConverter::mergeModuleChannels method.

References sistrip::DetSetVectorFiller< T, dsvIsSparse >::addItem(), sistrip::DetSetVectorFiller< T, dsvIsSparse >::createDetSetVector(), edm::DetSetVector< T >::end(), sistrip::FED_ID_MAX, sistrip::FED_ID_MIN, sistrip::FEDCH_PER_FED, SiStripFedCabling::fedConnections(), SiStripFedCabling::fedIds(), edm::DetSetVector< T >::find(), sistrip::invalid32_, sistrip::invalid_, sistrip::DetSetVectorFiller< T, dsvIsSparse >::newChannel(), and sistrip::STRIPS_PER_FEDCH.

Referenced by sistrip::SpyDigiConverterModule::produce().

◆ processFED()

void sistrip::SpyDigiConverter::processFED ( const uint16_t  aPreviousFedId,
const bool  discardDigisWithAPVAddrErr,
std::vector< uint32_t > *  pAPVAddresses,
std::vector< DetSetRawDigis > &  outputData,
std::vector< uint16_t > &  aAddrVec,
std::vector< uint16_t > &  aHeaderBitVec,
std::vector< uint16_t > &  aTrailBitVec,
std::vector< DSVRawDigis::const_iterator > &  aFedScopeDigis 
)
staticprivate

Definition at line 117 of file SiStripSpyDigiConverter.cc.

124  {
125  //extract majority address
126  uint32_t lMaj = sistrip::SpyUtilities::findMajorityValue(aAddrVec, aPreviousFedId).first;
127  if (pAPVAddresses)
128  (*pAPVAddresses)[aPreviousFedId] = lMaj;
129 
130  //loop over iterators and fill payload
131  std::vector<DSVRawDigis::const_iterator>::iterator lIter;
132  unsigned int lCh = 0;
133  for (lIter = aFedScopeDigis.begin(); lIter != aFedScopeDigis.end(); ++lIter, ++lCh) {
134  //discard if APV address different from majority.
135  //Keep if only one of them is wrong: the other APV might be alright ??
136 
137  if (discardDigisWithAPVAddrErr && aAddrVec[2 * lCh] != lMaj && aAddrVec[2 * lCh + 1] != lMaj) {
138  continue;
139  }
140 
141  DetSetRawDigis::const_iterator iDigi = (*lIter)->begin();
142  const DetSetRawDigis::const_iterator endOfChannel = (*lIter)->end();
143 
144  if (iDigi == endOfChannel) {
145  continue;
146  }
147 
148  //header starts in sample firstHeaderBit and is 18+6 samples long
149  const DetSetRawDigis::const_iterator payloadBegin = iDigi + aHeaderBitVec[lCh] + 24;
150  const DetSetRawDigis::const_iterator payloadEnd = payloadBegin + STRIPS_PER_FEDCH;
151 
152  if (payloadEnd - iDigi >= endOfChannel - iDigi)
153  continue; // few-cases where this is possible, i.e. nothing above frame-threhsold
154 
155  // Copy data into output collection
156  // Create new detSet with same key (in this case it is the fedKey, not detId)
157  outputData.push_back(DetSetRawDigis((*lIter)->detId()));
158  std::vector<SiStripRawDigi>& outputDetSetData = outputData.back().data;
159  outputDetSetData.resize(STRIPS_PER_FEDCH);
160  std::vector<SiStripRawDigi>::iterator outputBegin = outputDetSetData.begin();
161  std::copy(payloadBegin, payloadEnd, outputBegin);
162  }
163 
164  aFedScopeDigis.clear();
165  aAddrVec.clear();
166  aHeaderBitVec.clear();
167  aTrailBitVec.clear();
168 
169  aAddrVec.reserve(2 * sistrip::FEDCH_PER_FED);
170  aHeaderBitVec.reserve(sistrip::FEDCH_PER_FED);
171  aTrailBitVec.reserve(sistrip::FEDCH_PER_FED);
172  aFedScopeDigis.reserve(sistrip::FEDCH_PER_FED);
173  }

References filterCSVwithJSON::copy, sistrip::FEDCH_PER_FED, sistrip::SpyUtilities::findMajorityValue(), and sistrip::STRIPS_PER_FEDCH.

Referenced by extractPayloadDigis().

◆ reorderDigis()

std::unique_ptr< SpyDigiConverter::DSVRawDigis > sistrip::SpyDigiConverter::reorderDigis ( const DSVRawDigis inputPayloadDigis)
static

Definition at line 175 of file SiStripSpyDigiConverter.cc.

175  {
176  // Data is already sorted so push back fast into vector to avoid sorts and create DSV later
177  std::vector<DetSetRawDigis> outputData;
178  outputData.reserve(inputPayloadDigis->size());
179 
180  // Loop over channels in input collection
181  for (DSVRawDigis::const_iterator inputChannel = inputPayloadDigis->begin();
182  inputChannel != inputPayloadDigis->end();
183  ++inputChannel) {
184  const std::vector<SiStripRawDigi>& inputDetSetData = inputChannel->data;
185  outputData.push_back(DetSetRawDigis(inputChannel->detId()));
186  std::vector<SiStripRawDigi>& outputDetSetData = outputData.back().data;
187  outputDetSetData.resize(STRIPS_PER_FEDCH);
188  // Copy the data into the output vector reordering
189  for (uint16_t readoutOrderStripIndex = 0; readoutOrderStripIndex < inputDetSetData.size();
190  ++readoutOrderStripIndex) {
191  const uint16_t physicalOrderStripIndex =
192  FEDStripOrdering::physicalOrderForStripInChannel(readoutOrderStripIndex);
193  outputDetSetData.at(physicalOrderStripIndex) = inputDetSetData.at(readoutOrderStripIndex);
194  }
195  }
196 
197  //return DSV of output
198  return std::unique_ptr<DSVRawDigis>(new DSVRawDigis(outputData, true));
199  } // end of SpyDigiConverter::reorderDigis method.

References edm::DetSetVector< T >::begin(), edm::DetSetVector< T >::end(), sistrip::FEDStripOrdering::physicalOrderForStripInChannel(), edm::DetSetVector< T >::size(), and sistrip::STRIPS_PER_FEDCH.

Referenced by sistrip::SpyDigiConverterModule::produce().

sistrip::SpyUtilities::isValid
static const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
Definition: SiStripSpyUtilities.cc:222
sistrip::SpyUtilities::Frame::firstTrailerBit
uint16_t firstTrailerBit
Definition: SiStripSpyUtilities.h:31
sistrip::invalid32_
static const uint32_t invalid32_
Definition: Constants.h:15
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
sistrip::SpyDigiConverter::DSVRawDigis
edm::DetSetVector< SiStripRawDigi > DSVRawDigis
Definition: SiStripSpyDigiConverter.h:27
sistrip::FEDStripOrdering::physicalOrderForStripInChannel
static uint8_t physicalOrderForStripInChannel(const uint8_t readoutOrderStripIndexInChannel)
Definition: SiStripFEDBufferComponents.h:812
sistrip::SpyUtilities::Frame::apvAddress
std::pair< uint8_t, uint8_t > apvAddress
Definition: SiStripSpyUtilities.h:34
sistrip::FED_ID_MIN
static const uint16_t FED_ID_MIN
Definition: ConstantsForHardwareSystems.h:21
sistrip::SpyDigiConverter::DetSetRawDigis
DSVRawDigis::detset DetSetRawDigis
Definition: SiStripSpyDigiConverter.h:52
sistrip::SPY_SAMPLES_PER_CHANNEL
static const uint16_t SPY_SAMPLES_PER_CHANNEL
Definition: SiStripFEDSpyBuffer.h:23
sistrip::SpyUtilities::extractFrameInfo
static const Frame extractFrameInfo(const edm::DetSetVector< SiStripRawDigi >::detset &channelDigis, bool aPrintDebug=false)
Definition: SiStripSpyUtilities.cc:109
sistrip::RawDigiDetSetVectorFiller
DetSetVectorFiller< SiStripRawDigi, false > RawDigiDetSetVectorFiller
Definition: SiStripDetSetVectorFiller.h:112
sistrip::SpyUtilities::findMajorityValue
static std::pair< uint16_t, uint32_t > findMajorityValue(std::vector< uint16_t > &values, const uint16_t aFedId=0)
Definition: SiStripSpyUtilities.cc:409
edm::DetSetVector< SiStripRawDigi >::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
sistrip::STRIPS_PER_FEDCH
static const uint16_t STRIPS_PER_FEDCH
Definition: ConstantsForHardwareSystems.h:44
sistrip::invalid_
static const uint16_t invalid_
Definition: Constants.h:16
l1tstage2_dqm_sourceclient-live_cfg.fedId
fedId
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:82
sistrip::FED_ID_MAX
static const uint16_t FED_ID_MAX
Definition: ConstantsForHardwareSystems.h:22
sistrip::SpyUtilities::Frame::firstHeaderBit
uint16_t firstHeaderBit
Definition: SiStripSpyUtilities.h:30
sistrip::SpyDigiConverter::processFED
static void processFED(const uint16_t aPreviousFedId, const bool discardDigisWithAPVAddrErr, std::vector< uint32_t > *pAPVAddresses, std::vector< DetSetRawDigis > &outputData, std::vector< uint16_t > &aAddrVec, std::vector< uint16_t > &aHeaderBitVec, std::vector< uint16_t > &aTrailBitVec, std::vector< DSVRawDigis::const_iterator > &aFedScopeDigis)
Definition: SiStripSpyDigiConverter.cc:117
sistrip::FEDCH_PER_FED
static const uint16_t FEDCH_PER_FED
Definition: ConstantsForHardwareSystems.h:30
SiStripFedCabling::fedIds
FedsConstIterRange fedIds() const
Definition: SiStripFedCabling.h:154
sistrip::SpyUtilities::Frame
Definition: SiStripSpyUtilities.h:26
SiStripFedCabling::fedConnections
ConnsConstIterRange fedConnections(uint16_t fed_id) const
Definition: SiStripFedCabling.cc:160
edm::DetSet::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSet.h:31