CMS 3D CMS Logo

PixelAliasList.h
Go to the documentation of this file.
1 #ifndef PixelAliasList_h
2 #define PixelAliasList_h
3 
12 
13 #include <cassert>
14 #include <iostream>
15 #include <stdlib.h>
16 #include <map>
17 
18 namespace pos {
23  // Added by Dario, May 20th, 2008 =====================================================================
24  typedef std::pair<unsigned int, std::string> versionAliasPair;
25  typedef std::vector<versionAliasPair> vectorVAPairs;
26  typedef std::map<std::string, vectorVAPairs> pathVersionAliasMmap;
27  typedef std::map<std::string, std::string> pathAliasPair;
28  typedef std::map<std::string, pathAliasPair> pathAliasMmap;
29  // End of Dario's addition ============================================================================
31  public:
32  void writefile() {
33  std::string directory = std::getenv("PIXELCONFIGURATIONBASE");
34 
35  std::string filename = directory + "/aliases.txt";
36 
37  std::ofstream out(filename.c_str());
38 
39  out << "ConfigurationAliases" << std::endl;
40  for (unsigned int i = 0; i < pixelConfigAliases_.size(); i++) {
42  out << theAlias.name() << " " << theAlias.key() << " ";
43 
44  unsigned int n = theAlias.nVersionAliases();
45  for (unsigned int j = 0; j < n; j++) {
46  out << theAlias.versionAliasesPath(j) << " ";
47  out << theAlias.versionAliasesAlias(j) << " ";
48  }
49 
50  out << ";" << std::endl;
51  }
52 
53  out << "VersionAliases" << std::endl;
54  for (unsigned int i = 0; i < pixelVersionAliases_.size(); i++) {
56 
57  out << theAlias.path() << " " << theAlias.version() << " " << theAlias.alias() << " ;" << std::endl;
58  }
59  }
60 
62  std::ifstream in(filename.c_str());
63  if (!in.good()) {
64  std::cout << "[PixelAliasList::readfile()]\t\tCould not open file:" << filename << std::endl;
65  }
66  assert(in.good());
67 
68  // Added by Dario, May 28th, 2008 =====================================================================
69  pixelConfigAliases_.clear();
70  pixelVersionAliases_.clear();
71  aliasMmap.clear();
72  versionMmap.clear();
73  // End of Dario's addition ============================================================================
74 
76 
77  in >> tag;
78  while (tag.substr(0, 1) == "#") {
79  in.ignore(4096, '\n'); //skips to endl;
80  in >> tag;
81  }
82 
83  assert(tag == "ConfigurationAliases");
84 
85  in >> tag;
86 
87  while (tag != "VersionAliases") {
89 
90  unsigned int key;
91  in >> key;
92 
93  //std::cout << "[PixelAliasList::readfile()] Alias, key:"<<alias<<" "<<key<<std::endl;
94 
95  PixelConfigAlias anAlias(alias, key);
96 
97  in >> tag;
98  std::string theAlias = alias;
99 
100  // Added by Dario, May 20th, 2008 =====================================================================
101  pathAliasPair tmpPAPair;
102  if (tag == ";") {
103  tmpPAPair[""] = " ";
104  aliasMmap[theAlias] = tmpPAPair;
105  }
106  // End of Dario's addition ============================================================================
107  while (tag != ";") {
110 
111  path = tag;
112  in >> alias;
113  //std::cout << "[PixelAliasList::readfile()] path, alias:"<<path<<" "<<alias<<std::endl;
114 
115  anAlias.addVersionAlias(path, alias);
116  // Added by Dario, May 20th, 2008 =====================================================================
117  tmpPAPair[path] = alias;
118  aliasMmap[theAlias] = tmpPAPair;
119  // End of Dario's addition ============================================================================
120  in >> tag;
121  }
122 
123  pixelConfigAliases_.push_back(anAlias);
124 
125  in >> tag;
126  }
127 
128  assert(tag == "VersionAliases");
129 
132  unsigned int version;
133 
134  in >> path;
135  in >> version;
136  in >> alias;
137  in >> tag;
138 
139  //std::cout << "path version alias tag:"<<path<<" "<<version
140  // <<" "<<alias<<" "<<tag<<std::endl;
141 
142  // Added by Dario, May 23rd, 2008 =====================================================================
143  versionAliasPair tmpVAPair;
144  // End of Dario's addition ============================================================================
145  while (!in.eof()) {
146  assert(tag == ";");
147  PixelVersionAlias aVersionAlias(path, version, alias);
148  pixelVersionAliases_.push_back(aVersionAlias);
149 
150  // Added by Dario, May 23rd, 2008 =====================================================================
151  tmpVAPair.first = version;
152  tmpVAPair.second = alias;
153  versionMmap[path].push_back(tmpVAPair);
154  // End of Dario's addition ============================================================================
155 
156  in >> path;
157  in >> version;
158  in >> alias;
159  in >> tag;
160  }
161 
162  in.close();
163  }
164 
165  void insertAlias(PixelConfigAlias& anAlias) {
166  for (unsigned int i = 0; i < pixelConfigAliases_.size(); i++) {
167  if (pixelConfigAliases_[i].name() == anAlias.name()) {
168  std::cout << "[PixelAliasList::insertAlias()]\t\t\tReplacing existing alias:" << anAlias.name() << std::endl;
169  pixelConfigAliases_[i] = anAlias;
170  return;
171  }
172  }
173  pixelConfigAliases_.push_back(anAlias);
174  }
175 
177  for (unsigned int i = 0; i < pixelConfigAliases_.size(); i++) {
178  if (pixelConfigAliases_[i].name() == aliasName) {
179  return &(pixelConfigAliases_[i]);
180  }
181  }
182  return 0;
183  }
184 
186  for (unsigned int i = 0; i < pixelVersionAliases_.size(); i++) {
187  if (pixelVersionAliases_[i].alias() == anAlias.alias() && pixelVersionAliases_[i].path() == anAlias.path()) {
188  std::cout << "[PixelAliasList::insertVersionAlias()]\t\tReplacing existing version alias:" << anAlias.path()
189  << " " << anAlias.alias() << std::endl;
190  pixelVersionAliases_[i] = anAlias;
191  return;
192  }
193  }
194  pixelVersionAliases_.push_back(anAlias);
195  }
196 
198  //first loop over configuration aliases
199  for (unsigned int i = 0; i < pixelConfigAliases_.size(); i++) {
200  //std::cout << "Looping over aliases:"<<i<<std::endl;
201  for (unsigned int j = 0; j < pixelConfigAliases_[i].nVersionAliases(); j++) {
202  //std::cout << "Looping over versionAliases:"<<j<<std::endl;
203  if (path == pixelConfigAliases_[i].versionAliasesPath(j) &&
204  alias == pixelConfigAliases_[i].versionAliasesAlias(j)) {
205  //std::cout << "Making clone!"<<std::endl;
206  unsigned int newkey = config.clone(pixelConfigAliases_[i].key(), path, version);
207  pixelConfigAliases_[i].setKey(newkey);
208  }
209  }
210  }
211  }
212 
213  std::vector<std::string> getVersionAliases(std::string path) {
214  std::vector<std::string> tmp;
215  for (unsigned int i = 0; i < pixelVersionAliases_.size(); i++) {
216  //std::cout << "path alias:"<<pixelVersionAliases_[i].path()
217  // << pixelVersionAliases_[i].alias() << std::endl;
218  if (pixelVersionAliases_[i].path() == path) {
219  tmp.push_back(pixelVersionAliases_[i].alias());
220  }
221  }
222  return tmp;
223  }
224 
226  for (unsigned int i = 0; i < pixelVersionAliases_.size(); i++) {
227  if (pixelVersionAliases_[i].alias() == alias && pixelVersionAliases_[i].path() == path) {
228  return pixelVersionAliases_[i].version();
229  }
230  }
231  assert(0);
232  return 0;
233  }
234 
235  // Added by Dario, May 20th, 2008 =====================================================================
236  pathVersionAliasMmap getVersionData() { return versionMmap; }
237 
238  pathVersionAliasMmap getVersionData(std::string koc) {
239  pathVersionAliasMmap result;
240  for (pathVersionAliasMmap::iterator it = versionMmap.begin(); it != versionMmap.end(); it++) {
241  if ((*it).first.find(koc) != std::string::npos) {
242  result[(*it).first] = (*it).second;
243  }
244  }
245  return result;
246  }
247 
248  std::vector<pathAliasPair> getConfigAliases(std::string path) {
249  std::vector<pathAliasPair> configAliasVector;
250  for (pathAliasMmap::iterator it = aliasMmap.begin(); it != aliasMmap.end(); it++) {
251  if ((*it).first == path) {
252  configAliasVector.push_back((*it).second);
253  }
254  }
255  return configAliasVector;
256  }
257  // End of Dario's addition ============================================================================
258 
259  unsigned int nAliases() { return pixelConfigAliases_.size(); }
260  std::string name(unsigned int i) { return pixelConfigAliases_[i].name(); }
261  unsigned int key(unsigned int i) { return pixelConfigAliases_[i].key(); }
262  PixelConfigAlias operator[](unsigned int i) { return pixelConfigAliases_[i]; }
263 
264  unsigned int nVersionAliases() { return pixelVersionAliases_.size(); }
265  std::string path(unsigned int i) { return pixelVersionAliases_[i].path(); }
266  unsigned int version(unsigned int i) { return pixelVersionAliases_[i].version(); }
267  std::string alias(unsigned int i) { return pixelVersionAliases_[i].alias(); }
268 
269  private:
270  std::vector<PixelConfigAlias> pixelConfigAliases_;
271  std::vector<PixelVersionAlias> pixelVersionAliases_;
272  // Added by Dario, May 20th, 2008 =====================================================================
273  pathAliasMmap aliasMmap;
274  pathVersionAliasMmap versionMmap;
275  // End of Dario's addition ============================================================================
276  };
277 } // namespace pos
278 
279 #endif
unsigned int getVersion(std::string path, std::string alias)
void readfile(std::string filename)
std::string alias(unsigned int i)
This class implements..
unsigned int version(unsigned int i)
pathVersionAliasMmap getVersionData()
void updateConfigAlias(std::string path, unsigned int version, std::string alias, PixelConfigList &config)
Definition: config.py:1
std::string versionAliasesAlias(unsigned int i)
std::string versionAliasesPath(unsigned int i)
std::vector< pathAliasPair > getConfigAliases(std::string path)
unsigned int key(unsigned int i)
std::string path(unsigned int i)
std::pair< unsigned int, std::string > versionAliasPair
PixelConfigAlias operator[](unsigned int i)
std::map< std::string, vectorVAPairs > pathVersionAliasMmap
This class implements the configuration key which actually just is an integer.
std::map< std::string, std::string > pathAliasPair
std::string name(unsigned int i)
void insertVersionAlias(PixelVersionAlias &anAlias)
unsigned int nVersionAliases()
void addVersionAlias(std::string path, std::string alias)
void insertAlias(PixelConfigAlias &anAlias)
std::vector< std::string > getVersionAliases(std::string path)
pathVersionAliasMmap versionMmap
unsigned int nAliases()
PixelConfigAlias * versionAliases(std::string aliasName)
std::map< std::string, pathAliasPair > pathAliasMmap
pathVersionAliasMmap getVersionData(std::string koc)
std::vector< PixelVersionAlias > pixelVersionAliases_
pathAliasMmap aliasMmap
std::vector< PixelConfigAlias > pixelConfigAliases_
This class implements the steps that are used in a scan over Threshold and CalDelay.
std::vector< versionAliasPair > vectorVAPairs
tmp
align.sh
Definition: createJobs.py:716
unsigned int clone(unsigned int oldkey, std::string path, unsigned int version)
unsigned int nVersionAliases()