ATLAS Offline Software
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
TrigConf::ReplicaSorter Class Reference

#include <ReplicaSorter.h>

Inheritance diagram for TrigConf::ReplicaSorter:
Collaboration diagram for TrigConf::ReplicaSorter:

Public Member Functions

 ReplicaSorter ()
 
void sort (std::vector< const coral::IDatabaseServiceDescription * > &replicaSet)
 

Private Types

typedef std::pair< std::string, int > ServerPair
 
typedef std::vector< ServerPairServerMap
 

Private Member Functions

bool readConfig ()
 
FILE * findFile (const std::string &filename, const std::string &pathvar)
 

Private Attributes

std::string m_hostname
 
ServerMap m_servermap
 
bool m_frontiergen
 

Detailed Description

Definition at line 14 of file Trigger/TrigConfiguration/TrigConfStorage/src/ReplicaSorter.h.

Member Typedef Documentation

◆ ServerMap

typedef std::vector< ServerPair > TrigConf::ReplicaSorter::ServerMap
private

◆ ServerPair

typedef std::pair<std::string,int> TrigConf::ReplicaSorter::ServerPair
private

Constructor & Destructor Documentation

◆ ReplicaSorter()

ReplicaSorter::ReplicaSorter ( )

Definition at line 20 of file Trigger/TrigConfiguration/TrigConfStorage/src/ReplicaSorter.cxx.

20  :
21  m_frontiergen(false)
22 {
23  std::cout << "ReplicaSorter constructor" << std::endl;
24  readConfig();
25 }

Member Function Documentation

◆ findFile()

FILE * ReplicaSorter::findFile ( const std::string &  filename,
const std::string &  pathvar 
)
private

Definition at line 185 of file Trigger/TrigConfiguration/TrigConfStorage/src/ReplicaSorter.cxx.

187 {
188  // behave like pathresolver
189  std::string::size_type iofs1,iofs2,len;
190  FILE* fptr=0;
191  iofs1=0;
192  len=pathvar.size();
193  std::string name;
194  while (!fptr && iofs1<len) {
195  iofs2=pathvar.find(':',iofs1);
196  if (iofs2==std::string::npos) iofs2=len;
197  name=pathvar.substr(iofs1,iofs2-iofs1)+"/"+filename;
198  fptr=fopen(name.c_str(),"r");
199  iofs1=iofs2+1;
200  }
201  std::cout << "Opening " << name << endl;
202  return fptr;
203 }

◆ readConfig()

bool ReplicaSorter::readConfig ( )
private

Definition at line 66 of file Trigger/TrigConfiguration/TrigConfStorage/src/ReplicaSorter.cxx.

66  {
67  // determine the hostname from ATLAS_CONDDB, HOSTNAME or hostname -fqdn
68  m_hostname="";
69  const char* chost=getenv("ATLAS_CONDDB");
70  if (chost) m_hostname=chost;
71  if (m_hostname.empty()) {
72  const char* chost=getenv("HOSTNAME");
73  if (chost) m_hostname=chost;
74  // check if the returned host has a .
75  if (m_hostname.find('.')==std::string::npos) {
76  m_hostname="unknown";
77  char cstr_host[HOST_NAME_MAX];
78  if (gethostname(cstr_host, sizeof(cstr_host))==0) {
79  m_hostname=std::string(cstr_host);
80  }
81  }
82  }
83  std::cout << "Using machine hostname " << m_hostname << " for DB replica resolution" << std::endl;
84  // check if FRONTIER_SERVER is set, if so, allow generic replicas
85  const char* cfrontier=getenv("FRONTIER_SERVER");
86  if (cfrontier && strcmp(cfrontier,"")!=0) {
87  std::cout << "Frontier server at " << cfrontier << " will be considered"
88  << std::endl;
89  m_frontiergen=true;
90  }
91 
92  // try to locate configuration file using pathresolver
93  FILE* p_inp=0;
94  const char* datapath=getenv("DATAPATH");
95  if (datapath!=0) p_inp = findFile("dbreplica.config",datapath);
96  if (p_inp==0) {
97  std::cout << "Cannot open/locate configuration file dbreplica.config"
98  << std::endl;
99  return false;
100  }
101  // buffer for reading line
102  unsigned int bufsize=999;
103  char* p_buf=new char[bufsize];
104  while (!feof(p_inp)) {
105  char* p_line=fgets(p_buf,bufsize,p_inp);
106  if (p_line!=NULL && p_line[0]!='#') {
107  std::string buf=std::string(p_line);
108  std::string::size_type iofs1=0;
109  // analyse based on spaces as seperator
110  bool sequal=false;
111  std::vector<std::string> domains;
112  std::vector<std::string> servers;
113  bool atCERN = false;
114  while (iofs1<buf.size()) {
115  std::string::size_type iofs2=buf.find(' ',iofs1);
116  // allow for trailing linefeed
117  if (iofs2==std::string::npos) iofs2=buf.size()-1;
118  std::string token=buf.substr(iofs1,iofs2-iofs1);
119  // skip empty or space tokens
120  if (token!="" && token!=" ") {
121  if (token=="=") {
122  sequal=true;
123  } else if (!sequal) {
124  // token is a domain name
125  domains.push_back(token);
126  if(token=="cern.ch") atCERN = true;
127  } else {
128  // token is a server name
129  // only add Frontier ATLF server if FRONTIER_CLIENT set
130  if(atCERN && token=="ATONR_CONF") atCERN = false;
131  if (token!="ATLF" || m_frontiergen) servers.push_back(token);
132  }
133  }
134  iofs1=iofs2+1;
135  }
136  // check the list of domains against the hostname to see if this
137  // set of servers is appropriate
138  bool useit=false;
139  unsigned int bestlen=0;
140  for (std::vector<std::string>::const_iterator itr=domains.begin();
141  itr!=domains.end();++itr) {
142  std::string::size_type len=(itr->size());
143  std::string::size_type hlen=m_hostname.size();
144  if (hlen>=len && *itr==m_hostname.substr(hlen-len,len)) {
145  if (len>bestlen) {
146  atCERN=true;
147  useit=true;
148  bestlen=len;
149  }
150  }
151  // for 'default' domain name, add the servers as a last resort
152  // if nothing has been found so far
153  if ("default"==*itr && m_servermap.empty()) {
154  std::cout <<
155  "No specific match for domain found - use default fallback"
156  << std::endl;
157  useit=true;
158  bestlen=0;
159  }
160  }
161  if (useit) {
162  if(atCERN) {
163  servers.push_back("ATONR_COOL");
164  servers.push_back("ATONR_CONF");
165  }
166  // assign these servers, priority based on position in list
167  // and length of match of domain name
168  for (unsigned int i=0;i<servers.size();++i) {
169  int priority=i-100*bestlen;
170  m_servermap.push_back(ServerPair(servers[i],priority));
171  }
172  }
173  }
174  }
175  fclose(p_inp);
176  delete [] p_buf;
177  std::cout << "Total of " << m_servermap.size() <<
178  " servers found for host " << m_hostname << std::endl;
179  return true;
180 }

