CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/CalibFormats/SiPixelObjects/interface/PixelConfigList.h

Go to the documentation of this file.
00001 #ifndef PixelConfigList_h
00002 #define PixelConfigList_h
00003 
00009 namespace pos{
00015   class PixelConfigList {
00016 
00017   public:
00018 
00019     void writefile(){
00020 
00021       std::string directory=getenv("PIXELCONFIGURATIONBASE");
00022 /*       directory+="/PixelConfigDataExamples/"; */
00023       directory+="/";
00024     
00025       std::string filename=directory+"/configurations.txt";
00026 
00027       std::ofstream out(filename.c_str());
00028       assert(out.good());
00029 
00030       for (unsigned int i=0;i<configs.size();i++){
00031         //std::cout << "key "<<i<<std::endl; 
00032         out << "key "<<i<<std::endl;
00033         configs[i].write(out);
00034         out <<std::endl;
00035         //std::cout <<std::endl; 
00036       }
00037 
00038 
00039     }
00040 
00041 
00042     void readfile(std::string filename){
00043 
00044       std::ifstream in(filename.c_str());
00045 
00046       std::string tag;
00047             
00048       in >> tag;
00049       while(tag.substr(0,1) == "#") {
00050         in.ignore(4096, '\n'); //skips to endl;
00051         in >> tag;
00052       }
00053 
00054       unsigned int version=0;
00055 
00056       while(!in.eof()){
00057         if (tag!="key"){
00058           std::cout << "PixelConfigDB: tag="<<tag<<std::endl;
00059           assert(0);
00060         }
00061         unsigned int tmp_version;
00062         in >> tmp_version;
00063         if (version!=tmp_version){
00064           std::cout << "PixelConfigDB: read version: "<<tmp_version<<" while expected "
00065                     << version << std::endl;
00066           assert(0);
00067         }
00068 
00069         in >> tag;
00070         while(tag.substr(0,1) == "#") {
00071           in.ignore(4096, '\n'); //skips to endl;
00072           in >> tag;
00073         }
00074 
00075         PixelConfig aConfig;
00076         while (tag!="key"&&in.good()){
00077           unsigned int tmp;
00078           in >>tmp;
00079           //std::cout << "adding: "<<tag<<" "<<tmp<<std::endl;
00080           aConfig.add(tag,tmp);
00081           in >> tag;
00082           while(tag.substr(0,1) == "#") {
00083             in.ignore(4096, '\n'); //skips to endl;
00084             in >> tag;
00085           }
00086         }
00087       
00088         configs.push_back(aConfig);
00089         version++;
00090       
00091       };
00092                 
00093       in.close();
00094 
00095     }
00096 
00097     //Method will return new key
00098     unsigned int clone(unsigned int oldkey, std::string path, unsigned int version){
00099       PixelConfig aConfig=configs[oldkey];
00100     
00101       unsigned int oldversion;
00102     
00103       if (-1==aConfig.update(path,oldversion,version)){
00104         std::cout << "Old version not found for path="<<path<<" in config "<<oldkey<<std::endl;
00105         assert(0);
00106       }
00107 
00108       configs.push_back(aConfig);
00109     
00110       return configs.size()-1;
00111 
00112     }
00113 
00114 
00115     //Method will return new key
00116     unsigned int add(PixelConfig& aConfig){
00117 
00118       configs.push_back(aConfig);
00119     
00120       return configs.size()-1;
00121 
00122     }
00123 
00124     unsigned int size(){ return configs.size(); }
00125 
00126     PixelConfig& operator[](unsigned int i) {return configs[i];}
00127     
00128     void reload(std::string filename)
00129     {
00130       configs.clear() ;
00131       readfile(filename) ;
00132     }
00133 
00134     unsigned int numberOfConfigs() { return configs.size(); }
00135 
00136   private:
00137 
00138     std::vector<PixelConfig> configs;
00139 
00140   };
00141 }
00142 #endif