CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CondTools/SiPixel/src/PixelPopConCalibSourceHandler.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    CondTools/SiPixel
00004 // Class:      PixelPopConCalibSourceHandler
00005 // 
00013 //
00014 // Original Author:  Michael Eads
00015 //         Created:  8 Feb 2008
00016 // $Id: PixelPopConCalibSourceHandler.cc,v 1.4 2010/06/02 06:10:11 ursl Exp $
00017 //
00018 //
00019 
00020 #include "CondTools/SiPixel/interface/PixelPopConCalibSourceHandler.h"
00021 
00022 #include <iostream>
00023 #include <sstream>
00024 
00025 // DBCommon includes
00026 // #include "CondCore/DBCommon/interface/SessionConfiguration.h"
00027 // #include "CondCore/DBCommon/interface/Exception.h"
00028 // #include "CondCore/DBCommon/interface/Connection.h"
00029 
00030 // CORAL includes
00031 // #include "RelationalAccess/IView.h"
00032 // #include "RelationalAccess/ISessionProxy.h"
00033 // #include "RelationalAccess/ISchema.h"
00034 // #include "RelationalAccess/ISessionProperties.h"
00035 // #include "RelationalAccess/IQuery.h"
00036 // #include "RelationalAccess/ICursor.h"
00037 // #include "CoralBase/AttributeList.h"
00038 // #include "CoralBase/Attribute.h"
00039 
00040 #include "CalibFormats/SiPixelObjects/interface/PixelCalibConfiguration.h"
00041 
00042 // test poolDBOutput
00043 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00044 #include "FWCore/ServiceRegistry/interface/Service.h"
00045 
00046 
00047 using namespace std;
00048 
00049 // constructor
00050 PixelPopConCalibSourceHandler::PixelPopConCalibSourceHandler(edm::ParameterSet const &pset) {
00051 
00052   // try to get a parameter
00053   _connectString = pset.getParameter<string>("connectString");
00054   //cout << "  connectString: " << _connectString << endl;
00055 
00056   // get the schema and view name to use from the config file
00057   _viewName = pset.getParameter<string>("viewName");
00058   _schemaName = pset.getParameter<string>("schemaName");  
00059 
00060   // get the key name and/or run number to use
00061   _runNumber = pset.getParameter<int>("runNumber");
00062   _configKeyName = pset.getParameter<string>("configKeyName");
00063 
00064   // get the "since" IOV parameter
00065   _sinceIOV = pset.getParameter<unsigned int>("sinceIOV");
00066   
00067 } // constructor
00068 
00069 // destructor
00070 PixelPopConCalibSourceHandler::~PixelPopConCalibSourceHandler() {
00071 
00072 } // destructor
00073 
00074 string PixelPopConCalibSourceHandler::id() const {
00075 
00076   return string("PixelPopConCalibSourceHandler");
00077 
00078 } // string PixelPopConCalibSourceHandler::id()
00079 
00080 
00081 // getNewObjects method using coral 
00082 void PixelPopConCalibSourceHandler::getNewObjects_coral() {
00083         cout << "I'm sorry, the PixelPopConCalibSourceHandler::getNewObjects_coral() is not currently working." << endl;
00084         cout << "I am not able to build calibration configuration objects from the database" << endl;
00085         return;
00086         
00087 //   // create the empty SiPixelCalibConfiguration object
00088 //   SiPixelCalibConfiguration* calibConfig = new SiPixelCalibConfiguration();
00089   
00090 //   // set up the DB session
00091 //   cond::DBSession* dbsession = new cond::DBSession();
00092 //   dbsession->configuration().setAuthenticationMethod(cond::XML);
00093 //   dbsession->configuration().setMessageLevel(cond::Error);
00094 //   try{
00095 //     dbsession->open();
00096 //   }catch(cond::Exception& er){
00097 //     std::cerr<< "CoralIface::initialize cond " << er.what()<<std::endl;
00098 //     throw;
00099 //   }catch(std::exception& er){
00100 //     std::cerr<< "CoralIface::initialize std " << er.what()<<std::endl;
00101 //     throw;
00102 //   }
00103 
00104 //   cond::Connection dbconn(_connectString);
00105 //   dbconn.connect(dbsession);
00106 //   cond::CoralTransaction& coraldb=dbconn.coralTransaction();
00107 //   coraldb.start(true);
00108 
00109 //   // build and execute the query
00110 //   coral::IQuery* query = coraldb.coralSessionProxy().schema(_schemaName).newQuery();
00111 //   query->addToTableList(_viewName);
00112 //   query->addToOutputList("CONFG_KEY");
00113 //   query->addToOutputList("VERSION");
00114 //   query->addToOutputList("RUN_TYPE");
00115 //   query->addToOutputList("RUN_NUMBER");
00116 //   query->addToOutputList("CALIB_OBJ_DATA_FILE");
00117 //   query->addToOutputList("CALIB_OBJ_DATA_CLOB");
00118 
00119 //   // if _runNumber is -1, query by config key name
00120 //   if (_runNumber == -1)
00121 //     query->setCondition("CONFG_KEY = '" + _configKeyName + "'", coral::AttributeList());
00122 //   else // query by run number
00123 //     query->setCondition("RUN_NUMBER = " + _runNumber, coral::AttributeList());
00124 //   coral::ICursor& cursor = query->execute();
00125 
00126 //   // parse the response, build the Calib object
00127 //   bool found_fNtriggers = false;
00128 //   bool found_fRowPattern = false;
00129 //   bool found_fColumnPattern = false;
00130 //   bool found_fVCalValues = false;
00131 //   bool found_fMode = false;
00132 //   while ( cursor.next() ) {
00133 //        cout << "Inside cursor.next() loop" << endl;
00134 //     //cursor.currentRow().toOutputStream( std::cout ) << std::endl;
00135 //     coral::AttributeList row = cursor.currentRow();
00136     
00137 //     string mystring = row["CALIB_OBJ_DATA_CLOB"].data<string>();
00138 //     cout << "mystring: " << mystring << endl;
00139 
00140 //     // get fMode
00141 //     if (!found_fMode) {
00142 //       calibConfig->setCalibrationMode(row["CALIB_MODE"].data<string>());
00143 //       found_fMode = true;
00144 //     } // if (!found_fMode)
00145 
00146 //     // fill fNTriggers
00147 //     if (row["PARAMETER"].data<string>() == "Number of Triggers") {
00148 //       if (found_fNtriggers) {
00149 //      cout << "Warning: found mulitple entries for fNtriggers!" << endl;
00150 //       }
00151 //       int fNtriggers = atoi(row["VALUE"].data<string>().c_str());
00152 //       //cout << "Number of triggers: " << fNtriggers << endl;
00153 //       calibConfig->setNTriggers(static_cast<short>(fNtriggers));
00154 //       found_fNtriggers = true;
00155 //     } // fill fNTriggers
00156 
00157 //     /*
00158 //     // fill fROCIds
00159 //     if (row["PARAMETER"].data<string>() == "ROC") {
00160 //       if (found_fROCIds) {
00161 //      cout << "Warning: found mulitple entries for fROCIds!" << endl;
00162 //       }
00163 //       string rocidlist = row["VALUE"].data<string>();
00164 //       // split the string
00165 //       string buff;
00166 //       vector<string> ROCIds;
00167 //       stringstream ss(rocidlist);
00168 //       while (ss >> buff) {
00169 //      ROCIds.push_back(buff);
00170 //       }
00171 //       calibConfig->setROCIds(ROCIds);
00172 //       found_fROCIds = true;
00173 //     } // fill fROCIds
00174 //     */
00175 
00176 //     // fill fRowPattern
00177 //     if (row["PARAMETER"].data<string>() == "RowNums") {
00178 //       if (found_fRowPattern) {
00179 //      cout << "Warning: found mulitple entries for fRowPattern!" << endl;
00180 //       }
00181 //       string rowlist = row["VALUE"].data<string>();
00182 //       // split the string
00183 //       string buff;
00184 //       vector<short> rows;
00185 //       stringstream ss(rowlist);
00186 //       while (ss >> buff) {
00187 //      rows.push_back(static_cast<short>(atoi(buff.c_str())));
00188 //       }
00189 //       calibConfig->setRowPattern(rows);
00190 //       found_fRowPattern = true;
00191 //     } // fill fRowPattern
00192 
00193 //     // fill fColumnPattern
00194 //     if (row["PARAMETER"].data<string>() == "ColNums") {
00195 //       if (found_fColumnPattern) {
00196 //      cout << "Warning: found mulitple entries for fColumnPattern!" << endl;
00197 //       }
00198 //       string collist = row["VALUE"].data<string>();
00199 //       // split the string
00200 //       string buff;
00201 //       vector<short> cols;
00202 //       stringstream ss(collist);
00203 //       while (ss >> buff) {
00204 //      cols.push_back(static_cast<short>(atoi(buff.c_str())));
00205 //       }
00206 //       calibConfig->setColumnPattern(cols);
00207 //       found_fColumnPattern = true;
00208 //     } // fill fColumnPattern
00209 
00210 //     // fill fVCalValues
00211 //     if (row["CALIB_OBJECT"].data<string>() == "Vcal DAC") {
00212 //       if (found_fVCalValues) {
00213 //      cout << "Warning: found mulitple entries for fVCalValues!" << endl;
00214 //       }
00215 //       string vcallist = row["VALUE"].data<string>();
00216 //       // split the string
00217 //       string buff;
00218 //       vector<short> vcals;
00219 //       stringstream ss(vcallist);
00220 //       while (ss >> buff) {
00221 //      vcals.push_back(static_cast<short>(atoi(buff.c_str())));
00222 //       }
00223 //       calibConfig->setVCalValues(vcals);
00224 //       found_fVCalValues = true;
00225 //     } // fill fRowPattern
00226 
00227 //     /*
00228 //     for (coral::AttributeList::iterator it = row.begin();
00229 //       it != row.end(); ++it) {
00230 //       if it->specification().name() == "PARAMETER"
00231 
00232 //       if (it->specification().name() == "RUN_NUMBER")
00233 //      cout << it->specification().name() << ", " << it->data<long long>() << endl;
00234 //       else
00235 //      cout << it->specification().name() << ", " << it->data<string>() << endl;
00236     
00237 //     } // loop over attribute list
00238 //     */
00239 //   } // while (cursor.next())
00240 
00241 //   // spit out calibConfig object
00242 //   cout << endl << "** calibConfig: " << endl;
00243 //   cout << "      fNtriggers: " << calibConfig->getNTriggers() << endl;
00244 //   /*
00245 //   cout << "      fROCIds: ";
00246 //   vector<string> rocids = calibConfig->getROCIds();
00247 //   for (vector<string>::const_iterator it = rocids.begin();
00248 //        it != rocids.end(); ++it)
00249 //     cout << *it << ", ";
00250 //   cout << endl;
00251 //   */
00252 //   cout << "      fRowPattern: ";
00253 //   vector<short> rowpattern = calibConfig->getRowPattern();
00254 //   for (vector<short>::const_iterator it = rowpattern.begin();
00255 //        it != rowpattern.end(); ++it)
00256 //     cout << *it << ", ";
00257 //   cout << endl;
00258 //   cout << "      fColumnPattern: ";
00259 //   vector<short> columnpattern = calibConfig->getColumnPattern();
00260 //   for (vector<short>::const_iterator it = columnpattern.begin();
00261 //        it != columnpattern.end(); ++it)
00262 //     cout << *it << ", ";
00263 //   cout << endl;
00264 //   cout << "      fVcalValues: ";
00265 //   vector<short> vcalvalues = calibConfig->getVCalValues();
00266 //   for (vector<short>::const_iterator it = vcalvalues.begin();
00267 //        it != vcalvalues.end(); ++it)
00268 //     cout << *it << ", ";
00269 //   cout << endl;
00270 //   cout << "      fNmode: " << calibConfig->getCalibrationMode() << endl;
00271 
00272 //   // see what's in the db
00273 //   //cout << "tagInfo: " << tagInfo().name << ", " << tagInfo().lastInterval.first << endl;
00274 
00275 //   m_to_transfer.push_back(std::make_pair(calibConfig,_sinceIOV));
00276 
00277 
00278 //   delete dbsession;
00279 } // void PixelPopConCalibSourceHandler::getNewObjects_coral()
00280 
00281 // getNewObjects method using a text file
00282 void PixelPopConCalibSourceHandler::getNewObjects_file() {
00283         // check to make sure the _connectString begins with "file//"
00284         if (_connectString.find("file://") != 0) {
00285                 cout << "Invalid connectString: " << _connectString << endl;
00286                 cout << "It should begin with \"file://\"" << endl;
00287                 return;
00288         }
00289         // strip the "file://" from the connect string
00290         string inputFilename = _connectString.erase(0, 7);
00291         
00292         cout << "PopCon-ing the calibration configuration file located at " << inputFilename << endl;
00293 
00294         // use online code to parse the file
00295         pos::PixelCalibConfiguration fancyCalib(inputFilename);
00296         SiPixelCalibConfiguration *calibConfig = new SiPixelCalibConfiguration(fancyCalib);
00297         
00298         m_to_transfer.push_back(std::make_pair(calibConfig, _sinceIOV));
00299   
00300 } // void PixelPopConCalibSourceHandler::getNewObjects_file()
00301