CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions
conditionUploadTest Namespace Reference

Classes

class  DB
 
class  UploadTest
 

Functions

def main
 
def makeBaseFile
 
def makeMetadataFile
 
def uploadFile
 

Function Documentation

def conditionUploadTest.main ( )

Definition at line 165 of file conditionUploadTest.py.

References makeBaseFile(), and print().

166 def main():
167  print('Testing...')
168  serviceName = 'cms_orcoff_prep'
169  schemaName = 'CMS_CONDITIONS'
170  db = DB(serviceName,schemaName)
171  db.connect()
172  inputTag = 'runinfo_31X_mc'
173  bfile0 = makeBaseFile( inputTag,1)
174  bfile1 = makeBaseFile( inputTag,100)
175  test = UploadTest( db )
176  # test with synch=any
177  tag = 'test_CondUpload_any'
178  test.upload( inputTag, bfile0, tag, 'any', 1, True, 'CREATE' )
179  test.upload( inputTag, bfile1, tag, 'any', 1, False, 'FAIL' )
180  test.upload( inputTag, bfile0, tag, 'any', 200, True, 'APPEND' )
181  test.upload( inputTag, bfile0, tag, 'any', 100, True, 'INSERT')
182  test.upload( inputTag, bfile0, tag, 'any', 200, True, 'INSERT')
183  db.removeTag( tag )
184  # test with synch=validation
185  tag = 'test_CondUpload_validation'
186  test.upload( inputTag, bfile0, tag, 'validation', 1, True, 'CREATE')
187  db.setSynchronizationType( tag, 'validation' )
188  test.upload( inputTag, bfile0, tag, 'validation', 1, True, 'INSERT')
189  test.upload( inputTag, bfile0, tag, 'validation', 200, True, 'APPEND')
190  test.upload( inputTag, bfile0, tag, 'validation', 100, True, 'INSERT')
191  db.removeTag( tag )
192  # test with synch=mc
193  tag = 'test_CondUpload_mc'
194  test.upload( inputTag, bfile1, tag, 'mc', 1, False, 'FAIL')
195  test.upload( inputTag, bfile0, tag, 'mc', 1, True, 'CREATE')
196  db.setSynchronizationType( tag, 'mc' )
197  test.upload( inputTag, bfile0, tag, 'mc', 1, False, 'FAIL')
198  test.upload( inputTag, bfile0, tag, 'mc', 200, False, 'FAIL')
199  db.removeTag( tag )
200  # test with synch=hlt
201  tag = 'test_CondUpload_hlt'
202  test.upload( inputTag, bfile0, tag, 'hlt', 1, True, 'CREATE')
203  db.setSynchronizationType( tag, 'hlt' )
204  test.upload( inputTag, bfile0, tag, 'hlt', 200, True, 'SYNCHRONIZE')
205  fcsr = test.upload( inputTag, bfile0, tag, 'hlt', 100, True, 'SYNCHRONIZE')
206  if not fcsr is None:
207  since = fcsr + 200
208  test.upload( inputTag, bfile0, tag, 'hlt', since, True, 'APPEND')
209  since = fcsr + 100
210  test.upload( inputTag, bfile0, tag, 'hlt', since, True, 'INSERT')
211  db.removeTag( tag )
212  # test with synch=express
213  tag = 'test_CondUpload_express'
214  test.upload( inputTag, bfile0, tag, 'express', 1, True, 'CREATE')
215  db.setSynchronizationType( tag, 'express' )
216  test.upload( inputTag, bfile0, tag, 'express', 200, True, 'SYNCHRONIZE')
217  fcsr = test.upload( inputTag, bfile0, tag, 'express', 100, True, 'SYNCHRONIZE')
218  if not fcsr is None:
219  since = fcsr + 200
220  test.upload( inputTag, bfile0, tag, 'express', since, True, 'APPEND')
221  since = fcsr + 100
222  test.upload( inputTag, bfile0, tag, 'express', since, True, 'INSERT')
223  db.removeTag( tag )
224  # test with synch=prompt
225  tag = 'test_CondUpload_prompt'
226  test.upload( inputTag, bfile0, tag, 'prompt', 1, True, 'CREATE')
227  db.setSynchronizationType( tag, 'prompt' )
228  test.upload( inputTag, bfile0, tag, 'prompt', 200, True, 'SYNCHRONIZE')
229  fcsr = test.upload( inputTag, bfile0, tag, 'prompt', 100, True, 'SYNCHRONIZE')
230  if not fcsr is None:
231  since = fcsr + 200
232  test.upload( inputTag, bfile0, tag, 'prompt', since, True, 'APPEND')
233  since = fcsr + 100
234  test.upload( inputTag, bfile0, tag, 'prompt', since, True, 'INSERT')
235  db.removeTag( tag )
236  # test with synch=pcl
237  tag = 'test_CondUpload_pcl'
238  test.upload( inputTag, bfile0, tag, 'pcl', 1, True, 'CREATE')
239  db.setSynchronizationType( tag, 'pcl' )
240  test.upload( inputTag, bfile0, tag, 'pcl', 200, False, 'FAIL')
241  if not fcsr is None:
242  since = fcsr + 200
243  test.upload( inputTag, bfile0, tag, 'pcl', since, True, 'APPEND')
244  since = fcsr + 100
245  test.upload( inputTag, bfile0, tag, 'pcl', since, True, 'INSERT')
246  db.removeTag( tag )
247  # test with synch=offline
248  tag = 'test_CondUpload_offline'
249  test.upload( inputTag, bfile0, tag, 'offline', 1, True, 'CREATE')
250  db.setSynchronizationType( tag, 'offline' )
251  test.upload( inputTag, bfile0, tag, 'offline', 1000, True, 'APPEND')
252  test.upload( inputTag, bfile0, tag, 'offline', 500, False, 'FAIL' )
253  test.upload( inputTag, bfile0, tag, 'offline', 1000, False, 'FAIL' )
254  test.upload( inputTag, bfile0, tag, 'offline', 2000, True, 'APPEND' )
255  db.removeTag( tag )
256  # test with synch=runmc
257  tag = 'test_CondUpload_runmc'
258  test.upload( inputTag, bfile0, tag, 'runmc', 1, True, 'CREATE')
259  db.setSynchronizationType( tag, 'runmc' )
260  test.upload( inputTag, bfile0, tag, 'runmc', 1000, True, 'APPEND')
261  test.upload( inputTag, bfile0, tag, 'runmc', 500, False, 'FAIL' )
262  test.upload( inputTag, bfile0, tag, 'runmc', 1000, False, 'FAIL' )
263  test.upload( inputTag, bfile0, tag, 'runmc', 2000, True, 'APPEND' )
264  db.removeTag( tag )
265  os.remove( bfile0 )
266  os.remove( bfile1 )
267  print('Done. Errors: %s' %test.errors)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def conditionUploadTest.makeBaseFile (   inputTag,
  startingSince 
)

