CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
MP7FileReader Class Reference

#include <MP7FileReader.h>

Public Types

typedef std::vector< FileData >::const_iterator const_iterator
 expose vector's const iterator More...
 

Public Member Functions

const_iterator begin ()
 vector's begin iterator More...
 
const_iterator end ()
 vector's end iterator More...
 
const FileDataget (size_t k) const
 data getter via index More...
 
 MP7FileReader (const std::string &path)
 
std::vector< std::string > names () const
 raw data name collector More...
 
const std::string & path () const
 source file path More...
 
size_t size () const
 number of rawdata objects stored More...
 
bool valid () const
 reader status. valid() == 1 indicates that data was successfully read from file More...
 
virtual ~MP7FileReader ()
 

Public Attributes

std::vector< FileDatabuffers_
 

Private Member Functions

void load ()
 
std::vector< std::vector< uint64_t > > readRows ()
 
std::string searchBoard ()
 
std::vector< uint32_t > searchLinks ()
 

Static Private Member Functions

static uint64_t validStrToUint64 (const std::string &token)
 

Private Attributes

std::ifstream file_
 
std::string path_
 
bool valid_
 

Static Private Attributes

static boost::regex reBoard_
 
static boost::regex reFrame_
 
static boost::regex reLink_
 
static boost::regex reQuadChan_
 
static boost::regex reValid_
 

Detailed Description

Definition at line 43 of file MP7FileReader.h.

Member Typedef Documentation

◆ const_iterator

expose vector's const iterator

Definition at line 46 of file MP7FileReader.h.

Constructor & Destructor Documentation

◆ MP7FileReader()

MP7FileReader::MP7FileReader ( const std::string &  path)

Definition at line 33 of file MP7FileReader.cc.

References buffers_, file_, load(), LogDebug, path(), and valid_.

33  : valid_(false), path_(path), file_(path) {
34  if (!file_.is_open()) {
35  edm::LogError("L1T") << "File " << path << " not found";
36  valid_ = false;
37  return;
38  } else {
39  LogDebug("L1T") << "Reading file " << path;
40  }
41 
42  load();
43 
44  LogDebug("L1T") << "# buffers " << buffers_.size();
45 
46  if (!buffers_.empty()) {
47  LogDebug("L1T") << "# links " << buffers_.at(0).size();
48  if (buffers_.at(0).size() > 0) {
49  LogDebug("L1T") << "# frames " << buffers_.at(0).link(0).size();
50  }
51  }
52 }
const std::string & path() const
source file path
Definition: MP7FileReader.h:56
std::ifstream file_
Definition: MP7FileReader.h:86
Log< level::Error, false > LogError
std::string path_
Definition: MP7FileReader.h:85
std::vector< FileData > buffers_
Definition: MP7FileReader.h:89
#define LogDebug(id)

◆ ~MP7FileReader()

MP7FileReader::~MP7FileReader ( )
virtual

Definition at line 55 of file MP7FileReader.cc.

55 {}

Member Function Documentation

◆ begin()

const_iterator MP7FileReader::begin ( void  )
inline

vector's begin iterator

Definition at line 65 of file MP7FileReader.h.

References buffers_.

Referenced by MP7PacketReader::load().

65 { return buffers_.begin(); }
std::vector< FileData > buffers_
Definition: MP7FileReader.h:89

◆ end()

const_iterator MP7FileReader::end ( void  )
inline

vector's end iterator

Definition at line 68 of file MP7FileReader.h.

References buffers_.

Referenced by Types.LuminosityBlockRange::cppID(), Types.EventRange::cppID(), and MP7PacketReader::load().

68 { return buffers_.end(); }
std::vector< FileData > buffers_
Definition: MP7FileReader.h:89

◆ get()

const FileData & MP7FileReader::get ( size_t  k) const

◆ load()

void MP7FileReader::load ( )
private

Definition at line 69 of file MP7FileReader.cc.

References buffers_, data, file_, mps_fire::i, l1ctLayer2EG_cff::id, dqmiolumiharvest::j, electronStore::links, readRows(), alignCSCRings::s, searchBoard(), searchLinks(), AlCaHLTBitMon_QueryRunRegistry::string, and valid_.

Referenced by MP7FileReader().

