ATLAS Offline Software
Public Member Functions | Public Attributes | Private Member Functions | List of all members
python.DQUtilities.IDBSDefectWriter Class Reference
Collaboration diagram for python.DQUtilities.IDBSDefectWriter:

Public Member Functions

def __init__ (self, fileName, forceNew=False, dbName='IDBSDQ', tag='nominal', user='sys:dqBeamSpot')
 
def __del__ (self)
 
def connect (self, fileName, forceNew=False, dbName='IDBSDQ', tag='nominal')
 
def defectType (self, t)
 
def add (self, runMin=0, runMax=(1<< 31) -1, lbMin=0, lbMax=(1<< 32) -1)
 
def complete (self, runMin, runMax)
 
def writeDefects (self, tag='nominal', nonpresent=False)
 
def dump (self, filename=None)
 

Public Attributes

 defect
 
 iovs
 
 user
 
 db
 
 officialDb
 

Private Member Functions

def _writeDefect (self, defect, since, until, tag='nominal', description='', comment='', present=True, recoverable=False)
 

Detailed Description

Class for writing BS defects to an sqlite file

Definition at line 19 of file DQUtilities.py.

Constructor & Destructor Documentation

◆ __init__()

def python.DQUtilities.IDBSDefectWriter.__init__ (   self,
  fileName,
  forceNew = False,
  dbName = 'IDBSDQ',
  tag = 'nominal',
  user = 'sys:dqBeamSpot' 
)
Initialise database connection 

Definition at line 24 of file DQUtilities.py.

24  def __init__(self,fileName, forceNew=False, dbName='IDBSDQ', tag='nominal', user='sys:dqBeamSpot'): """
25  Initialise database connection
26  """
27  self.defect = None
28  self.iovs = IOVSet()
29  self.user = user
30 
31  #self.allowedDefects = DefectsDB('').defect_names
32 
33  if not fileName: fileName = 'tmp.'+str(os.getpid())+'.db'
34 
35  self.connect(fileName, forceNew, dbName, tag)
36 
37  pass
38 
39 

◆ __del__()

def python.DQUtilities.IDBSDefectWriter.__del__ (   self)
Delete db to clear connection

Definition at line 40 of file DQUtilities.py.

40  def __del__(self):
41  """
42  Delete db to clear connection
43  """
44 
45  os.system('[[ -f tmp.%s.db ]] && rm tmp.%s.db' %(os.getpid(), os.getpid()))
46  del self.db
47  pass
48 
49 

Member Function Documentation

◆ _writeDefect()

def python.DQUtilities.IDBSDefectWriter._writeDefect (   self,
  defect,
  since,
  until,
  tag = 'nominal',
  description = '',
  comment = '',
  present = True,
  recoverable = False 
)
private
Write a single defect to the database

Definition at line 158 of file DQUtilities.py.

158  def _writeDefect(self,defect, since, until, tag='nominal', description='', comment='', present=True, recoverable=False):
159  """
160  Write a single defect to the database
161  """
162 
163  if defect not in self.db.defect_names:
164  self.db.create_defect(defect, description)
165 
166  self.db.insert(defect, since, until, comment, self.user, present, recoverable)
167 
168  return
169 

◆ add()

def python.DQUtilities.IDBSDefectWriter.add (   self,
  runMin = 0,
  runMax = (1 << 31)-1,
  lbMin = 0,
  lbMax = (1 << 32)-1 
)
Add iovs which are NOT defective to the list
Note, lbMax is exclusive here (and inclusive when shown on defect web page). 

Definition at line 72 of file DQUtilities.py.

72  def add(self,runMin=0, runMax=(1 << 31)-1, lbMin=0, lbMax=(1 << 32)-1):
73  """
74  Add iovs which are NOT defective to the list
75  Note, lbMax is exclusive here (and inclusive when shown on defect web page).
76  """
77 
78  # Make since and until and convert to syntactially nice RunLumiType
79  since = RunLumiType((runMin << 32)+lbMin)
80  until = RunLumiType((runMax << 32)+lbMax)
81 
82  # IoVs which are not defective (i.e. beamspot good)
83  self.iovs.add(since, until, self.defect, False)
84  return
85 
86 

