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