ChainData.py
Go to the documentation of this file.
1 #!/bin/env python
2 import os, sys
3 from collections import OrderedDict
4 from DefinitionData import *
5 
6 class ChainData:
7  def __init__(self, name, title, description):
8  self.name = name
9  self.title=title
10  self.description=description
11  self.tierData=OrderedDict()
12 
13  def addTier(self,tier,defname):
14  self.tierData[tier]=DefinitionData(defname)
15 
16  def fetchData(self,maxCacheLifetime, dump=False):
17  for tier in self.tierData.keys():
18  self.tierData[tier].fetchData(maxCacheLifetime)
19  if dump:
20  dumpDefinitionData(self.tierData[tier])
21 
22  def loadData(self):
23  for tier in self.tierData.keys():
24  tmp=self.tierData[tier]
25  try:
26  self.tierData[tier]=loadDefinitionData(tmp.name)
27  except IOError:
28  print "SAM data not available for",tier, tmp.name,"yet"
29  except EOFError:
30  print "EOF error for ",tier, tmp.name
31 
32  def dump(self):
33  for tier in self.tierData.keys():
34  dumpDefinitionData(self.tierData[tier])
35 
36  ##these three functions just return an array of elements:
37  ## the chain title, and the value for each tier
38  def getFileCounts(self):
39  retVal=[self.title]
40  for tierName in self.tierData.keys():
41  tier=self.tierData[tierName]
42  if tier.state == "good":
43  retVal.append(tier.summary["file_count"])
44  else:
45  retVal.append(0)
46  return retVal
47 
48  def getTotEventCounts(self):
49  retVal=[self.title]
50  for tierName in self.tierData.keys():
51  tier=self.tierData[tierName]
52  if tier.state == "good":
53  retVal.append(tier.summary["total_event_count"])
54  else:
55  retVal.append(0)
56  return retVal
57 
58  def getTotFileSizes(self):
59  retVal=[self.title]
60  for tierName in self.tierData.keys():
61  tier=self.tierData[tierName]
62  if tier.state == "good":
63  totFileSize=tier.summary["total_file_size"]/(1024.*1024.*1024.)
64  retVal.append(totFileSize)
65  else:
66  retVal.append(0)
67  return retVal
68 
69 def makeChain(chainSection,cfg):
70 
71  chainName=chainSection.replace("chain","").strip()
72  title=cfg.get(chainSection,"title")
73  desc=cfg.get(chainSection,"description")
74  chain=ChainData(chainName,title,desc)
75 
76 
77  tiersSection=chainName + "/tiers"
78 
79  tiers=OrderedDict(cfg.items(tiersSection))
80  for tier in tiers.keys():
81  defname=tiers[tier]
82  chain.addTier(tier,defname)
83 
84 
85  return chain
def __init__(self, name, title, description)
Definition: ChainData.py:7
def dump(self)
Definition: ChainData.py:32
def getTotFileSizes(self)
Definition: ChainData.py:58
def getTotEventCounts(self)
Definition: ChainData.py:48
def makeChain(chainSection, cfg)
Definition: ChainData.py:69
def getFileCounts(self)
these three functions just return an array of elements: the chain title, and the value for each tier ...
Definition: ChainData.py:38
def loadDefinitionData(defname)
def dumpDefinitionData(defData, useCache=False)
def loadData(self)
Definition: ChainData.py:22
def fetchData(self, maxCacheLifetime, dump=False)
Definition: ChainData.py:16
def addTier(self, tier, defname)
Definition: ChainData.py:13