CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelAliasList.h
Go to the documentation of this file.
1 #ifndef PixelAliasList_h
2 #define PixelAliasList_h
3 
11 
12 #include <stdlib.h>
13 
14 namespace pos{
19  // Added by Dario, May 20th, 2008 =====================================================================
20  typedef std::pair<unsigned int, std::string > versionAliasPair ;
21  typedef std::vector<versionAliasPair> vectorVAPairs ;
22  typedef std::map<std::string, vectorVAPairs > pathVersionAliasMmap ;
23  typedef std::map<std::string, std::string> pathAliasPair ;
24  typedef std::map<std::string, pathAliasPair> pathAliasMmap ;
25  // End of Dario's addition ============================================================================
27 
28  public:
29 
30  void writefile(){
31 
32  std::string directory=getenv("PIXELCONFIGURATIONBASE");
33 
34  std::string filename=directory+"/aliases.txt";
35 
36  std::ofstream out(filename.c_str());
37 
38  out << "ConfigurationAliases" <<std::endl;
39  for(unsigned int i=0;i<pixelConfigAliases_.size();i++){
41  out << theAlias.name() << " "
42  << 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 
54  out << "VersionAliases" <<std::endl;
55  for(unsigned int i=0;i<pixelVersionAliases_.size();i++){
57 
58  out << theAlias.path() << " "
59  << theAlias.version() << " "
60  << theAlias.alias() << " ;"<<std::endl;
61 
62  }
63  }
64 
66 
67  std::ifstream in(filename.c_str());
68  if (!in.good()) {
69  std::cout << "[PixelAliasList::readfile()]\t\tCould not open file:"<<filename<<std::endl;
70  }
71  assert(in.good());
72 
73  // Added by Dario, May 28th, 2008 =====================================================================
74  pixelConfigAliases_.clear() ;
75  pixelVersionAliases_.clear() ;
76  aliasMmap.clear() ;
77  versionMmap.clear() ;
78  // End of Dario's addition ============================================================================
79 
81 
82  in >> tag;
83  while(tag.substr(0,1) == "#") {
84  in.ignore(4096, '\n'); //skips to endl;
85  in >> tag;
86  }
87 
88  assert(tag=="ConfigurationAliases");
89 
90  in >> tag;
91 
92  while(tag!="VersionAliases"){
93 
95 
96  unsigned int key;
97  in >> key;
98 
99  //std::cout << "[PixelAliasList::readfile()] Alias, key:"<<alias<<" "<<key<<std::endl;
100 
101  PixelConfigAlias anAlias(alias,key);
102 
103  in >> tag;
104  std::string theAlias = alias ;
105 
106  // Added by Dario, May 20th, 2008 =====================================================================
107  pathAliasPair tmpPAPair ;
108  if( tag == ";" )
109  {
110  tmpPAPair[""] = " " ;
111  aliasMmap[theAlias] = tmpPAPair ;
112  }
113  // End of Dario's addition ============================================================================
114  while(tag != ";") {
117 
118  path=tag;
119  in >> alias;
120  //std::cout << "[PixelAliasList::readfile()] path, alias:"<<path<<" "<<alias<<std::endl;
121 
122  anAlias.addVersionAlias(path,alias);
123  // Added by Dario, May 20th, 2008 =====================================================================
124  tmpPAPair[path] = alias ;
125  aliasMmap[theAlias] = tmpPAPair ;
126  // End of Dario's addition ============================================================================
127  in >> tag;
128 
129  }
130 
131  pixelConfigAliases_.push_back(anAlias);
132 
133  in >> tag;
134 
135  }
136 
137  assert(tag=="VersionAliases");
138 
141  unsigned int version;
142 
143  in >> path;
144  in >> version;
145  in >> alias;
146  in >> tag;
147 
148  //std::cout << "path version alias tag:"<<path<<" "<<version
149  // <<" "<<alias<<" "<<tag<<std::endl;
150 
151  // Added by Dario, May 23rd, 2008 =====================================================================
152  versionAliasPair tmpVAPair ;
153  // End of Dario's addition ============================================================================
154  while(!in.eof()){
155  assert(tag==";");
156  PixelVersionAlias aVersionAlias(path,version,alias);
157  pixelVersionAliases_.push_back(aVersionAlias);
158 
159  // Added by Dario, May 23rd, 2008 =====================================================================
160  tmpVAPair.first = version ;
161  tmpVAPair.second = alias ;
162  versionMmap[path].push_back(tmpVAPair) ;
163  // End of Dario's addition ============================================================================
164 
165  in >> path;
166  in >> version;
167  in >> alias;
168  in >> tag;
169 
170  }
171 
172  in.close();
173  }
174 
176  for(unsigned int i=0;i<pixelConfigAliases_.size();i++){
177  if (pixelConfigAliases_[i].name()==anAlias.name()){
178  std::cout << "[PixelAliasList::insertAlias()]\t\t\tReplacing existing alias:" << anAlias.name()<<std::endl;
179  pixelConfigAliases_[i]=anAlias;
180  return;
181  }
182  }
183  pixelConfigAliases_.push_back(anAlias);
184  }
185 
187  for(unsigned int i=0;i<pixelConfigAliases_.size();i++){
188  if (pixelConfigAliases_[i].name()==aliasName){
189  return &(pixelConfigAliases_[i]);
190  }
191  }
192  return 0;
193  }
194 
196  for(unsigned int i=0;i<pixelVersionAliases_.size();i++){
197  if (pixelVersionAliases_[i].alias()==anAlias.alias()&&
198  pixelVersionAliases_[i].path()==anAlias.path()){
199  std::cout << "[PixelAliasList::insertVersionAlias()]\t\tReplacing existing version alias:"
200  <<anAlias.path()<< " " << anAlias.alias() << std::endl;
201  pixelVersionAliases_[i]=anAlias;
202  return;
203  }
204  }
205  pixelVersionAliases_.push_back(anAlias);
206  }
207 
210 
211  //first loop over configuration aliases
212  for(unsigned int i=0;i<pixelConfigAliases_.size();i++){
213  //std::cout << "Looping over aliases:"<<i<<std::endl;
214  for(unsigned int j=0;j<pixelConfigAliases_[i].nVersionAliases();j++){
215  //std::cout << "Looping over versionAliases:"<<j<<std::endl;
216  if(path==pixelConfigAliases_[i].versionAliasesPath(j)&&
217  alias==pixelConfigAliases_[i].versionAliasesAlias(j)){
218  //std::cout << "Making clone!"<<std::endl;
219  unsigned int newkey=config.clone(pixelConfigAliases_[i].key(),path,version);
220  pixelConfigAliases_[i].setKey(newkey);
221  }
222  }
223  }
224  }
225 
226  std::vector<std::string> getVersionAliases(std::string path){
227  std::vector<std::string> tmp;
228  for(unsigned int i=0;i<pixelVersionAliases_.size();i++){
229  //std::cout << "path alias:"<<pixelVersionAliases_[i].path()
230  // << pixelVersionAliases_[i].alias() << std::endl;
231  if (pixelVersionAliases_[i].path()==path){
232  tmp.push_back(pixelVersionAliases_[i].alias());
233  }
234  }
235  return tmp;
236  }
237 
238 
240  for(unsigned int i=0;i<pixelVersionAliases_.size();i++){
241  if (pixelVersionAliases_[i].alias()==alias&&
242  pixelVersionAliases_[i].path()==path){
243  return pixelVersionAliases_[i].version();
244  }
245  }
246  assert(0);
247  return 0;
248  }
249 
250  // Added by Dario, May 20th, 2008 =====================================================================
252  return versionMmap ;
253  }
254 
256  {
258  for(pathVersionAliasMmap::iterator it = versionMmap.begin() ;it != versionMmap.end() ; it ++)
259  {
260  if((*it).first.find(koc) != std::string::npos)
261  {
262  result[(*it).first] = (*it).second ;
263  }
264  }
265  return result ;
266  }
267 
268  std::vector<pathAliasPair> getConfigAliases(std::string path) {
269  std::vector<pathAliasPair> configAliasVector ;
270  for(pathAliasMmap::iterator it=aliasMmap.begin(); it!=aliasMmap.end(); it++){
271  if( (*it).first == path ){
272  configAliasVector.push_back((*it).second) ;
273  }
274  }
275  return configAliasVector ;
276  }
277  // End of Dario's addition ============================================================================
278 
279  unsigned int nAliases() { return pixelConfigAliases_.size() ;}
280  std::string name( unsigned int i) { return pixelConfigAliases_[i].name() ;}
281  unsigned int key( unsigned int i) { return pixelConfigAliases_[i].key() ;}
282  PixelConfigAlias operator[](unsigned int i) { return pixelConfigAliases_[i] ;}
283 
284  unsigned int nVersionAliases() { return pixelVersionAliases_.size() ;}
285  std::string path( unsigned int i) { return pixelVersionAliases_[i].path() ;}
286  unsigned int version( unsigned int i) { return pixelVersionAliases_[i].version();}
287  std::string alias( unsigned int i) { return pixelVersionAliases_[i].alias() ;}
288 
289  private:
290 
291  std::vector<PixelConfigAlias> pixelConfigAliases_;
292  std::vector<PixelVersionAlias> pixelVersionAliases_;
293  // Added by Dario, May 20th, 2008 =====================================================================
296  // End of Dario's addition ============================================================================
297 
298  };
299 }
300 
301 #endif
unsigned int getVersion(std::string path, std::string alias)
int i
Definition: DBlmapReader.cc:9
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
assert(m_qm.get())
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)
tuple result
Definition: mps_fire.py:84
std::string path(unsigned int i)
PixelConfigAlias operator[](unsigned int i)
int j
Definition: DBlmapReader.cc:9
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
tuple filename
Definition: lut2db_cfg.py:20
std::vector< PixelConfigAlias > pixelConfigAliases_
tuple cout
Definition: gather_cfg.py:145
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()