CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
trackerTFP::Demonstrator Class Reference

Compares emulator with f/w. More...

#include <Demonstrator.h>

Public Member Functions

bool analyze (const std::vector< std::vector< tt::Frame >> &input, const std::vector< std::vector< tt::Frame >> &output) const
 
 Demonstrator ()
 
 Demonstrator (const edm::ParameterSet &iConfig, const tt::Setup *setup)
 
 ~Demonstrator ()
 

Private Member Functions

bool compare (std::stringstream &ss) const
 
void convert (const std::vector< std::vector< tt::Frame >> &bits, std::stringstream &ss) const
 
std::string frame (int &nFrame) const
 
std::string header (int numChannel) const
 
std::string hex (const tt::Frame &bv) const
 
std::string infraGap (int &nFrame, int numChannel) const
 
void sim (const std::stringstream &ss) const
 

Private Attributes

std::string dirDiff_
 
std::string dirIn_
 
std::string dirIPBB_
 
std::string dirOut_
 
std::string dirPre_
 
int numFrames_
 
int numFramesInfra_
 
int numRegions_
 
double runTime_
 

Detailed Description

Compares emulator with f/w.

Author
Thomas Schuh
Date
2021, April

Definition at line 19 of file Demonstrator.h.

Constructor & Destructor Documentation

◆ Demonstrator() [1/2]

trackerTFP::Demonstrator::Demonstrator ( )
inline

Definition at line 21 of file Demonstrator.h.

21 {}

◆ Demonstrator() [2/2]

trackerTFP::Demonstrator::Demonstrator ( const edm::ParameterSet iConfig,
const tt::Setup setup 
)

Definition at line 14 of file Demonstrator.cc.

15  : dirIPBB_(iConfig.getParameter<string>("DirIPBB")),
16  runTime_(iConfig.getParameter<double>("RunTime")),
17  dirIn_(dirIPBB_ + "in.txt"),
18  dirOut_(dirIPBB_ + "out.txt"),
19  dirPre_(dirIPBB_ + "pre.txt"),
20  dirDiff_(dirIPBB_ + "diff.txt"),
21  numFrames_(setup->numFramesIO()),
22  numFramesInfra_(setup->numFramesInfra()),
23  numRegions_(setup->numRegions()) {}
T getParameter(std::string const &) const
Definition: ParameterSet.h:303

◆ ~Demonstrator()

trackerTFP::Demonstrator::~Demonstrator ( )
inline

Definition at line 23 of file Demonstrator.h.

23 {}

Member Function Documentation

◆ analyze()

bool trackerTFP::Demonstrator::analyze ( const std::vector< std::vector< tt::Frame >> &  input,
const std::vector< std::vector< tt::Frame >> &  output 
) const

Definition at line 26 of file Demonstrator.cc.

References compare(), convert(), input, convertSQLitetoXML_cfg::output, sim(), and contentValuesCheck::ss.

26  {
27  stringstream ss;
28  // converts input into stringstream
29  convert(input, ss);
30  // play input through modelsim
31  sim(ss);
32  // converts output into stringstream
33  convert(output, ss);
34  // compares output with modelsim output
35  return compare(ss);
36  }
void convert(const std::vector< std::vector< tt::Frame >> &bits, std::stringstream &ss) const
Definition: Demonstrator.cc:39
static std::string const input
Definition: EdmProvDump.cc:50
void sim(const std::stringstream &ss) const
Definition: Demonstrator.cc:70
bool compare(std::stringstream &ss) const
Definition: Demonstrator.cc:84

◆ compare()

bool trackerTFP::Demonstrator::compare ( std::stringstream &  ss) const
private

Definition at line 84 of file Demonstrator.cc.

References HltBtagPostValidation_cff::c, dirDiff_, dirOut_, dirPre_, compareTotals::fs, recoMuon::in, dqmiodumpmetadata::n, MillePedeFileConverter_cfg::out, contentValuesCheck::ss, and unpackBuffers-CaloStage2::token.

Referenced by analyze().

84  {
85  // write ss to disk
86  fstream fs;
87  fs.open(dirPre_.c_str(), fstream::out);
88  fs << ss.rdbuf();
89  fs.close();
90  // use linux diff on disk
91  const string c = "diff " + dirPre_ + " " + dirOut_ + " &> " + dirDiff_;
92  system(c.c_str());
93  ss.str("");
94  ss.clear();
95  // read diff output
96  fs.open(dirDiff_.c_str(), fstream::in);
97  ss << fs.rdbuf();
98  fs.close();
99  // count lines, 4 are expected
100  int n(0);
101  string token;
102  while (getline(ss, token))
103  n++;
104  return n == 4;
105  }

◆ convert()

void trackerTFP::Demonstrator::convert ( const std::vector< std::vector< tt::Frame >> &  bits,
std::stringstream &  ss 
) const
private

Definition at line 39 of file Demonstrator.cc.

References gpuClustering::pixelStatus::bits, frame(), header(), hex(), infraGap(), createfilelist::int, numFrames_, numRegions_, hltrates_dqm_sourceclient-live_cfg::offset, HLT_2023v12_cff::region, TTBV::S_, and contentValuesCheck::ss.

Referenced by analyze().

