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 34 of file MP7FileReader.cc.

34  : valid_(false), path_(path), file_(path) {
35  if (!file_.is_open()) {
36  edm::LogError("L1T") << "File " << path << " not found";
37  valid_ = false;
38  return;
39  } else {
40  LogDebug("L1T") << "Reading file " << path;
41  }
42 
43  load();
44 
45  LogDebug("L1T") << "# buffers " << buffers_.size();
46 
47  if (!buffers_.empty()) {
48  LogDebug("L1T") << "# links " << buffers_.at(0).size();
49  if (buffers_.at(0).size() > 0) {
50  LogDebug("L1T") << "# frames " << buffers_.at(0).link(0).size();
51  }
52  }
53 }

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

◆ ~MP7FileReader()

MP7FileReader::~MP7FileReader ( )
virtual

Definition at line 56 of file MP7FileReader.cc.

56 {}

Member Function Documentation

◆ begin()

const_iterator MP7FileReader::begin ( void  )
inline

vector's begin iterator

Definition at line 65 of file MP7FileReader.h.

65 { return buffers_.begin(); }

References buffers_.

Referenced by MP7PacketReader::load().

◆ end()

const_iterator MP7FileReader::end ( void  )
inline

vector's end iterator

Definition at line 68 of file MP7FileReader.h.

68 { return buffers_.end(); }

References buffers_.

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

◆ get()

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

◆ load()

void MP7FileReader::load ( )
private

Definition at line 70 of file MP7FileReader.cc.

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

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

Referenced by MP7FileReader().

◆ names()

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

raw data name collector

Definition at line 61 of file MP7FileReader.cc.

61  {
62  std::vector<std::string> names(buffers_.size());
63 
64  for (auto const& r : buffers_) {
65  names.push_back(r.name());
66  }
67  return names;
68 }

References buffers_, names(), and alignCSCRings::r.

Referenced by names().

◆ path()

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

source file path

Definition at line 56 of file MP7FileReader.h.

56 { return path_; }

References path_.

Referenced by MP7FileReader().

◆ readRows()

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

Definition at line 190 of file MP7FileReader.cc.

190  {
192  boost::smatch what;
193  std::vector<std::vector<uint64_t> > data;
194  int place = file_.tellg();
195  while (getline(file_, line)) {
196  if (boost::regex_match(line, what, reBoard_)) {
197  // Upos, next board found. Go back by one line
198  file_.seekg(place);
199  return data;
200  }
201 
202  if (boost::regex_match(line, what, reFrame_)) {
203  // check frame number
204  uint32_t n = boost::lexical_cast<uint32_t>(what[1].str());
205 
206  if (n != data.size()) {
207  std::stringstream ss;
208  ss << "Frame misalignment! (expected " << data.size() << " found " << n;
209  throw std::logic_error(ss.str());
210  }
211  std::vector<std::string> tokens;
212  std::string tmp = what[2].str();
213  boost::trim(tmp);
214  boost::split(tokens, tmp, boost::is_any_of(" \t"), boost::token_compress_on);
215 
216  std::vector<uint64_t> row;
217  std::transform(tokens.begin(), tokens.end(), std::back_inserter(row), validStrToUint64);
218 
219  data.push_back(row);
220  }
221 
222  place = file_.tellg();
223  }
224 
225  return data;
226 }

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().

◆ searchBoard()

std::string MP7FileReader::searchBoard ( )
private

Definition at line 116 of file MP7FileReader.cc.

116  {
118  std::string id;
119  boost::smatch what;
120 
121  while (getline(file_, line)) {
122  // Trim and skip empties and comments
123  boost::trim(line);
124  if (line.empty())
125  continue;
126  if (line[0] == '#')
127  continue;
128 
129  if (boost::regex_match(line, what, reBoard_)) {
130  // Create a new buffer snapshot
131  id = what[1];
132  return id;
133  } else {
134  edm::LogError("L1T") << "Unexpected line found";
135  return std::string("");
136  }
137  }
138  edm::LogError("L1T") << "No board found";
139  return std::string("");
140 }

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

Referenced by load().

◆ searchLinks()

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

Definition at line 143 of file MP7FileReader.cc.

