Belle II Software development
SoftwareTriggerDBHandler Class Reference

Helper class for performing up- and downloads of SoftwareTriggerCuts from the database. More...

#include <SoftwareTriggerDBHandler.h>

Public Member Functions

 SoftwareTriggerDBHandler (const std::string &baseIdentifier)
 Use the default constructor (needed as we delete the copy constructor)
 
void initialize ()
 Download the trigger menu and afterwards the cuts with the given base name and specific names from the database and register them here.
 
void checkForChangedDBEntries ()
 Helper function to check for changes in the DB of all cuts registered in the initialize function.
 
const std::map< std::string, std::unique_ptr< const SoftwareTriggerCut > > & getCutsWithNames () const
 Get the already downloaded list of constant cuts with their identifiers.
 
bool getAcceptOverridesReject () const
 Return true of the trigger menu is in accept mode.
 

Static Public Member Functions

static std::unique_ptr< SoftwareTriggerCutcreateCutFromDB (const DBRepresentationOfSoftwareTriggerCut &dbCut)
 Helper factory function to generate a unique cut pointer from its representation in the database.
 
static std::string makeFullCutName (const std::string &baseCutIdentifier, const std::string &cutIdentifier)
 Helper function to compile the full identifier from the base and the specific cut name.
 
static std::string makeTotalResultName (const std::string &baseIdentifier="all")
 Handy function to create the name related to the total result of a specific trigger stage (either filter or skim) in the stored results or the total result.
 
static std::string makeFullTriggerMenuName (const std::string &baseIdentifier)
 Helper function to compile the full menu identifier from the base name.
 
static bool hasBaseIdentifier (const std::string &cutName, const std::string &baseIdentifier)
 Check if a given cut name in the form <package_identifier>&<base_name>&<cut_name> has the given base name.
 
static void upload (const std::unique_ptr< SoftwareTriggerCut > &cut, const std::string &baseCutIdentifier, const std::string &cutIdentifier, const IntervalOfValidity &iov)
 Upload a new (or replace an old version) cut with the given base and specific name.
 
static void uploadTriggerMenu (const std::string &baseCutIdentifier, const std::vector< std::string > &cutIdentifiers, bool acceptMode, const IntervalOfValidity &iov)
 Upload a new (or replace an old version) trigger menu with the given base and specific names.
 
static std::unique_ptr< SoftwareTriggerCutdownload (const std::string &baseCutIdentifier, const std::string &cutIdentifier)
 Download a cut from the database.
 
static std::unique_ptr< SoftwareTriggerMenudownloadTriggerMenu (const std::string &baseCutIdentifier)
 Download a trigger menu from the database.
 

Static Public Attributes

static const std::string s_dbPackageIdentifier = "software_trigger_cut"
 Common prefix to identify all software trigger cuts in the database.
 
static const std::string s_totalResultIdentifier = "total_result"
 Common suffix to identify all total results in the stored results.
 

Private Member Functions

 SoftwareTriggerDBHandler (const SoftwareTriggerDBHandler &rhs)=delete
 Delete the copy constructor.
 
SoftwareTriggerDBHandleroperator= (SoftwareTriggerDBHandler &rhs)=delete
 Delete the assignment constructror.
 

Private Attributes

std::string m_baseIdentifier = ""
 Base identifier.
 
DBObjPtr< SoftwareTriggerMenum_softwareTriggerMenu
 Database entry of the software trigger menu.
 
std::vector< DBObjPtr< DBRepresentationOfSoftwareTriggerCut > > m_databaseObjects
 Database entries of the cuts, which where created in the initialize function.
 
std::map< std::string, std::unique_ptr< const SoftwareTriggerCut > > m_cutsWithIdentifier
 Map of cuts with their identifiers, downloaded from the database.
 

Detailed Description

Helper class for performing up- and downloads of SoftwareTriggerCuts from the database.

In the typical module setup, you would create an instance of this class as a module member, call the initialize function with the cuts you want to process in the module's initialize method and look for changed DB entries in the beginRun function.

In the normal event function of the module, you can get a list of cuts with their names by calling the getCutsWithNames method.

You can also upload new cuts (or new versions of cuts) with the upload function.

In all download and upload methods, you have to provide both a base name and a specific name for the cut. Both names are used (together with a package name) to construct the identifier of the cut (using the getFullCutName method). You can only download cuts from the same set (defined with the same base name), to not mix e.g. level3 and hlt cuts.

