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