◆ complete()

def python.DQUtilities.IDBSDefectWriter.complete (   self,
  runMin,
  runMax 
)
Complete a list of IoVs to cover all LBs in a run, treating empty ones as having 'emptyState'

Definition at line 87 of file DQUtilities.py.

87  def complete(self, runMin, runMax):
88  """
89  Complete a list of IoVs to cover all LBs in a run, treating empty ones as having 'emptyState'
90 
91  """
92 
93  # Create an IOV set covering the entire run(s)
94  run_lbs = fetch_iovs("EOR", runs=(runMin, runMax), what=[], with_channel=False)
95 
96 
97  # run_lbs = IOVSet()
98  # lbMin = 1
99  # lbMax = (1 << 32) -1 # Note, lbMax is exclusive
100  # since = RunLumiType((runMin << 32)+lbMin)
101  # until = RunLumiType((runMax << 32)+lbMax)
102  # run_lbs.add(since, until)
103 
104  if not len(run_lbs):
105  print ("WARNING: No LBs in run according to EOR_Params - are we running before the run has finished?")
106 
107  def lbsStartAtOne(iov):
108  "Change LBs starting at 0 to start at 1"
109  return iov._replace(since=RunLumi(iov.since.run, 1))
110 
111  # Start LBs from 1 rather than 0 (at request of P. Onyisi) as long as run has more than one LB (else skip)
112  run_lbs = [lbsStartAtOne(iov) for iov in run_lbs if iov.until.lumi > 1]
113 
114  # Empty IOV set for adding full list of LBs too
115  iovs = IOVSet()
116 
117  # Ask official DB if an IoV is currently defective so can unset only those if doing reprocessing
118  defectsCurrentlyInDb = self.officialDb.retrieve((runMin, 0), (runMax+1, 0), [self.defect])
119 
120  # Order IOVs to avoid since > until
121  self.iovs = IOVSet(sorted(self.iovs))
122 
123  #for since, until, (run_lb, iov, dbDefect) in process_iovs(run_lbs.solidify(RANGEIOV_VAL), self.iovs.solidify(DEFECTIOV_VAL), defectsCurrentlyInDb):
124  for since, until, (run_lb, iov, dbDefect) in process_iovs(run_lbs, self.iovs.solidify(DEFECTIOV_VAL), defectsCurrentlyInDb):
125  if not run_lb: continue # Check valid
126 
127 # # Start LBs from 1 rather than 0 (at request of P. Onyisi)
128 # # If this makes since==until, i.e. it was a [0->1) LB range then skip
129 # if since.lumi==0:
130 # since = RunLumiType((since.run << 32)+since.lumi+1)
131 # if since==until: continue
132 
133  # Add iovs from self.iovs treating empty ones as defective (i.e. beamspot bad/missing)
134  if iov:
135  # These are not defective
136  if dbDefect and dbDefect.present:
137  # Only store not defective IoVs if they are present on the Db so we can unset them
138  # (don't want to write not present defects to Db unless really chaning an existing defect)
139  iovs.add(since, until, self.defect, False)
140  else:
141  # These are defective
142  iovs.add(since, until, self.defect, True)
143 
144  self.iovs = iovs
145  return
146 

◆ connect()

def python.DQUtilities.IDBSDefectWriter.connect (   self,
  fileName,
  forceNew = False,
  dbName = 'IDBSDQ',
  tag = 'nominal' 
)
Open connection to defect DB

Definition at line 50 of file DQUtilities.py.