Definition at line 38 of file SoftwareTriggerDBHandler.h.

Constructor & Destructor Documentation

◆ SoftwareTriggerDBHandler()

SoftwareTriggerDBHandler ( const std::string &  baseIdentifier)
inlineexplicit

Use the default constructor (needed as we delete the copy constructor)

Definition at line 128 of file SoftwareTriggerDBHandler.h.

128 :
129 m_baseIdentifier(baseIdentifier),
131 {
132 initialize();
133 }
static std::string makeFullTriggerMenuName(const std::string &baseIdentifier)
Helper function to compile the full menu identifier from the base name.
void initialize()
Download the trigger menu and afterwards the cuts with the given base name and specific names from th...
DBObjPtr< SoftwareTriggerMenu > m_softwareTriggerMenu
Database entry of the software trigger menu.

Member Function Documentation

◆ checkForChangedDBEntries()

void checkForChangedDBEntries ( )

Helper function to check for changes in the DB of all cuts registered in the initialize function.

Definition at line 104 of file SoftwareTriggerDBHandler.cc.

105 {
106 // In case the whole trigger menu has changed, we start from scratch and reload all triggers.
107 if (m_softwareTriggerMenu.hasChanged()) {
108 initialize();
109 return;
110 }
111
112 // In all other cases we just check each downloaded cut, if it has changed.
113 for (auto& databaseCutEntry : m_databaseObjects) {
114 if (databaseCutEntry.hasChanged()) {
115 B2ASSERT("The name of the database entry changed! This is not handled properly by the module.",
116 m_cutsWithIdentifier.find(databaseCutEntry.getName()) != m_cutsWithIdentifier.end());
117 m_cutsWithIdentifier[databaseCutEntry.getName()] = createCutFromDB(*databaseCutEntry);
118 }
119 }
120 }
static std::unique_ptr< SoftwareTriggerCut > createCutFromDB(const DBRepresentationOfSoftwareTriggerCut &dbCut)
Helper factory function to generate a unique cut pointer from its representation in the database.
std::map< std::string, std::unique_ptr< const SoftwareTriggerCut > > m_cutsWithIdentifier
Map of cuts with their identifiers, downloaded from the database.
std::vector< DBObjPtr< DBRepresentationOfSoftwareTriggerCut > > m_databaseObjects
Database entries of the cuts, which where created in the initialize function.

◆ createCutFromDB()

std::unique_ptr< SoftwareTriggerCut > createCutFromDB ( const DBRepresentationOfSoftwareTriggerCut dbCut)
static

Helper factory function to generate a unique cut pointer from its representation in the database.

Was part of the DBRepresentation before, but is now a standalone function.

Definition at line 22 of file SoftwareTriggerDBHandler.cc.

23 {
24 return SoftwareTrigger::SoftwareTriggerCut::compile(dbCut.getCutString(),
25 dbCut.getPreScaleFactor(),
26 dbCut.isRejectCut());
27 }
static std::unique_ptr< SoftwareTriggerCut > compile(const std::string &cut_string, const unsigned int prescaleFactor, const bool rejectCut=false)
Compile a new SoftwareTriggerCut from a cut string (by using the GeneralCut::compile function) and an...

◆ download()

std::unique_ptr< SoftwareTriggerCut > download ( const std::string &  baseCutIdentifier,
const std::string &  cutIdentifier 
)
static

Download a cut from the database.

This function should only be called from python to interact with/edit single cuts and not from your module to check the cuts (use the initialize method etc. for this).

Parameters
baseCutIdentifierThe base name of the cut to download.
cutIdentifierThe identifier of the cut to download.
Returns
A unique pointer to the downloaded cut or a nullptr of no cut with this name is in the DB.

Definition at line 80 of file SoftwareTriggerDBHandler.cc.

82 {
83 const std::string& fullCutName = makeFullCutName(baseCutIdentifier, cutIdentifier);
84 DBObjPtr<DBRepresentationOfSoftwareTriggerCut> downloadedCut(fullCutName);
85 if (downloadedCut) {
86 return createCutFromDB(*downloadedCut);
87 } else {
88 return nullptr;
89 }
90 }
static std::string makeFullCutName(const std::string &baseCutIdentifier, const std::string &cutIdentifier)
Helper function to compile the full identifier from the base and the specific cut name.

◆ downloadTriggerMenu()

std::unique_ptr< SoftwareTriggerMenu > downloadTriggerMenu ( const std::string &  baseCutIdentifier)
static

