CMS 3D CMS Logo

DTCCBConfigHandler Class Reference

Description:. More...

#include <CondTools/DT/interface/DTCCBConfigHandler.h>

Inheritance diagram for DTCCBConfigHandler:

popcon::PopConSourceHandler< DTCCBConfig >

List of all members.

Public Member Functions

 DTCCBConfigHandler (const edm::ParameterSet &ps)
 Constructor.
void getNewObjects ()
 Operations.
std::string id () const
virtual ~DTCCBConfigHandler ()
 Destructor.

Private Member Functions

void chkConfigList ()

Private Attributes

DTCCBConfigccbConfig
std::string dataTag
coral::ISessionProxy * isession
std::string listToken
std::string offlineAuthentication
std::string offlineCatalog
std::string offlineConnect
std::string onlineAuthentication
std::string onlineConnect


Detailed Description

Description:.

Date
2008/02/15 18:15:02
Revision
1.3
Author:
Paolo Ronchese INFN Padova

Definition at line 39 of file DTCCBConfigHandler.h.


Constructor & Destructor Documentation

DTCCBConfigHandler::DTCCBConfigHandler ( const edm::ParameterSet ps  ) 

Constructor.

Definition at line 49 of file DTCCBConfigHandler.cc.

References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), offlineAuthentication, and onlineAuthentication.

00049                                                                  :
00050  dataTag(               ps.getParameter<std::string> ( "tag" ) ),
00051  onlineConnect(         ps.getParameter<std::string> ( "onlineDB" ) ),
00052  onlineAuthentication(  ps.getParameter<std::string> ( 
00053                         "onlineAuthentication" ) ),
00054  offlineAuthentication( ps.getParameter<edm::ParameterSet>( "DBParameters" )
00055                           .getUntrackedParameter<std::string> (
00056                         "authenticationPath" ) ),
00057 // catalog(               ps.getParameter<std::string> ( "catalog" ) ),
00058  listToken(             ps.getParameter<std::string> ( "token" ) ) {
00059   std::cout <<  onlineAuthentication << " "
00060             << offlineAuthentication << std::endl;
00061 }

DTCCBConfigHandler::~DTCCBConfigHandler (  )  [virtual]

Destructor.

Definition at line 66 of file DTCCBConfigHandler.cc.

00066                                         {
00067 }


Member Function Documentation

void DTCCBConfigHandler::chkConfigList (  )  [private]

Definition at line 255 of file DTCCBConfigHandler.cc.

References DTConfigData::add(), DTConfigList::begin(), DTDBSession::connect(), GenMuonPlsPt100GeV_cfg::cout, DTConfigHandler::create(), DTDBSession::disconnect(), DTConfigList::end(), lat::endl(), DTConfigHandler::get(), DTConfigHandler::getContainer(), isession, iter, listToken, offlineAuthentication, offlineCatalog, offlineConnect, DTDBSession::poolDB(), row, python::TagTree::session, DTConfigHandler::set(), and DTConfigData::setId().

Referenced by getNewObjects().