50  def connect(self, fileName, forceNew=False, dbName='IDBSDQ', tag='nominal'):
51  """
52  Open connection to defect DB
53  """
54 
55  connString = 'sqlite://;schema=%s;dbname=%s' % (fileName,dbName)
56 
57  if forceNew and os.path.exists(fileName):
58  os.remove(fileName)
59 
60  self.db = DefectsDB(connString, read_only=False, create=True, tag=(tag, 'HEAD')) # Second tag is for virtual defects, which we are not interested in
61 
62  self.officialDb = DefectsDB()
63 
64  return
65 

◆ defectType()

def python.DQUtilities.IDBSDefectWriter.defectType (   self,
  t 
)
Set defect type

Definition at line 66 of file DQUtilities.py.

66  def defectType(self,t):
67  """
68  Set defect type
69  """
70  self.defect = t
71 

◆ dump()

def python.DQUtilities.IDBSDefectWriter.dump (   self,
  filename = None 
)
Dump defects to a file given by filename or stdout if no filename given

Definition at line 170 of file DQUtilities.py.

170  def dump(self, filename = None):
171  """
172  Dump defects to a file given by filename or stdout if no filename given
173  """
174 
175  from DQUtils.utils import pprint_objects
176 
177  if filename is not None:
178  f = open(filename.replace('.db', '.txt'), "w")
179  # If not defects then nothing will be in the database and we write an empty file
180  if len(self.iovs):
181  pprint_objects(self.db.retrieve(primary_only=True, nonpresent=True), f)
182  f.close()
183  else:
184  if len(self.iovs):
185  self.iovs.pprint()
186  else:
187  print ('\nNo DQ defects')
188 
189  # with open(filename.replace('.db', '.txt'), "w") as f:
190  # pprint_objects(self.db.retrieve(), f)
191 
192 
193  return
194 
195 

◆ writeDefects()

def python.DQUtilities.IDBSDefectWriter.writeDefects (   self,
  tag = 'nominal',
  nonpresent = False 
)
Write all defects to the database.  If 'nonpresent' is True then write the absent ones too

Definition at line 147 of file DQUtilities.py.

147  def writeDefects(self, tag='nominal', nonpresent=False):
148  """
149  Write all defects to the database. If 'nonpresent' is True then write the absent ones too
150  """
151 
152  with self.db.storage_buffer:
153  for since, until, defect, present in self.iovs:
154  if not present and not nonpresent: continue
155  #print (since, until, present)
156  self._writeDefect(defect, since, until, present = present)
157 

Member Data Documentation

◆ db

python.DQUtilities.IDBSDefectWriter.db

Definition at line 60 of file DQUtilities.py.

◆ defect

python.DQUtilities.IDBSDefectWriter.defect

Definition at line 28 of file DQUtilities.py.

◆ iovs

python.DQUtilities.IDBSDefectWriter.iovs

Definition at line 29 of file DQUtilities.py.

◆ officialDb

python.DQUtilities.IDBSDefectWriter.officialDb

Definition at line 62 of file DQUtilities.py.

◆ user

python.DQUtilities.IDBSDefectWriter.user

Definition at line 30 of file DQUtilities.py.


The documentation for this class was generated from the following file:
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
python.db.fetch_iovs
def fetch_iovs(folder_name, since=None, until=None, channels=None, tag="", what="all", max_records=-1, with_channel=True, loud=False, database=None, convert_time=False, named_channels=False, selection=None, runs=None, with_time=False, unicode_strings=False)
Definition: DQUtils/python/db.py:67
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
run_Egamma1_LArStrip_Fex.dump
dump
Definition: run_Egamma1_LArStrip_Fex.py:88
python.sugar.runlumi.RunLumi
RunLumi
Definition: runlumi.py:131
python.utils.pprint_objects
def pprint_objects(objects, where=stdout)
Definition: DataQuality/DQUtils/python/utils.py:129
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
python.events.process_iovs
def process_iovs(*iovsets)
Definition: events.py:30
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40
python.AthDsoLogger.__del__
def __del__(self)
Definition: AthDsoLogger.py:82
str
Definition: BTagTrackIpAccessor.cxx:11