CMS 3D CMS Logo

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