ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
COOLRates.COOLQueryHandler Class Reference
Inheritance diagram for COOLRates.COOLQueryHandler:
Collaboration diagram for COOLRates.COOLQueryHandler:

Public Member Functions

def __init__ (self, mySignal, numProc=None, timeConverter={}, verbose=False)
 
def createProcesses (self)
 
def addQueryBundle (self, queryBundle)
 
def beginQuery (self)
 
def processResults (self, resultBundle)
 
def terminateProcesses (self)
 
def collectResults (self)
 

Public Attributes

 troughQueue
 
 resultQueue
 
 QueryProcesses
 
 result
 
 counter
 
 verbose
 
 timeConverter
 
 mySignal
 
 numProc
 

Detailed Description

Definition at line 155 of file COOLRates.py.

Constructor & Destructor Documentation

◆ __init__()

def COOLRates.COOLQueryHandler.__init__ (   self,
  mySignal,
  numProc = None,
  timeConverter = {},
  verbose = False 
)

Definition at line 156 of file COOLRates.py.

156  def __init__(self,mySignal,numProc=None,timeConverter={},verbose=False):
157  self.troughQueue = Queue()
158  self.resultQueue = Queue()
159  self.QueryProcesses = []
160  self.result = {}
161  self.counter=0
162  self.verbose = verbose
163  self.timeConverter = timeConverter
164  self.mySignal = mySignal
165  if numProc is None: numProc = cpu_count()
166  self.numProc = numProc
167 

Member Function Documentation

◆ addQueryBundle()

def COOLRates.COOLQueryHandler.addQueryBundle (   self,
  queryBundle 
)

Definition at line 174 of file COOLRates.py.

174  def addQueryBundle(self,queryBundle):
175  self.counter+=1
176  self.troughQueue.put(queryBundle)
177 

◆ beginQuery()

def COOLRates.COOLQueryHandler.beginQuery (   self)

Definition at line 178 of file COOLRates.py.

178  def beginQuery(self):
179  self.createProcesses()
180  for i in range(self.numProc):
181  self.troughQueue.put(True)
182  logger.info('{0} queries distributed over {1} workers'.format(self.counter,len(self.QueryProcesses)))
183  for process in self.QueryProcesses: process.start()
184  try:
185  self.collectResults()
186  except KeyboardInterrupt:
187  logger.critical('Caught signal, terminating processes')
188  self.terminateProcesses()
189  return
190  for process in self.QueryProcesses: process.join()
191  return
192 

◆ collectResults()

def COOLRates.COOLQueryHandler.collectResults (   self)

Definition at line 211 of file COOLRates.py.

211  def collectResults(self):
212  finished = 0
213  startingQueries = self.counter
214  target=0.
215  while True:
216  if not self.mySignal.is_alive():
217  raise KeyboardInterrupt
218  break
219  #sys.exit(0)
220  try: resultBundle = self.resultQueue.get(False,0.001)
221  except Empty:
222  sleep(.001)
223  continue
224  if resultBundle is True:
225  finished+=1
226  if finished == self.numProc: break
227  continue
228  self.counter-=1
229  percentComplete = min(100,int(round(float(startingQueries-self.counter)/startingQueries*100+.5)))
230  if percentComplete>=target:
231  target+=5.
232  logger.info('{0}% complete'.format(percentComplete))
233  self.processResults(resultBundle)
234 # except KeyboardInterrupt:
235 # logger.critical('Caught signal, terminating processes')
236 # self.terminateProcesses()
237  return
238 
239 #====================================================================================================================
240 

◆ createProcesses()

def COOLRates.COOLQueryHandler.createProcesses (   self)

Reimplemented in COOLRates.RateQueryHandler.

Definition at line 168 of file COOLRates.py.

168  def createProcesses(self):
169  self.QueryProcesses = []
170  for i in range(self.numProc):
171  process = Process(target = COOLQueryWorker(timeConverter=self.timeConverter), args = (self.troughQueue,self.resultQueue,))
172  self.QueryProcesses.append(process)
173 

◆ processResults()

def COOLRates.COOLQueryHandler.processResults (   self,
  resultBundle 
)

Definition at line 193 of file COOLRates.py.

193  def processResults(self,resultBundle):
194  for resultAlias in resultBundle:
195  if resultAlias not in self.result: self.result[resultAlias]={}
196  self.result[resultAlias].update(resultBundle[resultAlias])
197 

◆ terminateProcesses()

def COOLRates.COOLQueryHandler.terminateProcesses (   self)

Definition at line 198 of file COOLRates.py.

198  def terminateProcesses(self):
199  while 1:
200  try:self.troughQueue.get(False)
201  except Empty: break
202  logger.critical('Queue is empty')
203  for i in range(self.numProc): self.troughQueue.put(True)
204  time.sleep(1)
205  for process in self.QueryProcesses:
206  process.terminate()
207  process.join()
208  logger.critical('Processes are joined')
209  raise KeyboardInterrupt
210 

Member Data Documentation

◆ counter

COOLRates.COOLQueryHandler.counter

Definition at line 161 of file COOLRates.py.

◆ mySignal

COOLRates.COOLQueryHandler.mySignal

Definition at line 164 of file COOLRates.py.

◆ numProc

COOLRates.COOLQueryHandler.numProc

Definition at line 166 of file COOLRates.py.

◆ QueryProcesses

COOLRates.COOLQueryHandler.QueryProcesses

Definition at line 159 of file COOLRates.py.

◆ result

COOLRates.COOLQueryHandler.result

Definition at line 160 of file COOLRates.py.

◆ resultQueue

COOLRates.COOLQueryHandler.resultQueue

Definition at line 158 of file COOLRates.py.

◆ timeConverter

COOLRates.COOLQueryHandler.timeConverter

Definition at line 163 of file COOLRates.py.

◆ troughQueue

COOLRates.COOLQueryHandler.troughQueue

Definition at line 157 of file COOLRates.py.

◆ verbose

COOLRates.COOLQueryHandler.verbose

Definition at line 162 of file COOLRates.py.


The documentation for this class was generated from the following file:
COOLRates.int
int
Definition: COOLRates.py:31
vtune_athena.format
format
Definition: vtune_athena.py:14
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
WriteBchToCool.update
update
Definition: WriteBchToCool.py:67
readCCLHist.float
float
Definition: readCCLHist.py:83