Definition at line 56 of file conditionUploadTest.py.

Referenced by main().

56 
57 def makeBaseFile( inputTag, startingSince ):
58  cwd = os.getcwd()
59  baseFile = '%s_%s.db' %(inputTag,startingSince)
60  baseFilePath = os.path.join(cwd,baseFile)
61  if os.path.exists( baseFile ):
62  os.remove( baseFile )
63  command = "conddb_import -c sqlite_file:%s -f oracle://cms_orcon_adg/CMS_CONDITIONS -i %s -t %s -b %s" %(baseFile,inputTag,inputTag,startingSince)
64  pipe = subprocess.Popen( command, shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
65  out = pipe.communicate()[0]
66  if not os.path.exists( baseFile ):
67  msg = 'ERROR: base file has not been created: %s' %out
68  raise Exception( msg )
69  return baseFile
70 
def conditionUploadTest.makeMetadataFile (   inputTag,
  destTag,
  since,
  description 
)

Definition at line 71 of file conditionUploadTest.py.

Referenced by conditionUploadTest.UploadTest.upload().

71 
72 def makeMetadataFile( inputTag, destTag, since, description ):
73  cwd = os.getcwd()
74  metadataFile = os.path.join(cwd,'%s.txt') %destTag
75  if os.path.exists( metadataFile ):
76  os.remove( metadataFile )
77  metadata = {}
78  metadata[ "destinationDatabase" ] = "oracle://cms_orcoff_prep/CMS_CONDITIONS"
79  tagList = {}
80  tagList[ destTag ] = { "dependencies": {}, "synchronizeTo": "any" }
81  metadata[ "destinationTags" ] = tagList
82  metadata[ "inputTag" ] = inputTag
83  metadata[ "since" ] = since
84  metadata[ "userText" ] = description
85  fileName = destTag+".txt"
86  with open( fileName, "w" ) as file:
87  file.write(json.dumps(metadata,file,indent=4,sort_keys=True))
def conditionUploadTest.uploadFile (   fileName,
  logFileName 
)

Definition at line 88 of file conditionUploadTest.py.

References digitizers_cfi.strip.

Referenced by conditionUploadTest.UploadTest.upload().

88 
89 def uploadFile( fileName, logFileName ):
90  command = "uploadConditions.py %s" %fileName
91  pipe = subprocess.Popen( command, shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
92  out = pipe.communicate()[0]
93  lines = out.split('\n')
94  ret = False
95  for line in lines:
96  if line.startswith('upload ended with code:'):
97  returnCode = line.split('upload ended with code:')[1].strip()
98  if returnCode == '0':
99  ret = True
100  break
101  with open(logFileName,'a') as logFile:
102  logFile.write(out)
103  return ret