ATLAS Offline Software
Loading...
Searching...
No Matches
python.oracle Namespace Reference

Functions

 parse_auth_file (file_name, connection)
 get_authentication (connection="oracle://ATLAS_COOLPROD/ATLAS_COOLONL_GLOBAL")
 make_oracle_connection (connection_string)
 fetch_recent_runs (how_recent=ONE_WEEK, ascending=False)
 fetch_runs_since (first_run=140000, ascending=False)
 make_atlas_partition_query ()
 fetch_last_n_atlas_runs (n=10)
 fetch_atlas_runs ()
 atlas_runs_set ()
 atlas_runs_between (first, last)
 filter_atlas_runs (iovs)

Variables

 engine
 metadata
 Session = sessionmaker(engine)
 run_table
int ONE_WEEK = 7*24*3600

Function Documentation

◆ atlas_runs_between()

python.oracle.atlas_runs_between ( first,
last )

Definition at line 143 of file oracle.py.

143def atlas_runs_between(first, last):
144
145 rows = make_atlas_partition_query()
146 rows = rows.where(run_table.c.RUNNUMBER.between(first, last))
147
148 with Session() as session:
149 return [row.RUNNUMBER for row in session.execute(rows).fetchall()]
150

◆ atlas_runs_set()

python.oracle.atlas_runs_set ( )

Definition at line 140 of file oracle.py.

140def atlas_runs_set():
141 return set(x.RUNNUMBER for x in fetch_atlas_runs())
142
STL class.

◆ fetch_atlas_runs()

python.oracle.fetch_atlas_runs ( )

Definition at line 135 of file oracle.py.

135def fetch_atlas_runs():
136 rows = make_atlas_partition_query()
137 with Session() as session:
138 return session.execute(rows).fetchall()
139

◆ fetch_last_n_atlas_runs()

python.oracle.fetch_last_n_atlas_runs ( n = 10)

Definition at line 127 of file oracle.py.

127def fetch_last_n_atlas_runs(n=10):
128 rows = (select(run_table.c.RUNNUMBER)
129 .where(run_table.c.PARTITIONNAME == "ATLAS")
130 .order_by(run_table.c.RUNNUMBER.desc()).limit(n))
131
132 with Session() as session:
133 return [row.RUNNUMBER for row in reversed(session.execute(rows).fetchall())]
134

◆ fetch_recent_runs()

python.oracle.fetch_recent_runs ( how_recent = ONE_WEEK,
ascending = False )
Retrieve a list of ATLAS runs from the database, since first_run

Definition at line 94 of file oracle.py.

94def fetch_recent_runs(how_recent=ONE_WEEK, ascending=False):
95 """
96 Retrieve a list of ATLAS runs from the database, since first_run
97 """
98 from time import time, strftime, gmtime
99 t = run_table
100
101 ordering = t.c.RUNNUMBER.asc() if ascending else t.c.RUNNUMBER.desc()
102
103 this_recent = strftime("%Y%m%dT%H%M%S", gmtime(time()-how_recent))
104 condition = and_(t.c.STARTAT >= this_recent, t.c.PARTITIONNAME == "ATLAS")
105 rows = select(run_table).where(condition).order_by(ordering)
106 with Session() as session:
107 return session.execute(rows).fetchall()
108

◆ fetch_runs_since()

python.oracle.fetch_runs_since ( first_run = 140000,
ascending = False )
Retrieve a list of ATLAS runs from the database, since first_run

Definition at line 109 of file oracle.py.

109def fetch_runs_since(first_run=140000, ascending=False):
110 """
111 Retrieve a list of ATLAS runs from the database, since first_run
112 """
113 t = run_table
114
115 ordering = t.c.RUNNUMBER.asc() if ascending else t.c.RUNNUMBER.desc()
116
117 condition = and_(t.c.RUNNUMBER > first_run, t.c.PARTITIONNAME == "ATLAS")
118 rows = select(run_table).where(condition).order_by(ordering)
119 with Session() as session:
120 return session.execute(rows).fetchall()
121

◆ filter_atlas_runs()

python.oracle.filter_atlas_runs ( iovs)

Definition at line 151 of file oracle.py.

151def filter_atlas_runs(iovs):
152
153 iov_runs = set(iov.since.run for iov in iovs)
154 first, last = min(iov_runs), max(iov_runs)
155
156 rows = make_atlas_partition_query()
157 rows = rows.where(run_table.c.RUNNUMBER.between(first, last))
158
159 with Session() as session:
160 atlas_runs = set(row.RUNNUMBER for row in session.execute(rows).fetchall())
161 keep_runs = atlas_runs.intersection(iov_runs)
162
163 return IOVSet(iov for iov in iovs if iov.since.run in keep_runs)
164
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41

