CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CalibFormats/SiPixelObjects/interface/PixelAliasList.h

Go to the documentation of this file.
00001 #ifndef PixelAliasList_h
00002 #define PixelAliasList_h
00003 
00009 #include "CalibFormats/SiPixelObjects/interface/PixelConfigAlias.h"
00010 #include "CalibFormats/SiPixelObjects/interface/PixelVersionAlias.h"
00011 
00012 
00013 namespace pos{
00018   // Added by Dario, May 20th, 2008 =====================================================================
00019   typedef std::pair<unsigned int, std::string >  versionAliasPair ;
00020   typedef std::vector<versionAliasPair>          vectorVAPairs ;
00021   typedef std::map<std::string, vectorVAPairs >  pathVersionAliasMmap ;
00022   typedef std::map<std::string, std::string>     pathAliasPair ;
00023   typedef std::map<std::string, pathAliasPair>   pathAliasMmap ;          
00024   // End of Dario's addition ============================================================================
00025   class PixelAliasList {
00026 
00027   public:
00028 
00029     void writefile(){
00030 
00031       std::string directory=getenv("PIXELCONFIGURATIONBASE");
00032     
00033       std::string filename=directory+"/aliases.txt";
00034 
00035       std::ofstream out(filename.c_str());
00036 
00037       out << "ConfigurationAliases" <<std::endl;
00038       for(unsigned int i=0;i<pixelConfigAliases_.size();i++){
00039         PixelConfigAlias& theAlias=pixelConfigAliases_[i];
00040         out << theAlias.name() << "     " 
00041             << theAlias.key()  << "   ";
00042       
00043         unsigned int n=theAlias.nVersionAliases();
00044         for (unsigned int j=0;j<n;j++){
00045           out << theAlias.versionAliasesPath(j) << "  ";
00046           out << theAlias.versionAliasesAlias(j) << "  ";
00047         }
00048 
00049         out << ";" << std::endl; 
00050 
00051       }
00052 
00053       out << "VersionAliases" <<std::endl;
00054       for(unsigned int i=0;i<pixelVersionAliases_.size();i++){
00055         PixelVersionAlias& theAlias=pixelVersionAliases_[i];
00056 
00057         out << theAlias.path() << "  "
00058             << theAlias.version() << " "
00059             << theAlias.alias() << " ;"<<std::endl;
00060 
00061       }
00062     }
00063 
00064     void readfile(std::string filename){
00065 
00066       std::ifstream in(filename.c_str());
00067       if (!in.good()) {
00068         std::cout << "[PixelAliasList::readfile()]\t\tCould not open file:"<<filename<<std::endl;
00069       }
00070       assert(in.good());
00071 
00072       // Added by Dario, May 28th, 2008 =====================================================================
00073       pixelConfigAliases_.clear() ;
00074       pixelVersionAliases_.clear() ;   
00075       aliasMmap.clear() ;
00076       versionMmap.clear() ;
00077       // End of Dario's addition ============================================================================
00078 
00079       std::string tag;
00080             
00081       in >> tag;
00082       while(tag.substr(0,1) == "#") {
00083         in.ignore(4096, '\n'); //skips to endl;
00084         in >> tag;
00085       }
00086 
00087       assert(tag=="ConfigurationAliases");
00088 
00089       in >> tag;
00090 
00091       while(tag!="VersionAliases"){
00092 
00093         std::string alias=tag;
00094 
00095         unsigned int key;
00096         in >> key;
00097 
00098         //std::cout << "[PixelAliasList::readfile()] Alias, key:"<<alias<<" "<<key<<std::endl;
00099 
00100         PixelConfigAlias anAlias(alias,key);
00101       
00102         in >> tag;
00103         std::string theAlias = alias ;
00104       
00105         // Added by Dario, May 20th, 2008 =====================================================================
00106         pathAliasPair tmpPAPair ;
00107         if( tag == ";" )
00108         {
00109          tmpPAPair[""]       = " " ;
00110          aliasMmap[theAlias] = tmpPAPair ;
00111         }
00112         // End of Dario's addition ============================================================================
00113         while(tag  != ";") {
00114           std::string path;
00115           std::string alias;
00116 
00117           path=tag;
00118           in >> alias;
00119           //std::cout << "[PixelAliasList::readfile()] path, alias:"<<path<<" "<<alias<<std::endl;
00120         
00121           anAlias.addVersionAlias(path,alias);
00122           // Added by Dario, May 20th, 2008 =====================================================================
00123           tmpPAPair[path]     = alias ;
00124           aliasMmap[theAlias] = tmpPAPair ;
00125           // End of Dario's addition ============================================================================
00126           in >> tag;
00127 
00128         }
00129 
00130         pixelConfigAliases_.push_back(anAlias);
00131 
00132         in >> tag;
00133 
00134       }
00135 
00136       assert(tag=="VersionAliases");
00137 
00138       std::string path;
00139       std::string alias;
00140       unsigned int version;
00141 
00142       in >> path;
00143       in >> version;
00144       in >> alias;
00145       in >> tag;
00146 
00147       //std::cout << "path version alias tag:"<<path<<" "<<version
00148       //              <<" "<<alias<<" "<<tag<<std::endl;
00149 
00150       // Added by Dario, May 23rd, 2008 =====================================================================
00151       versionAliasPair tmpVAPair ;
00152       // End of Dario's addition ============================================================================
00153       while(!in.eof()){
00154         assert(tag==";");
00155         PixelVersionAlias aVersionAlias(path,version,alias);
00156         pixelVersionAliases_.push_back(aVersionAlias);
00157         
00158         // Added by Dario, May 23rd, 2008 =====================================================================
00159         tmpVAPair.first  = version ;
00160         tmpVAPair.second = alias ; 
00161         versionMmap[path].push_back(tmpVAPair) ;
00162         // End of Dario's addition ============================================================================
00163 
00164         in >> path;
00165         in >> version;
00166         in >> alias;
00167         in >> tag;
00168 
00169       }
00170     
00171       in.close();
00172     }
00173 
00174     void insertAlias(PixelConfigAlias& anAlias){
00175       for(unsigned int i=0;i<pixelConfigAliases_.size();i++){
00176         if (pixelConfigAliases_[i].name()==anAlias.name()){
00177           std::cout << "[PixelAliasList::insertAlias()]\t\t\tReplacing existing alias:" << anAlias.name()<<std::endl;
00178           pixelConfigAliases_[i]=anAlias;
00179           return;
00180         }
00181       }
00182       pixelConfigAliases_.push_back(anAlias);
00183     }
00184 
00185     PixelConfigAlias* versionAliases(std::string aliasName){
00186       for(unsigned int i=0;i<pixelConfigAliases_.size();i++){
00187         if (pixelConfigAliases_[i].name()==aliasName){
00188           return &(pixelConfigAliases_[i]);
00189         }
00190       }
00191       return 0;
00192     }
00193 
00194     void insertVersionAlias(PixelVersionAlias& anAlias){
00195       for(unsigned int i=0;i<pixelVersionAliases_.size();i++){
00196         if (pixelVersionAliases_[i].alias()==anAlias.alias()&&
00197             pixelVersionAliases_[i].path()==anAlias.path()){
00198           std::cout << "[PixelAliasList::insertVersionAlias()]\t\tReplacing existing version alias:" 
00199                     <<anAlias.path()<< " " << anAlias.alias() << std::endl;
00200           pixelVersionAliases_[i]=anAlias;
00201           return;
00202         }
00203       }
00204       pixelVersionAliases_.push_back(anAlias);
00205     }
00206 
00207     void updateConfigAlias(std::string path,unsigned int version,
00208                            std::string alias, PixelConfigList& config){
00209  
00210       //first loop over configuration aliases
00211       for(unsigned int i=0;i<pixelConfigAliases_.size();i++){
00212         //std::cout << "Looping over aliases:"<<i<<std::endl;
00213         for(unsigned int j=0;j<pixelConfigAliases_[i].nVersionAliases();j++){
00214           //std::cout << "Looping over versionAliases:"<<j<<std::endl;
00215           if(path==pixelConfigAliases_[i].versionAliasesPath(j)&&
00216              alias==pixelConfigAliases_[i].versionAliasesAlias(j)){
00217             //std::cout << "Making clone!"<<std::endl;
00218             unsigned int newkey=config.clone(pixelConfigAliases_[i].key(),path,version);
00219             pixelConfigAliases_[i].setKey(newkey);
00220           }
00221         }
00222       }
00223     }
00224 
00225     std::vector<std::string> getVersionAliases(std::string path){
00226       std::vector<std::string> tmp;
00227       for(unsigned int i=0;i<pixelVersionAliases_.size();i++){
00228         //std::cout << "path alias:"<<pixelVersionAliases_[i].path()
00229         //        << pixelVersionAliases_[i].alias() << std::endl;
00230         if (pixelVersionAliases_[i].path()==path){
00231           tmp.push_back(pixelVersionAliases_[i].alias());
00232         }
00233       }
00234       return tmp;
00235     }
00236 
00237 
00238     unsigned int getVersion(std::string path, std::string alias){
00239       for(unsigned int i=0;i<pixelVersionAliases_.size();i++){
00240         if (pixelVersionAliases_[i].alias()==alias&&
00241             pixelVersionAliases_[i].path()==path){
00242           return pixelVersionAliases_[i].version();
00243         }
00244       }
00245       assert(0);
00246       return 0;
00247     }
00248     
00249     // Added by Dario, May 20th, 2008 =====================================================================
00250     pathVersionAliasMmap getVersionData(){
00251       return versionMmap ;
00252     }
00253     
00254     pathVersionAliasMmap getVersionData(std::string koc)
00255     {
00256       pathVersionAliasMmap result ;
00257       for(pathVersionAliasMmap::iterator it = versionMmap.begin() ;it != versionMmap.end() ; it ++)
00258         {
00259           if((*it).first.find(koc) != std::string::npos)
00260             {
00261               result[(*it).first] = (*it).second ;
00262             }
00263         }
00264       return result ;
00265     }
00266 
00267     std::vector<pathAliasPair> getConfigAliases(std::string path) {
00268      std::vector<pathAliasPair> configAliasVector ;
00269      for(pathAliasMmap::iterator it=aliasMmap.begin(); it!=aliasMmap.end(); it++){
00270       if( (*it).first == path ){
00271        configAliasVector.push_back((*it).second) ;
00272       }
00273      }
00274      return configAliasVector ;
00275     } 
00276     // End of Dario's addition ============================================================================
00277 
00278     unsigned int     nAliases()                     { return pixelConfigAliases_.size()       ;}
00279     std::string      name(          unsigned int i) { return pixelConfigAliases_[i].name()    ;}
00280     unsigned int     key(           unsigned int i) { return pixelConfigAliases_[i].key()     ;}
00281     PixelConfigAlias operator[](unsigned int i)     { return pixelConfigAliases_[i]           ;}
00282 
00283     unsigned int     nVersionAliases()              { return pixelVersionAliases_.size()      ;}
00284     std::string      path(          unsigned int i) { return pixelVersionAliases_[i].path()   ;} 
00285     unsigned int     version(       unsigned int i) { return pixelVersionAliases_[i].version();}
00286     std::string      alias(         unsigned int i) { return pixelVersionAliases_[i].alias()  ;} 
00287     
00288   private:
00289 
00290     std::vector<PixelConfigAlias> pixelConfigAliases_;
00291     std::vector<PixelVersionAlias> pixelVersionAliases_;
00292     // Added by Dario, May 20th, 2008 =====================================================================
00293     pathAliasMmap aliasMmap ;
00294     pathVersionAliasMmap versionMmap ;
00295     // End of Dario's addition ============================================================================
00296 
00297   };
00298 }
00299 
00300 #endif