CMS 3D CMS Logo

Functions
conddb_migrate Namespace Reference

Functions

def check_and_run (args)
 
def fetch_gts (connection)
 
def main ()
 
def make_gt_connection (args)
 
def migrate_account (args)
 
def migrate_accounts (args)
 
def migrate_gt (args)
 
def migrate_gts (args)
 
def run_command (command, output_file)
 
def tags_in_gts (args)
 

Detailed Description

CMS Conditions DB migration script.

Function Documentation

def conddb_migrate.check_and_run (   args)

Definition at line 179 of file conddb_migrate.py.

Referenced by main().

179 def check_and_run(args):
180  if 'SCRAM_ARCH' not in os.environ:
181  raise Exception('SCRAM_ARCH needs to be set: run cmsenv within a newish release.')
182 
183  if 'CMSSW_BASE' not in os.environ:
184  raise Exception('CMSSW_BASE needs to be set: run cmsenv within a newish release.')
185 
186  if 'jobs' in args and args.jobs <= 0:
187  raise Exception('If set, --jobs needs to be >= 1.')
188 
189  aliases = {
190  'root': 'oracle://cms_orcoff_prep/CMS_R5_CONDITIONS',
191  'boost': 'oracle://cms_orcoff_prep/CMS_CONDITIONS',
192  }
193 
194  if args.db in aliases:
195  args.db = aliases[args.db]
196 
197  # Check that the release and database match to prevent mistakes...
198  if args.db == 'oracle://cms_orcoff_prep/CMS_CONDITIONS' and \
199  not 'BOOST' in os.environ['CMSSW_VERSION']:
200  raise Exception('Boost database without a Boost release -- mistake?')
201 
202  if args.db == 'oracle://cms_orcoff_prep/CMS_R5_CONDITIONS' and \
203  'BOOST' in os.environ['CMSSW_VERSION']:
204  raise Exception('ROOT database with a Boost release -- mistake?')
205 
206  # Create output log folder
207  os.makedirs(args.output)
208 
209  args.func(args)
210 
211 
def check_and_run(args)
def conddb_migrate.fetch_gts (   connection)

Definition at line 122 of file conddb_migrate.py.

References ComparisonHelper.zip().

Referenced by migrate_gts(), and tags_in_gts().

122 def fetch_gts(connection):
123  logging.info('Fetching global tag list...')
124  cursor = connection.cursor()
125  cursor.execute('''
126  select substr(table_name, length('tagtree_table_') + 1) gt
127  from all_tables
128  where owner = 'CMS_COND_31X_GLOBALTAG'
129  and table_name like 'TAGTREE_TABLE_%'
130  order by gt
131  ''')
132  gts = zip(*cursor.fetchall())[0]
133  logging.info('Fetching global tag list... Done: %s global tags found.', len(gts))
134  return gts
135 
136 
def fetch_gts(connection)
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def conddb_migrate.main ( )
Entry point.

Definition at line 212 of file conddb_migrate.py.

References check_and_run().

212 def main():
213  '''Entry point.
214  '''
215 
216  parser = argparse.ArgumentParser(description='conddb_migrate - the CMS Conditions DB migration script')
217  parser.add_argument('--verbose', '-v', action='count', help='Verbosity level. -v prints debugging information of this tool, like tracebacks in case of errors.')
218  parser.add_argument('--output', '-o', default=time.strftime('%Y-%m-%d-%H-%M-%S'), help='Output folder. Default: {current_timestamp}, i.e. %(default)s')
219  parser.add_argument('db', help='Destination database. Aliases: "root" (CMS_CONDITIONS), "boost" (CMS_TEST_CONDITIONS), both in prep. *Make sure the database kind matches the code, i.e. use a BOOST IB when uploading to a Boost database; and a normal release when uploading to the ROOT database -- this script checks the CMSSW_VERSION when using the two official aliases in prep to prevent mistakes, but not for other databases.*')
220  parser_subparsers = parser.add_subparsers(title='Available subcommands')
221 
222  parser_account = parser_subparsers.add_parser('account', description='Migrates all (non-migrated) tags, IOVs and payloads, from an account.')
223  parser_account.add_argument('account', help='The account to migrate.')
224  parser_account.set_defaults(func=migrate_account)
225 
226  parser_accounts = parser_subparsers.add_parser('accounts', description='Migrates all accounts (see "account" command).')
227  parser_accounts.add_argument('--jobs', '-j', type=int, default=4, help='Number of jobs.')
228  parser_accounts.set_defaults(func=migrate_accounts)
229 
230  parser_gt = parser_subparsers.add_parser('gt', description='Migrates a single global tag.')
231  parser_gt.add_argument('gt', help='The global tag to migrate.')
232  parser_gt.set_defaults(func=migrate_gt)
233 
234  parser_gts = parser_subparsers.add_parser('gts', description='Migrates all global tags (see "gt" command).')
235  parser_gts.add_argument('authpath', help='Authentication path.')
236  parser_gts.add_argument('--jobs', '-j', type=int, default=4, help='Number of jobs.')
237  parser_gts.set_defaults(func=migrate_gts)
238 
239  parser_tags_in_gts = parser_subparsers.add_parser('tags_in_gts', description='Dumps the set of tags (including account name) which are in each global tag.')
240  parser_tags_in_gts.add_argument('authpath', help='Authentication path.')
241  parser_tags_in_gts.set_defaults(func=tags_in_gts)
242 
243  args = parser.parse_args()
244 
245  logging.basicConfig(
246  format = '[%(asctime)s] %(levelname)s: %(message)s',
247  level = logging.DEBUG if args.verbose >= 1 else logging.INFO,
248  )
249 
250  if args.verbose >= 1:
251  # Include the traceback
252  check_and_run(args)
253  else:
254  # Only one error line
255  try:
256  check_and_run(args)
257  except Exception as e:
258  logging.error(e)
259  sys.exit(1)
260 
261 
def check_and_run(args)
def conddb_migrate.make_gt_connection (   args)

