5 from __future__
import with_statement, print_function
7 from os
import listdir, makedirs
8 from os.path
import basename, exists, join
as pjoin
10 from .sugar
import define_iov_type, IOVSet
13 log = logging.getLogger(
"DQUtils.periods")
15 DATA_PERIODS_PATH =
"/afs/cern.ch/atlas/www/GROUPS/DATAPREPARATION/DataPeriods/"
23 Warning: Being deprecated
25 for period_file
in listdir(DATA_PERIODS_PATH):
26 if not period_file.endswith(
".runs.list"):
30 runs_file =
"%s.%s.runs.list" % (project_tag, period)
31 with open(pjoin(DATA_PERIODS_PATH, runs_file))
as fd:
32 period_data = fd.read()
35 period_data = map(int, period_data.strip().
split(
"\n"))
37 raise RuntimeError(
"Invalid period data")
39 return IOVSet.from_runs(period_data)
49 from pyAMI.client
import Client
50 amiclient =
Client(
'atlas')
51 amiclient.config.read()
53 args = [
'GetRunsForDataPeriod',
54 '-projectName=%s' % ptag,
55 '-period=%s' % period]
57 runs = amiclient.execute(args, format=
'dict_object').get_rows()
58 except pyAMI.exceptions.AMI_Error:
62 return sorted(
int(x[
'runNumber'])
for x
in runs.values())
66 Returns a dictionary {project_tag: {period: [runs]}}
68 retrieved from the coma database.
71 from sqlalchemy
import (select, Table, Column,
72 String, Integer, ForeignKey)
74 from re
import compile
76 LETTER_PART = compile(
r"^(\D+)")
78 from DQUtils.oracle
import make_oracle_connection
82 schema =
"ATLAS_TAGS_METADATA"
84 coma_runs = Table(
"coma_runs", metadata,
85 Column(
"run_index", Integer),
86 Column(
"run_number", Integer),
90 coma_period_definitions = Table(
"coma_period_defs", metadata,
91 Column(
"p_index", Integer),
92 Column(
"p_project_period", String),
95 project_period = coma_period_definitions.c.p_project_period
97 coma_period_p1_to_runs = Table(
"coma_period_p1_to_runs", metadata,
98 Column(
"p2r_index", Integer),
99 Column(
"p_index", Integer, ForeignKey(coma_period_definitions.c.p_index)),
100 Column(
"run_index", Integer, ForeignKey(coma_runs.c.run_index)),
103 joined = coma_period_p1_to_runs.join(coma_runs).
join(coma_period_definitions)
105 smt = (
select([project_period, coma_runs.c.run_number], from_obj=joined)
106 .order_by(coma_runs.c.run_number))
108 projectperiod_runs = smt.execute().fetchall()
111 for projectperiod, run
in projectperiod_runs:
112 project, period = projectperiod.split(
".")
113 period = period.replace(
"period",
"")
115 project_dict = mapping.setdefault(project, {})
116 period_runs = project_dict.setdefault(period, [])
117 if not period_runs
or period_runs[-1] != run:
118 period_runs.append(run)
120 period_letter = LETTER_PART.search(period)
122 (period_letter,) = period_letter.groups()
123 period_runs = project_dict.setdefault(period_letter, [])
124 if not period_runs
or period_runs[-1] != run:
125 period_runs.append(run)
129 def split_grl(project_tag, periods, grl_file, out_directory):
130 grl = IOVSet.from_grl(grl_file)
133 if project_tag
not in period_info:
134 raise RuntimeError(
"Unknown period {0}".
format(project_tag))
135 ptag_periods = period_info[project_tag]
139 periods =
sorted(ptag_periods.keys())
141 name_left, _, extension =
basename(grl_file).rpartition(
".")
142 assert name_left,
"No '.' in filename?"
144 if not exists(out_directory):
145 makedirs(out_directory)
147 for period
in periods:
148 iovs = grl & IOVSet.from_runs(ptag_periods[period])
150 output_name =
"{0}_period{1}.{2}".
format(name_left, period, extension)
151 log.info(
"{0:4s} : {1:3} runs, {2:5} lumiblocks".
format(
152 period, len(iovs.runs), iovs.lb_counts))
154 output_path = pjoin(out_directory, output_name)
155 iovs.to_grl(output_path)