CMS 3D CMS Logo

MP7FileReader.cc
Go to the documentation of this file.
1 
3 
5 
6 #include <boost/algorithm/string.hpp>
7 #include <boost/regex.hpp>
8 #include <boost/lexical_cast.hpp>
9 
10 #include <iostream>
11 #include <string>
12 
13 // Namespace resolution
14 using std::cout;
15 using std::endl;
16 
17 // Constants initialization
18 boost::regex MP7FileReader::reBoard_("^Board (.+)");
19 boost::regex MP7FileReader::reLink_("^Link : (.*)");
20 boost::regex MP7FileReader::reQuadChan_("^Quad/Chan : (.*)");
21 boost::regex MP7FileReader::reFrame_("^Frame (\\d{4}) : (.*)");
22 boost::regex MP7FileReader::reValid_("([01])v([0-9a-fA-F]{8})");
23 
24 //____________________________________________________________________________//
25 const std::vector<uint64_t>& FileData::link(uint32_t i) const {
26  LinkMap::const_iterator it = links_.find(i);
27  if (it == links_.end()) {
28  edm::LogError("L1T") << "Link id " << i << " not found";
29  }
30  return it->second;
31 }
32 
33 //____________________________________________________________________________//
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 }
54 
55 //____________________________________________________________________________//
57 
58 //____________________________________________________________________________//
59 const FileData& MP7FileReader::get(size_t k) const { return buffers_.at(k); }
60 
61 std::vector<std::string> MP7FileReader::names() const {
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 }
69 //____________________________________________________________________________//
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 }
114 
115 //____________________________________________________________________________//
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 }
141 
142 //____________________________________________________________________________//
143 std::vector<uint32_t> MP7FileReader::searchLinks() {
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 }
177 
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 }
188 
189 //____________________________________________________________________________//
190 std::vector<std::vector<uint64_t> > MP7FileReader::readRows() {
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 }
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
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
gather_cfg.cout
cout
Definition: gather_cfg.py:144
MP7FileReader::buffers_
std::vector< FileData > buffers_
Definition: MP7FileReader.h:89
MP7FileReader::readRows
std::vector< std::vector< uint64_t > > readRows()
Definition: MP7FileReader.cc:190
cms::dd::split
std::vector< std::string_view > split(std::string_view, const char *)
MP7FileReader::load
void load()
Definition: MP7FileReader.cc:70
MP7FileReader::~MP7FileReader
virtual ~MP7FileReader()
Definition: MP7FileReader.cc:56
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
boost
Definition: CLHEP.h:16
MP7FileReader::reFrame_
static boost::regex reFrame_
Definition: MP7FileReader.h:95
FileData::link
const std::vector< uint64_t > & link(uint32_t i) const
Definition: MP7FileReader.cc:25
sistrip::valid_
static const uint16_t valid_
Definition: Constants.h:17
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
alignCSCRings.s
s
Definition: alignCSCRings.py:92
MP7FileReader::reQuadChan_
static boost::regex reQuadChan_
Definition: MP7FileReader.h:94
str
#define str(s)
Definition: TestProcessor.cc:48
FileData::links_
LinkMap links_
Definition: MP7FileReader.h:38
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
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MP7FileReader::valid_
bool valid_
Definition: MP7FileReader.h:84
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::LogError
Definition: MessageLogger.h:183
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.h
MP7FileReader::searchLinks
std::vector< uint32_t > searchLinks()
Definition: MP7FileReader.cc:143
MP7FileReader::searchBoard
std::string searchBoard()
Definition: MP7FileReader.cc:116
alignCSCRings.r
r
Definition: alignCSCRings.py:93
MP7FileReader::get
const FileData & get(size_t k) const
data getter via index
Definition: MP7FileReader.cc:59
MP7FileReader::MP7FileReader
MP7FileReader(const std::string &path)
Definition: MP7FileReader.cc:34
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
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
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
path_
std::string & path_
Definition: PluginManager.cc:222
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