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, bool first=false) 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:307

◆ ~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, 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:72
bool compare(std::stringstream &ss) const
Definition: Demonstrator.cc:86
Definition: output.py:1

◆ compare()

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

Definition at line 86 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().

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

◆ 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 ALPAKA_ACCELERATOR_NAMESPACE::pixelClustering::pixelStatus::bits, ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), dqmdumpme::first, frame(), header(), hex(), infraGap(), createfilelist::int, numFrames_, numRegions_, hltrates_dqm_sourceclient-live_cfg::offset, nano_mu_digi_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  bool first = true;
52  for (int region = 0; region < numRegions_; region++) {
53  const int offset = region * numChannel;
54  // start with emp 6 frame gap
55  ss << infraGap(nFrame, numChannel + voidChannel);
56  for (int frame = 0; frame < numFrames_; frame++) {
57  // write one frame for all channel
58  ss << this->frame(nFrame);
59  for (int channel = 0; channel < numChannel; channel++) {
60  const vector<Frame>& bvs = bits[offset + channel];
61  ss << (frame < (int)bvs.size() ? hex(bvs[frame], first) : hex(Frame(), first));
62  }
63  for (int channel = 0; channel < voidChannel; channel++)
64  ss << " 0000 " << string(TTBV::S_ / 4, '0');
65  ss << endl;
66  first = false;
67  }
68  }
69  }
std::bitset< TTBV::S_ > Frame
Definition: TTTypes.h:58
std::string header(int numChannel) const
std::string infraGap(int &nFrame, int numChannel) const
static constexpr int S_
Definition: TTBV.h:22
std::string frame(int &nFrame) const
std::string hex(const tt::Frame &bv, bool first=false) 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 110 of file Demonstrator.cc.

References contentValuesCheck::ss.

Referenced by convert().

110  {
111  stringstream ss;
112  // file header
113  ss << "Board CMSSW" << endl
114  << "Metadata: (strobe,) start of orbit, start of packet, end of packet, valid" << endl
115  << 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,
bool  first = false 
) const
private

Definition at line 144 of file Demonstrator.cc.

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

Referenced by convert().

144  {
145  stringstream ss;
146  ss << (first ? " 1001 " : " 0001 ") << 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_2024v13_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 << " 0000 " << 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 72 of file Demonstrator.cc.

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

Referenced by analyze().

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