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 45 of file MP7FileReader.h.

Member Typedef Documentation

expose vector's const iterator

Definition at line 49 of file MP7FileReader.h.

Constructor & Destructor Documentation

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

Definition at line 38 of file MP7FileReader.cc.

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

38  : valid_(false), path_(path), file_(path) {
39  if (!file_.is_open()) {
40  edm::LogError("L1T") << "File " << path << " not found";
41  valid_ = false;
42  return;
43  }
44  else {
45  LogDebug("L1T") << "Reading file " << path;
46  }
47 
48  load();
49 
50  LogDebug("L1T") << "# buffers " << buffers_.size();
51 
52  if (!buffers_.empty()) {
53  LogDebug("L1T") << "# links " << buffers_.at(0).size();
54  if (buffers_.at(0).size()>0) {
55  LogDebug("L1T") << "# frames " << buffers_.at(0).link(0).size();
56  }
57  }
58 
59 }
#define LogDebug(id)
std::ifstream file_
Definition: MP7FileReader.h:90
const std::string & path() const
source file path
Definition: MP7FileReader.h:59
std::string path_
Definition: MP7FileReader.h:89
std::vector< FileData > buffers_
Definition: MP7FileReader.h:94
MP7FileReader::~MP7FileReader ( )
virtual

Definition at line 62 of file MP7FileReader.cc.

62  {
63 }

Member Function Documentation

const_iterator MP7FileReader::begin ( void  )
inline

vector's begin iterator

Definition at line 68 of file MP7FileReader.h.

Referenced by MP7PacketReader::load().

68 { return buffers_.begin(); }
std::vector< FileData > buffers_
Definition: MP7FileReader.h:94
const_iterator MP7FileReader::end ( void  )
inline

vector's end iterator

Definition at line 71 of file MP7FileReader.h.

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

71 { return buffers_.end(); }
std::vector< FileData > buffers_
Definition: MP7FileReader.h:94
const FileData & MP7FileReader::get ( size_t  k) const
void MP7FileReader::load ( )
private

Definition at line 83 of file MP7FileReader.cc.

References buffers_, data, file_, mps_fire::i, triggerObjects_cff::id, FileData::links_, FileData::name_, readRows(), alignCSCRings::s, searchBoard(), searchLinks(), AlCaHLTBitMon_QueryRunRegistry::string, and valid_.

Referenced by MP7FileReader().

83  {
84  using namespace boost;
85 
86 
87  // Data, to be stored in a BufferSnapshot object
88  while (file_.good()) {
89  std::string id = searchBoard();
90  //cout << "Id: " << id << endl;
91  std::vector<uint32_t> links = searchLinks();
92 
93  //cout << "Links (" << links.size() << ") : ";
94 
95  //BOOST_FOREACH(uint32_t l, links) {
96  //cout << l << ",";
97  //}
98  //cout << endl;
99 
100  std::vector< std::vector<uint64_t> > data = readRows();
101  //cout << "Data loaded (" << data.size() << ")" << endl;
102 
103  // Id, Link # and Data Loaded
104 
105  FileData s;
106  s.name_ = id;
107 
108  std::vector< std::vector<uint64_t> > chans( links.size(), std::vector<uint64_t>(data.size()) );
109 
110  // Transpose
111  for ( size_t i(0); i<links.size(); ++i) {
112  for ( size_t j(0); j<data.size(); ++j) {
113  chans[i][j] = data[j][i];
114  }
115  }
116 
117  // pack
118  for ( size_t i(0); i<links.size(); ++i) {
119  s.links_.insert( std::make_pair(links[i],chans[i]) );
120  }
121 
122  buffers_.push_back(s);
123  }
124 
125  // File successfully read
126  valid_ = true;
127 
128 }
Definition: CLHEP.h:16
std::ifstream file_
Definition: MP7FileReader.h:90
LinkMap links_
Definition: MP7FileReader.h:40
std::vector< std::vector< uint64_t > > readRows()
std::string name_
Definition: MP7FileReader.h:39
std::vector< FileData > buffers_
Definition: MP7FileReader.h:94
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
std::vector< uint32_t > searchLinks()
std::string searchBoard()
std::vector< std::string > MP7FileReader::names ( void  ) const

