CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
cond::TagCollectionRetriever Class Reference

#include <TagCollectionRetriever.h>

Public Member Functions

bool existsTagCollection (const std::string &globaltag)
 
bool existsTagDatabase ()
 
void getTagCollection (const std::string &globaltag, std::set< cond::TagMetadata > &result)
 
bool selectTagCollection (const std::string &globaltag, std::set< cond::TagMetadata > &result)
 
 TagCollectionRetriever (cond::DbSession &coraldb)
 constructor More...
 
 TagCollectionRetriever (cond::DbSession &coraldb, std::string const &prefix, std::string const &postfix)
 
 ~TagCollectionRetriever ()
 destructor More...
 

Private Member Functions

std::pair< std::string,
std::string > 
parseglobaltag (const std::string &globaltag)
 parse global tag string returns result in pair <treename,nodename> More...
 

Private Attributes

cond::DbSession m_coraldb
 
PfnEditor pfnEditor
 

Detailed Description

Definition at line 20 of file TagCollectionRetriever.h.

Constructor & Destructor Documentation

TagCollectionRetriever::TagCollectionRetriever ( cond::DbSession coraldb)
explicit

constructor

Definition at line 18 of file TagCollectionRetriever.cc.

18  :
19  m_coraldb(coraldb)
20 {}
TagCollectionRetriever::TagCollectionRetriever ( cond::DbSession coraldb,
std::string const &  prefix,
std::string const &  postfix 
)

Definition at line 23 of file TagCollectionRetriever.cc.

25  :
26  m_coraldb(coraldb), pfnEditor(prefix,postfix)
27 {}
TagCollectionRetriever::~TagCollectionRetriever ( )

destructor

Definition at line 31 of file TagCollectionRetriever.cc.

31 {}

Member Function Documentation

bool TagCollectionRetriever::existsTagCollection ( const std::string &  globaltag)

Definition at line 38 of file TagCollectionRetriever.cc.

References i, AlCaHLTBitMon_QueryRunRegistry::string, and cond::tagTreeTablePrefix.

Referenced by cond::persistency::OraGTTable::select().

38  {
39  if(!existsTagDatabase()){
40  throw cond::nonExistentGlobalTagInventoryException("TagCollectionRetriever::selectTagCollection");
41  }
42  std::pair<std::string,std::string> treenodepair=parseglobaltag(globaltag);
43  std::string treename=treenodepair.first;
44  std::string nodename=treenodepair.second;
46  if( !treename.empty() ){
47  for(unsigned int i=0; i<treename.size(); ++i){
48  treename[i]=std::toupper(treename[i]);
49  }
50  treetablename+="_";
51  treetablename+=treename;
52  }
53  return m_coraldb.nominalSchema().existsTable(treetablename);
54 }
int i
Definition: DBlmapReader.cc:9
list globaltag
Definition: align_cfg.py:7
const std::string tagTreeTablePrefix
std::pair< std::string, std::string > parseglobaltag(const std::string &globaltag)
parse global tag string returns result in pair &lt;treename,nodename&gt;
coral::ISchema & nominalSchema()
Definition: DbSession.cc:243
bool TagCollectionRetriever::existsTagDatabase ( )

Definition at line 33 of file TagCollectionRetriever.cc.

References cond::tagInventoryTable.

Referenced by cond::persistency::OraGTSchema::exists().

33  {
34  return m_coraldb.nominalSchema().existsTable(cond::tagInventoryTable);
35 }
const std::string tagInventoryTable
coral::ISchema & nominalSchema()
Definition: DbSession.cc:243
void TagCollectionRetriever::getTagCollection ( const std::string &  globaltag,
std::set< cond::TagMetadata > &  result 
)

given global tag return the basic tag collection. The global tag has the format TreeName::NodeName

Definition at line 57 of file TagCollectionRetriever.cc.

Referenced by cond::RDBMS::globalTag().

58  {
60  throw cond::nonExistentGlobalTagException("TagCollectionRetriever::getTagCollection",globaltag);
61 }
bool selectTagCollection(const std::string &globaltag, std::set< cond::TagMetadata > &result)
list globaltag
Definition: align_cfg.py:7
tuple result
Definition: query.py:137
std::pair< std::string, std::string > TagCollectionRetriever::parseglobaltag ( const std::string &  globaltag)
private

parse global tag string returns result in pair <treename,nodename>

Definition at line 152 of file TagCollectionRetriever.cc.

References align_cfg::globaltag, and query::result.

152  {
153  std::pair<std::string,std::string> result;
154  std::size_t pos=globaltag.find("::");
155  if(pos==std::string::npos){
156  result.first="";
157  result.second=globaltag;
158  }else{
159  result.first=globaltag.substr(0,pos);
160  result.second=globaltag.substr(pos+2);
161  }
162  return result;
163 }
list globaltag
Definition: align_cfg.py:7
tuple result
Definition: query.py:137
bool TagCollectionRetriever::selectTagCollection ( const std::string &  globaltag,
std::set< cond::TagMetadata > &  result 
)

Definition at line 64 of file TagCollectionRetriever.cc.

References Exception, i, cond::TagMetadata::labelname, cond::TagMetadata::objectname, cond::TagMetadata::pfn, o2o::query, cond::TagMetadata::recordname, AlCaHLTBitMon_QueryRunRegistry::string, cond::TagMetadata::tag, cond::tagInventoryTable, createPayload::tagname, and cond::tagTreeTablePrefix.

Referenced by cond::persistency::OraGTMapTable::select().