39  {
40  // reset ss
41  ss.str("");
42  ss.clear();
43  // number of tranceiver in a quad
44  static constexpr int quad = 4;
45  const int numChannel = bits.size() / numRegions_;
46  const int voidChannel = numChannel % quad == 0 ? 0 : quad - numChannel % quad;
47  // start with header
48  ss << header(numChannel + voidChannel);
49  int nFrame(0);
50  // create one packet per region
51  for (int region = 0; region < numRegions_; region++) {
52  const int offset = region * numChannel;
53  // start with emp 6 frame gap
54  ss << infraGap(nFrame, numChannel + voidChannel);
55  for (int frame = 0; frame < numFrames_; frame++) {
56  // write one frame for all channel
57  ss << this->frame(nFrame);
58  for (int channel = 0; channel < numChannel; channel++) {
59  const vector<Frame>& bvs = bits[offset + channel];
60  ss << (frame < (int)bvs.size() ? hex(bvs[frame]) : hex(Frame()));
61  }
62  for (int channel = 0; channel < voidChannel; channel++)
63  ss << " 0v" << string(TTBV::S_ / 4, '0');
64  ss << endl;
65  }
66  }
67  }
std::bitset< TTBV::S_ > Frame
Definition: TTTypes.h:58
constexpr uint32_t bits
Definition: gpuClustering.h:25
std::string header(int numChannel) const
std::string infraGap(int &nFrame, int numChannel) const
std::string hex(const tt::Frame &bv) const
static constexpr int S_
Definition: TTBV.h:22
std::string frame(int &nFrame) const

◆ frame()

string trackerTFP::Demonstrator::frame ( int &  nFrame) const
private

Definition at line 137 of file Demonstrator.cc.

References contentValuesCheck::ss.

Referenced by convert(), and infraGap().

137  {
138  stringstream ss;
139  ss << "Frame " << setfill('0') << setw(4) << nFrame++ << " :";
140  return ss.str();
141  }

◆ header()

string trackerTFP::Demonstrator::header ( int  numChannel) const
private

Definition at line 108 of file Demonstrator.cc.

References contentValuesCheck::ss.

Referenced by convert().

108  {
109  stringstream ss;
110  // file header
111  ss << "Board CMSSW" << endl << " Quad/Chan :";
112  // quad header
113  for (int link = 0; link < numLinks; link++)
114  ss << " q" << setfill('0') << setw(2) << link / 4 << "c" << link % 4 << " ";
115  ss << endl;
116  // link header
117  ss << " Link :";
118  for (int link = 0; link < numLinks; link++)
119  ss << " " << setfill('0') << setw(3) << link << " ";
120  ss << endl;
121  return ss.str();
122  }

◆ hex()

string trackerTFP::Demonstrator::hex ( const tt::Frame bv) const
private

Definition at line 144 of file Demonstrator.cc.

References TTBV::S_, and contentValuesCheck::ss.

Referenced by convert().

144  {
145  stringstream ss;
146  ss << " 1v" << setfill('0') << setw(TTBV::S_ / 4) << std::hex << bv.to_ullong();
147  return ss.str();
148  }
static constexpr int S_
Definition: TTBV.h:22

◆ infraGap()

string trackerTFP::Demonstrator::infraGap ( int &  nFrame,
int  numChannel 
) const
private

Definition at line 125 of file Demonstrator.cc.

References frame(), HLT_2023v12_cff::gap, numFramesInfra_, TTBV::S_, and contentValuesCheck::ss.

Referenced by convert().

125  {
126  stringstream ss;
127  for (int gap = 0; gap < numFramesInfra_; gap++) {
128  ss << frame(nFrame);
129  for (int link = 0; link < numLinks; link++)
130  ss << " 0v" << string(TTBV::S_ / 4, '0');
131  ss << endl;
132  }
133  return ss.str();
134  }
static constexpr int S_
Definition: TTBV.h:22
std::string frame(int &nFrame) const

◆ sim()

void trackerTFP::Demonstrator::sim ( const std::stringstream &  ss) const
private

Definition at line 70 of file Demonstrator.cc.

References mps_setup::cmd, dirIn_, dirIPBB_, compareTotals::fs, MillePedeFileConverter_cfg::out, runTime_, and contentValuesCheck::ss.

Referenced by analyze().

70  {
71  // write ss to disk
72  fstream fs;
73  fs.open(dirIn_.c_str(), fstream::out);
74  fs << ss.rdbuf();
75  fs.close();
76  // run modelsim
77  stringstream cmd;
78  cmd << "cd " << dirIPBB_ << " && ./run_sim -quiet -c work.top -do 'run " << runTime_
79  << "us' -do 'quit' &> /dev/null";
80  system(cmd.str().c_str());
81  }
list cmd
Definition: mps_setup.py:244

Member Data Documentation

◆ dirDiff_

std::string trackerTFP::Demonstrator::dirDiff_
private

Definition at line 55 of file Demonstrator.h.

Referenced by compare().

◆ dirIn_

std::string trackerTFP::Demonstrator::dirIn_
private

Definition at line 49 of file Demonstrator.h.

Referenced by sim().

◆ dirIPBB_

std::string trackerTFP::Demonstrator::dirIPBB_
private

Definition at line 45 of file Demonstrator.h.

Referenced by sim().

◆ dirOut_

std::string trackerTFP::Demonstrator::dirOut_
private

Definition at line 51 of file Demonstrator.h.

Referenced by compare().

◆ dirPre_

std::string trackerTFP::Demonstrator::dirPre_
private

Definition at line 53 of file Demonstrator.h.

Referenced by compare().

◆ numFrames_

int trackerTFP::Demonstrator::numFrames_
private

Definition at line 57 of file Demonstrator.h.

Referenced by convert().

◆ numFramesInfra_

int trackerTFP::Demonstrator::numFramesInfra_
private

Definition at line 59 of file Demonstrator.h.

Referenced by infraGap().

◆ numRegions_

int trackerTFP::Demonstrator::numRegions_
private

Definition at line 61 of file Demonstrator.h.

Referenced by convert().

◆ runTime_

double trackerTFP::Demonstrator::runTime_
private

Definition at line 47 of file Demonstrator.h.

Referenced by sim().