2 #ifdef SiStripMonitorHardware_BuildEventMatchingCode
17 #include "boost/bind.hpp"
18 #include "boost/shared_ptr.hpp"
31 : eventId_(eventId), apvAddress_(apvAddress) {}
34 outputRawData_(outputRawData),
35 outputTotalEventCounters_(sistrip::
FED_ID_MAX+1),
42 :
rawDataTag_(config.getParameter<edm::InputTag>(
"RawSpyDataTag")),
44 l1aCountersTag_(config.getParameter<edm::InputTag>(
"SpyL1ACountersTag")),
46 scopeDigisTag_(config.getParameter<edm::InputTag>(
"SpyScopeDigisTag")),
66 std::ostringstream ss;
67 ss <<
"Events with possible matches (eventID,apvAddress): ";
68 for (std::map<EventKey,SpyEventList>::const_iterator iSpyEvent =
eventMatches_.begin(); iSpyEvent !=
eventMatches_.end(); ++iSpyEvent) {
69 ss <<
"(" << iSpyEvent->first.eventId() <<
"," << uint16_t(iSpyEvent->first.apvAddress()) <<
") ";
83 std::vector<uint32_t>::const_iterator iTotalEventCount = totalEventCounters->begin();
84 std::vector<uint32_t>::const_iterator iL1ACount = l1aCounters->begin();
85 std::vector<uint32_t>::const_iterator iAPVAddress = apvAddresses->begin();
87 std::map<EventKey,uint16_t> fedCounts;
88 unsigned int fedid = 0;
90 ( (iTotalEventCount != totalEventCounters->end()) && (iL1ACount != l1aCounters->end()) && (iAPVAddress != apvAddresses->end()) );
91 (++iTotalEventCount, ++iL1ACount, ++iAPVAddress, ++fedid)
93 if (*iAPVAddress == 0) {
97 if ( ((*iTotalEventCount) > (*iL1ACount) ) ||
101 <<
" error in counter values for FED " << fedid
102 <<
", totCount = " << *iTotalEventCount
103 <<
", L1Acount = " << *iL1ACount
109 for (uint32_t eventId = (*iTotalEventCount)+1; eventId <= (*iL1ACount)+1; ++eventId) {
117 std::ostringstream ss;
118 ss <<
"Spy event " << spyEventId.
event() <<
" matches (eventID,apvAddress,nFEDs): ";
119 for (std::map<EventKey,uint16_t>::const_iterator iEventFEDCount = fedCounts.begin(); iEventFEDCount != fedCounts.end(); ++iEventFEDCount) {
120 ss <<
"(" << iEventFEDCount->first.eventId() <<
"," << uint16_t(iEventFEDCount->first.apvAddress()) <<
"," << iEventFEDCount->second <<
") ";
127 EventKey eventKey(eventId,apvAddress);
128 std::map<EventKey,SpyEventList>::const_iterator iMatch =
eventMatches_.find(eventKey);
130 LogDebug(
mlLabel_) <<
"No match found for event " << eventId <<
" with APV address " << uint16_t(apvAddress);
134 std::ostringstream ss;
135 ss <<
"Found matches to event " << eventId <<
" with address " << uint16_t(apvAddress) <<
" in spy events ";
136 for (SpyEventList::const_iterator iMatchingSpyEvent = iMatch->second.begin(); iMatchingSpyEvent != iMatch->second.end(); ++iMatchingSpyEvent) {
137 ss << iMatchingSpyEvent->event() <<
" ";
140 return &(iMatch->second);
150 if (!inputRawDataPtr) {
167 std::set<uint16_t> matchingFeds;
168 findMatchingFeds(eventId,apvAddress,inputTotalEventCounters,inputL1ACounters,inputAPVAddresses,matchingFeds);
169 LogInfo(
mlLabel_) <<
"Spy event " <<
event.id() <<
" has " << matchingFeds.size() <<
" matching FEDs";
170 std::ostringstream ss;
171 ss <<
"Matching FEDs for event " <<
event.id() <<
": ";
172 for (std::set<uint16_t>::const_iterator iFedId = matchingFeds.begin(); iFedId != matchingFeds.end(); ++iFedId) {
173 ss << *iFedId <<
" ";
178 std::vector<uint16_t>::iterator duplicatesBegin = duplicateFeds.begin();
180 matchingFeds.begin(),matchingFeds.end(),
182 if ( (duplicatesEnd-duplicatesBegin) != 0 ) {
183 std::ostringstream ss;
184 ss <<
"Found a match for FEDs ";
185 for (std::vector<uint16_t>::const_iterator iDup = duplicatesBegin; iDup != duplicatesEnd; ++iDup) {
188 ss <<
". Output SetSetVectors will be unusable!";
192 mergeMatchingData(matchingFeds,inputRawData,inputTotalEventCounters,inputL1ACounters,inputAPVAddresses,
193 inputScopeDigis,inputPayloadDigis,inputReorderedDigis,inputVirginRawDigis,
205 if (!matchingEvents)
return;
209 eventId,apvAddress,boost::cref(cabling),boost::ref(mo)));
213 collectionsToCreate = collections;
220 std::set<uint16_t>& matchingFeds)
223 std::vector<uint32_t>::const_iterator iTotalEventCount = totalEventCounters->begin();
224 std::vector<uint32_t>::const_iterator iL1ACount = l1aCounters->begin();
225 std::vector<uint32_t>::const_iterator iAPVAddress = apvAddresses->begin();
227 ( (iTotalEventCount != totalEventCounters->end()) && (iL1ACount != l1aCounters->end()) && (iAPVAddress != apvAddresses->end()) );
228 (++iTotalEventCount, ++iL1ACount, ++iAPVAddress)
230 if (*iAPVAddress == 0) {
233 if ( (eventId > *iTotalEventCount) && (eventId <= (*iL1ACount)+1) && (*iAPVAddress == apvAddress) ) {
234 matchingFeds.insert(matchingFeds.end(),iTotalEventCount-totalEventCounters->begin());
249 std::vector<uint32_t>& outputTotalEventCounters,
250 std::vector<uint32_t>& outputL1ACounters,
251 std::vector<uint32_t>& outputAPVAddresses,
259 if (inputScopeDigis) {
260 outputScopeDigisVector->reserve(outputScopeDigisVector->size()+matchingFeds.size()*
FEDCH_PER_FED);
262 if (inputPayloadDigis) {
263 outputPayloadDigisVector->reserve(outputPayloadDigisVector->size()+matchingFeds.size()*
FEDCH_PER_FED);
265 if (inputReorderedDigis) {
266 outputReorderedDigisVector->reserve(outputReorderedDigisVector->size()+matchingFeds.size()*
FEDCH_PER_FED);
268 if (inputVirginRawDigis) {
269 outputVirginRawDigisVector->reserve(outputVirginRawDigisVector->size()+matchingFeds.size()*
FEDCH_PER_FED/2);
272 std::set<uint32_t> usedDetIds;
273 for (std::set<uint16_t>::const_iterator iFedId = matchingFeds.begin(); iFedId != matchingFeds.end(); ++iFedId) {
274 const uint32_t fedId = *iFedId;
279 outputTotalEventCounters[fedId] = (*inputTotalEventCounters)[fedId];
280 outputL1ACounters[fedId] = (*inputL1ACounters)[fedId];
281 outputAPVAddresses[fedId] = (*inputAPVAddresses)[fedId];
284 if (inputScopeDigis) {
286 if (iScopeDigis != inputScopeDigis->
end()) {
287 outputScopeDigisVector->push_back(*iScopeDigis);
290 if (inputPayloadDigis) {
292 if (iPayloadDigis != inputPayloadDigis->
end()) {
293 outputPayloadDigisVector->push_back(*iPayloadDigis);
296 if (inputReorderedDigis) {
298 if (iReorderedDigis != inputReorderedDigis->
end()) {
299 outputReorderedDigisVector->push_back(*iReorderedDigis);
303 if (inputVirginRawDigis) {
304 std::set<uint32_t> fedDetIds;
305 const std::vector<FedChannelConnection>& conns = cabling.
connections(fedId);
306 for (std::vector<FedChannelConnection>::const_iterator iConn = conns.begin(); iConn != conns.end(); ++iConn) {
307 if (!iConn->isConnected())
continue;
308 const uint32_t detId = iConn->detId();
309 if (usedDetIds.find(detId) != usedDetIds.end()) {
310 LogError(
mlLabel_) <<
"Duplicate DetID found " << detId <<
" skipping data for this Det from FED " << fedId;
313 fedDetIds.insert(iConn->detId());
315 usedDetIds.insert(fedDetIds.begin(),fedDetIds.end());
316 for (std::set<uint32_t>::const_iterator iDetId = fedDetIds.begin(); iDetId != fedDetIds.end(); ++iDetId) {
318 if (iVirginRawDigis != inputVirginRawDigis->
end()) {
319 outputVirginRawDigisVector->push_back(*iVirginRawDigis);
328 const std::vector<uint32_t>* vectorFromEvent = getProduct< std::vector<uint32_t> >(
event,
tag);
329 if (vectorFromEvent) {
333 const std::map<uint32_t,uint32_t>* mapFromEvent = getProduct< std::map<uint32_t,uint32_t> >(
event,
tag);
335 std::vector<uint32_t>* newVector =
new std::vector<uint32_t>(
FED_ID_MAX+1,0);
336 if (mapKeyIsByFedID) {
337 for (std::map<uint32_t,uint32_t>::const_iterator iIdValue = mapFromEvent->begin(); iIdValue != mapFromEvent->end(); ++iIdValue) {
338 newVector->at(iIdValue->first) = iIdValue->second;
351 return newCountersPtr;
359 std::vector<uint32_t>& theTotalEventCounters,
360 std::vector<uint32_t>& theL1ACounters,
361 std::vector<uint32_t>& theAPVAddresses,
367 totalEventCounters(new std::vector<uint32_t>),
368 l1aCounters(new std::vector<uint32_t>),
369 apvAddresses(new std::vector<uint32_t>),
370 scopeDigis(theScopeDigisVector ? new edm::DetSetVector<
SiStripRawDigi>(*theScopeDigisVector) :
NULL),
371 payloadDigis(thePayloadDigisVector ? new edm::DetSetVector<
SiStripRawDigi>(*thePayloadDigisVector) :
NULL),
372 reorderedDigis(theReorderedDigisVector ? new edm::DetSetVector<
SiStripRawDigi>(*theReorderedDigisVector) :
NULL),
373 virginRawDigis(theVirginRawDigisVector ? new edm::DetSetVector<
SiStripRawDigi>(*theVirginRawDigisVector) :
NULL)
383 totalEventCounters(),
405 : pConst(theCounters),
412 : pConst(theCounters),
414 deleteP(takeOwnership)
421 if (deleteP)
delete p;
426 #endif //SiStripMonitorHardware_BuildEventMatchingCode
CountersWrapper(const Counters *theCounters)
EventNumber_t event() const
edm::InputTag virginRawDigisTag_
static void findMatchingFeds(const uint32_t eventId, const uint8_t apvAddress, CountersPtr totalEventCounters, CountersPtr l1aCounters, CountersPtr apvAddresses, std::set< uint16_t > &matchingFeds)
iterator find(det_id_type id)
std::auto_ptr< std::vector< uint32_t > > apvAddresses
static const char * mlLabel_
boost::shared_ptr< CountersWrapper > CountersPtr
edm::InputTag rawDataTag_
edm::InputTag payloadDigisTag_
std::set< uint16_t > alreadyMergedFeds_
std::vector< uint32_t > outputL1ACounters_
std::auto_ptr< Source > source_
void getCollections(const edm::EventPrincipal &event, const uint32_t eventId, const uint8_t apvAddress, const SiStripFedCabling &cabling, MatchingOutput &matchingOutput)
EventID const & id() const
static CountersPtr getCounters(const edm::EventPrincipal &event, const edm::InputTag &tag, const bool mapKeyIsByFedID=true)
FEDRawDataCollection & outputRawData_
void getMatchedCollections(const uint32_t eventId, const uint8_t apvAddress, const SpyEventList *matchingEvents, const SiStripFedCabling &cabling, SpyDataCollections &collectionsToCreate)
edm::InputTag apvAddressesTag_
edm::InputTag scopeDigisTag_
std::auto_ptr< std::vector< uint32_t > > l1aCounters
std::auto_ptr< std::vector< uint32_t > > totalEventCounters
SpyDataCollections & operator=(SpyDataCollections original)
static uint32_t fedIndex(const uint16_t &fed_id, const uint16_t &fed_ch)
boost::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputReorderedDigisVector_
size_t size() const
Lenght of the data buffer in bytes.
std::vector< uint32_t > outputAPVAddresses_
boost::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputScopeDigisVector_
edm::InputTag l1aCountersTag_
static void fillFEDMajorities(const std::map< uint32_t, uint32_t > &channelValues, std::vector< uint32_t > &fedMajoritiesToFill)
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
const T & max(const T &a, const T &b)
boost::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputPayloadDigisVector_
std::set< EventID > SpyEventList
virtual ~SpyEventMatcher()
std::auto_ptr< edm::DetSetVector< SiStripRawDigi > > payloadDigis
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
MatchingOutput(FEDRawDataCollection &outputRawData)
iterator end()
Return the off-the-end iterator.
edm::InputTag totalEventCountersTag_
const SpyEventList * matchesForEvent(const uint32_t eventId, const uint8_t apvAddress) const
EventKey(const uint32_t eventId, const uint8_t apvAddress)
std::auto_ptr< edm::DetSetVector< SiStripRawDigi > > scopeDigis
std::auto_ptr< FEDRawDataCollection > rawData
std::vector< uint32_t > outputTotalEventCounters_
edm::InputTag reorderedDigisTag_
static std::auto_ptr< Source > constructSource(const edm::ParameterSet &sourceConfig)
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
boost::shared_ptr< std::vector< edm::DetSet< SiStripRawDigi > > > outputVirginRawDigisVector_
std::auto_ptr< edm::DetSetVector< SiStripRawDigi > > virginRawDigis
void addNextEventToMap(const edm::EventPrincipal &nextSpyEvent)
static const uint16_t FEDCH_PER_FED
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
static void mergeMatchingData(const std::set< uint16_t > &matchingFeds, const FEDRawDataCollection &inputRawData, CountersPtr inputTotalEventCounters, CountersPtr inputL1ACounters, CountersPtr inputAPVAddresses, const edm::DetSetVector< SiStripRawDigi > *inputScopeDigis, const edm::DetSetVector< SiStripRawDigi > *inputPayloadDigis, const edm::DetSetVector< SiStripRawDigi > *inputReorderedDigis, const edm::DetSetVector< SiStripRawDigi > *inputVirginRawDigis, FEDRawDataCollection &outputRawData, std::vector< uint32_t > &outputTotalEventCounters, std::vector< uint32_t > &outputL1ACounters, std::vector< uint32_t > &outputAPVAddresses, std::vector< edm::DetSet< SiStripRawDigi > > *outputScopeDigisVector, std::vector< edm::DetSet< SiStripRawDigi > > *outputPayloadDigisVector, std::vector< edm::DetSet< SiStripRawDigi > > *outputReorderedDigisVector, std::vector< edm::DetSet< SiStripRawDigi > > *outputVirginRawDigisVector, const SiStripFedCabling &cabling)
SpyEventMatcher(const edm::ParameterSet &config)
static const uint16_t FED_ID_MAX
collection_type::const_iterator const_iterator
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
std::map< EventKey, SpyEventList > eventMatches_
const std::vector< FedChannelConnection > & connections(uint16_t fed_id) const