00255                                        {
00256   std::cout << "create session: "
00257             << offlineConnect << " , "
00258             << offlineCatalog << " , "
00259             << offlineAuthentication << std::endl;
00260 
00261   DTDBSession* session = new DTDBSession( offlineConnect, offlineCatalog,
00262                                           offlineAuthentication );
00263   session->connect( false );
00264   const DTConfigList* rs;
00265   std::cout << "read full list: " << listToken << std::endl;
00266   DTConfigHandler* ri = DTConfigHandler::create( session, listToken );
00267   rs = ri->getContainer();
00268   DTConfigList::const_iterator iter = rs->begin();
00269   DTConfigList::const_iterator iend = rs->end();
00270   while ( iter != iend ) {
00271     int id = iter->first;
00272     std::cout << "brick " << id
00273               << " -> "   << iter->second.ref << std::endl;
00274     std::cout << "========> " << std::endl;
00275     iter++;
00276   }
00277 
00278   coral::ITable& fullConfigTable =
00279     isession->nominalSchema().tableHandle( "CONFIGSETS" );
00280   std::auto_ptr<coral::IQuery>
00281     fullConfigQuery( fullConfigTable.newQuery() );
00282   fullConfigQuery->addToOutputList( "CONFKEY" );
00283   fullConfigQuery->addToOutputList( "NAME" );
00284   coral::ICursor& fullConfigCursor = fullConfigQuery->execute();
00285   while( fullConfigCursor.next() ) {
00286     const coral::AttributeList& row = fullConfigCursor.currentRow();
00287     int fullConfigId = row["CONFKEY"].data<int>();
00288     std::string fullConfigName = row["NAME"].data<std::string>();
00289     std::cout << "config " << fullConfigId
00290               << " : "     << fullConfigName << std::endl;
00291   }
00292 
00293   std::cout << " ===============" << std::endl;
00294 
00295   coral::AttributeList emptyBindVariableList;
00296   coral::ITable& brickConfigTable =
00297     isession->nominalSchema().tableHandle( "CFGBRICKS" );
00298   std::auto_ptr<coral::IQuery>
00299     brickConfigQuery( brickConfigTable.newQuery() );
00300   brickConfigQuery->addToOutputList( "BRKID" );
00301   brickConfigQuery->addToOutputList( "BRKNAME" );
00302   coral::ICursor& brickConfigCursor = brickConfigQuery->execute();
00303   DTConfigData* brickData = 0;
00304   char brickIdString[20];
00305   std::vector<int> missingList;
00306   while( brickConfigCursor.next() ) {
00307     const coral::AttributeList& row = brickConfigCursor.currentRow();
00308     int brickConfigId = row["BRKID"].data<int>();
00309     std::string brickConfigName = row["BRKNAME"].data<std::string>();
00310     std::cout << "brick " << brickConfigId
00311               << " : "    << brickConfigName << std::endl;
00312     ri->get( brickConfigId, brickData );
00313     if ( brickData == 0 ) {
00314       std::cout << "brick missing, copy request" << std::endl;
00315       missingList.push_back( brickConfigId );
00316 //      break; // REMOVE
00317     }
00318   }
00319   std::vector<int>::const_iterator brickIter = missingList.begin();
00320   std::vector<int>::const_iterator brickIend = missingList.end();
00321   while ( brickIter != brickIend ) {
00322     int brickConfigId = *brickIter++;
00323       std::auto_ptr<coral::IQuery>
00324            brickDataQuery( isession->nominalSchema().newQuery() );
00325       brickDataQuery->addToTableList( "CFGRELATIONS" );
00326       brickDataQuery->addToTableList( "CONFIGCMDS" );
00327       sprintf( brickIdString, "%i", brickConfigId );
00328       std::string
00329       brickCondition  =      "CONFIGCMDS.CMDID=CFGRELATIONS.CMDID";
00330       brickCondition += " and CFGRELATIONS.BRKID=";
00331       brickCondition += brickIdString;
00332       std::cout << "+++" << brickCondition << "+++" << std::endl;
00333       brickDataQuery->addToOutputList( "CFGRELATIONS.BRKID" );
00334       brickDataQuery->addToOutputList( "CONFIGCMDS.CONFDATA" );
00335       brickDataQuery->setCondition( brickCondition, emptyBindVariableList );
00336       coral::ICursor& brickDataCursor = brickDataQuery->execute();
00337       brickData = new DTConfigData();
00338       brickData->setId( brickConfigId );
00339       while( brickDataCursor.next() ) {
00340         const coral::AttributeList& row = brickDataCursor.currentRow();
00341         for ( coral::AttributeList::const_iterator iColumn = row.begin();
00342               iColumn != row.end(); ++iColumn ) {
00343           std::cout << iColumn->specification().name() << " : ";
00344           iColumn->toOutputStream( std::cout, false ) << "\t";
00345           std::cout << std::endl;
00346           if ( iColumn->specification().name() == "CONFIGCMDS.CONFDATA" )
00347           std::cout << "add : " << iColumn->data<std::string>()
00348                       << std::endl;
00349         }
00350         std::cout << "add : "
00351                   << row["CONFIGCMDS.CONFDATA"].data<std::string>()
00352                   << std::endl;
00353         brickData->add( row["CONFIGCMDS.CONFDATA"].data<std::string>() );
00354       }
00355       cond::TypedRef<DTConfigData> brickRef( *session->poolDB(), brickData );
00356       brickRef.markWrite( "DTConfigData" );
00357       ri->set( brickConfigId, brickRef.token() );
00358   }
00359 
00360   std::cout << "disconnect session..." << std::endl;
00361   session->disconnect();
00362   std::cout << "delete session..." << std::endl;
00363   delete session;
00364   std::cout << "list updated..." << std::endl;
00365 
00366   return;
00367 
00368 }