raw data name collector

Definition at line 73 of file MP7FileReader.cc.

References buffers_, FileData::name(), and alignCSCRings::r.

73  {
74  std::vector<std::string> names(buffers_.size());
75 
76  BOOST_FOREACH( const FileData& r, buffers_ ) {
77  names.push_back(r.name());
78  }
79  return names;
80 }
std::vector< FileData > buffers_
Definition: MP7FileReader.h:94
const std::string & name() const
Definition: MP7FileReader.h:28
std::vector< std::string > names() const
raw data name collector
const std::string& MP7FileReader::path ( ) const
inline

source file path

Definition at line 59 of file MP7FileReader.h.

References gen::k, cscdqm::h::names, and path_.

Referenced by MP7FileReader().

59 { return path_; }
std::string path_
Definition: MP7FileReader.h:89
std::vector< std::vector< uint64_t > > MP7FileReader::readRows ( )
private

Definition at line 207 of file MP7FileReader.cc.

References data, file_, geometryCSVtoXML::line, gen::n, reBoard_, reFrame_, split, AlCaHLTBitMon_QueryRunRegistry::string, tmp, create_public_lumi_plots::transform, and validStrToUint64().

Referenced by load().

207  {
209  boost::smatch what;
210  std::vector< std::vector<uint64_t> > data;
211  int place = file_.tellg();
212  while (getline(file_, line)) {
213 
214  if (boost::regex_match(line, what, reBoard_)) {
215  // Upos, next board found. Go back by one line
216  file_.seekg(place);
217  return data;
218  }
219 
220  if (boost::regex_match(line, what, reFrame_)) {
221  // check frame number
222  uint32_t n = boost::lexical_cast<uint32_t>(what[1].str());
223 
224  if (n != data.size()) {
225  std::stringstream ss;
226  ss << "Frame misalignment! (expected " << data.size() << " found " << n;
227  throw std::logic_error(ss.str());
228  }
229  std::vector<std::string> tokens;
230  std::string tmp = what[2].str();
231  boost::trim(tmp);
232  boost::split(tokens, tmp, boost::is_any_of(" \t"), boost::token_compress_on);
233 
234  std::vector<uint64_t> row;
235  std::transform(tokens.begin(), tokens.end(), std::back_inserter(row), validStrToUint64);
236 
237  data.push_back(row);
238  }
239 
240  place = file_.tellg();
241  }
242 
243  return data;
244 
245 }
static boost::regex reBoard_
Definition: MP7FileReader.h:97
static boost::regex reFrame_
std::ifstream file_
Definition: MP7FileReader.h:90
static uint64_t validStrToUint64(const std::string &token)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double split
Definition: MVATrainer.cc:139
std::string MP7FileReader::searchBoard ( )
private

Definition at line 132 of file MP7FileReader.cc.

References file_, triggerObjects_cff::id, geometryCSVtoXML::line, reBoard_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by load().

132  {
134  std::string id;
135  boost::smatch what;
136 
137  while (getline(file_, line)) {
138 
139  // Trim and skip empties and comments
140  boost::trim(line);
141  if (line.empty()) continue;
142  if (line[0] == '#') continue;
143 
144  if (boost::regex_match(line, what, reBoard_)) {
145  // Create a new buffer snapshot
146  id = what[1];
147  return id;
148  } else {
149  edm::LogError("L1T") << "Unexpected line found";
150  return std::string("");
151  }
152  }
153  edm::LogError("L1T") << "No board found";
154  return std::string("");
155 }
static boost::regex reBoard_
Definition: MP7FileReader.h:97
std::ifstream file_
Definition: MP7FileReader.h:90
std::vector< uint32_t > MP7FileReader::searchLinks ( )
private