143  {
145  boost::smatch what;
146 
147  while (getline(file_, line)) {
148  boost::trim(line);
149  if (line.empty())
150  continue;
151  if (line[0] == '#')
152  continue;
153 
154  if (boost::regex_match(line, what, reQuadChan_)) {
155  // Not used
156  continue;
157  }
158 
159  if (boost::regex_match(line, what, reLink_)) {
160  std::vector<std::string> tokens;
161  std::string tmp = what[1].str();
162  // Trim the line
163  boost::trim(tmp);
164  // Split line into tokens
165  boost::split(tokens, tmp, boost::is_any_of(" \t"), boost::token_compress_on);
166  // Convert it into uint32 s
167  std::vector<uint32_t> links;
169  tokens.begin(), tokens.end(), std::back_inserter(links), boost::lexical_cast<uint32_t, const std::string&>);
170  return links;
171  } else {
172  throw std::logic_error("Unexpected line found!");
173  }
174  }
175  throw std::logic_error("No list of links found");
176 }

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

Referenced by load().

◆ size()

size_t MP7FileReader::size ( void  ) const
inline

number of rawdata objects stored

Definition at line 71 of file MP7FileReader.h.

71 { return buffers_.size(); }

References buffers_.

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

◆ 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.

53 { return valid_; }

References valid_.

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

◆ validStrToUint64()

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

Definition at line 178 of file MP7FileReader.cc.

178  {
179  boost::smatch what;
180  if (!boost::regex_match(token, what, reValid_)) {
181  throw std::logic_error("Token '" + token + "' doesn't match the valid format");
182  }
183 
184  uint64_t value = (uint64_t)(what[1] == "1") << 32;
185  value += std::stoul(what[2].str(), nullptr, 16);
186  return value;
187 }

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

Referenced by readRows().

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().

mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
FileData
Definition: MP7FileReader.h:21
MP7FileReader::validStrToUint64
static uint64_t validStrToUint64(const std::string &token)
Definition: MP7FileReader.cc:178
MP7FileReader::buffers_
std::vector< FileData > buffers_
Definition: MP7FileReader.h:89
MP7FileReader::readRows
std::vector< std::vector< uint64_t > > readRows()
Definition: MP7FileReader.cc:190
MP7FileReader::load
void load()
Definition: MP7FileReader.cc:70
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
boost
Definition: CLHEP.h:16
MP7FileReader::reFrame_
static boost::regex reFrame_
Definition: MP7FileReader.h:95
MP7FileReader::path_
std::string path_
Definition: MP7FileReader.h:85
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
alignCSCRings.s
s
Definition: alignCSCRings.py:92
MP7FileReader::reQuadChan_
static boost::regex reQuadChan_
Definition: MP7FileReader.h:94
submitPVValidationJobs.split
def split(sequence, size)
Definition: submitPVValidationJobs.py:352
str
#define str(s)
Definition: TestProcessor.cc:53
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
MP7FileReader::reLink_
static boost::regex reLink_
Definition: MP7FileReader.h:93
dqmdumpme.k
k
Definition: dqmdumpme.py:60
MP7FileReader::reValid_
static boost::regex reValid_
Definition: MP7FileReader.h:96
MP7FileReader::valid_
bool valid_
Definition: MP7FileReader.h:84
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
MP7FileReader::path
const std::string & path() const
source file path
Definition: MP7FileReader.h:56
MP7FileReader::names
std::vector< std::string > names() const
raw data name collector
Definition: MP7FileReader.cc:61
value
Definition: value.py:1
MP7FileReader::searchLinks
std::vector< uint32_t > searchLinks()
Definition: MP7FileReader.cc:143
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MP7FileReader::searchBoard
std::string searchBoard()
Definition: MP7FileReader.cc:116
alignCSCRings.r
r
Definition: alignCSCRings.py:93
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
relativeConstraints.value
value
Definition: relativeConstraints.py:53
electronStore.links
links
Definition: electronStore.py:149
MP7FileReader::file_
std::ifstream file_
Definition: MP7FileReader.h:86
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
MP7FileReader::reBoard_
static boost::regex reBoard_
Definition: MP7FileReader.h:92
mps_splice.line
line
Definition: mps_splice.py:76
trim
static void trim(std::string &s)
Definition: DTCCablingMapProducer.cc:67
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316