void DTCCBConfigHandler::getNewObjects (  )  [virtual]

Operations.

Implements popcon::PopConSourceHandler< DTCCBConfig >.

Definition at line 72 of file DTCCBConfigHandler.cc.

References chkConfigList(), cond::DBSession::configuration(), cond::Connection::connect(), cond::CoralTransaction::coralSessionProxy(), cond::Connection::coralTransaction(), GenMuonPlsPt100GeV_cfg::cout, dataTag, lat::endl(), cond::Error, isession, prof2calltree::last, cond::TagInfo::lastInterval, trackerGeometricDetLoaderSQLITE_cfg::lastRun, popcon::PopConSourceHandler< DTCCBConfig >::m_connection, popcon::PopConSourceHandler< DTCCBConfig >::m_to_transfer, onlineAuthentication, onlineConnect, cond::DBSession::open(), row, cond::SessionConfiguration::setAuthenticationMethod(), cond::SessionConfiguration::setAuthenticationPath(), DTCCBConfig::setConfigKey(), DTCCBConfig::setFullKey(), cond::SessionConfiguration::setMessageLevel(), DTCCBConfig::setStamp(), cond::CoralTransaction::start(), DTCCBId::stationId, popcon::PopConSourceHandler< DTCCBConfig >::tagInfo(), ti, muonGeometry::wheel, and cond::XML.