Definition at line 159 of file MP7FileReader.cc.

References file_, geometryCSVtoXML::line, reLink_, reQuadChan_, split, AlCaHLTBitMon_QueryRunRegistry::string, tmp, and create_public_lumi_plots::transform.

Referenced by load().

159  {
161  boost::smatch what;
162 
163  while (getline(file_, line)) {
164 
165  boost::trim(line);
166  if (line.empty()) continue;
167  if (line[0] == '#') continue;
168 
169  if (boost::regex_match(line, what, reQuadChan_)) {
170  // Not used
171  continue;
172  }
173 
174  if (boost::regex_match(line, what, reLink_)) {
175 
176  std::vector<std::string> tokens;
177  std::string tmp = what[1].str();
178  // Trim the line
179  boost::trim(tmp);
180  // Split line into tokens
181  boost::split(tokens, tmp, boost::is_any_of(" \t"), boost::token_compress_on);
182  // Convert it into uint32 s
183  std::vector<uint32_t> links;
184  std::transform(tokens.begin(), tokens.end(), std::back_inserter(links), boost::lexical_cast<uint32_t, const std::string&>);
185  return links;
186  } else {
187  throw std::logic_error("Unexpected line found!");
188  }
189  }
190  throw std::logic_error("No list of links found");
191 }
std::ifstream file_
Definition: MP7FileReader.h:90
static boost::regex reLink_
Definition: MP7FileReader.h:98
static boost::regex reQuadChan_
Definition: MP7FileReader.h:99
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
double split
Definition: MVATrainer.cc:139
size_t MP7FileReader::size ( void  ) const
inline

number of rawdata objects stored

Definition at line 74 of file MP7FileReader.h.

References svgfig::load(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

74 { return buffers_.size(); }
std::vector< FileData > buffers_
Definition: MP7FileReader.h:94
bool MP7FileReader::valid ( ) const
inline

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

Definition at line 56 of file MP7FileReader.h.

References sistrip::valid_.

Referenced by MP7PacketReader::MP7PacketReader().

56 { return valid_; }
uint64_t MP7FileReader::validStrToUint64 ( const std::string &  token)
staticprivate

Definition at line 193 of file MP7FileReader.cc.

References reValid_, str, and relativeConstraints::value.

Referenced by readRows().

193  {
194 
195  boost::smatch what;
196  if (!boost::regex_match(token, what, reValid_)) {
197  throw std::logic_error("Token '" + token + "' doesn't match the valid format");
198  }
199 
200  uint64_t value = (uint64_t) (what[1] == "1") << 32;
201  value += std::stoul(what[2].str(), nullptr, 16);
202  return value;
203 }
Definition: value.py:1
unsigned long long uint64_t
Definition: Time.h:15
static boost::regex reValid_
#define str(s)

Member Data Documentation

std::vector<FileData> MP7FileReader::buffers_

Definition at line 94 of file MP7FileReader.h.

Referenced by get(), load(), MP7FileReader(), and names().

std::ifstream MP7FileReader::file_
private

Definition at line 90 of file MP7FileReader.h.

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

std::string MP7FileReader::path_
private
boost::regex MP7FileReader::reBoard_
staticprivate

Definition at line 97 of file MP7FileReader.h.

Referenced by readRows(), and searchBoard().

boost::regex MP7FileReader::reFrame_
staticprivate

Definition at line 100 of file MP7FileReader.h.

Referenced by readRows().

boost::regex MP7FileReader::reLink_
staticprivate

Definition at line 98 of file MP7FileReader.h.

Referenced by searchLinks().

boost::regex MP7FileReader::reQuadChan_
staticprivate

Definition at line 99 of file MP7FileReader.h.

Referenced by searchLinks().

boost::regex MP7FileReader::reValid_
staticprivate

Definition at line 101 of file MP7FileReader.h.

Referenced by validStrToUint64().

bool MP7FileReader::valid_
private

Definition at line 88 of file MP7FileReader.h.

Referenced by load(), and MP7FileReader().