"""
Athenaeum Proxy to get Cool data
The script uses following initialisation variables:
server
dbname
schema
user
password
lod = "" || "everything" || "summary"
foldersChoice ("" == everything)
tagsChoice ("" == everything)
channelChoice ("" == everything)
startTime
stopTime
startRun
startLumi
stopRun
stopLumi
payloadLimit
showPoolRef = "true" || "false"
$Log: Cool.py,v $
Revision 1.6 2010/01/28 16:08:34 hrivnac
fix to always return Msg
Revision 1.5 2009/09/10 13:10:25 hrivnac
better integration with tag extraction
Revision 1.4 2009/03/19 21:17:51 hrivnac
progress bar generalised
Revision 1.3 2009/03/17 20:27:37 hrivnac
Cool.py LAr payloads fixed
Revision 1.2 2009/03/17 16:07:25 hrivnac
fix to LAr Cool browsing
Revision 1.1 2009/03/12 15:44:57 hrivnac
removing JAS/FreeHEP
Revision 1.81 2008/12/08 14:31:22 hrivnac
log() function added
Revision 1.80 2008/07/03 13:25:49 hrivnac
payloadLimit inforced
Revision 1.78 2008/03/12 16:24:28 hrivnac
event => lumi, LarcondType not required
Revision 1.77 2008/03/12 16:16:09 hrivnac
event => lumi
Revision 1.76 2008/02/13 15:27:26 hrivnac
LArCaliWaveContainer added
Revision 1.75 2008/02/13 11:41:12 hrivnac
possibility to get just Cool folders
Revision 1.74 2008/01/16 15:23:46 hrivnac
support for SQLite database; PoolRef strings can be shown
Revision 1.73 2007/12/22 15:24:32 hrivnac
Google Analytics added
Revision 1.72 2007/11/14 14:17:36 hrivnac
crash after second Cool call fixed
Revision 1.71 2007/10/27 22:04:49 hrivnac
standard servers reconfiguration
Revision 1.70 2007/10/25 10:28:49 hrivnac
LAr payloads fixes
Revision 1.69 2007/10/24 23:02:29 hrivnac
lar payloads improved
Revision 1.68 2007/10/24 13:49:26 hrivnac
LAr payload seledtion improved
Revision 1.67 2007/10/23 14:09:35 hrivnac
cleaning
Revision 1.66 2007/10/18 15:34:59 hrivnac
subtasks runninmg in a Thread; distributed via WebStart
Revision 1.65 2007/10/15 14:48:10 hrivnac
Cool payloads work
Revision 1.64 2007/10/09 23:51:13 hrivnac
channels work
Revision 1.63 2007/10/04 14:59:22 hrivnac
Cool updated
Revision 1.62 2007/09/27 21:00:06 hrivnac
Web Service stores Cool data in cookieslarCondTypeChoice
Revision 1.61 2007/09/20 15:01:44 hrivnac
even in case of partial everything choice, summary is shown for other folders
Revision 1.60 2007/07/06 15:52:45 hrivnac
prepared for 1.5.0
Revision 1.59 2007/06/19 15:18:24 hrivnac
works fine with Cool2
Revision 1.58 2007/06/14 15:12:15 hrivnac
Simple PyCool server supported
Revision 1.57 2007/06/04 14:16:20 hrivnac
SSH Tunnel is available via JAS
Revision 1.56 2007/04/23 15:46:46 hrivnac
improved xslt
Revision 1.55 2007/03/27 13:40:55 hrivnac
key/passwerd invisible; log files visible
Revision 1.54 2007/02/20 15:47:51 hrivnac
better LAr payploads, server connection timeout
Revision 1.53 2007/02/06 11:35:05 hrivnac
payloads are converted to NTuples
Revision 1.52 2007/02/01 18:14:08 hrivnac
larcodtypechoice simplified
Revision 1.51 2007/02/01 17:53:34 hrivnac
ntuple creation local; lar payloads improved
Revision 1.50 2006/12/22 14:24:24 hrivnac
reusing Athena dictionaries and Cool connections
Revision 1.49 2006/12/21 20:09:19 hrivnac
Cool looks also for related hierarchical tags
Revision 1.48 2006/12/21 15:55:50 hrivnac
time profiling added
Revision 1.47 2006/11/24 16:58:02 hrivnac
Progress bar improved
Revision 1.46 2006/11/23 20:43:36 hrivnac
progress bar added to WS
Revision 1.45 2006/11/02 16:20:39 hrivnac
staged request is available in WebService too
Revision 1.44 2006/11/02 11:19:16 hrivnac
more info for Cool
Revision 1.43 2006/10/31 18:42:52 hrivnac
set of tags and folders supported
Revision 1.42 2006/10/25 13:39:19 hrivnac
mail fix, other fixes
Revision 1.41 2006/10/24 15:23:52 hrivnac
ntuples work, nicer xslt
Revision 1.40 2006/10/20 16:38:18 hrivnac
better Cool.pyt & comp
Revision 1.39 2006/10/09 15:09:31 hrivnac
Python help added
Revision 1.38 2006/10/03 15:34:19 hrivnac
interactivity moved into XMLEditor
Revision 1.37 2006/09/29 14:49:59 hrivnac
Requester added, used for Cool
Revision 1.36 2006/09/26 13:59:38 hrivnac
ntuple/xml payload extraction possible
Revision 1.35 2006/09/22 13:34:40 hrivnac
Athenaeum.xsd updated
Revision 1.34 2006/09/20 08:11:03 hrivnac
works with ntuples on server
Revision 1.33 2006/09/17 14:19:19 hrivnac
LAr payloads as NTuple - half way through
Revision 1.32 2006/07/28 14:55:36 hrivnac
reports also about FolderSets
Revision 1.31 2006/07/27 16:19:49 hrivnac
LAr ramps and peds accessible
Revision 1.30 2006/07/26 14:05:57 hrivnac
12345,6 not advertised
Revision 1.29 2006/07/25 19:59:13 hrivnac
jaxml used to create xml
Revision 1.28 2006/07/10 14:00:58 hrivnac
migrated to 1.3.0
Revision 1.27 2006/06/22 16:40:17 hrivnac
payload analyses is optional
Revision 1.26 2006/04/27 11:33:38 hrivnac
1.4.0
Revision 1.25 2006/04/26 20:17:08 hrivnac
selection based on tag, channels and periods introduced
Revision 1.24 2006/04/26 12:14:35 hrivnac
C++ XSD Model added
Revision 1.23 2006/04/25 20:23:37 hrivnac
Cool selection enabled
Revision 1.22 2006/04/25 13:58:44 hrivnac
CPP wrapper introduced
Revision 1.21 2006/04/21 14:24:33 hrivnac
tuning
Revision 1.20 2006/04/20 15:40:03 hrivnac
cleaning
@version $Id: Cool.py 22023 2010-11-03 14:02:03Z hrivnac $
@author J.Hrivnac
@author R.D.Schaffer
"""
# Initialisation ###############################################################
resultTxt = ""
reportFebs = False
import re
import os
import socket
import PyCintex as pylcgdict
import jaxml
import time
from time import ctime, strptime, mktime
from PyCool import *
from IOVDbSvc.ConditionsContainerAccess import *
try:
from LArRawConditions.LArConditionsContainer import *
from LArConditionsCommon.LArCondContChannels import *
except:
resultTxt += "ATHENAEUM: Can't import LAr Conditions" + "\n"
# Initialise Time
t0 = time.time()
# Load LCG Dictionaries
global athenaAvailable
global coolInitialised
if athenaAvailable and not coolInitialised:
resultTxt += "ATHENAEUM: Initialising Cool in Athena" + "\n"
pylcgdict.loadDictionary('ReflexRflx')
coolInitialised = True
# Make folder helper class
CoolFolderHelper = PyLCGDict.makeClass('CoolFolderHelper')
coolFolderHelper = CoolFolderHelper()
# Utilities
class Utility:
resultTxt = ""
def __init__(self, rm):
resultTxt = rm
# This class is used to overcome the problem of vector iterators
# being 'destroyed' in a clash between the versions in ROOT and
# Reflex. This problem makes it impossible to iterate over a vector
# of simple types.
#
# The idea is to copy the contents of the vector into a list so then
# one can then iterate over the list.
#
# Usage:
#
# provide a vector object and its type as input, e.g.
#
# chs = vecIter(chans, "unsigned int")
#
# this returns a list-like object which can be iterated over, e.g.
#
# i = 0
# for c in chs:
# print 'i,c',i,c
# i += 1
#
class vecIter:
def __init__(self, vec, vecType):
# Get the class object for this type of vector
if vecType == 'int':
vectorType = pylcgdict.makeClass("std::vector")
elif vecType == 'unsigned int':
vectorType = pylcgdict.makeClass("std::vector")
elif vecType == 'float':
vectorType = pylcgdict.makeClass("std::vector")
elif vecType == 'double':
vectorType = pylcgdict.makeClass("std::vector")
else :
resultTxt += "ATHENAEUM: vecIter: unknown vector type " + str(vecType) + "\n"
raise
# Copy vector into a locally held list
tmp, self.vec = vectorType(vec),[]
for i in range(len(tmp)):
self.vec.append(tmp.back())
tmp.pop_back()
self.vec.reverse()
self.next = self._next().next
def _next(self):
for i in self.vec:
yield i
raise StopIteration
def __iter__(self):
return self._next()
def toArray(self):
arr = []
for element in self.vec:
arr += [element]
return arr
# Look to see if this is a LArConditionsContainer.
# Must check class name and its base classes
def isLArConditionsContainer(self, name):
self.resultTxt += "ATHENAEUM: Looking for LArConditionsContainer in name: " + str(name) + "\n"
if (name.find("LArConditionsContainer") != -1):
self.resultTxt += "ATHENAEUM: Found LArConditionsContainer in " + str(name) + "\n"
return True
# Not at this level, check base classes
# Create type object
rflxType = pylcgdict.makeClass("ROOT::Reflex::Type")
rtype = rflxType.ByName(name)
if rtype:
# Found type, check bases
for i in range(rtype.BaseSize()):
# For templates, extract the arguments
bname = rtype.BaseAt(i).ToType().Name()
self.resultTxt += "ATHENAEUM: Found base name: " + str(bname) + "\n"
found = self.isLArConditionsContainer(bname)
if found:
return found
else:
self.resultTxt += "ATHENAEUM: Could not get type for name: " + str(name) + "\n"
return False
# Loop over data members and print them out.
# We assume here that they are simple types or vectors of simple types
# Get object type
def getDataMembers(self, obj, objName):
import operator
if operator.isNumberType(obj):
self.resultTxt += "ATHENAEUM: Attribute name = " + str(objName) + ", value = " + str(obj) + "\n"
else:
objType = type(obj)
# If Object is a method, replace obj with the result of the method
if objType.__name__ == 'MethodProxy':
try:
obj = obj()
objType = type(obj)
# Exception is thrown for functions that take arguments. We
# ignore them for the moment. It may be that there are two
# methods, one providing access to individual values, and
# another giving a whole vector of values.
except:
pass
if operator.isNumberType(obj):
self.resultTxt += "ATHENAEUM: obj type = " + str(objType.__name__) + "\n"
self.resultTxt += "ATHENAEUM: Attribute name = " + str(objName) + ", value = " + str(obj) + "\n"
return
self.resultTxt += "ATHENAEUM: obj type = " + str(objType.__name__) + "\n"
# Is this a vector?
isVector = False
if objType.__name__.find('vector') == 0:
isVector = True
elif hasattr(obj,'begin') and hasattr(obj,'end') and hasattr(obj,'size'):
isVector = True
# If a vector, loop over elements and print each one out
if isVector:
i = 0
for o in obj:
self.getDataMembers(o, objName + '_' + str(i))
i += 1
# Assume a complex type, loop over attributes and print them out
else:
attrNames = dir(obj)
self.resultTxt += "ATHENAEUM: found attributes: " + str(attrNames) + "\n"
for attrName in attrNames:
# Select attributes that begin with m_ or get
if attrName.find("m_") == 0 or attrName.find("get") == 0:
try:
attr = getattr(obj, attrName)
except:
self.resultTxt += "ATHENAEUM: Could not get attr " + (attrName) + "\n"
self.getDataMembers(attr, attrName)
# Fill XML structure with conditions/corrections
# Documentation taken from http://atlas-computing.web.cern.ch/atlas-computing/links/nightlyDevDirectory/AtlasOffline/rel_2/InstallArea/doc//LArRawConditions/html/annotated.html
def analyseCondCorr(self, cond, larCondType, xml, gain, id, onlineID, start, stop, chan, type):
entry = cond[0]
id = cond[1]
# Don't test emptiness because its buggy
# if larCondType == "LArCaliWaveContainer":
# analyse = (entry.size() > 0)
# else:
# analyse = entry.isEmpty()
analyse = True
if analyse:
entries = []
# std::vector LArRampP.m_vRamp
if larCondType == "LArRampComplete":
vs = self.vecIter(entry.m_vRamp, "float")
# std::vector LArPedestalP.m_vPedestal
# std::vector LArPedestalP.m_vPedestalRMS
elif larCondType == "LArPedestalComplete":
vs = self.vecIter(entry.m_vPedestal, "float").toArray()
vs += self.vecIter(entry.m_vPedestalRMS, "float").toArray()
# std::vector LArAutoCorrP.m_vAutoCorr
elif larCondType == "LArAutoCorrComplete":
vs = self.vecIter(entry.m_vAutoCorr, "double")
# float LAruA2MeVP.m_uA2MeV
elif larCondType == "LAruA2MeVMC":
vs = [entry.m_uA2MeV]
# std::vector LArShapeP.m_vShape
# std::vector LArShapeP.m_vShapeDer
elif larCondType == "LArShapeComplete":
vs = self.vecIter(entry.m_vShape, "double").toArray()
vs += self.vecIter(entry.m_vShapeDer, "double").toArray()
# float LArOFCP.m_timeOffset
# std::vector> LArOFCP.m_vOFC_a
# std::vector> LArOFCP.m_vOFC_b
elif larCondType == "LArOFCComplete":
vs = [entry.m_timeOffset]
for x in entry.m_vOFC_a:
vs += self.vecIter(x, "float").toArray()
for x in entry.m_vOFC_b:
vs += self.vecIter(x, "float").toArray()
# float LArDAC2uAP.m_DAC2uA
elif larCondType == "LArDAC2uAMC":
vs = [entry.m_DAC2uA]
# float LArDetCellParamsP.m_Omega0
# float LArDetCellParamsP.m_Taur
elif larCondType == "LArDetCellParamsComplete":
vs = [entry.m_Omega0, entry.m_Taur]
# float LArMphysOverMcalP.m_MphysOverMcal
elif larCondType == "LArMphysOverMcalComplete":
vs = [entry.m_MphysOverMcal]
# float LArCaliPulseParamsP.m_Tcal
# float LArCaliPulseParamsP.m_Fstep
# float LArCaliPulseParamsP.m_Offset
# float LArCaliPulseParamsP.m_dTimeCal
# short LArCaliPulseParamsP.m_nCB
elif larCondType == "LArCaliPulseParamsComplete":
vs = [entry.m_Tcal, entry.m_Fstep, entry.m_Offset, entry.m_dTimeCal, entry.m_nCB]
# int LArCaliWave.getDAC()
# int LArCaliWave.getIsPulsedInt()
# std::vector LArWaveCumul.getTriggers()
# std::vector LArWaveCumul.getErrors()
# std::vector LArWave.getWave()
# double LArWave.getDt()
# unsigned LArWave.getFlag()
elif larCondType == "LArCaliWaveContainer":
vs = []
for e in entry:
vs += [e.getDAC(), e.getIsPulsedInt()]
vs += self.vecIter(e.getTriggers(), "int" )
vs += self.vecIter(e.getErrors(), "double")
vs += self.vecIter(e.getWave(), "double")
vs += [e.getDt(), e.getFlag()]
for v in vs:
entries += [str(v)]
xml._push()
if (type == "condition"):
xml.condition(content = entries,
channelID = id.get_compact(),
febID = onlineID.feb_Id(id).get_compact(),
onlineID = onlineID.show_to_string(id))
if (type == "correction"):
xml.correction(content = entries,
channelID = id.get_compact(),
febID = onlineID.feb_Id(id).get_compact(),
onlineID = onlineID.show_to_string(id))
xml._pop()
utility = Utility(resultTxt)
# Give Lower Bytes
def lowBytes(number):
return long(number) & 0xffffffffL
# Give Higher Bytes
def highBytes(number):
return (long(number) & 0xffffffff00000000L) >> 32
# Give all tags for a folder
def getTags(folder):
tags = folder.listTags()
tagList = []
if len(tags) > 0:
for i in range(0, len(tags)):
tagList += [tags[i]]
return tagList
# Report Exception
def reportException(message):
msg = "ATHENAEUM: Exception (line = " + str(sys.exc_traceback.tb_lineno) + ")" + str(message) + "\n"
msg += "ATHENAEUM: " + str(sys.exc_info()[0]) + "\n"
msg += "ATHENAEUM: " + str(sys.exc_info()[1]) + "\n"
return msg
# Execution ####################################################################
# Preparation ==================================================================
try:
setProgress("task", 0, "Initialising")
except:
pass
# Create IOV Classes
try:
IOVRange = PyLCGDict.makeClass('IOVRange')
IOVTime = PyLCGDict.makeClass('IOVTime')
start = IOVTime()
stop = IOVTime()
def iovPrint(self):
pass
IOVRange.iovPrint = iovPrint
except:
resultTxt += "ATHENAEUM: Can't get IOVRange, IOVTime" + "\n"
# Get Conditions Container Accessor
try:
accessor = ConditionsContainerAccess(theApp)
resultTxt += "ATHENAEUM: Got Conditions Container Accessor" + "\n"
except:
resultTxt += "ATHENAEUM: Can't get Conditions Container Accessor" + "\n"
resultTxt += "ATHENAEUM: " + str(sys.exc_info()[0]) + "\n"
resultTxt += "ATHENAEUM: " + str(sys.exc_info()[1]) + "\n"
# Get Database Connection
try:
dbSvc = cool.DatabaseSvcFactory.databaseService()
connection = server + ";dbname=" + dbname + ";schema=" + schema
if user != "":
connection += ";user=" + user
if password != "":
connection += ";password=" + password
resultTxt += "ATHENAEUM: Creating connection to " + str(connection) + "\n"
db = dbSvc.openDatabase(connection)
except:
resultTxt += "ATHENAEUM: Can't connect to " + str(connection) + "\n"
raise
# Get Channel Decoder
try:
chanDecoder = LArCondContChannels()
resultTxt += "ATHENAEUM: Got LAr channel decoder" + "\n"
except:
resultTxt += "ATHENAEUM: Cannot get LAr channel decoder" + "\n"
# Start XML Output
xml = jaxml.XML_document(encoding = "UTF-8", version = "1.0")
# Give Server Parameters
try:
server = str(self.serverName) + ":" + str(self.serverPort)
except:
server = "standalone"
xml.athenaeum({"xmlns" : {"xsi" : "http://www.w3.org/2001/XMLSchema-instance"},
"xsi" : {"noNamespaceSchemaLocation" : "Athenaeum.xsd" }},
server = server)
xml._push()
xml.cool(server = server,
dbname = dbname,
schema = schema,
user = user,
password = password,
lod = lod,
folders = foldersChoice,
tags = tagsChoice,
channels = channelsChoice,
startTime = startTime,
stopTime = stopTime,
startRun = startRun,
startLumi = startLumi,
stopRun = stopRun,
stopLumi = stopLumi,
limit = payloadLimit)
# Get Run/Lumi/Time Limits
try:
if startRun == "" or startLumi == "" or stopRun == "" or stopLumi == "" or long(startRun) > 0 or long(startLumi) > 0 or long(stopRun) > 0 or long(stopLumi) > 0:
startRELimit = IOVTime(long(startRun), long(startLumi)).re_time()
stopRELimit = IOVTime(long(stopRun ), long(stopLumi )).re_time()
resultTxt += "ATHENAEUM: Using Run/Lumi limits" + "\n"
else:
startRELimit = cool.ValidityKeyMin
stopRELimit = cool.ValidityKeyMax
resultTxt += "ATHENAEUM: Not Using Run/Lumi limits" + "\n"
except:
startRELimit = cool.ValidityKeyMin
stopRELimit = cool.ValidityKeyMax
resultTxt += "ATHENAEUM: Not Using Run/Lumi limits" + "\n"
resultTxt += "ATHENAEUM: " + str(sys.exc_info()[0]) + "\n"
resultTxt += "ATHENAEUM: " + str(sys.exc_info()[1]) + "\n"
try:
startTLimit = IOVTime(long(1000000000.0 * mktime(strptime(startTime, "%a %b %d %H:%M:%S %Z %Y")))).timestamp()
stopTLimit = IOVTime(long(1000000000.0 * mktime(strptime(stopTime, "%a %b %d %H:%M:%S %Z %Y")))).timestamp()
resultTxt += "ATHENAEUM: Using Time limits" + "\n"
except:
startTLimit = cool.ValidityKeyMin
stopTLimit = cool.ValidityKeyMax
resultTxt += "ATHENAEUM: Not Using Time limit" + "\n"
resultTxt += "ATHENAEUM: " + str(sys.exc_info()[0]) + "\n"
resultTxt += "ATHENAEUM: " + str(sys.exc_info()[1]) + "\n"
# Main Loop Over Folders =======================================================
# Loop Over Nodes
folders = db.listAllNodes()
ifolder = 0
for ff in folders:
ifolder += 1
# Get FolderSet
try:
f = db.getFolderSet(ff)
resultTxt += "ATHENAEUM: Analysing FolderSet " + str(ff) + "\n"
insertionTime = f.insertionTime()
xml._push()
xml.folderSet(name = ff,
time = insertionTime,
tags = getTags(f))
xml._pop()
continue
except:
pass
# Get Folder
try:
f = db.getFolder(ff)
resultTxt += "ATHENAEUM: Analysing Folder" + str(ff) + "\n"
try:
setProgress("task", 100.0 * float(ifolder) / float(len(folders)), "Looping over folders: " + str(ff))
except:
pass
except:
resultTxt += "ATHENAEUM: Skipping " + str(ff) + "\n"
continue
try:
insertionTime = f.insertionTime()
versionXML = ""
if f.isLeaf():
if f.versioningMode() == 0:
versionXML = "single"
else:
versionXML = "multi"
xml._push()
# Everything or Summary
if lod == "":
everything = False
summary = False
xml.folder(name = ff,
id = f.id(),
time = insertionTime,
version = versionXML,
tags = getTags(f))
else:
everything = (lod == "everything" and (foldersChoice.find(ff) > -1 or foldersChoice == ""))
summary = not everything
if everything:
lod0 = "everything"
else:
lod0 = "summary"
xml.folder(name = ff,
id = f.id(),
time = insertionTime,
version = versionXML,
tags = getTags(f),
lod = lod0)
# Summary
if summary:
script0 = "lod='everything';foldersChoice='" + ff + "';"
for t in getTags(f):
title = "tag: " + t
script = script0 + "tagsChoice='" + t + "'"
xml._push()
xml.detail(title = title,
path = ff,
script = script)
xml._pop()
xml._push()
title = "tag: (all)"
script = script0 + "tagsChoice=''"
xml.detail(title = title,
path = ff,
script = script)
xml._pop()
# Everything
elif everything:
# Get list of selected tags
if tagsChoice == "":
tags = getTags(f)
else:
tags = tagsChoice.split()
resultTxt += "ATHENAEUM: Asking for tags: " + str(tags) + "\n"
# Fill Folder
try:
# Get Folder Attributes
fa = f.folderAttributes()
xml._push()
xml.attributes()
for a in fa:
xml._push()
xml.attrribute(name = a,
value = fa[a])
xml._pop()
xml._pop() # attributes
# Get Folder Description
xml._push()
xml.description()
xml._text(f.description().replace('>', '<').replace('<', '<'))
xml._pop()
# Initialise Accessor
useAccessor = False
try:
accessor.setDescription(f.description())
useAccessor = True
resultTxt += "ATHENAEUM: Working with object of type: " + str(accessor.typeName) + "\n"
except:
resultTxt += "ATHENAEUM: Can't use Accessor" + "\n"
resultTxt += "ATHENAEUM: " + str(sys.exc_info()[0]) + "\n"
resultTxt += "ATHENAEUM: " + str(sys.exc_info()[1]) + "\n"
# Find if Time-like or Run/Lumi-like
# ... handle old Run/Event as well
if re.compile('.*run-lumi.*').match(f.description()) or re.compile('.*run-event.*').match(f.description()):
timeLike = False
startLimit = startRELimit
stopLimit = stopRELimit
else:
timeLike = True
startLimit = startTLimit
stopLimit = stopTLimit
# Initialise Flags
signed = 0
# Find Channels Selection
if channelsChoice != "":
channels = channelsChoice.split(" ")
else:
channels = []
coolFolderHelper.setFolderChanList(f)
for i in f.listChannels():
channels.append(coolFolderHelper.channel(i))
# Loop Over Channels and save each channel in a separate attribute list
attrLists = []
iovs = []
chans = []
if payloadLimit != "":
channels = channels[0:int(payloadLimit)]
for c in channels:
sel = cool.ChannelSelection(int(c))
if len(tags) == 0:
tags = [""]
for tag in tags:
# Only browse if valid tag is found (empty tag is valid tag)
try:
foundTag = False
useNewTag = False
if tag != "":
# Check if tag exists
if f.existsUserTag(tag):
foundTag = True
# Look for related tag
else:
newTag = f.resolveTag(tag)
if newTag != "":
foundTag = True
useNewTag = True
# Empty tag if valid
else:
foundTag = True
# Skip if tag is not found
if not foundTag:
continue
# Select tag
if useNewTag:
testTag = newTag
resultTxt += "ATHENAEUM: Substituting tag " + str(tag) + " --> " + str(testTag) + "\n"
else:
testTag = tag
except:
resultTxt += reportException("Tags selection failed")
# Loop Over Objects
iterator = f.browseObjects(startLimit, stopLimit, sel, testTag)
itLimit = iterator.size()
if payloadLimit < iterator.size:
itLimit = payloadLimit
for i in range(0, itLimit):
obj = iterator.next()
insertionTime = obj.insertionTime()
try:
if timeLike:
start.setTimestamp(obj.since())
stop.setTimestamp( obj.until())
else:
start.setRETime(obj.since())
stop.setRETime( obj.until())
except:
resultTxt += "ATHENAEUM: Can't get limits" + "\n"
start = startLimit
stop = stopLimit
# Give Signature
if signed == 0:
xml._push()
xml.signature()
for j in range(0, obj.payload().size()):
xml._push()
xml.item(name = obj.payload().keys()[j],
type = obj.payload().typeNames()[j])
xml._pop()
signed = 1
xml._pop() # signature
# Fill Accessor
if useAccessor:
# Test if it has POOLRef
try:
strAddress = obj.payload()["PoolRef"]
except:
pass
# Get IOVRange
iov = IOVRange(start, stop)
# Get AttributeList Collection for Multichannels, Rezero Lists for IOV and Channels
try:
CondAttrListCollection = PyLCGDict.makeClass('CondAttrListCollection')
attrListColl = CondAttrListCollection(timeLike)
except:
resultTxt += "ATHENAEUM: Can't get AttributeList Collection" + "\n"
resultTxt += "ATHENAEUM: " + str(sys.exc_info()[0]) + "\n"
resultTxt += "ATHENAEUM: " + str(sys.exc_info()[1]) + "\n"
# Add in Payload and IOV
attrListColl.add(obj.channelId(), iov)
AttrList = PyLCGDict.makeClass('coral::AttributeList')
attrList = AttrList(obj.payload().attributeList());
attrListColl.add(obj.channelId(), attrList)
iovs += [iov]
chans += [obj.channelId()]
attrLists += [attrListColl]
# Give Payload
payload = str(obj.payload())[2:-2].split()
intervalXML = ""
if start.isRunEvent():
intervalXML = "run:" + str(start.run()) + " lumi:" + str(start.event()) + " - " + "run:" + str(stop.run()) + " lumi:" + str(stop.event()) + "' "
elif start.isTimestamp():
startTS = start.timestamp()
stopTS = stop.timestamp()
if abs(cool.ValidityKeyMax - startTS) < 5:
startTS = "inf"
else:
startTS = str(ctime(startTS / 1000000000.0))
if abs(cool.ValidityKeyMax - stopTS) < 5:
stopTS = "inf"
else:
stopTS = str(ctime(stopTS / 1000000000.0))
intervalXML = str(startTS) + " - " + str(stopTS) + "' "
else:
resultTxt += "ATHENAEUM: " + str(start) + " is neither RunLumi nor Timestamp" + "\n"
intervalXML = str(start).replace('<', '(').replace('>', ')') + " - " + str(stop).replace('<', '(').replace('>', ')')
xml._push()
xml.payload(object = obj.objectId(),
tag = tag,
channel = obj.channelId(),
time = insertionTime,
interval = intervalXML)
for j in range(0, obj.payload().size()):
p = str(obj.payloadValue(str(obj.payload().keys()[j])))
if showPoolRef == "true" or obj.payload().keys()[j] != "PoolRef":
xml._push()
xml.entry(name = obj.payload().keys()[j],
value = p.replace('<', '<').replace('>', '>').replace('"', '"'))
xml._pop()
xml._pop() # payload
# If Accessor is available -----------------------------------------------
if useAccessor:
# Check if this is a LArConditionsContainer
isLArCondCont = False
if (utility.isLArConditionsContainer(accessor.typeName)):
isLArCondCont = accessor.typeName
resultTxt += "ATHENAEUM: isLArCondCont = " + str(isLArCondCont) + "\n"
# Add iterators to the concrete LArConditionsContainer class
larCondType = 'None'
if isLArCondCont:
larCondType = accessor.typeName
try:
cont = LArConditionsContainer(larCondType)
resultTxt += "ATHENAEUM: Got LArConditionsContainer for type " + str(larCondType) + "\n"
except:
resultTxt += "ATHENAEUM: Can't get LArConditionsContainer for type " + str(larCondType) + "\n"
# Analyse LAr Conditions Container
Identifier = PyLCGDict.makeClass('Identifier')
HWIdentifier = PyLCGDict.makeClass('HWIdentifier')
if isLArCondCont:
if (larCondType == "LArRampComplete" or \
larCondType == "LArPedestalComplete" or \
larCondType == "LArAutoCorrComplete" or \
larCondType == "LAruA2MeVMC" or \
larCondType == "LArShapeComplete" or \
larCondType == "LArOFCComplete" or \
larCondType == "LArDAC2uAMC" or \
larCondType == "LArDetCellParamsComplete" or \
larCondType == "LArMphysOverMcalComplete" or \
larCondType == "LArCaliWaveContainer" or \
larCondType == "LArCaliPulseParamsComplete"):
for i in range(len(iovs)):
iov = iovs[i]
chan = chans[i]
attrListColl = attrLists[i]
resultTxt += "ATHENAEUM: Accessing " + larCondType + " for channel " + str(chan) + "\n"
chans1 = [chan]
iovs1 = [iov]
start = iov.start()
stop = iov.stop()
try:
container = accessor.getMultiCondContainer(chans1, attrListColl, iovs1)
except:
resultTxt += "ATHENAEUM: Exception (line = " + str(sys.exc_traceback.tb_lineno) + ")" + "\n"
resultTxt += "ATHENAEUM: " + str(sys.exc_info()[0]) + "\n"
resultTxt += "ATHENAEUM: " + str(sys.exc_info()[1]) + "\n"
continue
onlineID = container.onlineHelper()
if start.isRunEvent():
iovStart = "run:" + str(start.run()) + " lumi:" + str(start.event())
iovStop = "run:" + str(stop.run() ) + " lumi:" + str(stop.event() )
else:
iovStart = str(ctime(start.timestamp() / 1000000000.0))
iovStop = str(ctime(stop.timestamp() / 1000000000.0))
xml._push()
xml.LArOnlCalibDataContainer(larCondType = larCondType,
iovStart = iovStart,
iovStop = iovStop,
channel = chan)
# Loop Over Gains
for gain in range(container.minGain(), container.minGain() + container.nGains()):
xml._push()
xml.data(gain = gain)
# Give Conditions
limit = 0
for cond in container.conditionsIter(gain):
limit += 1
if limit > int(payloadLimit):
break
utility.analyseCondCorr(cond, larCondType, xml, gain, id, onlineID, start, stop, chan, "condition")
# Give Corrections
limit = 0
for corr in container.correctionsIter(gain):
limit += 1
if limit > int(payloadLimit):
break
utility.analyseCondCorr(corr, larCondType, xml, gain, id, onlineID, start, stop, chan, "correction")
# Give Febs
if reportFebs:
nGroups = container.nGroups() + 3
group = 3
while group < nGroups:
febids = container.febIdVector(gain, group)
nfebids = febids.size()
febid = 0
febs = []
while febid < nfebids:
febs += [ febids[febid] ]
febid += 1
xml._push()
xml.febs(group = group)
xml._text(febs)
xml._pop() # febs
group += 1
xml._pop() # ramp/ped/...
xml._pop() # ramps/peds/...
# Others
else:
resultTxt += "ATHENAEUM: No payload analyses defined for " + str(larCondType) + "\n"
except:
resultTxt += reportException("")
xml._pop() # folder
except:
resultTxt += reportException("while processing " + str(ff) + " :")
xml._pop() # cool
# Report Time
xml._push()
xml.profile(time = int(time.time() - t0))
xml._pop()
# Close
global answer
answer[pid] = resultTxt + "\n" + str(xml)
try:
setProgress("task", 100, "Job finished - Returning Results and Waiting for new Job")
except:
pass