◆ sort()

void ReplicaSorter::sort ( std::vector< const coral::IDatabaseServiceDescription * > &  replicaSet)

Definition at line 28 of file Trigger/TrigConfiguration/TrigConfStorage/src/ReplicaSorter.cxx.

28  {
29  // loop through all the offered replicas
30  std::map<int,const coral::IDatabaseServiceDescription*> primap;
31  for (std::vector<const coral::IDatabaseServiceDescription*>::const_iterator
32  itr=replicaSet.begin();itr!=replicaSet.end();++itr) {
33  const std::string conn=(**itr).connectionString();
34  // do not use SQLite files
35  if (conn.find("sqlite_file")==std::string::npos) {
36  // extract the server name (assuming URLs "techno://server/schema")
37  // example of current conn naming scheme: coral://127.0.0.1:3320/&oracle://ATLAS_CONFIG/ATLAS_CONF_TRIGGER_REPR
38  std::string::size_type ipos0=conn.find('&');
39  std::string::size_type ipos1=conn.find("://",ipos0+1);
40  std::string::size_type ipos2=conn.find('/',ipos1+3);
41  if (ipos1!=std::string::npos && ipos2!=std::string::npos) {
42  const std::string server=conn.substr(ipos1+3,ipos2-ipos1-3);
43  // check if this server is on list of replicas to use for domain
44  // if so, add it with its associated priority
45  for (ServerMap::const_iterator sitr=m_servermap.begin();
46  sitr!=m_servermap.end();++sitr) {
47  if (sitr->first==server)
48  primap[sitr->second]=*itr;
49  }
50  }
51  }
52  }
53  // now create sorted list
54  replicaSet.clear();
55  for (std::map<int,const coral::IDatabaseServiceDescription*>::const_iterator
56  itr=primap.begin();itr!=primap.end();++itr) {
57  replicaSet.push_back(itr->second);
58  std::cout << "Allowed replica to try (priority " << itr->first
59  << ") : " << (itr->second)->connectionString() << std::endl;
60  }
61  if (replicaSet.empty())
62  std::cout << "No matching replicas found" << std::endl;
63 }

Member Data Documentation

◆ m_frontiergen

bool TrigConf::ReplicaSorter::m_frontiergen
private

◆ m_hostname

std::string TrigConf::ReplicaSorter::m_hostname
private

◆ m_servermap

ServerMap TrigConf::ReplicaSorter::m_servermap
private

The documentation for this class was generated from the following files:
checkCorrelInHIST.conn
conn
Definition: checkCorrelInHIST.py:25
TrigConf::ReplicaSorter::m_hostname
std::string m_hostname
Definition: Trigger/TrigConfiguration/TrigConfStorage/src/ReplicaSorter.h:22
python.selector.AtlRunQuerySelectorLhcOlc.priority
priority
Definition: AtlRunQuerySelectorLhcOlc.py:611
TrigConf::ReplicaSorter::readConfig
bool readConfig()
Definition: Trigger/TrigConfiguration/TrigConfStorage/src/ReplicaSorter.cxx:66
lumiFormat.i
int i
Definition: lumiFormat.py:92
python.DecayParser.buf
buf
print ("=> [%s]"cmd)
Definition: DecayParser.py:27
python.html.AtlRunQueryDQSummary.datapath
datapath
Definition: AtlRunQueryDQSummary.py:1205
fptr
std::vector< TFile * > fptr
Definition: hcg.cxx:48
TrigConf::ReplicaSorter::ServerPair
std::pair< std::string, int > ServerPair
Definition: Trigger/TrigConfiguration/TrigConfStorage/src/ReplicaSorter.h:23
TrigConf::ReplicaSorter::findFile
FILE * findFile(const std::string &filename, const std::string &pathvar)
Definition: Trigger/TrigConfiguration/TrigConfStorage/src/ReplicaSorter.cxx:185
TrigConf::ReplicaSorter::m_frontiergen
bool m_frontiergen
Definition: Trigger/TrigConfiguration/TrigConfStorage/src/ReplicaSorter.h:26
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
python.html.AtlRunQueryDQSummary.server
server
Definition: AtlRunQueryDQSummary.py:22
TrigConf::ReplicaSorter::m_servermap
ServerMap m_servermap
Definition: Trigger/TrigConfiguration/TrigConfStorage/src/ReplicaSorter.h:25