00072                                        {
00073 
00074   cond::DBSession* coralSession;
00075   cond::Connection* m_connection;
00076   cond::CoralTransaction* m_coraldb;
00077 
00078   coralSession = new cond::DBSession();
00079   // to get the username/passwd from $CORAL_AUTH_PATH/authentication.xml
00080   coralSession->configuration().setAuthenticationMethod( cond::XML );
00081   coralSession->configuration().setAuthenticationPath( onlineAuthentication );
00082   // set message level to Error or Debug
00083   coralSession->configuration().setMessageLevel( cond::Error );
00084 //  coralSession->connectionConfiguration().setConnectionRetrialTimeOut( 60 );
00085   coralSession->open();
00086 
00087   m_connection = new cond::Connection( onlineConnect );
00088   m_connection->connect( coralSession );
00089   m_coraldb = &( m_connection->coralTransaction() );
00090   m_coraldb->start( true );
00091 
00092   std::cout << "get session proxy... " << std::endl;
00093   isession = &( m_coraldb->coralSessionProxy() );
00094   std::cout << "session proxy got" << std::endl;
00095   m_coraldb->start( true );
00096 //  m_coraldb = new cond::RelationalStorageManager( onlineConnect,
00097 //                                                  coralSession );
00098 //  isession =
00099 //  m_coraldb->connect( cond::ReadOnly );
00100 //  m_coraldb->startTransaction( true );
00101 
00102   chkConfigList();
00103   std::cout << "get run config..." << std::endl;
00104 
00105   //to access the information on the tag inside the offline database:
00106   cond::TagInfo const & ti = tagInfo();
00107   unsigned int last = ti.lastInterval.first;
00108   std::cout << "last: " << last << std::endl;
00109 
00110   //to access the information on last successful log entry for this tag:
00111 //  cond::LogDBEntry const & lde = logDBEntry();     
00112 
00113   //to access the lastest payload (Ref is a smart pointer)
00114 //  Ref payload = lastPayload();
00115 
00116 /*
00117   std::map<std::string, popcon::PayloadIOV> mp = getOfflineInfo();
00118   std::cout << "tag map got..." << std::endl;
00119   std::map<std::string, popcon::PayloadIOV>::iterator iter = mp.begin();
00120   std::map<std::string, popcon::PayloadIOV>::iterator iend = mp.end();
00121   while ( iter != iend ) {
00122     std::cout << "Tag: "                       << iter->first
00123               << " , last object valid since " << iter->second.last_since
00124               << " to "                        << iter->second.last_till
00125               << std::endl;
00126     iter++;
00127   }
00128   std::cout << "loop over tags done..." << std::endl;
00129 */
00130 
00131   coral::AttributeList emptyBindVariableList;
00132 
00133   unsigned lastRun = last;
00134 /*
00135   std::map<std::string, popcon::PayloadIOV>::iterator itag =
00136     mp.find( dataTag );
00137   if ( itag != mp.end() ) lastRun = itag->second.last_since;
00138   else                    std::cout << "tag " << dataTag
00139                                     << " not found" << std::endl;
00140 
00141   std::cout << "last run found..." << std::endl;
00142 */
00143 
00144     std::cout << "LAST RUN: " << lastRun << std::endl;
00145     std::map<int,int> cfgMap;
00146 
00147     std::cout << "get table handle... " << std::endl;
00148     coral::ITable& runConfigTable =
00149       isession->nominalSchema().tableHandle( "TBRUN" );
00150     std::cout << "table handle got " << std::endl;
00151     std::auto_ptr<coral::IQuery>
00152       runConfigQuery( runConfigTable.newQuery() );
00153     runConfigQuery->addToOutputList( "RUN" );
00154     runConfigQuery->addToOutputList( "CONFKEY" );
00155 
00156     coral::ICursor& runConfigCursor = runConfigQuery->execute();
00157     while( runConfigCursor.next() ) {
00158       const coral::AttributeList& row = runConfigCursor.currentRow();
00159       int runConfigId = row["CONFKEY"].data<int>();
00160       int runId       = row[    "RUN"].data<int>();
00161       if ( static_cast<unsigned>( runId ) > lastRun ) 
00162            cfgMap.insert( std::pair<int,int>( runId,
00163                                               runConfigId ) );
00164     }
00165     std::map<int,int>::const_iterator runIter = cfgMap.begin();
00166     std::map<int,int>::const_iterator runIend = cfgMap.end();
00167     char confKeyString[20];
00168     char brickIdString[20];
00169     while ( runIter != runIend ) {
00170       const std::pair<int,int>& runEntry = *runIter++;
00171       std::cout << "run "          << runEntry.first
00172                 << " ---> config " << runEntry.second << std::endl;
00173       DTCCBConfig* fullConf = new DTCCBConfig( dataTag );
00174       fullConf->setFullKey( runEntry.second );
00175       fullConf->setStamp(   runEntry.first );
00176       std::vector< std::pair<DTCCBId,int> > ccbMap;
00177       std::auto_ptr<coral::IQuery>
00178            ccbDataQuery( isession->nominalSchema().newQuery() );
00179       ccbDataQuery->addToTableList( "CCBRELATIONS" );
00180       ccbDataQuery->addToTableList( "CCBMAP" );
00181       ccbDataQuery->addToOutputList( "CCBMAP.WHEEL" );
00182       ccbDataQuery->addToOutputList( "CCBMAP.SECTOR" );
00183       ccbDataQuery->addToOutputList( "CCBMAP.STATION" );
00184       ccbDataQuery->addToOutputList( "CCBRELATIONS.CONFCCBKEY" );
00185       sprintf( confKeyString, "%i", runEntry.second );
00186       std::string
00187       ccbDataCondition  =      "CCBRELATIONS.CCBID = CCBMAP.CCBID";
00188       ccbDataCondition += " and CCBRELATIONS.CONFKEY = ";
00189       ccbDataCondition += confKeyString;
00190       ccbDataQuery->setCondition( ccbDataCondition, emptyBindVariableList );
00191       std::cout << ccbDataCondition << std::endl;
00192       coral::ICursor& ccbDataCursor = ccbDataQuery->execute();
00193       while( ccbDataCursor.next() ) {
00194         const coral::AttributeList& row = ccbDataCursor.currentRow();
00195         int wheel   = row["CCBMAP.WHEEL"  ].data<int>();
00196         int sector  = row["CCBMAP.SECTOR" ].data<int>();
00197         int station = row["CCBMAP.STATION"].data<int>();
00198         int ccbConf = row["CCBRELATIONS.CONFCCBKEY"].data<int>();
00199         DTCCBId ccbId;
00200         ccbId.  wheelId =   wheel;
00201         ccbId.stationId = station;
00202         ccbId. sectorId =  sector;
00203         ccbMap.push_back( std::pair<DTCCBId,int>( ccbId, ccbConf ) );
00204       }
00205 
00206       std::vector< std::pair<DTCCBId,int> >::const_iterator ccbIter
00207                                                           = ccbMap.begin();
00208       std::vector< std::pair<DTCCBId,int> >::const_iterator ccbIend
00209                                                           = ccbMap.end();
00210       while ( ccbIter != ccbIend ) {
00211         std::pair<DTCCBId,int> ccbEntry = *ccbIter++;
00212         DTCCBId& ccbId = ccbEntry.first;
00213         int ccbConfId  = ccbEntry.second;
00214         int   wheel = ccbId.  wheelId;
00215         int station = ccbId.stationId;
00216         int  sector = ccbId. sectorId;
00217         std::vector<int> ccbConf;
00218         coral::ITable& confBrickTable =
00219           isession->nominalSchema().tableHandle( "CFG2BRKREL" );
00220         std::auto_ptr<coral::IQuery>
00221           confBrickQuery( confBrickTable.newQuery() );
00222         confBrickQuery->addToOutputList( "BRKID" );
00223         sprintf( brickIdString, "%i", ccbConfId );
00224         std::string
00225         confBrickCondition  = "CONFID = ";
00226         confBrickCondition += brickIdString;
00227         std::cout << confBrickCondition << std::endl;
00228         confBrickQuery->setCondition( confBrickCondition,
00229                                       emptyBindVariableList );
00230         coral::ICursor& confBrickCursor = confBrickQuery->execute();
00231         while( confBrickCursor.next() ) {
00232           const coral::AttributeList& row = confBrickCursor.currentRow();
00233           int confBrickId = row["BRKID"].data<int>();
00234           ccbConf.push_back( confBrickId );
00235         }
00236         fullConf->setConfigKey( wheel, station, sector, ccbConf );
00237       }
00238 /*
00239       popcon::IOVPair iop = { runEntry.first, 0xffffffff };
00240       std::cout << "APPEND NEW OBJECT: "
00241                 << runEntry.first << " " << fullConf << std::endl;
00242       m_to_transfer->push_back( std::make_pair( fullConf, iop ) );
00243 */
00244       cond::Time_t snc = runEntry.first;
00245       m_to_transfer.push_back( std::make_pair( fullConf, snc ) );
00246     }
00247 
00248   delete m_connection;
00249   delete coralSession;
00250 
00251   return;
00252 }