◆ get_authentication()

python.oracle.get_authentication ( connection = "oracle://ATLAS_COOLPROD/ATLAS_COOLONL_GLOBAL")
Retrieves authentication information from CORAL_AUTH_PATH authentication.xml

Definition at line 36 of file oracle.py.

36def get_authentication(connection="oracle://ATLAS_COOLPROD/ATLAS_COOLONL_GLOBAL"):
37 """
38 Retrieves authentication information from CORAL_AUTH_PATH authentication.xml
39 """
40
41 from os import environ
42 from os.path import join as pjoin
43 assert "CORAL_AUTH_PATH" in environ, "CORAL_AUTH_PATH environment var not set"
44
45 auth_paths = environ["CORAL_AUTH_PATH"].split(":")
46
47 for auth_path in auth_paths + ["."]:
48 file_name = pjoin(auth_path, "authentication.xml")
49 if exists(file_name):
50 authentication = parse_auth_file(file_name, connection)
51 if authentication:
52 return authentication
53
54 raise RuntimeError("Unable to locate credentials for %s."
55 % connection)
56
bool exists(const std::string &filename)
does a file exist
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177

◆ make_atlas_partition_query()

python.oracle.make_atlas_partition_query ( )

Definition at line 122 of file oracle.py.

122def make_atlas_partition_query():
123 return (select(run_table.c.RUNNUMBER)
124 .where(run_table.c.PARTITIONNAME == "ATLAS")
125 .order_by(run_table.c.RUNNUMBER))
126

◆ make_oracle_connection()

python.oracle.make_oracle_connection ( connection_string)

Definition at line 57 of file oracle.py.

57def make_oracle_connection(connection_string):
58 "oracle://ATLAS_COOLPROD/ATLAS_COOLONL_GLOBAL"
59 assert connection_string.startswith("oracle://"), "Not a connection string"
60 host = urlparse (connection_string[len("oracle:"):]).netloc
61 username, password = get_authentication(connection_string)
62 conn_str = "oracle://%s:%s@%s" % (username, password, host)
63 engine = create_engine(conn_str, pool_recycle=10*60)
64 metadata = MetaData()
65 metadata.reflect(engine)
66 return engine, metadata
67
68#conn_str = "oracle://%s:%s@ATLAS_COOLPROD" % get_authentication()
69
70# Recycle the connection every 10 minutes
71#engine = create_engine(conn_str, pool_recycle=10*60)
72#metadata = MetaData(bind=engine)
73

◆ parse_auth_file()

python.oracle.parse_auth_file ( file_name,
connection )

Definition at line 16 of file oracle.py.

16def parse_auth_file(file_name, connection):
17
18 dom = parse(file_name)
19
20 connections = dom.getElementsByTagName("connection")
21 desired_conn = lambda c: c.attributes.get("name").value == connection
22
23 connections = list(filter(desired_conn, connections))
24
25 if len(connections) < 1:
26 return None
27
28 info = {}
29 for node in connections[0].childNodes:
30 if node.nodeName == "parameter":
31 info[node.getAttribute("name")] = str(node.getAttribute("value"))
32
33 authentication = info["user"], info["password"]
34 return authentication
35
std::map< std::string, std::string > parse(const std::string &list)

Variable Documentation

◆ engine

python.oracle.engine

Definition at line 74 of file oracle.py.

◆ metadata

python.oracle.metadata

Definition at line 74 of file oracle.py.

◆ ONE_WEEK

int python.oracle.ONE_WEEK = 7*24*3600

Definition at line 92 of file oracle.py.

◆ run_table

python.oracle.run_table
Initial value:
1= Table("ATLAS_RUN_NUMBER.RUNNUMBER", metadata,
2 Column("NAME", String),
3 Column("RUNNUMBER", String),
4 Column("STARTAT", String),
5 Column("DURATION", Integer),
6 Column("CREATEDBY", String),
7 Column("HOST", String),
8 Column("PARTITIONNAME", String),
9 Column("CONFIGSCHEMA", Integer),
10 Column("CONFIGDATA", String),
11 Column("COMMENTS", String),
12 quote=False
13)

Definition at line 78 of file oracle.py.

◆ Session

python.oracle.Session = sessionmaker(engine)

Definition at line 76 of file oracle.py.