#include <Alignment/OptAlignCSV2DB/interface/OptAlignDataConverter.h>
Public Member Functions | |
virtual void | analyze (const edm::Event &, const edm::EventSetup &) |
virtual void | endJob () |
OptAlignDataConverter (const edm::ParameterSet &iConfig) | |
~OptAlignDataConverter () | |
Private Attributes | |
CSVFieldMap | m_fieldMap |
std::string | m_inFileName |
Definition at line 12 of file OptAlignDataConverter.h.
OptAlignDataConverter::OptAlignDataConverter | ( | const edm::ParameterSet & | iConfig | ) | [explicit] |
Definition at line 14 of file OptAlignDataConverter.cc.
00014 :m_inFileName( iConfig.getUntrackedParameter< std::string >("inputFile") ){}
OptAlignDataConverter::~OptAlignDataConverter | ( | ) | [inline] |
virtual void OptAlignDataConverter::analyze | ( | const edm::Event & | , | |
const edm::EventSetup & | ||||
) | [inline, virtual] |
Reimplemented from edm::EDAnalyzer.
Definition at line 16 of file OptAlignDataConverter.cc.
References OpticalAlignInfo::angx_, OpticalAlignInfo::angy_, OpticalAlignInfo::angz_, counter(), GenMuonPlsPt100GeV_cfg::cout, lat::endl(), OpticalAlignParam::error_, exception, Exception, OpticalAlignInfo::extraEntries_, CSVFieldMap::fieldName(), CSVFieldMap::fieldType(), OpticalAlignInfo::ID_, int, edm::Service< T >::isAvailable(), CSVBlankLineParser::isBlank(), it, kk, parsecf::pyparsing::line(), m_fieldMap, m_inFileName, name, OpticalAlignInfo::name_, OpticalAlignParam::name_, OpticalAlignments::opticalAlignments_, CSVDataLineParser::parse(), CSVHeaderLineParser::parse(), CSVFieldMap::push_back(), CSVHeaderLineParser::result(), HLT_VtxMuL3::result, CSVDataLineParser::result(), OpticalAlignInfo::type_, OpticalAlignParam::value_, cms::Exception::what(), OpticalAlignInfo::x_, OpticalAlignInfo::y_, and OpticalAlignInfo::z_.
00017 { 00018 std::ifstream myfile(m_inFileName.c_str()); 00019 if ( !myfile.is_open() ) throw cms::Exception("unable to open file"); 00020 OpticalAlignments* myobj=new OpticalAlignments; 00021 std::vector<std::string> fieldNames,fieldTypes; 00022 CSVHeaderLineParser headerParser; 00023 CSVDataLineParser dataParser; 00024 int counter=0; 00025 while (! myfile.eof() ){ 00026 std::string line; 00027 std::getline (myfile,line); 00028 std::cout << " line read " << line << std::endl; 00029 00030 CSVBlankLineParser blank; 00031 if(blank.isBlank(line)){ 00032 continue; 00033 } 00034 if(counter<2){//two lines of header 00035 if(counter==0) { 00036 if(!headerParser.parse(line)) { 00037 throw cms::Exception("unable to parse header: ")<<line; 00038 } 00039 fieldNames=headerParser.result(); 00040 } 00041 if(counter==1) { 00042 if(!headerParser.parse(line)) { 00043 } 00044 fieldTypes=headerParser.result(); 00045 int idx=0; 00046 for(std::vector<std::string>::iterator it=fieldTypes.begin(); it!=fieldTypes.end(); ++it, ++idx){ 00047 std::cout<<fieldNames[idx]<<":"<<*it<<std::endl; 00048 m_fieldMap.push_back(fieldNames[idx],*it); 00049 } 00050 } 00051 ++counter; 00052 continue; 00053 } 00054 if(!dataParser.parse(line)) { 00055 throw cms::Exception("unable to parse data :")<<line; 00056 } 00057 std::vector<boost::any> result=dataParser.result(); 00058 OpticalAlignInfo* oaInfo = new OpticalAlignInfo; 00059 std::string theLastExtraEntryName; 00060 OpticalAlignParam* theLastExtraEntry = 0; 00061 std::vector<OpticalAlignParam*> theExtraEntries; 00062 00063 int idx=0; 00064 for(std::vector<boost::any>::iterator it=result.begin(); it!=result.end(); ++it, ++idx){ 00065 std::string fieldName=m_fieldMap.fieldName(idx); 00066 // std::cout << " idx " << idx << " = " << fieldName << std::endl; 00067 if(fieldName=="ID"){ 00068 //std::cout<<"fieldName "<<fieldName<<" field type "<<m_fieldMap.fieldTypeName(idx)<<std::endl; 00069 if( m_fieldMap.fieldType(idx)!= typeid(int) ) throw cond::Exception("unexpected type"); 00070 oaInfo->ID_=boost::any_cast<int>(*it); 00071 } else if(fieldName=="type"){ 00072 //std::cout<<"fieldName "<<fieldName<<" field type "<<m_fieldMap.fieldTypeName(idx)<<std::endl; 00073 if( m_fieldMap.fieldType(idx)!= typeid(std::string) ) throw cond::Exception("unexpected type"); 00074 oaInfo->type_=boost::any_cast<std::string>(*it); 00075 } 00076 if(fieldName=="name"){ 00077 //std::cout<<"fieldName "<<fieldName<<" field type "<<m_fieldMap.fieldTypeName(idx)<<std::endl; 00078 if( m_fieldMap.fieldType(idx)!= typeid(std::string) ) throw cond::Exception("unexpected type"); 00079 oaInfo->name_=boost::any_cast<std::string>(*it); 00080 } 00081 if(fieldName=="centre_X"){ 00082 if( m_fieldMap.fieldType(idx) != typeid(float) ) throw cond::Exception("unexpected type"); 00083 oaInfo->x_.value_=boost::any_cast<double>(*it); 00084 } else if(fieldName=="centre_Y"){ 00085 if( m_fieldMap.fieldType(idx) != typeid(float) ) throw cond::Exception("unexpected type"); 00086 oaInfo->y_.value_=boost::any_cast<double>(*it); 00087 } else if(fieldName=="centre_Z"){ 00088 if( m_fieldMap.fieldType(idx) != typeid(float) ) throw cond::Exception("unexpected type"); 00089 oaInfo->z_.value_=boost::any_cast<double>(*it); 00090 } else if(fieldName=="centre_sigma_X" || fieldName=="centre_error_X"){ 00091 if( m_fieldMap.fieldType(idx) != typeid(float) ) throw cond::Exception("unexpected type"); 00092 oaInfo->x_.error_=boost::any_cast<double>(*it); 00093 } else if(fieldName=="centre_sigma_Y" || fieldName=="centre_error_Y"){ 00094 if( m_fieldMap.fieldType(idx) != typeid(float) ) throw cond::Exception("unexpected type"); 00095 oaInfo->y_.error_=boost::any_cast<double>(*it); 00096 } else if(fieldName=="centre_sigma_Z" || fieldName=="centre_error_Z"){ 00097 if( m_fieldMap.fieldType(idx) != typeid(float) ) throw cond::Exception("unexpected type"); 00098 oaInfo->z_.error_=boost::any_cast<double>(*it); 00099 } else if(fieldName=="angles_X"){ 00100 if( m_fieldMap.fieldType(idx) != typeid(float) ) throw cond::Exception("unexpected type"); 00101 oaInfo->angx_.value_=boost::any_cast<double>(*it); 00102 } else if(fieldName=="angles_Y"){ 00103 if( m_fieldMap.fieldType(idx) != typeid(float) ) throw cond::Exception("unexpected type"); 00104 oaInfo->angy_.value_=boost::any_cast<double>(*it); 00105 } else if(fieldName=="angles_Z"){ 00106 if( m_fieldMap.fieldType(idx) != typeid(float) ) throw cond::Exception("unexpected type"); 00107 oaInfo->angz_.value_=boost::any_cast<double>(*it); 00108 } else if(fieldName=="angles_sigma_X" || fieldName=="angles_error_X"){ 00109 if( m_fieldMap.fieldType(idx) != typeid(float) ) throw cond::Exception("unexpected type"); 00110 oaInfo->angx_.error_=boost::any_cast<double>(*it); 00111 } else if(fieldName=="angles_sigma_Y" || fieldName=="angles_error_Y"){ 00112 if( m_fieldMap.fieldType(idx) != typeid(float) ) throw cond::Exception("unexpected type"); 00113 oaInfo->angy_.error_=boost::any_cast<double>(*it); 00114 } else if(fieldName=="angles_sigma_Z" || fieldName=="angles_error_Z"){ 00115 if( m_fieldMap.fieldType(idx) != typeid(float) ) throw cond::Exception("unexpected type"); 00116 oaInfo->angz_.error_=boost::any_cast<double>(*it); 00117 } else if( fieldName.substr(0,5) == "param" && fieldName.substr(fieldName.length()-4,4) == "name"){ 00118 if( m_fieldMap.fieldType(idx) != typeid(std::string) ) throw cond::Exception("unexpected type"); 00119 std::string name = boost::any_cast<std::string>(*it); 00120 theLastExtraEntry = new OpticalAlignParam; 00121 theExtraEntries.push_back( theLastExtraEntry ); 00122 theLastExtraEntry->name_ = name; 00123 if( name != "None" ){ 00124 theLastExtraEntryName = name; 00125 } 00126 } else if( fieldName.substr(0,5) == "param" && fieldName.substr(fieldName.length()-5,5) == "value"){ 00127 if( m_fieldMap.fieldType(idx) != typeid(float) ) throw cond::Exception("unexpected type"); 00128 if( boost::any_cast<double>(*it) != -9.999E9 ){ 00129 if( theLastExtraEntryName == "None" ) throw cond::Exception("unexpected type: setting a value != -9.999E9 for a parameter that is 'None' "); 00130 theLastExtraEntry->value_ = boost::any_cast<double>(*it); 00131 } 00132 } else if( fieldName.substr(0,5) == "param" && ( fieldName.substr(fieldName.length()-5,5) == "sigma" || fieldName.substr(fieldName.length()-5,5) == "error") ) { 00133 if( m_fieldMap.fieldType(idx) != typeid(float) ) throw cond::Exception("unexpected type"); 00134 if( boost::any_cast<double>(*it) != -9.999E9 ){ 00135 if( theLastExtraEntryName == "None" ) throw cond::Exception("unexpected type: setting an error != -9.999E9 for a parameter that is 'None' "); 00136 theLastExtraEntry->error_ = boost::any_cast<double>(*it); 00137 } 00138 } // end loop to one oaInfo 00139 } 00140 00141 for( size_t kk = 0; kk < theExtraEntries.size(); kk++) { 00142 oaInfo->extraEntries_.push_back( *(theExtraEntries[kk]) ); 00143 delete theExtraEntries[kk]; 00144 } 00145 00146 myobj->opticalAlignments_.push_back(*oaInfo); 00147 std::cout << " OptAlignInfo read " << *oaInfo << std::endl; 00148 00149 delete oaInfo; 00150 ++counter; 00151 } 00152 myfile.close(); 00153 edm::Service<cond::service::PoolDBOutputService> mydbservice; 00154 if( mydbservice.isAvailable() ){ 00155 try{ 00156 if ( mydbservice->isNewTagRequest( "OpticalAlignmentsRcd" ) ) 00157 mydbservice->createNewIOV<OpticalAlignments>(myobj, 00158 mydbservice->endOfTime(), 00159 "OpticalAlignmentsRcd"); 00160 else 00161 mydbservice->appendSinceTime<OpticalAlignments>( myobj, 00162 mydbservice->endOfTime(), 00163 "OpticalAlignmentsRcd"); 00164 }catch(const cond::Exception& er){ 00165 std::cout<<er.what()<<std::endl; 00166 }catch(const std::exception& er){ 00167 std::cout<<"caught std::exception "<<er.what()<<std::endl; 00168 }catch(...){ 00169 std::cout<<"Funny error"<<std::endl; 00170 } 00171 } 00172 std::cout << "@@@@ OPTICALALIGNMENTS WRITTEN TO DB " << *myobj << std::endl; 00173 }
CSVFieldMap OptAlignDataConverter::m_fieldMap [private] |
std::string OptAlignDataConverter::m_inFileName [private] |