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< 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

Definition at line 53 of file SiStripSpyDigiConverter.h.

Definition at line 28 of file SiStripSpyDigiConverter.h.

Constructor & Destructor Documentation

sistrip::SpyDigiConverter::SpyDigiConverter ( )
inline

Definition at line 31 of file SiStripSpyDigiConverter.h.

31 {}
sistrip::SpyDigiConverter::~SpyDigiConverter ( )
inline

Definition at line 32 of file SiStripSpyDigiConverter.h.

References extractPayloadDigis(), mergeModuleChannels(), and reorderDigis().

32 {}

Member Function Documentation

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

References sistrip::SpyUtilities::Frame::apvAddress, edm::DetSetVector< T >::begin(), edm::DetSetVector< T >::end(), sistrip::SpyUtilities::extractFrameInfo(), sistrip::FED_ID_MAX, sistrip::FEDCH_PER_FED, l1t::stage2::layer2::fedId, sistrip::SpyUtilities::Frame::firstHeaderBit, sistrip::SpyUtilities::isValid(), sistrip::SpyUtilities::print(), processFED(), edm::DetSetVector< T >::size(), sistrip::SPY_SAMPLES_PER_CHANNEL, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by sistrip::SpyDigiConverterModule::produce(), and ~SpyDigiConverter().

29  {
30  // Data is already sorted so push back fast into vector to avoid sorts and create DSV later
31  std::vector<DetSetRawDigis> outputData;
32  outputData.reserve(inputScopeDigis->size());
33 
34  //APV address vector indexed by fedid, majority value written.
35  pAPVAddresses->resize(sistrip::FED_ID_MAX+1,0);
36  std::vector<uint16_t> lAddrVec;
37  lAddrVec.reserve(2*sistrip::FEDCH_PER_FED);
38  uint16_t lPreviousFedId = 0;
39  std::vector<uint16_t> lHeaderBitVec;
40  lHeaderBitVec.reserve(sistrip::FEDCH_PER_FED);
41 
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 
54  // Fill frame parameters. Second parameter is to print debug info (if logDebug enabled....)
56 
57  const uint32_t lFedIndex = inputChannel->detId();
58  const uint16_t fedId = static_cast<uint16_t>(lFedIndex/sistrip::FEDCH_PER_FED);
59  const uint16_t fedCh = static_cast<uint16_t>(lFedIndex%sistrip::FEDCH_PER_FED);
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)){
67  //print out only for non-empty frames, else too many prints...
69  edm::LogWarning("SiStripSpyDigiConverter") << " FED ID: " << fedId << ", channel: " << fedCh << std::endl
71  std::string(" -- Invalid Frame ")
72  );
73  }
74 
75  continue;
76  }
77 
78  //fill local vectors per FED
79  if (fedId == lPreviousFedId) {
80  if (hasBeenProcessed) hasBeenProcessed = false;
81  }
82  if (fedId != lPreviousFedId) {
83  SpyDigiConverter::processFED(lPreviousFedId,
84  discardDigisWithAPVAddrErr,
85  pAPVAddresses,
86  outputData,
87  lAddrVec,
88  lHeaderBitVec,
89  lFedScopeDigis
90  );
91  lPreviousFedId = fedId;
92  hasBeenProcessed = true;
93  }
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 
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  lFedScopeDigis
111  );
112  }
113 
114  //return DSV of output
115  return std::unique_ptr<DSVRawDigis>( new DSVRawDigis(outputData, true) );
116 
117  } // end of SpyDigiConverter::extractPayloadDigis method
static const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
static const uint16_t SPY_SAMPLES_PER_CHANNEL
std::pair< uint8_t, uint8_t > apvAddress
static const Frame extractFrameInfo(const edm::DetSetVector< SiStripRawDigi >::detset &channelDigis, bool aPrintDebug=false)
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< DSVRawDigis::const_iterator > &aFedScopeDigis)
edm::DetSetVector< SiStripRawDigi > DSVRawDigis
static const uint16_t FEDCH_PER_FED
static const uint16_t FED_ID_MAX
static std::string print(const Frame &aFrame, std::string aErr)
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:104
std::unique_ptr< SpyDigiConverter::DSVRawDigis > sistrip::SpyDigiConverter::mergeModuleChannels ( const DSVRawDigis inputPhysicalOrderChannelDigis,
const SiStripFedCabling cabling 
)
static

Definition at line 210 of file SiStripSpyDigiConverter.cc.

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(), and ~SpyDigiConverter().

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

Definition at line 120 of file SiStripSpyDigiConverter.cc.

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

Referenced by extractPayloadDigis().

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

Definition at line 185 of file SiStripSpyDigiConverter.cc.

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(), and ~SpyDigiConverter().

186  {
187  // Data is already sorted so push back fast into vector to avoid sorts and create DSV later
188  std::vector<DetSetRawDigis> outputData;
189  outputData.reserve(inputPayloadDigis->size());
190 
191  // Loop over channels in input collection
192  for (DSVRawDigis::const_iterator inputChannel = inputPayloadDigis->begin(); inputChannel != inputPayloadDigis->end(); ++inputChannel) {
193  const std::vector<SiStripRawDigi>& inputDetSetData = inputChannel->data;
194  // Create new detSet with same key (in this case it is the fedKey, not detId)
195  outputData.push_back( DetSetRawDigis(inputChannel->detId()) );
196  std::vector<SiStripRawDigi>& outputDetSetData = outputData.back().data;
197  outputDetSetData.resize(STRIPS_PER_FEDCH);
198  // Copy the data into the output vector reordering
199  for (uint16_t readoutOrderStripIndex = 0; readoutOrderStripIndex < inputDetSetData.size(); ++readoutOrderStripIndex) {
200  const uint16_t physicalOrderStripIndex = FEDStripOrdering::physicalOrderForStripInChannel(readoutOrderStripIndex);
201  outputDetSetData.at(physicalOrderStripIndex) = inputDetSetData.at(readoutOrderStripIndex);
202  }
203  }
204 
205  //return DSV of output
206  return std::unique_ptr<DSVRawDigis>( new DSVRawDigis(outputData,true) );
207  } // end of SpyDigiConverter::reorderDigis method.
static uint8_t physicalOrderForStripInChannel(const uint8_t readoutOrderStripIndexInChannel)
DSVRawDigis::detset DetSetRawDigis
static const uint16_t STRIPS_PER_FEDCH
edm::DetSetVector< SiStripRawDigi > DSVRawDigis
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:104