Definition at line 116 of file conddb_migrate.py.

References digitizers_cfi.strip.

Referenced by migrate_gts(), and tags_in_gts().

117  logging.info('Fetching global tag list...')
118  password = subprocess.check_output('''cat %s | grep -F 'CMS_COND_31X_GLOBALTAG' -2 | tail -1 | cut -d'"' -f4''' % os.path.join(args.authpath, 'readOnlyProd.xml'), shell=True).strip()
119  return cx_Oracle.connect('CMS_COND_GENERAL_R', password, 'cms_orcon_adg')
120 
121 
def make_gt_connection(args)
def conddb_migrate.migrate_account (   args)

Definition at line 95 of file conddb_migrate.py.

References run_command().

95 def migrate_account(args):
96  command_template = '$CMSSW_BASE/bin/$SCRAM_ARCH/conddb_migrate -s oracle://cms_orcon_adg/%s -d %s'
97  command = command_template % (args.account, args.db)
98  run_command(command, os.path.join(args.output, args.account))
99 
100 
def migrate_account(args)
def run_command(command, output_file)
def conddb_migrate.migrate_accounts (   args)

Definition at line 101 of file conddb_migrate.py.

References genParticles_cff.map.

102  def _make_args(args, account):
103  newargs = argparse.Namespace(**vars(args))
104  newargs.account = account
105  return newargs
106 
107  multiprocessing.Pool(args.jobs).map(migrate_account, [_make_args(args, account) for account in accounts])
108 
109 
def migrate_accounts(args)
def conddb_migrate.migrate_gt (   args)

Definition at line 110 of file conddb_migrate.py.

References run_command().

110 def migrate_gt(args):
111  command_template = '$CMSSW_BASE/bin/$SCRAM_ARCH/conddb_migrate_gt -s oracle://cms_orcon_adg/CMS_COND_31X_GLOBALTAG -d %s -g %s'
112  command = command_template % (args.db, args.gt)
113  run_command(command, os.path.join(args.output, args.gt))
114 
115 
def migrate_gt(args)
def run_command(command, output_file)
def conddb_migrate.migrate_gts (   args)

Definition at line 137 of file conddb_migrate.py.

References fetch_gts(), make_gt_connection(), and genParticles_cff.map.

137 def migrate_gts(args):
138  gts = fetch_gts(make_gt_connection(args))
139 
140  def _make_args(args, gt):
141  newargs = argparse.Namespace(**vars(args))
142  newargs.gt = gt
143  return newargs
144 
145  multiprocessing.Pool(args.jobs).map(migrate_gt, [_make_args(args, gt) for gt in gts])
146 
147 
def fetch_gts(connection)
def make_gt_connection(args)
def migrate_gts(args)
def conddb_migrate.run_command (   command,
  output_file 
)

Definition at line 86 of file conddb_migrate.py.

Referenced by migrate_account(), and migrate_gt().

86 def run_command(command, output_file):
87  command = '%s > %s 2>&1' % (command, output_file)
88  logging.info('Running %s', command)
89  try:
90  subprocess.check_call(command, shell=True)
91  except subprocess.CalledProcessError as e:
92  logging.error('Error while running %s: return code %s', command, e.returncode)
93 
94 
def run_command(command, output_file)
def conddb_migrate.tags_in_gts (   args)

Definition at line 148 of file conddb_migrate.py.

References PVValHelper.add(), fetch_gts(), and make_gt_connection().

148 def tags_in_gts(args):
149  # Dynamic SQL is used due to the schema
150  # This is OK since we trust the input,
151  # which is the GT database's tables.
152 
153  connection = make_gt_connection(args)
154  gts = fetch_gts(connection)
155  account_tags = {}
156 
157  for i, gt in enumerate(gts):
158  logging.info('[%s/%s] Reading %s ...', i+1, len(gts), gt)
159  cursor = connection.cursor()
160  cursor.execute('''
161  select "pfn", "tagname"
162  from CMS_COND_31X_GLOBALTAG.TAGINVENTORY_TABLE
163  where "tagid" in (
164  select "tagid"
165  from CMS_COND_31X_GLOBALTAG.TAGTREE_TABLE_%s
166  )
167  ''' % gt)
168 
169  for account, tag in cursor:
170  account_tags.setdefault(account, set([])).add(tag)
171 
172  for account in sorted(account_tags):
173  print account
174  for tag in sorted(account_tags[account]):
175  print ' ', tag
176  print
177 
178 
def fetch_gts(connection)
def make_gt_connection(args)
def tags_in_gts(args)
void add(std::map< std::string, TH1 * > &h, TH1 *hist)