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 25 of file SiStripSpyDigiConverter.cc.

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

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

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

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 177 of file SiStripSpyDigiConverter.cc.

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