Download a trigger menu from the database.

This function should only be called from python to interact with/edit single menus and not from your module to check the cuts (use the initialize method etc. for this).

Parameters
baseCutIdentifierThe base name of the trigger menu to download.
Returns
A unique pointer to the downloaded menu or a nullptr of no menu with this name is in the DB.

Definition at line 93 of file SoftwareTriggerDBHandler.cc.

94 {
95 const std::string& fullMenuName = makeFullTriggerMenuName(baseCutIdentifier);
96 DBObjPtr<SoftwareTriggerMenu> downloadedMenu(fullMenuName);
97 if (downloadedMenu) {
98 return std::make_unique<SoftwareTriggerMenu>(*downloadedMenu);
99 } else {
100 return nullptr;
101 }
102 }

◆ getAcceptOverridesReject()

bool getAcceptOverridesReject ( ) const

Return true of the trigger menu is in accept mode.

Definition at line 149 of file SoftwareTriggerDBHandler.cc.

150 {
151 return m_softwareTriggerMenu->isAcceptMode();
152 }

◆ getCutsWithNames()

const std::map< std::string, std::unique_ptr< const SoftwareTriggerCut > > & getCutsWithNames ( ) const

Get the already downloaded list of constant cuts with their identifiers.

Definition at line 154 of file SoftwareTriggerDBHandler.cc.

155 {
157 };

◆ hasBaseIdentifier()

bool hasBaseIdentifier ( const std::string &  cutName,
const std::string &  baseIdentifier 
)
static

Check if a given cut name in the form <package_identifier>&<base_name>&<cut_name> has the given base name.

Definition at line 50 of file SoftwareTriggerDBHandler.cc.

51 {
52 assert(baseIdentifier.find("&") == std::string::npos);
53 assert(std::count(cutName.begin(), cutName.end(), '&') == 2);
54
55 return boost::starts_with(cutName, makeFullCutName(baseIdentifier, ""));
56 }

◆ initialize()

void initialize ( )

Download the trigger menu and afterwards the cuts with the given base name and specific names from the database and register them here.

When calling the checkForChangedDBEntries, these cuts will be checked for changes.

To get the cuts with their identifiers, call the getCutsWithNames function.

Definition at line 122 of file SoftwareTriggerDBHandler.cc.

123 {
124 B2ASSERT("Could not find a valid trigger name with this "
125 "base identifier (" << m_baseIdentifier << ") in the database.", m_softwareTriggerMenu);
126
127 m_databaseObjects.clear();
128 m_cutsWithIdentifier.clear();
129
130 const auto& cutIdentifiers = m_softwareTriggerMenu->getCutIdentifiers();
131 m_databaseObjects.reserve(cutIdentifiers.size());
132
133 B2DEBUG(20, "Initializing SoftwareTrigger DB with baseIdentifier " << m_baseIdentifier << " and " << cutIdentifiers.size() <<
134 " cutIdentifiers");
135
136 for (const std::string& cutIdentifier : cutIdentifiers) {
137 B2DEBUG(20, "-> with CutIndentifier " << cutIdentifier);
138
139 const std::string& fullIdentifier = makeFullCutName(m_baseIdentifier, cutIdentifier);
140 m_databaseObjects.emplace_back(fullIdentifier);
141 if (m_databaseObjects.back()) {
142 m_cutsWithIdentifier[fullIdentifier] = createCutFromDB(*m_databaseObjects.back());
143 } else {
144 B2FATAL("There is no DB object with the name " << fullIdentifier);
145 }
146 }
147 }

◆ makeFullCutName()

std::string makeFullCutName ( const std::string &  baseCutIdentifier,
const std::string &  cutIdentifier 
)
static

Helper function to compile the full identifier from the base and the specific cut name.

The full name is then created as: <package_identifier>&<base_name>&<cut_name>

Make sure to not include & into the base or cut name.

Definition at line 29 of file SoftwareTriggerDBHandler.cc.

31 {
32 assert(baseCutIdentifier.find("&") == std::string::npos);
33 assert(cutIdentifier.find("&") == std::string::npos);
34
35 return s_dbPackageIdentifier + "&" + baseCutIdentifier + "&" + cutIdentifier;
36 }
static const std::string s_dbPackageIdentifier
Common prefix to identify all software trigger cuts in the database.

◆ makeFullTriggerMenuName()

std::string makeFullTriggerMenuName ( const std::string &  baseIdentifier)
static

Helper function to compile the full menu identifier from the base name.

