Skip to content

Commit

Permalink
Merge pull request #29103 from Dr15Jones/globalL1Comparator
Browse files Browse the repository at this point in the history
Make L1Comparator a global module
  • Loading branch information
cmsbuild committed Mar 17, 2020
2 parents a4e64ba + 30ac87b commit 6746515
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 210 deletions.
7 changes: 7 additions & 0 deletions DataFormats/L1Trigger/interface/L1DataEmulRecord.h
Expand Up @@ -9,6 +9,7 @@

#include <ostream>
#include <vector>
#include <array>

#include "DataFormats/L1Trigger/interface/L1DataEmulDigi.h"

Expand All @@ -24,6 +25,12 @@ class L1DataEmulRecord {
int nCand[DEnsys][2],
const L1DEDigiCollection&,
const GltDEDigi&);
L1DataEmulRecord(bool evt_match,
std::array<bool, DEnsys> const& sys_comp,
std::array<bool, DEnsys> const& sys_match,
std::array<std::array<int, 2>, DEnsys> const& nCand,
const L1DEDigiCollection&,
const GltDEDigi&);
~L1DataEmulRecord();

bool get_status() const { return deAgree; }
Expand Down
16 changes: 16 additions & 0 deletions DataFormats/L1Trigger/src/L1DataEmulRecord.cc
Expand Up @@ -26,6 +26,22 @@ L1DataEmulRecord::L1DataEmulRecord(bool evt_match,
deColl = coll;
}

L1DataEmulRecord::L1DataEmulRecord(bool evt_match,
std::array<bool, DEnsys> const& sys_comp,
std::array<bool, DEnsys> const& sys_match,
std::array<std::array<int, 2>, DEnsys> const& nCand,
const L1DEDigiCollection& coll,
const GltDEDigi& glt)
: deAgree(evt_match), deGlt(glt) {
for (int i = 0; i < DEnsys; i++) {
deMatch[i] = sys_match[i];
deSysCompared[i] = sys_comp[i];
for (int j = 0; j < 2; j++)
deNCand[i][j] = nCand[i][j];
}
deColl = coll;
}

L1DataEmulRecord::~L1DataEmulRecord() {}

