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 
32  public:
33 
34  void writefile(){
35 
36  std::string directory=getenv("PIXELCONFIGURATIONBASE");
37 
38  std::string filename=directory+"/aliases.txt";
39 
40  std::ofstream out(filename.c_str());
41 
42  out << "ConfigurationAliases" <<std::endl;
43  for(unsigned int i=0;i<pixelConfigAliases_.size();i++){
45  out << theAlias.name() << " "
46  << theAlias.key() << " ";
47 
48  unsigned int n=theAlias.nVersionAliases();
49  for (unsigned int j=0;j<n;j++){
50  out << theAlias.versionAliasesPath(j) << " ";
51  out << theAlias.versionAliasesAlias(j) << " ";
52  }
53 
54  out << ";" << std::endl;
55 
56  }
57 
58  out << "VersionAliases" <<std::endl;
59  for(unsigned int i=0;i<pixelVersionAliases_.size();i++){
61 
62  out << theAlias.path() << " "
63  << theAlias.version() << " "
64  << theAlias.alias() << " ;"<<std::endl;
65 
66  }
67  }
68 
70 
71  std::ifstream in(filename.c_str());
72  if (!in.good()) {
73  std::cout << "[PixelAliasList::readfile()]\t\tCould not open file:"<<filename<<std::endl;
74  }
75  assert(in.good());
76 
77  // Added by Dario, May 28th, 2008 =====================================================================
78  pixelConfigAliases_.clear() ;
79  pixelVersionAliases_.clear() ;
80  aliasMmap.clear() ;
81  versionMmap.clear() ;
82  // End of Dario's addition ============================================================================
83 
85 
86  in >> tag;
87  while(tag.substr(0,1) == "#") {
88  in.ignore(4096, '\n'); //skips to endl;
89  in >> tag;
90  }
91 
92  assert(tag=="ConfigurationAliases");
93 
94  in >> tag;
95 
96  while(tag!="VersionAliases"){
97 
99 
100  unsigned int key;
101  in >> key;
102 
103  //std::cout << "[PixelAliasList::readfile()] Alias, key:"<<alias<<" "<<key<<std::endl;
104 
105  PixelConfigAlias anAlias(alias,key);
106 
107  in >> tag;
108  std::string theAlias = alias ;
109 
110  // Added by Dario, May 20th, 2008 =====================================================================
111  pathAliasPair tmpPAPair ;
112  if( tag == ";" )
113  {
114  tmpPAPair[""] = " " ;
115  aliasMmap[theAlias] = tmpPAPair ;
116  }
117  // End of Dario's addition ============================================================================
118  while(tag != ";") {
121 
122  path=tag;
123  in >> alias;
124  //std::cout << "[PixelAliasList::readfile()] path, alias:"<<path<<" "<<alias<<std::endl;
125 
126  anAlias.addVersionAlias(path,alias);
127  // Added by Dario, May 20th, 2008 =====================================================================
128  tmpPAPair[path] = alias ;
129  aliasMmap[theAlias] = tmpPAPair ;
130  // End of Dario's addition ============================================================================
131  in >> tag;
132 
133  }
134 
135  pixelConfigAliases_.push_back(anAlias);
136 
137  in >> tag;
138 
139  }
140 
141  assert(tag=="VersionAliases");
142 
145  unsigned int version;
146 
147  in >> path;
148  in >> version;
149  in >> alias;
150  in >> tag;
151 
152  //std::cout << "path version alias tag:"<<path<<" "<<version
153  // <<" "<<alias<<" "<<tag<<std::endl;
154 
155  // Added by Dario, May 23rd, 2008 =====================================================================
156  versionAliasPair tmpVAPair ;
157  // End of Dario's addition ============================================================================
158  while(!in.eof()){
159  assert(tag==";");
160  PixelVersionAlias aVersionAlias(path,version,alias);
161  pixelVersionAliases_.push_back(aVersionAlias);
162 
163  // Added by Dario, May 23rd, 2008 =====================================================================
164  tmpVAPair.first = version ;
165  tmpVAPair.second = alias ;
166  versionMmap[path].push_back(tmpVAPair) ;
167  // End of Dario's addition ============================================================================
168 
169  in >> path;
170  in >> version;
171  in >> alias;
172  in >> tag;
173 
174  }
175 
176  in.close();
177  }
178 
180  for(unsigned int i=0;i<pixelConfigAliases_.size();i++){
181  if (pixelConfigAliases_[i].name()==anAlias.name()){
182  std::cout << "[PixelAliasList::insertAlias()]\t\t\tReplacing existing alias:" << anAlias.name()<<std::endl;
183  pixelConfigAliases_[i]=anAlias;
184  return;
185  }
186  }
187  pixelConfigAliases_.push_back(anAlias);
188  }
189 
191  for(unsigned int i=0;i<pixelConfigAliases_.size();i++){
192  if (pixelConfigAliases_[i].name()==aliasName){
193  return &(pixelConfigAliases_[i]);
194  }
195  }
196  return 0;
197  }
198 
200  for(unsigned int i=0;i<pixelVersionAliases_.size();i++){
201  if (pixelVersionAliases_[i].alias()==anAlias.alias()&&
202  pixelVersionAliases_[i].path()==anAlias.path()){
203  std::cout << "[PixelAliasList::insertVersionAlias()]\t\tReplacing existing version alias:"
204  <<anAlias.path()<< " " << anAlias.alias() << std::endl;
205  pixelVersionAliases_[i]=anAlias;
206  return;
207  }
208  }
209  pixelVersionAliases_.push_back(anAlias);
210  }
211 
214 
215  //first loop over configuration aliases
216  for(unsigned int i=0;i<pixelConfigAliases_.size();i++){
217  //std::cout << "Looping over aliases:"<<i<<std::endl;
218  for(unsigned int j=0;j<pixelConfigAliases_[i].nVersionAliases();j++){
219  //std::cout << "Looping over versionAliases:"<<j<<std::endl;
220  if(path==pixelConfigAliases_[i].versionAliasesPath(j)&&
221  alias==pixelConfigAliases_[i].versionAliasesAlias(j)){
222  //std::cout << "Making clone!"<<std::endl;
223  unsigned int newkey=config.clone(pixelConfigAliases_[i].key(),path,version);
224  pixelConfigAliases_[i].setKey(newkey);
225  }
226  }
227  }
228  }
229 
230  std::vector<std::string> getVersionAliases(std::string path){
231  std::vector<std::string> tmp;
232  for(unsigned int i=0;i<pixelVersionAliases_.size();i++){
233  //std::cout << "path alias:"<<pixelVersionAliases_[i].path()
234  // << pixelVersionAliases_[i].alias() << std::endl;
235  if (pixelVersionAliases_[i].path()==path){
236  tmp.push_back(pixelVersionAliases_[i].alias());
237  }
238  }
239  return tmp;
240  }
241 
242 
244  for(unsigned int i=0;i<pixelVersionAliases_.size();i++){
245  if (pixelVersionAliases_[i].alias()==alias&&
246  pixelVersionAliases_[i].path()==path){
247  return pixelVersionAliases_[i].version();
248  }
249  }
250  assert(0);
251  return 0;
252  }
253 
254  // Added by Dario, May 20th, 2008 =====================================================================
255  pathVersionAliasMmap getVersionData(){
256  return versionMmap ;
257  }
258 
259  pathVersionAliasMmap getVersionData(std::string koc)
260  {
261  pathVersionAliasMmap result ;
262  for(pathVersionAliasMmap::iterator it = versionMmap.begin() ;it != versionMmap.end() ; it ++)
263  {
264  if((*it).first.find(koc) != std::string::npos)
265  {
266  result[(*it).first] = (*it).second ;
267  }
268  }
269  return result ;
270  }
271 
272  std::vector<pathAliasPair> getConfigAliases(std::string path) {
273  std::vector<pathAliasPair> configAliasVector ;
274  for(pathAliasMmap::iterator it=aliasMmap.begin(); it!=aliasMmap.end(); it++){
275  if( (*it).first == path ){
276  configAliasVector.push_back((*it).second) ;
277  }
278  }
279  return configAliasVector ;
280  }
281  // End of Dario's addition ============================================================================
282 
283  unsigned int nAliases() { return pixelConfigAliases_.size() ;}
284  std::string name( unsigned int i) { return pixelConfigAliases_[i].name() ;}
285  unsigned int key( unsigned int i) { return pixelConfigAliases_[i].key() ;}
286  PixelConfigAlias operator[](unsigned int i) { return pixelConfigAliases_[i] ;}
287 
288  unsigned int nVersionAliases() { return pixelVersionAliases_.size() ;}
289  std::string path( unsigned int i) { return pixelVersionAliases_[i].path() ;}
290  unsigned int version( unsigned int i) { return pixelVersionAliases_[i].version();}
291  std::string alias( unsigned int i) { return pixelVersionAliases_[i].alias() ;}
292 
293  private:
294 
295  std::vector<PixelConfigAlias> pixelConfigAliases_;
296  std::vector<PixelVersionAlias> pixelVersionAliases_;
297  // Added by Dario, May 20th, 2008 =====================================================================
298  pathAliasMmap aliasMmap ;
299  pathVersionAliasMmap versionMmap ;
300  // End of Dario's addition ============================================================================
301 
302  };
303 }
304 
305 #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)
std::map< std::string, vectorVAPairs > pathVersionAliasMmap
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)
PixelConfigAlias operator[](unsigned int i)
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()
std::pair< unsigned int, std::string > versionAliasPair
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
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
unsigned int clone(unsigned int oldkey, std::string path, unsigned int version)
unsigned int nVersionAliases()