AEM
master.WriterThread Class Reference
Inheritance diagram for master.WriterThread:

Public Member Functions

def __init__ (self, name, q, lock, fileLockDict, syncTimeFunc, dataDir, stopEvt)
 
def getFormattedRow (self, row)
 
def createDataFile (self, outFile)
 
def decodeADCCID (self, coded)
 
def getFile (self, row)
 
def releaseFile (self, filename)
 
def do_work (self, thing)
 
def run (self)
 

Data Fields

 fileLockDict
 for file name lookup More...
 
 name
 string name of the thread, used for debugging or information messages More...
 
 q
 work q, source of data to be written to files More...
 
 dictLock
 semaphore for exclusive access to the fileLockDict More...
 
 fileLock
 semaphore locking access to the file currently being written More...
 
 dataDir
 path to the data file target directory More...
 
 getSynchTimeFunc
 function which when called will return the synchronisation time of the boards More...
 
 stopEvent
 setting this event cause the main program to exit More...
 

Constructor & Destructor Documentation

def master.WriterThread.__init__ (   self,
  name,
  q,
  lock,
  fileLockDict,
  syncTimeFunc,
  dataDir,
  stopEvt 
)
Consumer class instanciation:
The Writer thread implements the consumer in the producer/consumer paradigm.
The number of threads created is not known by the individual threads. They
simply pop things off the shared thread-safe queue, extract the data, and
write to the correct data (csv) file, creating it and the data directory if needed.
The file names for the data files are created from the data elts themselves, in combination
with the information obtained by callingthe syncTimeFunc provided as argument.
Data file names are used as keys in the shared fileLockDict, whre the values are semaphores
ensuring unique access to each file.
@param self
@param name a string naming the thread, legacy but left to allow for easier debugging
@param q the thread-safe q which will be popped to get data
@param lock the semaphore ensure unique access to the fileLockDict
@param dataDir the path to the data directory
@param syncTimeFunc a function that will be called to get the synch time to be used 
in naming the data files.
#param stopEvt an event that is set in case this thread has detected 
a failure contidition

Member Function Documentation

def master.WriterThread.createDataFile (   self,
  outFile 
)
Called to create the data csv file and write the header row.
def master.WriterThread.decodeADCCID (   self,
  coded 
)
Decodes the ADC and Channel values which were encoded onto a single byte such that
the top 4 bits are the ADC id, and the lower four are the channel id.
@param coded a single byte containing the encoded values
@return a list as decoded into [ADC_ID, Channel_ID]
def master.WriterThread.do_work (   self,
  thing 
)
This method handles the 'consuming' of the thing popped from the queue.
After obtaining a lock for the appropriate data file, a csv row is written,
the lock is released.
@param the object popped from the queue, in our case a list of length 4:
ADCCID,Timestamp,value, Board_ID
def master.WriterThread.getFile (   self,
  row 
)
the filename is computed, then the dictLock is acquired to access the fileLockDict and
get a lock for the data file, creating the lock if needed.
the dictLock is released and the fileLock is aquire before returning
@param row the data to be used to get the file name
def master.WriterThread.getFormattedRow (   self,
  row 
)
Formats a row by rounding the float values to 4 decimals
@param row the data row,
@return the row as a list ready to be written to the csv data file.
def master.WriterThread.releaseFile (   self,
  filename 
)
Simply releases the fileLock
def master.WriterThread.run (   self)
Thread run method. pops the queue, sends the popped thing to be consumed.
if a None value is popped, the method exits properply and the thread ends.

Field Documentation

master.WriterThread.dataDir

path to the data file target directory

master.WriterThread.dictLock

semaphore for exclusive access to the fileLockDict

master.WriterThread.fileLock

semaphore locking access to the file currently being written

master.WriterThread.fileLockDict

for file name lookup

master.WriterThread.getSynchTimeFunc

function which when called will return the synchronisation time of the boards

master.WriterThread.name

string name of the thread, used for debugging or information messages

master.WriterThread.q

work q, source of data to be written to files

master.WriterThread.stopEvent

setting this event cause the main program to exit


The documentation for this class was generated from the following file: