CMS 3D CMS Logo

PixelConfigList.h
Go to the documentation of this file.
1 #ifndef PixelConfigList_h
2 #define PixelConfigList_h
3 
10 
11 #include <cassert>
12 #include <iostream>
13 #include <stdlib.h>
14 #include <string>
15 
16 namespace pos{
23 
24  public:
25 
26  void writefile(){
27 
28  std::string directory=getenv("PIXELCONFIGURATIONBASE");
29 /* directory+="/PixelConfigDataExamples/"; */
30  directory+="/";
31 
32  std::string filename=directory+"/configurations.txt";
33 
34  std::ofstream out(filename.c_str());
35  assert(out.good());
36 
37  for (unsigned int i=0;i<configs.size();i++){
38  //std::cout << "key "<<i<<std::endl;
39  out << "key "<<i<<std::endl;
40  configs[i].write(out);
41  out <<std::endl;
42  //std::cout <<std::endl;
43  }
44 
45 
46  }
47 
48 
50 
51  std::ifstream in(filename.c_str());
52 
54 
55  in >> tag;
56  while(tag.substr(0,1) == "#") {
57  in.ignore(4096, '\n'); //skips to endl;
58  in >> tag;
59  }
60 
61  unsigned int version=0;
62 
63  while(!in.eof()){
64  if (tag!="key"){
65  std::cout << "PixelConfigDB: tag="<<tag<<std::endl;
66  assert(0);
67  }
68  unsigned int tmp_version;
69  in >> tmp_version;
70  if (version!=tmp_version){
71  std::cout << "PixelConfigDB: read version: "<<tmp_version<<" while expected "
72  << version << std::endl;
73  assert(0);
74  }
75 
76  in >> tag;
77  while(tag.substr(0,1) == "#") {
78  in.ignore(4096, '\n'); //skips to endl;
79  in >> tag;
80  }
81 
82  PixelConfig aConfig;
83  while (tag!="key"&&in.good()){
84  unsigned int tmp;
85  in >>tmp;
86  //std::cout << "adding: "<<tag<<" "<<tmp<<std::endl;
87  aConfig.add(tag,tmp);
88  in >> tag;
89  while(tag.substr(0,1) == "#") {
90  in.ignore(4096, '\n'); //skips to endl;
91  in >> tag;
92  }
93  }
94 
95  configs.push_back(aConfig);
96  version++;
97 
98  };
99 
100  in.close();
101 
102  }
103 
104  //Method will return new key
105  unsigned int clone(unsigned int oldkey, std::string path, unsigned int version){
106  PixelConfig aConfig=configs[oldkey];
107 
108  unsigned int oldversion;
109 
110  if (-1==aConfig.update(path,oldversion,version)){
111  std::cout << "Old version not found for path="<<path<<" in config "<<oldkey<<std::endl;
112  assert(0);
113  }
114 
115  configs.push_back(aConfig);
116 
117  return configs.size()-1;
118 
119  }
120 
121 
122  //Method will return new key
123  unsigned int add(PixelConfig& aConfig){
124 
125  configs.push_back(aConfig);
126 
127  return configs.size()-1;
128 
129  }
130 
131  unsigned int size(){ return configs.size(); }
132 
133  PixelConfig& operator[](unsigned int i) {return configs[i];}
134 
136  {
137  configs.clear() ;
138  readfile(filename) ;
139  }
140 
141  unsigned int numberOfConfigs() { return configs.size(); }
142 
143  private:
144 
145  std::vector<PixelConfig> configs;
146 
147  };
148 }
149 #endif
This class implements..
void add(std::string dir, unsigned int version)
Definition: PixelConfig.h:30
std::vector< PixelConfig > configs
void readfile(std::string filename)
int update(std::string dir, unsigned int &version, unsigned int newversion)
Definition: PixelConfig.h:49
unsigned int add(PixelConfig &aConfig)
unsigned int numberOfConfigs()
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
void reload(std::string filename)
PixelConfig & operator[](unsigned int i)
unsigned int clone(unsigned int oldkey, std::string path, unsigned int version)
This class implements..
This class implements..
Definition: PixelConfig.h:20