std::string DTCCBConfigHandler::id ( void   )  const [virtual]

Implements popcon::PopConSourceHandler< DTCCBConfig >.

Definition at line 371 of file DTCCBConfigHandler.cc.

References dataTag.

00371                                        {
00372   return dataTag;
00373 }


Member Data Documentation

DTCCBConfig* DTCCBConfigHandler::ccbConfig [private]

Definition at line 66 of file DTCCBConfigHandler.h.

std::string DTCCBConfigHandler::dataTag [private]

Definition at line 59 of file DTCCBConfigHandler.h.

Referenced by getNewObjects(), and id().

coral::ISessionProxy* DTCCBConfigHandler::isession [private]

Definition at line 68 of file DTCCBConfigHandler.h.

Referenced by chkConfigList(), and getNewObjects().

std::string DTCCBConfigHandler::listToken [private]

Definition at line 65 of file DTCCBConfigHandler.h.

Referenced by chkConfigList().

std::string DTCCBConfigHandler::offlineAuthentication [private]

Definition at line 62 of file DTCCBConfigHandler.h.

Referenced by chkConfigList(), and DTCCBConfigHandler().

std::string DTCCBConfigHandler::offlineCatalog [private]

Definition at line 64 of file DTCCBConfigHandler.h.

Referenced by chkConfigList().

std::string DTCCBConfigHandler::offlineConnect [private]

Definition at line 63 of file DTCCBConfigHandler.h.

Referenced by chkConfigList().

std::string DTCCBConfigHandler::onlineAuthentication [private]

Definition at line 61 of file DTCCBConfigHandler.h.

Referenced by DTCCBConfigHandler(), and getNewObjects().

std::string DTCCBConfigHandler::onlineConnect [private]

Definition at line 60 of file DTCCBConfigHandler.h.

Referenced by getNewObjects().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:18:45 2009 for CMSSW by  doxygen 1.5.4