00001
00002
00003
00004
00005
00006
00007
00008 #include "CalibFormats/SiPixelObjects/interface/PixelMaxVsf.h"
00009 #include <fstream>
00010 #include <iostream>
00011 #include <sstream>
00012 #include <ios>
00013 #include <assert.h>
00014 #include <stdio.h>
00015
00016 using namespace std;
00017 using namespace pos;
00018
00019
00020 PixelMaxVsf::PixelMaxVsf(std::vector< std::vector< std::string > > &tableMat):PixelConfigBase("","","")
00021 {
00022 std::map<std::string , int > colM;
00023 std::vector<std::string > colNames;
00035 colNames.push_back("CONFIG_KEY_ID");
00036 colNames.push_back("CONFG_KEY" );
00037 colNames.push_back("VERSION" );
00038 colNames.push_back("KIND_OF_COND" );
00039 colNames.push_back("ROC_NAME" );
00040 colNames.push_back("MAXVSF" );
00041
00042 for(unsigned int c = 0 ; c < tableMat[0].size() ; c++)
00043 {
00044 for(unsigned int n=0; n<colNames.size(); n++)
00045 {
00046 if(tableMat[0][c] == colNames[n])
00047 {
00048 colM[colNames[n]] = c;
00049 break;
00050 }
00051 }
00052 }
00053 for(unsigned int n=0; n<colNames.size(); n++)
00054 {
00055 if(colM.find(colNames[n]) == colM.end())
00056 {
00057 std::cerr << "[PixelMaxVsf::PixelMaxVsf()]\tCouldn't find in the database the column with name " << colNames[n] << std::endl;
00058 assert(0);
00059 }
00060 }
00061
00062 rocs_.clear();
00063
00064 for(unsigned int r = 1 ; r < tableMat.size() ; r++)
00065 {
00066 PixelROCName roc(tableMat[r][colM["ROC_NAME"]]);
00067 unsigned int vsf;
00068 vsf = atoi(tableMat[r][colM["MAXVSF"]].c_str());
00069 rocs_[roc]=vsf;
00070 }
00071 }
00072
00073
00074
00075 PixelMaxVsf::PixelMaxVsf(std::string filename):
00076 PixelConfigBase("","",""){
00077
00078
00079 if (filename[filename.size()-1]=='t'){
00080
00081 std::ifstream in(filename.c_str());
00082
00083 if (!in.good()){
00084 std::cout << "[PixelMaxVsf::PixelMaxVsf()]\t\tCould not open:"<<filename<<std::endl;
00085 assert(0);
00086 }
00087 else {
00088 std::cout << "[PixelMaxVsf::PixelMaxVsf()]\t\tOpened:"<<filename<<std::endl;
00089 }
00090
00091 if (in.eof()){
00092 std::cout << "[PixelMaxVsf::PixelMaxVsf()]\t\teof before reading anything!"<<std::endl;
00093 ::abort();
00094 }
00095
00096
00097 rocs_.clear();
00098
00099 std::string rocname;
00100
00101 in >> rocname;
00102 while (!in.eof()){
00103
00104 PixelROCName roc(rocname);
00105 unsigned int vsf;
00106 in >> vsf;
00107 rocs_[roc]=vsf;
00108 in >> rocname;
00109 }
00110 return;
00111 }
00112 else{
00113 assert(0);
00114 }
00115
00116 }
00117
00118 bool PixelMaxVsf::getVsf(PixelROCName roc, unsigned int& Vsf) const{
00119
00120 std::map<PixelROCName,unsigned int>::const_iterator itr = rocs_.find(roc);
00121
00122 if (itr==rocs_.end()) {
00123 return false;
00124 }
00125
00126 Vsf=itr->second;
00127
00128 return true;
00129
00130 }
00131
00132
00133 void PixelMaxVsf::setVsf(PixelROCName roc, unsigned int Vsf){
00134
00135 rocs_[roc]=Vsf;
00136
00137 }
00138
00139
00140
00141 void PixelMaxVsf::writeASCII(std::string dir) const {
00142
00143 if (dir!="") dir+="/";
00144 std::string filename=dir+"maxvsf.dat";
00145
00146 std::ofstream out(filename.c_str(), std::ios_base::out) ;
00147 if(!out) {
00148 std::cout << "[PixelMaxVsf::writeASCII()] Could not open file " << filename << " for write" << std::endl ;
00149 exit(1);
00150 }
00151
00152
00153 std::map<PixelROCName, unsigned int>::const_iterator irocs = rocs_.begin();
00154 for(; irocs != rocs_.end() ; irocs++){
00155 out << (irocs->first).rocname() << " " << irocs->second << endl ;
00156 }
00157
00158 out.close();
00159
00160 }
00161
00162
00163