void L1DataEmulRecord::get_status(bool result[]) const {
Expand Down
14 changes: 7 additions & 7 deletions L1Trigger/HardwareValidation/interface/DEcompare.h
Expand Up @@ -9,7 +9,7 @@

/*\note specialization free*/

#include <fstream>
#include <ostream>

#include "L1Trigger/HardwareValidation/interface/DEtrait.h"
#include "L1Trigger/HardwareValidation/interface/DEutils.h"
Expand Down Expand Up @@ -59,10 +59,10 @@ class DEcompare {
}
*/

bool do_compare(std::ofstream&, int dump = 0);
bool CompareCollections(std::ofstream&, int dump = 0);
bool do_compare(std::ostream&, int dump = 0);
bool CompareCollections(std::ostream&, int dump = 0);
bool SortCollections(cand_vec& dg, cand_vec& eg, cand_vec& db, cand_vec& eb);
bool DumpCandidate(col_cit itd, col_cit itm, std::ofstream&, int mode = 0);
bool DumpCandidate(col_cit itd, col_cit itm, std::ostream&, int mode = 0);
int get_ncand(typeT) const;
int get_ncand(int i) const {
if (debug_ && (i < 0 || i > 2))
Expand Down Expand Up @@ -102,7 +102,7 @@ class DEcompare {
};

template <typename T>
bool DEcompare<T>::do_compare(std::ofstream& os, int dump) {
bool DEcompare<T>::do_compare(std::ostream& os, int dump) {
if (debug_)
std::cout << " DEcompare::do_compare... " << GetName() << "\n" << std::flush;
t_match = CompareCollections(os, dump);
Expand All @@ -128,7 +128,7 @@ int DEcompare<T>::get_ncand(typeT col) const {
}

template <typename T>
bool DEcompare<T>::CompareCollections(std::ofstream& os, int dump) {
bool DEcompare<T>::CompareCollections(std::ostream& os, int dump) {
if (debug_)
std::cout << " DEcompare::CompareCollections...\n" << std::flush;
bool match = true;
Expand Down Expand Up @@ -301,7 +301,7 @@ bool DEcompare<T>::SortCollections(cand_vec& data_good, cand_vec& emul_good, can
}

template <typename T>
bool DEcompare<T>::DumpCandidate(col_cit itd, col_cit itm, std::ofstream& os, int mode) {
bool DEcompare<T>::DumpCandidate(col_cit itd, col_cit itm, std::ostream& os, int mode) {
if (mode != 2)
os << " data: " << print(itd);
if (mode != 1)
Expand Down
61 changes: 35 additions & 26 deletions L1Trigger/HardwareValidation/interface/L1Comparator.h
Expand Up @@ -15,9 +15,10 @@
#include <iomanip>
#include <vector>
#include <algorithm>
#include <atomic>
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
Expand All @@ -39,39 +40,49 @@
template <class T>
class DEcompare;

class L1Comparator : public edm::EDProducer {
class L1Comparator : public edm::global::EDProducer<edm::RunCache<std::array<bool, dedefs::DEnsys>>> {
public:
explicit L1Comparator(const edm::ParameterSet&);
~L1Comparator() override;

private:
void beginJob(void) override;
void beginRun(edm::Run const&, const edm::EventSetup&) final;
void produce(edm::Event&, const edm::EventSetup&) override;
using RunCache = std::array<bool, dedefs::DEnsys>;
std::shared_ptr<RunCache> globalBeginRun(edm::Run const&, const edm::EventSetup&) const final;
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
void globalEndRun(edm::Run const&, edm::EventSetup const&) const final {}
void endJob() override;

struct EventInfo {
L1DEDigiCollection m_dedigis;
std::array<bool, dedefs::DEnsys> DEmatchEvt = {{true}};
std::array<std::array<int, 2>, dedefs::DEnsys> DEncand = {{{{0, 0}}}};
std::ostringstream dumpToFile_;
int nevt_;
int evtNum_;
int runNum_;
//flag whether event id has already been written to dumpFile
bool dumpEvent_ = true;
};

template <class T>
void process(T const*, T const*, const int, const int);
void process(T const*, T const*, const int, const int, EventInfo& eventInfo) const;
template <class T>
void process(const edm::Handle<T> data, const edm::Handle<T> emul, const int sys, const int cid) {
void process(
const edm::Handle<T> data, const edm::Handle<T> emul, const int sys, const int cid, EventInfo& eventInfo) const {
if (data.isValid() && emul.isValid())
process(data.product(), emul.product(), sys, cid);
process(data.product(), emul.product(), sys, cid, eventInfo);
}

template <class T>
bool CompareCollections(edm::Handle<T> data, edm::Handle<T> emul);
bool CompareCollections(edm::Handle<T> data, edm::Handle<T> emul, std::ostream&) const;
template <class T>
bool dumpCandidate(const T& dt, const T& em, std::ostream& s);
bool dumpCandidate(const T& dt, const T& em, std::ostream& s) const;

int verbose() { return verbose_; }
bool m_stage1_layer2_;
int verbose() const { return verbose_; }
const bool m_stage1_layer2_;

private:
int nevt_;
int evtNum_;
int runNum_;
int verbose_;
bool dumpEvent_;
mutable std::atomic<int> nevt_;
const int verbose_;

edm::EDGetTokenT<L1CaloEmCollection> tokenCaloEm_[2];
edm::EDGetTokenT<L1CaloRegionCollection> tokenCaloRegion_[2];
Expand All @@ -97,14 +108,12 @@ class L1Comparator : public edm::EDProducer {
edm::EDGetTokenT<L1MuGMTCandCollection> tokenMuGMTCand_[2];
edm::EDGetTokenT<L1MuGMTReadoutCollection> tokenMuReadoutCand_[2];

bool m_doSys[dedefs::DEnsys];
std::string m_dumpFileName;
std::ofstream m_dumpFile;
int m_dumpMode;
bool m_match;
bool DEmatchEvt[dedefs::DEnsys];
int DEncand[dedefs::DEnsys][2];
L1DEDigiCollection m_dedigis;
const std::array<bool, dedefs::DEnsys> m_doSys;
const std::string m_dumpFileName;
CMS_THREAD_GUARD(m_fileGuard) mutable std::ofstream m_dumpFile;
const int m_dumpMode;
mutable std::mutex m_fileGuard;
mutable std::atomic<bool> m_match;
};

#endif

0 comments on commit 6746515

Please sign in to comment.