Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-12 00:00:55

0001 // -*- C++ -*-
0002 //
0003 // Package:    CondTools/SiPixel
0004 // Class:      PixelPopConCalibSourceHandler
0005 //
0006 /**\class PixelPopConCalibSourcehandler PixelPopConCalibSourceHandler.cc CondTools/SiPixel/src/PixelPopConCalibSourceHandler.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Michael Eads
0015 //         Created:  8 Feb 2008
0016 // $Id: PixelPopConCalibSourceHandler.cc,v 1.3 2010/01/21 21:11:46 meads Exp $
0017 //
0018 //
0019 
0020 #include "CondTools/SiPixel/interface/PixelPopConCalibSourceHandler.h"
0021 
0022 #include <iostream>
0023 #include <sstream>
0024 
0025 // DBCommon includes
0026 // #include "CondCore/DBCommon/interface/SessionConfiguration.h"
0027 // #include "CondCore/DBCommon/interface/Exception.h"
0028 // #include "CondCore/DBCommon/interface/Connection.h"
0029 
0030 // CORAL includes
0031 // #include "RelationalAccess/IView.h"
0032 // #include "RelationalAccess/ISessionProxy.h"
0033 // #include "RelationalAccess/ISchema.h"
0034 // #include "RelationalAccess/ISessionProperties.h"
0035 // #include "RelationalAccess/IQuery.h"
0036 // #include "RelationalAccess/ICursor.h"
0037 // #include "CoralBase/AttributeList.h"
0038 // #include "CoralBase/Attribute.h"
0039 
0040 #include "CalibFormats/SiPixelObjects/interface/PixelCalibConfiguration.h"
0041 
0042 // test poolDBOutput
0043 #include "FWCore/ServiceRegistry/interface/Service.h"
0044 
0045 using namespace std;
0046 
0047 // constructor
0048 PixelPopConCalibSourceHandler::PixelPopConCalibSourceHandler(edm::ParameterSet const &pset) {
0049   // try to get a parameter
0050   _connectString = pset.getParameter<string>("connectString");
0051   //cout << "  connectString: " << _connectString << endl;
0052 
0053   // get the schema and view name to use from the config file
0054   _viewName = pset.getParameter<string>("viewName");
0055   _schemaName = pset.getParameter<string>("schemaName");
0056 
0057   // get the key name and/or run number to use
0058   _runNumber = pset.getParameter<int>("runNumber");
0059   _configKeyName = pset.getParameter<string>("configKeyName");
0060 
0061   // get the "since" IOV parameter
0062   _sinceIOV = pset.getParameter<unsigned int>("sinceIOV");
0063 
0064 }  // constructor
0065 
0066 // destructor
0067 PixelPopConCalibSourceHandler::~PixelPopConCalibSourceHandler() {}  // destructor
0068 
0069 string PixelPopConCalibSourceHandler::id() const {
0070   return string("PixelPopConCalibSourceHandler");
0071 
0072 }  // string PixelPopConCalibSourceHandler::id()
0073 
0074 // getNewObjects method using coral
0075 void PixelPopConCalibSourceHandler::getNewObjects_coral() {
0076   cout << "I'm sorry, the PixelPopConCalibSourceHandler::getNewObjects_coral() is not currently working." << endl;
0077   cout << "I am not able to build calibration configuration objects from the database" << endl;
0078   return;
0079 
0080   //   // create the empty SiPixelCalibConfiguration object
0081   //   SiPixelCalibConfiguration* calibConfig = new SiPixelCalibConfiguration();
0082 
0083   //   // set up the DB session
0084   //   cond::DBSession* dbsession = new cond::DBSession();
0085   //   dbsession->configuration().setAuthenticationMethod(cond::XML);
0086   //   dbsession->configuration().setMessageLevel(cond::Error);
0087   //   try{
0088   //     dbsession->open();
0089   //   }catch(cond::Exception& er){
0090   //     std::cerr<< "CoralIface::initialize cond " << er.what()<<std::endl;
0091   //     throw;
0092   //   }catch(std::exception& er){
0093   //     std::cerr<< "CoralIface::initialize std " << er.what()<<std::endl;
0094   //     throw;
0095   //   }
0096 
0097   //   cond::Connection dbconn(_connectString);
0098   //   dbconn.connect(dbsession);
0099   //   cond::CoralTransaction& coraldb=dbconn.coralTransaction();
0100   //   coraldb.start(true);
0101 
0102   //   // build and execute the query
0103   //   coral::IQuery* query = coraldb.coralSessionProxy().schema(_schemaName).newQuery();
0104   //   query->addToTableList(_viewName);
0105   //   query->addToOutputList("CONFG_KEY");
0106   //   query->addToOutputList("VERSION");
0107   //   query->addToOutputList("RUN_TYPE");
0108   //   query->addToOutputList("RUN_NUMBER");
0109   //   query->addToOutputList("CALIB_OBJ_DATA_FILE");
0110   //   query->addToOutputList("CALIB_OBJ_DATA_CLOB");
0111 
0112   //   // if _runNumber is -1, query by config key name
0113   //   if (_runNumber == -1)
0114   //     query->setCondition("CONFG_KEY = '" + _configKeyName + "'", coral::AttributeList());
0115   //   else // query by run number
0116   //     query->setCondition("RUN_NUMBER = " + _runNumber, coral::AttributeList());
0117   //   coral::ICursor& cursor = query->execute();
0118 
0119   //   // parse the response, build the Calib object
0120   //   bool found_fNtriggers = false;
0121   //   bool found_fRowPattern = false;
0122   //   bool found_fColumnPattern = false;
0123   //   bool found_fVCalValues = false;
0124   //   bool found_fMode = false;
0125   //   while ( cursor.next() ) {
0126   //      cout << "Inside cursor.next() loop" << endl;
0127   //     //cursor.currentRow().toOutputStream( std::cout ) << std::endl;
0128   //     coral::AttributeList row = cursor.currentRow();
0129 
0130   //     string mystring = row["CALIB_OBJ_DATA_CLOB"].data<string>();
0131   //     cout << "mystring: " << mystring << endl;
0132 
0133   //     // get fMode
0134   //     if (!found_fMode) {
0135   //       calibConfig->setCalibrationMode(row["CALIB_MODE"].data<string>());
0136   //       found_fMode = true;
0137   //     } // if (!found_fMode)
0138 
0139   //     // fill fNTriggers
0140   //     if (row["PARAMETER"].data<string>() == "Number of Triggers") {
0141   //       if (found_fNtriggers) {
0142   //    cout << "Warning: found mulitple entries for fNtriggers!" << endl;
0143   //       }
0144   //       int fNtriggers = atoi(row["VALUE"].data<string>().c_str());
0145   //       //cout << "Number of triggers: " << fNtriggers << endl;
0146   //       calibConfig->setNTriggers(static_cast<short>(fNtriggers));
0147   //       found_fNtriggers = true;
0148   //     } // fill fNTriggers
0149 
0150   //     /*
0151   //     // fill fROCIds
0152   //     if (row["PARAMETER"].data<string>() == "ROC") {
0153   //       if (found_fROCIds) {
0154   //    cout << "Warning: found mulitple entries for fROCIds!" << endl;
0155   //       }
0156   //       string rocidlist = row["VALUE"].data<string>();
0157   //       // split the string
0158   //       string buff;
0159   //       vector<string> ROCIds;
0160   //       stringstream ss(rocidlist);
0161   //       while (ss >> buff) {
0162   //    ROCIds.push_back(buff);
0163   //       }
0164   //       calibConfig->setROCIds(ROCIds);
0165   //       found_fROCIds = true;
0166   //     } // fill fROCIds
0167   //     */
0168 
0169   //     // fill fRowPattern
0170   //     if (row["PARAMETER"].data<string>() == "RowNums") {
0171   //       if (found_fRowPattern) {
0172   //    cout << "Warning: found mulitple entries for fRowPattern!" << endl;
0173   //       }
0174   //       string rowlist = row["VALUE"].data<string>();
0175   //       // split the string
0176   //       string buff;
0177   //       vector<short> rows;
0178   //       stringstream ss(rowlist);
0179   //       while (ss >> buff) {
0180   //    rows.push_back(static_cast<short>(atoi(buff.c_str())));
0181   //       }
0182   //       calibConfig->setRowPattern(rows);
0183   //       found_fRowPattern = true;
0184   //     } // fill fRowPattern
0185 
0186   //     // fill fColumnPattern
0187   //     if (row["PARAMETER"].data<string>() == "ColNums") {
0188   //       if (found_fColumnPattern) {
0189   //    cout << "Warning: found mulitple entries for fColumnPattern!" << endl;
0190   //       }
0191   //       string collist = row["VALUE"].data<string>();
0192   //       // split the string
0193   //       string buff;
0194   //       vector<short> cols;
0195   //       stringstream ss(collist);
0196   //       while (ss >> buff) {
0197   //    cols.push_back(static_cast<short>(atoi(buff.c_str())));
0198   //       }
0199   //       calibConfig->setColumnPattern(cols);
0200   //       found_fColumnPattern = true;
0201   //     } // fill fColumnPattern
0202 
0203   //     // fill fVCalValues
0204   //     if (row["CALIB_OBJECT"].data<string>() == "Vcal DAC") {
0205   //       if (found_fVCalValues) {
0206   //    cout << "Warning: found mulitple entries for fVCalValues!" << endl;
0207   //       }
0208   //       string vcallist = row["VALUE"].data<string>();
0209   //       // split the string
0210   //       string buff;
0211   //       vector<short> vcals;
0212   //       stringstream ss(vcallist);
0213   //       while (ss >> buff) {
0214   //    vcals.push_back(static_cast<short>(atoi(buff.c_str())));
0215   //       }
0216   //       calibConfig->setVCalValues(vcals);
0217   //       found_fVCalValues = true;
0218   //     } // fill fRowPattern
0219 
0220   //     /*
0221   //     for (coral::AttributeList::iterator it = row.begin();
0222   //     it != row.end(); ++it) {
0223   //       if it->specification().name() == "PARAMETER"
0224 
0225   //       if (it->specification().name() == "RUN_NUMBER")
0226   //    cout << it->specification().name() << ", " << it->data<long long>() << endl;
0227   //       else
0228   //    cout << it->specification().name() << ", " << it->data<string>() << endl;
0229 
0230   //     } // loop over attribute list
0231   //     */
0232   //   } // while (cursor.next())
0233 
0234   //   // spit out calibConfig object
0235   //   cout << endl << "** calibConfig: " << endl;
0236   //   cout << "      fNtriggers: " << calibConfig->getNTriggers() << endl;
0237   //   /*
0238   //   cout << "      fROCIds: ";
0239   //   vector<string> rocids = calibConfig->getROCIds();
0240   //   for (vector<string>::const_iterator it = rocids.begin();
0241   //        it != rocids.end(); ++it)
0242   //     cout << *it << ", ";
0243   //   cout << endl;
0244   //   */
0245   //   cout << "      fRowPattern: ";
0246   //   vector<short> rowpattern = calibConfig->getRowPattern();
0247   //   for (vector<short>::const_iterator it = rowpattern.begin();
0248   //        it != rowpattern.end(); ++it)
0249   //     cout << *it << ", ";
0250   //   cout << endl;
0251   //   cout << "      fColumnPattern: ";
0252   //   vector<short> columnpattern = calibConfig->getColumnPattern();
0253   //   for (vector<short>::const_iterator it = columnpattern.begin();
0254   //        it != columnpattern.end(); ++it)
0255   //     cout << *it << ", ";
0256   //   cout << endl;
0257   //   cout << "      fVcalValues: ";
0258   //   vector<short> vcalvalues = calibConfig->getVCalValues();
0259   //   for (vector<short>::const_iterator it = vcalvalues.begin();
0260   //        it != vcalvalues.end(); ++it)
0261   //     cout << *it << ", ";
0262   //   cout << endl;
0263   //   cout << "      fNmode: " << calibConfig->getCalibrationMode() << endl;
0264 
0265   //   // see what's in the db
0266   //   //cout << "tagInfo: " << tagInfo().name << ", " << tagInfo().lastInterval.first << endl;
0267 
0268   //   m_to_transfer.push_back(std::make_pair(calibConfig,_sinceIOV));
0269 
0270   //   delete dbsession;
0271 }  // void PixelPopConCalibSourceHandler::getNewObjects_coral()
0272 
0273 // getNewObjects method using a text file
0274 void PixelPopConCalibSourceHandler::getNewObjects_file() {
0275   // check to make sure the _connectString begins with "file//"
0276   if (_connectString.find("file://") != 0) {
0277     cout << "Invalid connectString: " << _connectString << endl;
0278     cout << "It should begin with \"file://\"" << endl;
0279     return;
0280   }
0281   // strip the "file://" from the connect string
0282   string inputFilename = _connectString.erase(0, 7);
0283 
0284   cout << "PopCon-ing the calibration configuration file located at " << inputFilename << endl;
0285 
0286   // use online code to parse the file
0287   pos::PixelCalibConfiguration fancyCalib(inputFilename);
0288   auto calibConfig = std::make_shared<SiPixelCalibConfiguration>(fancyCalib);
0289 
0290   m_iovs.insert(std::make_pair(_sinceIOV, calibConfig));
0291 
0292 }  // void PixelPopConCalibSourceHandler::getNewObjects_file()