69  {
70  using namespace boost;
71 
72  // Data, to be stored in a BufferSnapshot object
73  while (file_.good()) {
74  std::string id = searchBoard();
75  //cout << "Id: " << id << endl;
76  std::vector<uint32_t> links = searchLinks();
77 
78  //cout << "Links (" << links.size() << ") : ";
79 
80  //for(uint32_t l : links) {
81  //cout << l << ",";
82  //}
83  //cout << endl;
84 
85  std::vector<std::vector<uint64_t> > data = readRows();
86  //cout << "Data loaded (" << data.size() << ")" << endl;
87 
88  // Id, Link # and Data Loaded
89 
90  FileData s;
91  s.name_ = id;
92 
93  std::vector<std::vector<uint64_t> > chans(links.size(), std::vector<uint64_t>(data.size()));
94 
95  // Transpose
96  for (size_t i(0); i < links.size(); ++i) {
97  for (size_t j(0); j < data.size(); ++j) {
98  chans[i][j] = data[j][i];
99  }
100  }
101 
102  // pack
103  for (size_t i(0); i < links.size(); ++i) {
104  s.links_.insert(std::make_pair(links[i], chans[i]));
105  }
106 
107  buffers_.push_back(s);
108  }
109 
110  // File successfully read
111  valid_ = true;
112 }
Definition: CLHEP.h:16
std::ifstream file_
Definition: MP7FileReader.h:86
std::vector< std::vector< uint64_t > > readRows()
std::vector< FileData > buffers_
Definition: MP7FileReader.h:89
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
std::vector< uint32_t > searchLinks()
std::string searchBoard()

◆ names()

std::vector< std::string > MP7FileReader::names ( void  ) const

raw data name collector

Definition at line 60 of file MP7FileReader.cc.

References buffers_, and alignCSCRings::r.

60  {
61  std::vector<std::string> names(buffers_.size());
62 
63  for (auto const& r : buffers_) {
64  names.push_back(r.name());
65  }
66  return names;
67 }
std::vector< FileData > buffers_
Definition: MP7FileReader.h:89
std::vector< std::string > names() const
raw data name collector

◆ path()

const std::string& MP7FileReader::path ( ) const
inline

source file path

Definition at line 56 of file MP7FileReader.h.

References path_.

Referenced by MP7FileReader().

56 { return path_; }
std::string path_
Definition: MP7FileReader.h:85

◆ readRows()

std::vector< std::vector< uint64_t > > MP7FileReader::readRows ( )
private

Definition at line 189 of file MP7FileReader.cc.

References data, file_, mps_splice::line, dqmiodumpmetadata::n, reBoard_, reFrame_, submitPVValidationJobs::split(), contentValuesCheck::ss, str, AlCaHLTBitMon_QueryRunRegistry::string, createJobs::tmp, HcalDetIdTransform::transform(), trim(), and validStrToUint64().

Referenced by load().

189  {
191  boost::smatch what;
192  std::vector<std::vector<uint64_t> > data;
193  int place = file_.tellg();
194  while (getline(file_, line)) {
195  if (boost::regex_match(line, what, reBoard_)) {
196  // Upos, next board found. Go back by one line
197  file_.seekg(place);
198  return data;
199  }
200 
201  if (boost::regex_match(line, what, reFrame_)) {
202  // check frame number
203  uint32_t n = std::stoul(what[1].str());
204 
205  if (n != data.size()) {
206  std::stringstream ss;
207  ss << "Frame misalignment! (expected " << data.size() << " found " << n;
208  throw std::logic_error(ss.str());
209  }
210  std::vector<std::string> tokens;
211  std::string tmp = what[2].str();
212  boost::trim(tmp);
213  boost::split(tokens, tmp, boost::is_any_of(" \t"), boost::token_compress_on);
214 
215  std::vector<uint64_t> row;
216  std::transform(tokens.begin(), tokens.end(), std::back_inserter(row), validStrToUint64);
217 
218  data.push_back(row);
219  }
220 
221  place = file_.tellg();
222  }
223 
224  return data;
225 }
static boost::regex reBoard_
Definition: MP7FileReader.h:92
static boost::regex reFrame_
Definition: MP7FileReader.h:95
std::ifstream file_
Definition: MP7FileReader.h:86
static void trim(std::string &s)
static uint64_t validStrToUint64(const std::string &token)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
#define str(s)
tmp
align.sh
Definition: createJobs.py:716
unsigned transform(const HcalDetId &id, unsigned transformCode)

◆ searchBoard()

std::string MP7FileReader::searchBoard ( )
private

Definition at line 115 of file MP7FileReader.cc.

References file_, l1ctLayer2EG_cff::id, mps_splice::line, reBoard_, AlCaHLTBitMon_QueryRunRegistry::string, and trim().

Referenced by load().

115  {
117  std::string id;
118  boost::smatch what;
119 
120  while (getline(file_, line)) {
121  // Trim and skip empties and comments
122  boost::trim(line);
123  if (line.empty())
124  continue;
125  if (line[0] == '#')
126  continue;
127 
128  if (boost::regex_match(line, what, reBoard_)) {
129  // Create a new buffer snapshot
130  id = what[1];
131  return id;
132  } else {
133  edm::LogError("L1T") << "Unexpected line found";
134  return std::string("");
135  }
136  }
137  edm::LogError("L1T") << "No board found";
138  return std::string("");
139 }
static boost::regex reBoard_
Definition: MP7FileReader.h:92
std::ifstream file_
Definition: MP7FileReader.h:86
static void trim(std::string &s)
Log< level::Error, false > LogError

◆ searchLinks()

std::vector< uint32_t > MP7FileReader::searchLinks ( )
private