65  {
67  throw cond::nonExistentGlobalTagInventoryException("TagCollectionRetriever::selectTagCollection");
68  }
69  std::pair<std::string,std::string> treenodepair=parseglobaltag(globaltag);
70  std::string treename=treenodepair.first;
71  std::string nodename=treenodepair.second;
72  //std::cout<<"treename "<<treename<<std::endl;
73  //std::cout<<"nodename "<<nodename<<std::endl;
75  if( !treename.empty() ){
76  for(unsigned int i=0; i<treename.size(); ++i){
77  treename[i]=std::toupper(treename[i]);
78  }
79  treetablename+="_";
80  treetablename+=treename;
81  }
82  if( !m_coraldb.nominalSchema().existsTable(treetablename) ) return false;
83 
84  coral::IQuery* query=m_coraldb.nominalSchema().newQuery();
85  //std::cout<<"treetablename "<<treetablename<<std::endl;
86  query->addToTableList( treetablename, "p1" );
87  query->addToTableList( treetablename, "p2" );
88  query->addToOutputList( "p1.tagid" );
89  query->setRowCacheSize( 100 );
90  coral::AttributeList bindData;
91  bindData.extend( "nodelabel",typeid(std::string) );
92  bindData.extend( "tagid",typeid(unsigned int) );
93  bindData["tagid"].data<unsigned int>()=0;
94  bindData["nodelabel"].data<std::string>()=nodename;
95  query->setCondition( "p1.lft BETWEEN p2.lft AND p2.rgt AND p2.nodelabel = :nodelabel AND p1.tagid <> :tagid", bindData );
96  coral::AttributeList qresult;
97  qresult.extend("tagid", typeid(unsigned int));
98  query->defineOutput(qresult);
99  std::vector<unsigned int> leaftagids;
100  leaftagids.reserve(100);
101  coral::ICursor& cursor = query->execute();
102  while( cursor.next() ) {
103  const coral::AttributeList& row = cursor.currentRow();
104  leaftagids.push_back(row["tagid"].data<unsigned int>());
105  }
106  cursor.close();
107  delete query;
108  std::vector<unsigned int>::iterator it;
109  std::vector<unsigned int>::iterator itBeg=leaftagids.begin();
110  std::vector<unsigned int>::iterator itEnd=leaftagids.end();
111  coral::ITable& tagInventorytable=m_coraldb.nominalSchema().tableHandle(cond::tagInventoryTable);
112  for( it=itBeg; it!=itEnd; ++it ){
113  coral::IQuery* leaftagquery=tagInventorytable.newQuery();
114  leaftagquery->addToOutputList( "tagname" );
115  leaftagquery->addToOutputList( "pfn" );
116  leaftagquery->addToOutputList( "recordname" );
117  leaftagquery->addToOutputList( "objectname" );
118  leaftagquery->addToOutputList( "labelname" );
119  coral::AttributeList myresult;
120  myresult.extend("tagname",typeid(std::string));
121  myresult.extend("pfn",typeid(std::string));
122  myresult.extend("recordname",typeid(std::string));
123  myresult.extend("objectname",typeid(std::string));
124  myresult.extend("labelname",typeid(std::string));
125  leaftagquery->defineOutput( myresult );
126  coral::AttributeList bindVariableList;
127  bindVariableList.extend("tagid",typeid(unsigned int));
128  leaftagquery->setCondition( "tagid = :tagid",bindVariableList );
129  leaftagquery->limitReturnedRows(1,0);
130  bindVariableList["tagid"].data<unsigned int>()=*it;
131  coral::ICursor& cursor2 =leaftagquery->execute();
132  if( cursor2.next() ){
133  const coral::AttributeList& row = cursor2.currentRow();
134  cond::TagMetadata tagmetadata;
135  std::string tagname=row["tagname"].data<std::string>();
136  tagmetadata.tag=tagname;
137  tagmetadata.pfn=pfnEditor(row["pfn"].data<std::string>());
138  tagmetadata.recordname=row["recordname"].data<std::string>();
139  tagmetadata.objectname=row["objectname"].data<std::string>();
140  tagmetadata.labelname=row["labelname"].data<std::string>();
141  if(! result.insert(tagmetadata).second ){
142  throw cond::Exception("cond::TagCollectionRetriever::getTagCollection tag "+tagname+" from "+tagmetadata.pfn+" already exist, cannot insert in the tag collection ");
143  }
144  }
145  cursor2.close();
146  delete leaftagquery;
147  }
148  return true;
149 }
int i
Definition: DBlmapReader.cc:9
list globaltag
Definition: align_cfg.py:7
std::string objectname
Definition: TagMetadata.h:12
std::string labelname
Definition: TagMetadata.h:11
const std::string tagTreeTablePrefix
std::string tag
Definition: TagMetadata.h:8
std::pair< std::string, std::string > parseglobaltag(const std::string &globaltag)
parse global tag string returns result in pair &lt;treename,nodename&gt;
tuple result
Definition: query.py:137
const std::string tagInventoryTable
coral::ISchema & nominalSchema()
Definition: DbSession.cc:243
std::string pfn
Definition: TagMetadata.h:9
tuple query
Definition: o2o.py:269
std::string recordname
Definition: TagMetadata.h:10

Member Data Documentation

cond::DbSession cond::TagCollectionRetriever::m_coraldb
private

Definition at line 44 of file TagCollectionRetriever.h.

PfnEditor cond::TagCollectionRetriever::pfnEditor
private

Definition at line 45 of file TagCollectionRetriever.h.