Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-31 23:14:01

0001 #include "DQM/SiStripMonitorHardware/interface/SiStripSpyEventMatcher.h"
0002 #ifdef SiStripMonitorHardware_BuildEventMatchingCode
0003 
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/Sources/interface/VectorInputSource.h"
0007 #include "FWCore/Sources/interface/VectorInputSourceDescription.h"
0008 #include "FWCore/Sources/interface/VectorInputSourceFactory.h"
0009 #include "FWCore/Framework/interface/SignallingProductRegistry.h"
0010 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0011 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
0012 #include "DataFormats/Common/interface/DetSetVector.h"
0013 #include "DataFormats/Provenance/interface/BranchIDListHelper.h"
0014 #include "DataFormats/Provenance/interface/EventID.h"
0015 #include "DataFormats/Provenance/interface/ModuleDescription.h"
0016 #include "DataFormats/Provenance/interface/ThinnedAssociationsHelper.h"
0017 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0018 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
0019 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0020 #include "FWCore/Utilities/interface/Exception.h"
0021 #include "FWCore/Utilities/interface/GetPassID.h"
0022 #include "FWCore/Version/interface/GetReleaseVersion.h"
0023 #include "DQM/SiStripMonitorHardware/interface/SiStripSpyUtilities.h"
0024 #include <algorithm>
0025 #include <limits>
0026 #include <memory>
0027 
0028 using edm::LogError;
0029 using edm::LogInfo;
0030 using edm::LogWarning;
0031 
0032 namespace sistrip {
0033 
0034   const char* const SpyEventMatcher::mlLabel_ = "SpyEventMatcher";
0035 
0036   SpyEventMatcher::EventKey::EventKey(const uint32_t eventId, const uint8_t apvAddress)
0037       : eventId_(eventId), apvAddress_(apvAddress) {}
0038 
0039   SpyEventMatcher::MatchingOutput::MatchingOutput(FEDRawDataCollection& outputRawData)
0040       : outputRawData_(outputRawData),
0041         outputTotalEventCounters_(sistrip::FED_ID_MAX + 1),
0042         outputL1ACounters_(sistrip::FED_ID_MAX + 1),
0043         outputAPVAddresses_(sistrip::FED_ID_MAX + 1) {}
0044 
0045   SpyEventMatcher::~SpyEventMatcher() {}
0046 
0047   SpyEventMatcher::SpyEventMatcher(const edm::ParameterSet& config)
0048       : rawDataTag_(config.getParameter<edm::InputTag>("RawSpyDataTag")),
0049         totalEventCountersTag_(config.getParameter<edm::InputTag>("SpyTotalEventCountersTag")),
0050         l1aCountersTag_(config.getParameter<edm::InputTag>("SpyL1ACountersTag")),
0051         apvAddressesTag_(config.getParameter<edm::InputTag>("SpyAPVAddressesTag")),
0052         scopeDigisTag_(config.getParameter<edm::InputTag>("SpyScopeDigisTag")),
0053         payloadDigisTag_(config.getParameter<edm::InputTag>("SpyPayloadDigisTag")),
0054         reorderedDigisTag_(config.getParameter<edm::InputTag>("SpyReorderedDigisTag")),
0055         virginRawDigisTag_(config.getParameter<edm::InputTag>("SpyVirginRawDigisTag")),
0056         counterDiffMax_(config.getParameter<uint32_t>("CounterDiffMaxAllowed")),
0057         productRegistry_(new edm::SignallingProductRegistry),
0058         source_(constructSource(config.getParameter<edm::ParameterSet>("SpySource"))),
0059         processConfiguration_(
0060             new edm::ProcessConfiguration(std::string("@MIXING"), edm::getReleaseVersion(), edm::getPassID())),
0061         eventPrincipal_() {
0062     // Use the empty parameter set for the parameter set ID of our "@MIXING" process.
0063     processConfiguration_->setParameterSetID(edm::ParameterSet::emptyParameterSetID());
0064     productRegistry_->setFrozen();
0065 
0066     eventPrincipal_ = std::make_unique<edm::EventPrincipal>(source_->productRegistry(),
0067                                                             std::make_shared<edm::BranchIDListHelper>(),
0068                                                             std::make_shared<edm::ThinnedAssociationsHelper>(),
0069                                                             *processConfiguration_,
0070                                                             nullptr);
0071   }
0072 
0073   std::unique_ptr<SpyEventMatcher::Source> SpyEventMatcher::constructSource(const edm::ParameterSet& sourceConfig) {
0074     const edm::VectorInputSourceFactory* sourceFactory = edm::VectorInputSourceFactory::get();
0075     edm::VectorInputSourceDescription description(productRegistry_, edm::PreallocationConfiguration());
0076     return sourceFactory->makeVectorInputSource(sourceConfig, description);
0077   }
0078 
0079   void SpyEventMatcher::initialize() {
0080     size_t fileNameHash = 0U;
0081     //add spy events to the map until there are none left
0082     source_->loopOverEvents(
0083         *eventPrincipal_,
0084         fileNameHash,
0085         std::numeric_limits<size_t>::max(),
0086         [this](auto const& iE, auto const&) {
0087           this->addNextEventToMap(iE);
0088           return true;
0089         },
0090         nullptr,
0091         nullptr,
0092         false);
0093     //debug
0094     std::ostringstream ss;
0095     ss << "Events with possible matches (eventID,apvAddress): ";
0096     for (std::map<EventKey, SpyEventList>::const_iterator iSpyEvent = eventMatches_.begin();
0097          iSpyEvent != eventMatches_.end();
0098          ++iSpyEvent) {
0099       ss << "(" << iSpyEvent->first.eventId() << "," << uint16_t(iSpyEvent->first.apvAddress()) << ") ";
0100     }
0101     LogDebug(mlLabel_) << ss.str();
0102   }
0103 
0104   void SpyEventMatcher::addNextEventToMap(const edm::EventPrincipal& nextSpyEvent) {
0105     edm::EventID spyEventId = nextSpyEvent.id();
0106 
0107     CountersPtr totalEventCounters = getCounters(nextSpyEvent, totalEventCountersTag_);
0108     CountersPtr l1aCounters = getCounters(nextSpyEvent, l1aCountersTag_);
0109     CountersPtr apvAddresses = getCounters(nextSpyEvent, apvAddressesTag_, false);
0110     //loop over all FEDs. Maps should have same content and be in order so, avoid searches by iterating (and checking keys match)
0111     //add all possible event keys to the map
0112     std::vector<uint32_t>::const_iterator iTotalEventCount = totalEventCounters->begin();
0113     std::vector<uint32_t>::const_iterator iL1ACount = l1aCounters->begin();
0114     std::vector<uint32_t>::const_iterator iAPVAddress = apvAddresses->begin();
0115     //for debug
0116     std::map<EventKey, uint16_t> fedCounts;
0117     unsigned int fedid = 0;
0118     for (; ((iTotalEventCount != totalEventCounters->end()) && (iL1ACount != l1aCounters->end()) &&
0119             (iAPVAddress != apvAddresses->end()));
0120          (++iTotalEventCount, ++iL1ACount, ++iAPVAddress, ++fedid)) {
0121       if (*iAPVAddress == 0) {
0122         continue;
0123       }
0124 
0125       if (((*iTotalEventCount) > (*iL1ACount)) || ((*iL1ACount) - (*iTotalEventCount) > counterDiffMax_)) {
0126         LogWarning(mlLabel_) << "Spy event " << spyEventId.event() << " error in counter values for FED " << fedid
0127                              << ", totCount = " << *iTotalEventCount << ", L1Acount = " << *iL1ACount << std::endl;
0128 
0129         continue;
0130       }
0131 
0132       for (uint32_t eventId = (*iTotalEventCount) + 1; eventId <= (*iL1ACount) + 1; ++eventId) {
0133         EventKey key(eventId, *iAPVAddress);
0134         eventMatches_[key].insert(spyEventId);
0135         fedCounts[key]++;
0136       }
0137     }
0138 
0139     //for debug
0140     std::ostringstream ss;
0141     ss << "Spy event " << spyEventId.event() << " matches (eventID,apvAddress,nFEDs): ";
0142     for (std::map<EventKey, uint16_t>::const_iterator iEventFEDCount = fedCounts.begin();
0143          iEventFEDCount != fedCounts.end();
0144          ++iEventFEDCount) {
0145       ss << "(" << iEventFEDCount->first.eventId() << "," << uint16_t(iEventFEDCount->first.apvAddress()) << ","
0146          << iEventFEDCount->second << ") ";
0147     }
0148     LogDebug(mlLabel_) << ss.str();
0149   }
0150 
0151   const SpyEventMatcher::SpyEventList* SpyEventMatcher::matchesForEvent(const uint32_t eventId,
0152                                                                         const uint8_t apvAddress) const {
0153     EventKey eventKey(eventId, apvAddress);
0154     std::map<EventKey, SpyEventList>::const_iterator iMatch = eventMatches_.find(eventKey);
0155     if (iMatch == eventMatches_.end()) {
0156       LogDebug(mlLabel_) << "No match found for event " << eventId << " with APV address " << uint16_t(apvAddress);
0157       return nullptr;
0158     } else {
0159       std::ostringstream ss;
0160       ss << "Found matches to event " << eventId << " with address " << uint16_t(apvAddress) << " in spy events ";
0161       for (SpyEventList::const_iterator iMatchingSpyEvent = iMatch->second.begin();
0162            iMatchingSpyEvent != iMatch->second.end();
0163            ++iMatchingSpyEvent) {
0164         ss << iMatchingSpyEvent->event() << " ";
0165       }
0166       LogInfo(mlLabel_) << ss.str();
0167       return &(iMatch->second);
0168     }
0169   }
0170 
0171   void SpyEventMatcher::getCollections(const edm::EventPrincipal& event,
0172                                        const uint32_t eventId,
0173                                        const uint8_t apvAddress,
0174                                        const SiStripFedCabling& cabling,
0175                                        MatchingOutput& mo) {
0176     //read the input collections from the event
0177     const FEDRawDataCollection* inputRawDataPtr = getProduct<FEDRawDataCollection>(event, rawDataTag_);
0178     if (!inputRawDataPtr) {
0179       throw cms::Exception(mlLabel_) << "Failed to get raw spy data with tag " << rawDataTag_ << " from spy event";
0180     }
0181     const FEDRawDataCollection& inputRawData = *inputRawDataPtr;
0182     CountersPtr inputTotalEventCounters = getCounters(event, totalEventCountersTag_);
0183     CountersPtr inputL1ACounters = getCounters(event, l1aCountersTag_);
0184     CountersPtr inputAPVAddresses = getCounters(event, apvAddressesTag_, false);
0185     const edm::DetSetVector<SiStripRawDigi>* inputScopeDigis =
0186         getProduct<edm::DetSetVector<SiStripRawDigi> >(event, scopeDigisTag_);
0187     const edm::DetSetVector<SiStripRawDigi>* inputPayloadDigis =
0188         getProduct<edm::DetSetVector<SiStripRawDigi> >(event, payloadDigisTag_);
0189     const edm::DetSetVector<SiStripRawDigi>* inputReorderedDigis =
0190         getProduct<edm::DetSetVector<SiStripRawDigi> >(event, reorderedDigisTag_);
0191     const edm::DetSetVector<SiStripRawDigi>* inputVirginRawDigis =
0192         getProduct<edm::DetSetVector<SiStripRawDigi> >(event, virginRawDigisTag_);
0193     //construct the output vectors if the digis were found and they do not exist
0194     if (inputScopeDigis && !mo.outputScopeDigisVector_.get())
0195       mo.outputScopeDigisVector_.reset(new std::vector<edm::DetSet<SiStripRawDigi> >);
0196     if (inputPayloadDigis && !mo.outputPayloadDigisVector_.get())
0197       mo.outputPayloadDigisVector_.reset(new std::vector<edm::DetSet<SiStripRawDigi> >);
0198     if (inputReorderedDigis && !mo.outputReorderedDigisVector_.get())
0199       mo.outputReorderedDigisVector_.reset(new std::vector<edm::DetSet<SiStripRawDigi> >);
0200     if (inputVirginRawDigis && !mo.outputVirginRawDigisVector_.get())
0201       mo.outputVirginRawDigisVector_.reset(new std::vector<edm::DetSet<SiStripRawDigi> >);
0202     //find matching FEDs
0203     std::set<uint16_t> matchingFeds;
0204     findMatchingFeds(eventId, apvAddress, inputTotalEventCounters, inputL1ACounters, inputAPVAddresses, matchingFeds);
0205     LogInfo(mlLabel_) << "Spy event " << event.id() << " has " << matchingFeds.size() << " matching FEDs";
0206     std::ostringstream ss;
0207     ss << "Matching FEDs for event " << event.id() << ": ";
0208     for (std::set<uint16_t>::const_iterator iFedId = matchingFeds.begin(); iFedId != matchingFeds.end(); ++iFedId) {
0209       ss << *iFedId << " ";
0210     }
0211     LogDebug(mlLabel_) << ss.str();
0212     //check there are no duplicates
0213     std::vector<uint16_t> duplicateFeds(std::min(mo.alreadyMergedFeds_.size(), matchingFeds.size()));
0214     std::vector<uint16_t>::iterator duplicatesBegin = duplicateFeds.begin();
0215     std::vector<uint16_t>::iterator duplicatesEnd = std::set_intersection(mo.alreadyMergedFeds_.begin(),
0216                                                                           mo.alreadyMergedFeds_.end(),
0217                                                                           matchingFeds.begin(),
0218                                                                           matchingFeds.end(),
0219                                                                           duplicatesBegin);
0220     if ((duplicatesEnd - duplicatesBegin) != 0) {
0221       std::ostringstream ss;
0222       ss << "Found a match for FEDs ";
0223       for (std::vector<uint16_t>::const_iterator iDup = duplicatesBegin; iDup != duplicatesEnd; ++iDup) {
0224         ss << *iDup << " ";
0225       }
0226       ss << ". Output SetSetVectors will be unusable!";
0227       LogError(mlLabel_) << ss.str();
0228     }
0229     //merge the matching data
0230     mergeMatchingData(matchingFeds,
0231                       inputRawData,
0232                       inputTotalEventCounters,
0233                       inputL1ACounters,
0234                       inputAPVAddresses,
0235                       inputScopeDigis,
0236                       inputPayloadDigis,
0237                       inputReorderedDigis,
0238                       inputVirginRawDigis,
0239                       mo.outputRawData_,
0240                       mo.outputTotalEventCounters_,
0241                       mo.outputL1ACounters_,
0242                       mo.outputAPVAddresses_,
0243                       mo.outputScopeDigisVector_.get(),
0244                       mo.outputPayloadDigisVector_.get(),
0245                       mo.outputReorderedDigisVector_.get(),
0246                       mo.outputVirginRawDigisVector_.get(),
0247                       cabling);
0248     mo.alreadyMergedFeds_.insert(matchingFeds.begin(), matchingFeds.end());
0249   }
0250 
0251   void SpyEventMatcher::getMatchedCollections(const uint32_t eventId,
0252                                               const uint8_t apvAddress,
0253                                               const SpyEventList* matchingEvents,
0254                                               const SiStripFedCabling& cabling,
0255                                               SpyDataCollections& collectionsToCreate) {
0256     if (!matchingEvents)
0257       return;
0258     size_t fileNameHash = 0U;
0259     FEDRawDataCollection outputRawData;
0260     MatchingOutput mo(outputRawData);
0261     source_->loopSpecified(
0262         *eventPrincipal_,
0263         fileNameHash,
0264         matchingEvents->begin(),
0265         matchingEvents->end(),
0266         [&](auto const& iE, auto const&) { this->getCollections(iE, eventId, apvAddress, cabling, mo); });
0267     collectionsToCreate = SpyDataCollections(mo.outputRawData_,
0268                                              mo.outputTotalEventCounters_,
0269                                              mo.outputL1ACounters_,
0270                                              mo.outputAPVAddresses_,
0271                                              mo.outputScopeDigisVector_.get(),
0272                                              mo.outputPayloadDigisVector_.get(),
0273                                              mo.outputReorderedDigisVector_.get(),
0274                                              mo.outputVirginRawDigisVector_.get());
0275   }
0276 
0277   void SpyEventMatcher::findMatchingFeds(const uint32_t eventId,
0278                                          const uint8_t apvAddress,
0279                                          SpyEventMatcher::CountersPtr totalEventCounters,
0280                                          SpyEventMatcher::CountersPtr l1aCounters,
0281                                          SpyEventMatcher::CountersPtr apvAddresses,
0282                                          std::set<uint16_t>& matchingFeds) {
0283     //loop over all FEDs. Maps should have same content and be in order so, avoid searches by iterating (and checking keys match)
0284     std::vector<uint32_t>::const_iterator iTotalEventCount = totalEventCounters->begin();
0285     std::vector<uint32_t>::const_iterator iL1ACount = l1aCounters->begin();
0286     std::vector<uint32_t>::const_iterator iAPVAddress = apvAddresses->begin();
0287     for (; ((iTotalEventCount != totalEventCounters->end()) && (iL1ACount != l1aCounters->end()) &&
0288             (iAPVAddress != apvAddresses->end()));
0289          (++iTotalEventCount, ++iL1ACount, ++iAPVAddress)) {
0290       if (*iAPVAddress == 0) {
0291         continue;
0292       }
0293       if ((eventId > *iTotalEventCount) && (eventId <= (*iL1ACount) + 1) && (*iAPVAddress == apvAddress)) {
0294         matchingFeds.insert(matchingFeds.end(), iTotalEventCount - totalEventCounters->begin());
0295       }
0296     }
0297   }
0298 
0299   void SpyEventMatcher::mergeMatchingData(const std::set<uint16_t>& matchingFeds,
0300                                           const FEDRawDataCollection& inputRawData,
0301                                           SpyEventMatcher::CountersPtr inputTotalEventCounters,
0302                                           SpyEventMatcher::CountersPtr inputL1ACounters,
0303                                           SpyEventMatcher::CountersPtr inputAPVAddresses,
0304                                           const edm::DetSetVector<SiStripRawDigi>* inputScopeDigis,
0305                                           const edm::DetSetVector<SiStripRawDigi>* inputPayloadDigis,
0306                                           const edm::DetSetVector<SiStripRawDigi>* inputReorderedDigis,
0307                                           const edm::DetSetVector<SiStripRawDigi>* inputVirginRawDigis,
0308                                           FEDRawDataCollection& outputRawData,
0309                                           std::vector<uint32_t>& outputTotalEventCounters,
0310                                           std::vector<uint32_t>& outputL1ACounters,
0311                                           std::vector<uint32_t>& outputAPVAddresses,
0312                                           std::vector<edm::DetSet<SiStripRawDigi> >* outputScopeDigisVector,
0313                                           std::vector<edm::DetSet<SiStripRawDigi> >* outputPayloadDigisVector,
0314                                           std::vector<edm::DetSet<SiStripRawDigi> >* outputReorderedDigisVector,
0315                                           std::vector<edm::DetSet<SiStripRawDigi> >* outputVirginRawDigisVector,
0316                                           const SiStripFedCabling& cabling) {
0317     //reserve space in vectors
0318     if (inputScopeDigis) {
0319       outputScopeDigisVector->reserve(outputScopeDigisVector->size() +
0320                                       matchingFeds.size() *
0321                                           FEDCH_PER_FED);  //maximum number of channels on matching FEDs
0322     }
0323     if (inputPayloadDigis) {
0324       outputPayloadDigisVector->reserve(outputPayloadDigisVector->size() + matchingFeds.size() * FEDCH_PER_FED);
0325     }
0326     if (inputReorderedDigis) {
0327       outputReorderedDigisVector->reserve(outputReorderedDigisVector->size() + matchingFeds.size() * FEDCH_PER_FED);
0328     }
0329     if (inputVirginRawDigis) {
0330       outputVirginRawDigisVector->reserve(outputVirginRawDigisVector->size() +
0331                                           matchingFeds.size() * FEDCH_PER_FED /
0332                                               2);  //maximum number of dets on matching FEDs
0333     }
0334     //copy the data into output collections
0335     std::set<uint32_t> usedDetIds;
0336     for (std::set<uint16_t>::const_iterator iFedId = matchingFeds.begin(); iFedId != matchingFeds.end(); ++iFedId) {
0337       const uint32_t fedId = *iFedId;
0338       LogDebug(mlLabel_) << "Copying data for FED " << fedId;
0339       if (inputRawData.FEDData(fedId).size() && inputRawData.FEDData(fedId).data()) {
0340         outputRawData.FEDData(fedId) = inputRawData.FEDData(fedId);
0341       }
0342       outputTotalEventCounters[fedId] = (*inputTotalEventCounters)[fedId];
0343       outputL1ACounters[fedId] = (*inputL1ACounters)[fedId];
0344       outputAPVAddresses[fedId] = (*inputAPVAddresses)[fedId];
0345       for (uint8_t chan = 0; chan < FEDCH_PER_FED; ++chan) {
0346         uint32_t fedIndex = ((fedId & sistrip::invalid_) << 16) | (chan & sistrip::invalid_);
0347         ;
0348         if (inputScopeDigis) {
0349           edm::DetSetVector<SiStripRawDigi>::const_iterator iScopeDigis = inputScopeDigis->find(fedIndex);
0350           if (iScopeDigis != inputScopeDigis->end()) {
0351             outputScopeDigisVector->push_back(*iScopeDigis);
0352           }
0353         }
0354         if (inputPayloadDigis) {
0355           edm::DetSetVector<SiStripRawDigi>::const_iterator iPayloadDigis = inputPayloadDigis->find(fedIndex);
0356           if (iPayloadDigis != inputPayloadDigis->end()) {
0357             outputPayloadDigisVector->push_back(*iPayloadDigis);
0358           }
0359         }
0360         if (inputReorderedDigis) {
0361           edm::DetSetVector<SiStripRawDigi>::const_iterator iReorderedDigis = inputReorderedDigis->find(fedIndex);
0362           if (iReorderedDigis != inputReorderedDigis->end()) {
0363             outputReorderedDigisVector->push_back(*iReorderedDigis);
0364           }
0365         }
0366       }
0367       if (inputVirginRawDigis) {
0368         std::set<uint32_t> fedDetIds;
0369         auto conns = cabling.fedConnections(fedId);
0370         for (auto iConn = conns.begin(); iConn != conns.end(); ++iConn) {
0371           if (!iConn->isConnected())
0372             continue;
0373           const uint32_t detId = iConn->detId();
0374           if (usedDetIds.find(detId) != usedDetIds.end()) {
0375             LogError(mlLabel_) << "Duplicate DetID found " << detId << " skipping data for this Det from FED " << fedId;
0376             continue;
0377           }
0378           fedDetIds.insert(iConn->detId());
0379         }
0380         usedDetIds.insert(fedDetIds.begin(), fedDetIds.end());
0381         for (std::set<uint32_t>::const_iterator iDetId = fedDetIds.begin(); iDetId != fedDetIds.end(); ++iDetId) {
0382           edm::DetSetVector<SiStripRawDigi>::const_iterator iVirginRawDigis = inputVirginRawDigis->find(*iDetId);
0383           if (iVirginRawDigis != inputVirginRawDigis->end()) {
0384             outputVirginRawDigisVector->push_back(*iVirginRawDigis);
0385           }
0386         }
0387       }
0388     }
0389   }
0390 
0391   SpyEventMatcher::CountersPtr SpyEventMatcher::getCounters(const edm::EventPrincipal& event,
0392                                                             const edm::InputTag& tag,
0393                                                             const bool mapKeyIsByFedID) {
0394     const std::vector<uint32_t>* vectorFromEvent = getProduct<std::vector<uint32_t> >(event, tag);
0395     if (vectorFromEvent) {
0396       //vector is from event so, will be deleted when the event is destroyed (and not before)
0397       return std::make_shared<CountersWrapper>(vectorFromEvent);
0398     } else {
0399       const std::map<uint32_t, uint32_t>* mapFromEvent = getProduct<std::map<uint32_t, uint32_t> >(event, tag);
0400       if (mapFromEvent) {
0401         std::vector<uint32_t>* newVector = new std::vector<uint32_t>(FED_ID_MAX + 1, 0);
0402         if (mapKeyIsByFedID) {
0403           for (std::map<uint32_t, uint32_t>::const_iterator iIdValue = mapFromEvent->begin();
0404                iIdValue != mapFromEvent->end();
0405                ++iIdValue) {
0406             newVector->at(iIdValue->first) = iIdValue->second;
0407           }
0408         } else {
0409           SpyUtilities::fillFEDMajorities(*mapFromEvent, *newVector);
0410         }
0411         //  std::cout << " -- Map " << tag << std::endl;
0412         //  for (uint32_t lIt= 0;
0413         //       lIt < newVector->size();
0414         //       lIt++) {
0415         //    std::cout << lIt << " " << newVector->at(lIt) << std::endl;
0416         //  }
0417         //vector was allocated here so, will need to be deleted when finished with
0418         CountersPtr newCountersPtr(new CountersWrapper(newVector, true));
0419         return newCountersPtr;
0420       } else {
0421         throw cms::Exception(mlLabel_) << "Unable to get product " << tag << " from spy event";
0422       }
0423     }
0424   }
0425 
0426   SpyEventMatcher::SpyDataCollections::SpyDataCollections(
0427       FEDRawDataCollection& theRawData,
0428       std::vector<uint32_t>& theTotalEventCounters,
0429       std::vector<uint32_t>& theL1ACounters,
0430       std::vector<uint32_t>& theAPVAddresses,
0431       std::vector<edm::DetSet<SiStripRawDigi> >* theScopeDigisVector,
0432       std::vector<edm::DetSet<SiStripRawDigi> >* thePayloadDigisVector,
0433       std::vector<edm::DetSet<SiStripRawDigi> >* theReorderedDigisVector,
0434       std::vector<edm::DetSet<SiStripRawDigi> >* theVirginRawDigisVector)
0435       : rawData(new FEDRawDataCollection),
0436         totalEventCounters(new std::vector<uint32_t>),
0437         l1aCounters(new std::vector<uint32_t>),
0438         apvAddresses(new std::vector<uint32_t>),
0439         scopeDigis(theScopeDigisVector ? new edm::DetSetVector<SiStripRawDigi>(*theScopeDigisVector) : nullptr),
0440         payloadDigis(thePayloadDigisVector ? new edm::DetSetVector<SiStripRawDigi>(*thePayloadDigisVector) : nullptr),
0441         reorderedDigis(theReorderedDigisVector ? new edm::DetSetVector<SiStripRawDigi>(*theReorderedDigisVector)
0442                                                : nullptr),
0443         virginRawDigis(theVirginRawDigisVector ? new edm::DetSetVector<SiStripRawDigi>(*theVirginRawDigisVector)
0444                                                : nullptr) {
0445     rawData->swap(theRawData);
0446     totalEventCounters->swap(theTotalEventCounters);
0447     l1aCounters->swap(theL1ACounters);
0448     apvAddresses->swap(theAPVAddresses);
0449   }
0450 
0451   SpyEventMatcher::SpyDataCollections::SpyDataCollections()
0452       : rawData(),
0453         totalEventCounters(),
0454         l1aCounters(),
0455         apvAddresses(),
0456         scopeDigis(),
0457         payloadDigis(),
0458         reorderedDigis(),
0459         virginRawDigis() {}
0460 
0461   SpyEventMatcher::CountersWrapper::CountersWrapper(const Counters* theCounters)
0462       : pConst(theCounters), p(nullptr), deleteP(false) {}
0463 
0464   SpyEventMatcher::CountersWrapper::CountersWrapper(Counters* theCounters, const bool takeOwnership)
0465       : pConst(theCounters), p(theCounters), deleteP(takeOwnership) {}
0466 
0467   SpyEventMatcher::CountersWrapper::~CountersWrapper() {
0468     if (deleteP)
0469       delete p;
0470   }
0471 
0472 }  // namespace sistrip
0473 
0474 #endif  //SiStripMonitorHardware_BuildEventMatchingCode