Definition at line 142 of file MP7FileReader.cc.

References file_, mps_splice::line, electronStore::links, reLink_, reQuadChan_, submitPVValidationJobs::split(), str, AlCaHLTBitMon_QueryRunRegistry::string, createJobs::tmp, HcalDetIdTransform::transform(), and trim().

Referenced by load().

142  {
144  boost::smatch what;
145 
146  while (getline(file_, line)) {
147  boost::trim(line);
148  if (line.empty())
149  continue;
150  if (line[0] == '#')
151  continue;
152 
153  if (boost::regex_match(line, what, reQuadChan_)) {
154  // Not used
155  continue;
156  }
157 
158  if (boost::regex_match(line, what, reLink_)) {
159  std::vector<std::string> tokens;
160  std::string tmp = what[1].str();
161  // Trim the line
162  boost::trim(tmp);
163  // Split line into tokens
164  boost::split(tokens, tmp, boost::is_any_of(" \t"), boost::token_compress_on);
165  // Convert it into uint32 s
166  std::vector<uint32_t> links;
167  std::transform(tokens.begin(), tokens.end(), std::back_inserter(links), [](const std::string& str) {
168  return std::stoul(str);
169  });
170  } else {
171  throw std::logic_error("Unexpected line found!");
172  }
173  }
174  throw std::logic_error("No list of links found");
175 }
std::ifstream file_
Definition: MP7FileReader.h:86
static void trim(std::string &s)
static boost::regex reLink_
Definition: MP7FileReader.h:93
static boost::regex reQuadChan_
Definition: MP7FileReader.h:94
#define str(s)
tmp
align.sh
Definition: createJobs.py:716
unsigned transform(const HcalDetId &id, unsigned transformCode)

◆ size()

size_t MP7FileReader::size ( void  ) const
inline

number of rawdata objects stored

Definition at line 71 of file MP7FileReader.h.

References buffers_.

Referenced by ntupleDataFormat._Collection::__iter__(), ntupleDataFormat._Collection::__len__(), MP7PacketReader::load(), and l1t::MP7BufferDumpToRaw::MP7BufferDumpToRaw().

71 { return buffers_.size(); }
std::vector< FileData > buffers_
Definition: MP7FileReader.h:89

◆ valid()

bool MP7FileReader::valid ( ) const
inline

reader status. valid() == 1 indicates that data was successfully read from file

Definition at line 53 of file MP7FileReader.h.

References valid_.

Referenced by MP7PacketReader::MP7PacketReader(), and MP7PacketReader::valid().

53 { return valid_; }

◆ validStrToUint64()

uint64_t MP7FileReader::validStrToUint64 ( const std::string &  token)
staticprivate

Definition at line 177 of file MP7FileReader.cc.

References reValid_, str, unpackBuffers-CaloStage2::token, and relativeConstraints::value.

Referenced by readRows().

177  {
178  boost::smatch what;
179  if (!boost::regex_match(token, what, reValid_)) {
180  throw std::logic_error("Token '" + token + "' doesn't match the valid format");
181  }
182 
183  uint64_t value = (uint64_t)(what[1] == "1") << 32;
184  value += std::stoul(what[2].str(), nullptr, 16);
185  return value;
186 }
Definition: value.py:1
unsigned long long uint64_t
Definition: Time.h:13
static boost::regex reValid_
Definition: MP7FileReader.h:96
#define str(s)

Member Data Documentation

◆ buffers_

std::vector<FileData> MP7FileReader::buffers_

Definition at line 89 of file MP7FileReader.h.

Referenced by begin(), end(), get(), load(), MP7FileReader(), names(), and size().

◆ file_

std::ifstream MP7FileReader::file_
private

Definition at line 86 of file MP7FileReader.h.

Referenced by load(), MP7FileReader(), readRows(), searchBoard(), and searchLinks().

◆ path_

std::string MP7FileReader::path_
private

Definition at line 85 of file MP7FileReader.h.

Referenced by path().

◆ reBoard_

boost::regex MP7FileReader::reBoard_
staticprivate

Definition at line 92 of file MP7FileReader.h.

Referenced by readRows(), and searchBoard().

◆ reFrame_

boost::regex MP7FileReader::reFrame_
staticprivate

Definition at line 95 of file MP7FileReader.h.

Referenced by readRows().

◆ reLink_

boost::regex MP7FileReader::reLink_
staticprivate

Definition at line 93 of file MP7FileReader.h.

Referenced by searchLinks().

◆ reQuadChan_

boost::regex MP7FileReader::reQuadChan_
staticprivate

Definition at line 94 of file MP7FileReader.h.

Referenced by searchLinks().

◆ reValid_

boost::regex MP7FileReader::reValid_
staticprivate

Definition at line 96 of file MP7FileReader.h.

Referenced by validStrToUint64().

◆ valid_

bool MP7FileReader::valid_
private

Definition at line 84 of file MP7FileReader.h.

Referenced by load(), MP7FileReader(), and valid().