47 #include "DQM/SiStripMonitorHardware/interface/FEDHistograms.hh"
48 #include "DQM/SiStripMonitorHardware/interface/FEDErrors.hh"
55 #include "DQM/SiStripMonitorHardware/interface/CMHistograms.hh"
77 virtual void endJob()
override;
83 void fillMaps(uint32_t aDetId,
unsigned short aChInModule, std::pair<uint16_t,uint16_t> aMedians);
128 : rawDataTag_(iConfig.getUntrackedParameter<edm::InputTag>(
"RawDataTag",edm::InputTag(
"source",
""))),
129 folderName_(iConfig.getUntrackedParameter<std::
string>(
"HistogramFolderName",
"SiStrip/ReadoutView/CMMonitoring")),
130 fedIdVec_(iConfig.getUntrackedParameter<std::vector<unsigned int> >(
"FedIdVec")),
131 fillAllDetailedHistograms_(iConfig.getUntrackedParameter<bool>(
"FillAllDetailedHistograms",
false)),
132 fillWithEvtNum_(iConfig.getUntrackedParameter<bool>(
"FillWithEventNumber",
false)),
133 fillWithLocalEvtNum_(iConfig.getUntrackedParameter<bool>(
"FillWithLocalEventNumber",
false)),
134 printDebug_(iConfig.getUntrackedParameter<unsigned int>(
"PrintDebugMessages",1)),
135 writeDQMStore_(iConfig.getUntrackedParameter<bool>(
"WriteDQMStore",
false)),
136 dqmStoreFileName_(iConfig.getUntrackedParameter<std::
string>(
"DQMStoreFileName",
"DQMStore.root")),
143 std::ostringstream debugStream;
145 debugStream <<
"[SiStripCMMonitorPlugin]Configuration for SiStripCMMonitorPlugin: " << std::endl
146 <<
"[SiStripCMMonitorPlugin]\tRawDataTag: " <<
rawDataTag_ << std::endl
147 <<
"[SiStripCMMonitorPlugin]\tHistogramFolderName: " <<
folderName_ << std::endl
149 <<
"[SiStripCMMonitorPlugin]\tFillWithEventNumber?" << (
fillWithEvtNum_ ?
"yes" :
"no") << std::endl
150 <<
"[SiStripCMMonitorPlugin]\tPrintDebugMessages? " << (
printDebug_ ?
"yes" :
"no") << std::endl
151 <<
"[SiStripCMMonitorPlugin]\tWriteDQMStore? " << (
writeDQMStore_ ?
"yes" :
"no") << std::endl;
155 std::ostringstream* pDebugStream = (
printDebug_>1 ? &debugStream :
NULL);
157 cmHists_.initialise(iConfig,pDebugStream);
166 prevMedians_[fedId][iCh] = std::pair<uint16_t,uint16_t>(0,0);
172 LogTrace(
"SiStripMonitorHardware") << debugStream.str();
209 FEDErrors lFedErrors;
218 lFedErrors.initialiseFED(fedId,
cabling_,tTopo);
222 bool lDataExist = lFedErrors.checkDataPresent(fedData);
227 std::auto_ptr<const sistrip::FEDBuffer> buffer;
229 if (!lFedErrors.fillFatalFEDErrors(fedData,0)) {
235 bool channelLengthsOK = buffer->checkChannelLengthsMatchBufferLength();
236 bool channelPacketCodesOK = buffer->checkChannelPacketCodes();
237 bool feLengthsOK = buffer->checkFEUnitLengths();
238 if ( !channelLengthsOK ||
239 !channelPacketCodesOK ||
245 std::ostringstream infoStream;
249 infoStream <<
" --- Processing FED #" << fedId << std::endl;
253 std::vector<CMHistograms::CMvalues>
values;
255 for (
unsigned int iCh = 0;
268 uint32_t lDetId = lConnection.
detId();
269 unsigned short nChInModule = lConnection.
nApvPairs();
273 bool lFailUnpackerChannelCheck = !buffer->channelGood(iCh) && connected;
275 if (lFailUnpackerChannelCheck) {
304 std::ostringstream lMode;
305 lMode << buffer->readoutMode();
307 static bool lFirst =
true;
309 std::cout <<
"Readout mode: " << lMode.str() << std::endl;
316 std::pair<uint16_t,uint16_t> medians = std::pair<uint16_t,uint16_t>(0,0);
318 if (lMode.str().find(
"Zero suppressed") != lMode.str().npos && lMode.str().find(
"lite") == lMode.str().npos) medians = std::pair<uint16_t,uint16_t>(lChannel.
cmMedian(0),lChannel.
cmMedian(1));
320 CMHistograms::CMvalues lVal;
321 lVal.ChannelID = iCh;
322 lVal.Medians = std::pair<uint16_t,uint16_t>(medians.first,medians.second);
333 if (lChannel.
length() > 7) {
334 infoStream <<
"Medians for channel #" << iCh <<
" (length " << lChannel.
length() <<
"): " << medians.first <<
", " << medians.second << std::endl;
338 values.push_back(lVal);
341 fillMaps(lDetId,nChInModule,medians);
343 prevMedians_[fedId][iCh] = std::pair<uint16_t,uint16_t>(medians.first,medians.second);
352 cmHists_.fillHistograms(values,lTime,fedId);
388 std::map<unsigned int,Statistics>::iterator fracIter;
393 uint32_t
detid = fracIter->first;
408 message <<
"TkHistoMap CM: Detid " << detid <<
", mean = " << mean <<
", rms = " << rms <<
", counter = " << lStat.
Counter << std::endl;
416 uint32_t
detid = fracIter->first;
431 message <<
"TkHistoMap APV0minusAPV1: Detid " << detid <<
", mean = " << mean <<
", rms = " << rms <<
", counter = " << lStat.
Counter << std::endl;
459 std::pair<std::map<unsigned int,Statistics>::iterator,
bool> alreadyThere[2];
462 lStat.
Mean = (aMedians.first+aMedians.second)*1./(2*aChInModule);
463 lStat.
Rms = (aMedians.first+aMedians.second)*(aMedians.first+aMedians.second)*1./(4*aChInModule);
464 lStat.
Counter = 1./aChInModule;
466 alreadyThere[0] =
CommonModes_.insert(std::pair<unsigned int,Statistics>(aDetId,lStat));
467 if (!alreadyThere[0].
second) {
468 ((alreadyThere[0].first)->second).Mean += (aMedians.first+aMedians.second)*1./(2*aChInModule);
469 ((alreadyThere[0].first)->second).Rms += (aMedians.first+aMedians.second)*(aMedians.first+aMedians.second)*1./(4*aChInModule);
470 ((alreadyThere[0].first)->second).Counter += 1./aChInModule;
473 lStat.
Mean = (aMedians.first-aMedians.second)*1./aChInModule;
474 lStat.
Rms = (aMedians.first-aMedians.second)*(aMedians.first-aMedians.second)*1./aChInModule;
475 lStat.
Counter = 1./aChInModule;
478 if (!alreadyThere[1].second) {
479 ((alreadyThere[1].first)->second).Mean += (aMedians.first-aMedians.second)*1./aChInModule;
480 ((alreadyThere[1].first)->second).Rms += (aMedians.first-aMedians.second)*(aMedians.first-aMedians.second)*1./aChInModule;
481 ((alreadyThere[1].first)->second).Counter += 1./aChInModule;
EventNumber_t event() const
std::pair< uint16_t, uint16_t > prevMedians_[FEDNumbering::MAXSiStripFEDID+1][sistrip::FEDCH_PER_FED]
virtual void endJob() override
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
FedChannelConnection fedConnection(uint16_t fed_id, uint16_t fed_ch) const
edm::InputTag rawDataTag_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
static const uint32_t invalid32_
#define DEFINE_FWK_MODULE(type)
void fillMaps(uint32_t aDetId, unsigned short aChInModule, std::pair< uint16_t, uint16_t > aMedians)
std::vector< unsigned int > fedIdVec_
std::map< unsigned int, Statistics > CommonModesAPV0minusAPV1_
size_t size() const
Lenght of the data buffer in bytes.
U second(std::pair< T, U > const &p)
std::string dqmStoreFileName_
uint16_t cmMedian(const uint8_t apvIndex) const
SiStripCMMonitorPlugin(const edm::ParameterSet &)
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void updateCabling(const edm::EventSetup &eventSetup)
const uint32_t & detId() const
Class containning control, module, detector and connection information, at the level of a FED channel...
edm::EDGetTokenT< FEDRawDataCollection > rawDataToken_
bool fillAllDetailedHistograms_
std::map< unsigned int, Statistics > CommonModes_
const uint16_t & nApvPairs() const
T const * product() const
const SiStripFedCabling * cabling_
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
~SiStripCMMonitorPlugin()
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, const uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE", const bool resetMEsAfterWriting=false)
static const uint16_t FEDCH_PER_FED
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
volatile std::atomic< bool > shutdown_flag false
virtual void beginJob() override
void setCurrentFolder(const std::string &fullpath)
bool fillWithLocalEvtNum_