The full name is then created as: <package_identifier>&<base_name>

Make sure to not include & into the base name.

Definition at line 43 of file SoftwareTriggerDBHandler.cc.

44 {
45 assert(baseIdentifier.find("&") == std::string::npos);
46
47 return s_dbPackageIdentifier + "&" + baseIdentifier;
48 }

◆ makeTotalResultName()

std::string makeTotalResultName ( const std::string &  baseIdentifier = "all")
static

Handy function to create the name related to the total result of a specific trigger stage (either filter or skim) in the stored results or the total result.

It is in the form <package_identifier>&<base_name>&total_result

Parameters
baseIdentifierThe baseIdentifier (either filter or skim or all)
Returns
then name.

Definition at line 38 of file SoftwareTriggerDBHandler.cc.

39 {
40 return makeFullCutName(baseIdentifier, s_totalResultIdentifier);
41 }
static const std::string s_totalResultIdentifier
Common suffix to identify all total results in the stored results.

◆ upload()

void upload ( const std::unique_ptr< SoftwareTriggerCut > &  cut,
const std::string &  baseCutIdentifier,
const std::string &  cutIdentifier,
const IntervalOfValidity iov 
)
static

Upload a new (or replace an old version) cut with the given base and specific name.

Neither the base nor the cut name are allowed to have '&' in it. Please make sure that the base name must correspond to the identifiers of the calculation objects created in the SoftwareTriggerModule.

Definition at line 58 of file SoftwareTriggerDBHandler.cc.

60 {
61 B2ASSERT("The name " << s_totalResultIdentifier << " is already used for the total result of each trigger stage. "
62 "You can not create a cut with the same name.", cutIdentifier != s_totalResultIdentifier);
63 const std::string& fullCutName = makeFullCutName(baseCutIdentifier, cutIdentifier);
64 DBImportObjPtr<DBRepresentationOfSoftwareTriggerCut> cutToUpload(fullCutName);
65 cutToUpload.construct(cut->getPreScaleFactor(), cut->isRejectCut(), cut->decompile());
66 cutToUpload.import(iov);
67 }

◆ uploadTriggerMenu()

void uploadTriggerMenu ( const std::string &  baseCutIdentifier,
const std::vector< std::string > &  cutIdentifiers,
bool  acceptMode,
const IntervalOfValidity iov 
)
static

Upload a new (or replace an old version) trigger menu with the given base and specific names.

Neither the base nor the cut names are allowed to have '&' in it. Please make sure that the base name must correspond to the identifiers of the calculation objects created in the SoftwareTriggerModule and the cut names must correspond to cuts uploaded into the database.

Definition at line 69 of file SoftwareTriggerDBHandler.cc.

73 {
74 const std::string& fullMenuName = makeFullTriggerMenuName(baseCutIdentifier);
75 DBImportObjPtr<SoftwareTriggerMenu> menuToUpload(fullMenuName);
76 menuToUpload.construct(cutIdentifiers, acceptMode);
77 menuToUpload.import(iov);
78 }

Member Data Documentation

◆ m_baseIdentifier

std::string m_baseIdentifier = ""
private

Base identifier.

Definition at line 161 of file SoftwareTriggerDBHandler.h.

◆ m_cutsWithIdentifier

std::map<std::string, std::unique_ptr<const SoftwareTriggerCut> > m_cutsWithIdentifier
private

Map of cuts with their identifiers, downloaded from the database.

Definition at line 167 of file SoftwareTriggerDBHandler.h.

◆ m_databaseObjects

std::vector<DBObjPtr<DBRepresentationOfSoftwareTriggerCut> > m_databaseObjects
private

Database entries of the cuts, which where created in the initialize function.

Definition at line 165 of file SoftwareTriggerDBHandler.h.

◆ m_softwareTriggerMenu

DBObjPtr<SoftwareTriggerMenu> m_softwareTriggerMenu
private

Database entry of the software trigger menu.

Definition at line 163 of file SoftwareTriggerDBHandler.h.

◆ s_dbPackageIdentifier

const std::string s_dbPackageIdentifier = "software_trigger_cut"
static

Common prefix to identify all software trigger cuts in the database.

Definition at line 41 of file SoftwareTriggerDBHandler.h.

◆ s_totalResultIdentifier

const std::string s_totalResultIdentifier = "total_result"
static

Common suffix to identify all total results in the stored results.

Definition at line 43 of file SoftwareTriggerDBHandler.h.


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