CMS 3D CMS Logo

SiStripSpyUnpacker.cc
Go to the documentation of this file.
1 /* \file SiStripSpyUnpacker.cc
2  * \brief Source code for the SpyChannel unpacking factory.
3  */
6 
9 
15 
17 
20 
21 #include <algorithm>
22 #include <vector>
23 #include <ext/algorithm>
24 
25 using namespace std;
26 
27 namespace sistrip {
28 
29  SpyUnpacker::SpyUnpacker(const bool allowIncompleteEvents) : allowIncompleteEvents_(allowIncompleteEvents) {
30  if (edm::isDebugEnabled()) {
31  LogTrace("SiStripSpyUnpacker") << "[sistrip::SpyUnpacker::" << __func__ << "]"
32  << " Constructing object...";
33  }
34  } // end of SpyUnpacker constructor.
35 
37  if (edm::isDebugEnabled()) {
38  LogTrace("SiStripSpyUnpacker") << "[sistrip::SpyUnpacker::" << __func__ << "]"
39  << " Destructing object...";
40  }
41  } // end of SpyUnpacker destructor.
42 
44  const FEDRawDataCollection& buffers,
45  RawDigis* pDigis,
46  const std::vector<uint32_t>& ids,
47  Counters* pTotalEventCounts,
48  Counters* pL1ACounts,
49  uint32_t* aRunRef) {
50  //create DSV filler to fill output
51 
52  //As of Feb 2010, bug in DataFormats/SiStripCommon/interface/ConstantsForHardwareSystems.h:
53  //number of feds=max-min+1 (440...). Corrected in head of DataFormats/SiStripCommon package.
54 
55  uint16_t nFeds = static_cast<uint16_t>(FED_ID_MAX - FED_ID_MIN + 1);
56 
58 
59  //check if FEDs found in cabling map and event data
60  if (edm::isDebugEnabled()) {
61  if (cabling.fedIds().empty()) {
62  edm::LogWarning("SiStripSpyUnpacker") << "[sistrip::SpyUnpacker::" << __func__ << "]"
63  << " No FEDs found in cabling map!";
64  }
65  }
66 
67  //retrieve FED ids from cabling map and iterate through
68  std::vector<uint32_t>::const_iterator ifed = ids.begin();
69  std::vector<uint32_t>::const_iterator endfed = ids.end();
70 
71  //reference value for run number
72  //encoded per fed but should be the same for all feds
73  uint32_t lRef = 0;
74 
75  //initialise counter vectors to FED_ID_MAX+1
76  pTotalEventCounts->resize(FED_ID_MAX + 1, 0);
77  pL1ACounts->resize(FED_ID_MAX + 1, 0);
78 
79  for (; ifed != endfed; ++ifed) {
80  uint32_t lFedId = (*ifed);
81 
82  //check the fedid is valid:
83  if (lFedId < FED_ID_MIN || lFedId > FED_ID_MAX) {
84  if (edm::isDebugEnabled()) {
85  edm::LogWarning("SiStripSpyUnpacker") << "[sistrip::SpyUnpacker::" << __func__ << "]"
86  << " Invalid FED id provided: " << lFedId;
87  }
88  continue;
89  }
90 
91  //retrieve FED raw data for given FED
92  const FEDRawData& input = buffers.FEDData(static_cast<int>(lFedId));
93  //check on FEDRawData pointer
94  if (!input.data()) {
95  if (edm::isDebugEnabled()) {
96  edm::LogWarning("SiStripSpyUnpacker") << "[sistrip::SpyUnpacker::" << __func__ << "]"
97  << " NULL pointer to FEDRawData for FED id " << lFedId;
98  }
99  continue;
100  }
101  //check on FEDRawData size
102  if (!input.size()) {
103  if (edm::isDebugEnabled()) {
104  edm::LogWarning("SiStripSpyUnpacker") << "[sistrip::SpyUnpacker::" << __func__ << "]"
105  << " FEDRawData has zero size for FED id " << lFedId;
106  }
107  continue;
108  }
109 
110  //get the cabling connections for this FED
111  auto conns = cabling.fedConnections(lFedId);
112 
113  //construct FEDBuffer
114  const auto st_buffer = preconstructCheckFEDSpyBuffer(input);
115  if (sistrip::FEDBufferStatusCode::SUCCESS != st_buffer) {
116  edm::LogWarning("SiStripSpyUnpacker")
117  << "Exception caught when creating FEDSpyBuffer object for FED " << lFedId << ": "
118  << "An exception of category 'FEDBuffer' occurred.\n"
119  << st_buffer;
120  continue;
121  }
123  if (!buffer.doChecks() && !allowIncompleteEvents_) {
124  edm::LogWarning("SiStripSpyUnpacker")
125  << "Exception caught when creating FEDSpyBuffer object for FED " << lFedId << ": "
126  << "An exception of category 'FEDSpyBuffer' occurred.\n"
127  << "FED Buffer check fails for FED ID " << lFedId << ".";
128  continue;
129  }
130  // end of buffer reset try.
131 
132  // Get the event counter values
133  uint32_t totalEvCount = buffer.spyHeaderTotalEventCount();
134  uint32_t l1ID = buffer.spyHeaderL1ID();
135 
136  uint32_t lGRun = buffer.globalRunNumber();
137 
138  //for the first fed, put it as reference value for others
139  if (lRef == 0)
140  lRef = lGRun;
141  if (lGRun != lRef) {
142  edm::LogError("SiStripSpyUnpacker") << " -- Global run encoded in buffer for FED " << lFedId << ": " << lGRun
143  << " is different from reference value " << lRef << std::endl;
144  }
145 
146  // Add event counters
147  (*pL1ACounts)[lFedId] = l1ID;
148  (*pTotalEventCounts)[lFedId] = totalEvCount;
149 
150  //iterate through FED channels, extract payload and create Digis
151  std::vector<FedChannelConnection>::const_iterator iconn = conns.begin();
152  std::vector<FedChannelConnection>::const_iterator endconn = conns.end();
153  for (; iconn != endconn; ++iconn) {
154  //check if fed connection is valid
155  if (!iconn->isConnected()) {
156  continue;
157  }
158 
159  //FED channel
160  uint16_t chan = iconn->fedCh();
161 
162  //check values are valid:
163  if (chan > FEDCH_PER_FED || iconn->fedId() != lFedId) {
164  if (edm::isDebugEnabled()) {
165  std::ostringstream ss;
166  ss << "Channel connection values invalid: iconn->fedId() = " << iconn->fedId() << " for FED " << lFedId
167  << ", iconn->fedCh() = " << chan << std::endl;
168  edm::LogWarning("SiStripSpyUnpacker") << ss.str();
169  }
170  continue;
171  }
172 
173  //check FED channel
174  if (!buffer.channelGood(chan)) {
175  if (edm::isDebugEnabled()) {
176  std::ostringstream ss;
177  ss << "Channel check failed for FED " << lFedId << " channel " << chan << std::endl;
178  edm::LogWarning("SiStripSpyUnpacker") << ss.str();
179  }
180  continue;
181  }
182 
183  //determine key from cabling
184  const uint32_t key = ((lFedId & sistrip::invalid_) << 16) | (chan & sistrip::invalid_);
185 
186  // Start a new channel in the filler
187  dsvFiller.newChannel(key);
188  // Create the unpacker object
190 
191  // Unpack the data into dsv filler
192  while (unpacker.hasData()) {
193  dsvFiller.addItem(SiStripRawDigi{unpacker.adc()});
194  unpacker++;
195  }
196  } // end of channel loop
197 
198  } //fed loop
199 
200  //set the run number
201  *aRunRef = lRef;
202 
203  //create DSV to return
204  std::unique_ptr<RawDigis> pResult = dsvFiller.createDetSetVector();
205  pDigis->swap(*pResult);
206 
207  } // end of SpyUnpacker::createDigis method.
208 
209 } // namespace sistrip
FEDNumbering.h
edm::DetSetVector< SiStripRawDigi >
sistrip::preconstructCheckFEDSpyBuffer
FEDBufferStatusCode preconstructCheckFEDSpyBuffer(const FEDRawData &fedBuffer)
Definition: SiStripFEDSpyBuffer.h:108
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
sistrip::SpyUnpacker::Counters
std::vector< uint32_t > Counters
Definition: SiStripSpyUnpacker.h:34
sistrip::FEDSpyChannelUnpacker::adc
uint16_t adc() const
Definition: SiStripFEDSpyBuffer.cc:139
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
SiStripRawDigi.h
SiStripFedCabling.h
sistrip::FEDSpyChannelUnpacker::hasData
bool hasData() const
Definition: SiStripFEDSpyBuffer.h:128
sistrip::FED_ID_MIN
static const uint16_t FED_ID_MIN
Definition: ConstantsForHardwareSystems.h:21
SiStripFedCabling
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses,...
Definition: SiStripFedCabling.h:25
edm::DetSetVector::swap
void swap(DetSetVector &other)
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
FEDRawData
Definition: FEDRawData.h:19
sistrip::DetSetVectorFiller::newChannel
void newChannel(const uint32_t key, const uint16_t firstItem=0)
Definition: SiStripDetSetVectorFiller.h:59
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
SiStripRawDigi
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
Definition: SiStripRawDigi.h:15
sistrip::SPY_SAMPLES_PER_CHANNEL
static const uint16_t SPY_SAMPLES_PER_CHANNEL
Definition: SiStripFEDSpyBuffer.h:23
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
SiStripFedKey.h
SiStripDetSetVectorFiller.h
sistrip::SpyUnpacker::~SpyUnpacker
~SpyUnpacker()
Destructor.
Definition: SiStripSpyUnpacker.cc:36
sistrip::SpyUnpacker::allowIncompleteEvents_
const bool allowIncompleteEvents_
Definition: SiStripSpyUnpacker.h:54
SiStripSpyUnpacker.h
sistrip::FEDBufferStatusCode::SUCCESS
FEDRawDataCollection.h
sistrip::DetSetVectorFiller::createDetSetVector
std::unique_ptr< edm::DetSetVector< T > > createDetSetVector()
Definition: SiStripDetSetVectorFiller.h:70
sistrip::DetSetVectorFiller::addItem
void addItem(const T &item)
Definition: SiStripDetSetVectorFiller.h:64
sistrip::FEDSpyChannelUnpacker
Definition: SiStripFEDSpyBuffer.h:76
sistrip::invalid_
static const uint16_t invalid_
Definition: Constants.h:16
DetSetVector.h
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
sistrip::FED_ID_MAX
static const uint16_t FED_ID_MAX
Definition: ConstantsForHardwareSystems.h:22
std
Definition: JetResolutionObject.h:76
officialStyle.chan
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi....
Definition: officialStyle.py:106
sistrip::DetSetVectorFiller
Definition: SiStripDetSetVectorFiller.h:18
Exception.h
sistrip::FEDSpyBuffer
Definition: SiStripFEDSpyBuffer.h:33
sistrip::FEDCH_PER_FED
static const uint16_t FEDCH_PER_FED
Definition: ConstantsForHardwareSystems.h:30
SiStripFedCabling::fedIds
FedsConstIterRange fedIds() const
Definition: SiStripFedCabling.h:154
edm::isDebugEnabled
bool isDebugEnabled()
Definition: MessageLogger.cc:12
DetSet.h
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
sistrip
sistrip classes
Definition: EnsembleCalibrationLA.cc:10
SiStripFedCabling::fedConnections
ConnsConstIterRange fedConnections(uint16_t fed_id) const
Definition: SiStripFedCabling.cc:160
crabWrapper.key
key
Definition: crabWrapper.py:19
SiStripFEDSpyBuffer.h
sistrip::SpyUnpacker::createDigis
void createDigis(const SiStripFedCabling &, const FEDRawDataCollection &, RawDigis *pDigis, const std::vector< uint32_t > &ids, Counters *pTotalEventCounts, Counters *pL1ACounts, uint32_t *aRunRef)
Creates the scope mode digis for the supplied FED IDs or detIds and stores event counters.
Definition: SiStripSpyUnpacker.cc:43