1 | from CPconfig import configuration
|
---|
2 | from importlib import import_module
|
---|
3 |
|
---|
4 | # A proper implementation of the event selection will at least
|
---|
5 | # define the following:
|
---|
6 | # - categoryNames (list of names of categories)
|
---|
7 | # - eventCategory (category data producer)
|
---|
8 | # - isInCategory (category definition, from category data)
|
---|
9 |
|
---|
10 | # the list of category names
|
---|
11 | categoryNames = [ ]
|
---|
12 |
|
---|
13 | def eventCategory(event):
|
---|
14 | """Check analysis requirements for various steps
|
---|
15 | and return a tuple of data used to decide
|
---|
16 | to what category an event belong """
|
---|
17 | raise NotImplementedError
|
---|
18 | return []
|
---|
19 |
|
---|
20 | def isInCategory(category, categoryData):
|
---|
21 | """Check if the event enters category X, given the tuple computed by eventCategory."""
|
---|
22 | raise NotImplementedError
|
---|
23 | return True
|
---|
24 |
|
---|
25 | # specific implementation of the "virtual methods" above
|
---|
26 | EventSelectionImplementation = __import__(configuration.eventSelection)
|
---|
27 | categoryNames = EventSelectionImplementation.categoryNames
|
---|
28 | eventCategory = EventSelectionImplementation.eventCategory
|
---|
29 | isInCategory = EventSelectionImplementation.isInCategory
|
---|
30 |
|
---|
31 | # Functions below should not be touched in any implementation.
|
---|
32 |
|
---|
33 | def eventCategories():
|
---|
34 | """Return the number of catefories """
|
---|
35 | return len(categoryNames)
|
---|
36 |
|
---|
37 | def categoryName(category):
|
---|
38 | """Return the name of category x"""
|
---|
39 | if category<eventCategories() and category>=0: return categoryNames[category]
|
---|
40 | else: return "None"
|
---|
41 |
|
---|
42 | def categoriesHierarchy():
|
---|
43 | """Return a hierarchically organized list of categories"""
|
---|
44 | dct = {}
|
---|
45 | for i,item in enumerate(categoryNames):
|
---|
46 | p = dct
|
---|
47 | splitted = item.split('/')
|
---|
48 | for x in splitted[:-1]:
|
---|
49 | p = p.setdefault(x,{})
|
---|
50 | p[splitted[-1]] = i
|
---|
51 | return dct
|
---|
52 |
|
---|
53 | def prepareAnalysisEvent(event):
|
---|
54 | """Define collections and producers"""
|
---|
55 | for coll in configuration.eventCollections:
|
---|
56 | event.addCollection(coll.label,coll.collection)
|
---|
57 | for prod in configuration.eventProducers:
|
---|
58 | event.addProducer(prod.label,getattr(import_module(prod.module),prod.function),**prod.kwargs)
|
---|
59 | for weight in configuration.eventWeights:
|
---|
60 | events.addWeight(weight.label,getattr(import_module(weight.module),weight.classname)(**weight.kwargs))
|
---|
61 |
|
---|