10 #include <background/modules/BGOverlayInput/BGOverlayInputModule.h>
13 #include <framework/dataobjects/BackgroundInfo.h>
14 #include <framework/dataobjects/EventMetaData.h>
15 #include <framework/dataobjects/FileMetaData.h>
16 #include <framework/datastore/DataStore.h>
17 #include <framework/datastore/StoreObjPtr.h>
18 #include <framework/io/RootFileInfo.h>
19 #include <framework/io/RootIOUtilities.h>
20 #include <framework/logging/Logger.h>
23 #include <TClonesArray.h>
43 BGOverlayInputModule::BGOverlayInputModule() :
Module()
47 setDescription(
"Input for BG overlay, either in form of Digits or raw data.");
51 "List of files with measured beam background ");
53 "Name added to default branch names",
string(
"_beamBG"));
56 "If true, skip the check on the experiment number consistency between the basf2 process and the beam background files. By default, it is set to false, since the check should be skipped only by experts.",
67 B2WARNING(R
"RAW(The BGOverlayInput module will skip the check on the experiment number
68 consistency between the basf2 process and the beam background files.
70 This should be done only if you are extremely sure about what you are doing.
72 Be aware that you are not protected by the possible usage of beam background
73 files not suitabile for the experiment number you selected.)RAW");
78 B2FATAL(
"No valid files specified!");
83 int experiment{eventMetaData->getExperiment()};
89 const std::set<std::string>& branchNames = fileInfo.getBranchNames(
true);
90 if (branchNames.count(
"BackgroundMetaData"))
91 B2FATAL(
"The BG sample used is aimed for BG mixing, not for BG mixing."
92 <<
LogVar(
"File name", fileName));
94 const FileMetaData& fileMetaData = fileInfo.getFileMetaData();
97 B2FATAL(
"The BG sample used is aimed for a different experiment number. Please check what you are doing."
98 <<
LogVar(
"File name", fileName)
99 <<
LogVar(
"Experiment number of the basf2 process", experiment)
102 }
catch (
const std::invalid_argument& e) {
103 B2FATAL(
"One of the BG files can not be opened."
104 <<
LogVar(
"File name", fileName));
105 }
catch (
const std::runtime_error& e) {
106 B2FATAL(
"Something went wrong with one of the BG files."
107 <<
LogVar(
"File name", fileName)
108 <<
LogVar(
"Issue", e.what()));
115 m_tree->AddFile(fileName.c_str());
120 B2INFO(
"BGOverlayInput: starting with event " <<
m_firstEvent);
126 B2ERROR(
"No branches found to be connected");
136 descr.type = string(
"RandomTrigger");
139 m_index = bkgInfo->appendBackgroundDescr(descr);
154 entry->resetForGetEntry();
158 B2INFO(
"BGOverlayInput: events for BG overlay will be re-used");
159 bkgInfo->incrementReusedCounter(
m_index);
171 entry->ptr = entry->object;
173 entry->recoverFromNullObject();
201 const std::set<std::string> objPtrNames = {
"Belle2::ECLWaveforms",
"Belle2::PXDInjectionBGTiming",
"Belle2::EventLevelTriggerTimeInfo"};
203 const TObjArray* branches =
m_tree->GetListOfBranches();
204 if (!branches)
return false;
206 for (
int jj = 0; jj < branches->GetEntriesFast(); jj++) {
207 TBranch* branch =
static_cast<TBranch*
>(branches->At(jj));
208 if (!branch)
continue;
209 const std::string branchName = branch->GetName();
211 TObject* objectPtr = 0;
212 branch->SetAddress(&objectPtr);
214 std::string objName = branch->GetClassName();
216 if (objName ==
"TClonesArray") {
217 TClass* objClass = (
static_cast<TClonesArray*
>(objectPtr))->GetClass();
218 branch->ResetAddress();
221 const std::string className = objClass->GetName();
222 if (className.find(
"Belle2::") == std::string::npos) {
223 m_tree->SetBranchStatus(branchName.c_str(), 0);
231 m_tree->SetBranchStatus(branchName.c_str(), 0);
235 m_tree->SetBranchAddress(branchName.c_str(), &(entry.
object));
237 }
else if (objPtrNames.find(objName) != objPtrNames.end()) {
238 std::string name = branchName;
241 branch->ResetAddress();
245 m_tree->SetBranchStatus(branchName.c_str(), 0);
249 m_tree->SetBranchAddress(branchName.c_str(), &(entry.
object));
253 m_tree->SetBranchStatus(branchName.c_str(), 0);
254 branch->ResetAddress();
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
StoreEntryMap & getStoreEntryMap(EDurability durability)
Get a reference to the object/array map.
@ c_Persistent
Object is available during entire execution time.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
static DataStore & Instance()
Instance of singleton Store.
bool registerEntry(const std::string &name, EDurability durability, TClass *objClass, bool array, EStoreFlags storeFlags)
Register an entry in the DataStore map.
void setDescription(const std::string &description)
Sets the description of the module.
Helper class to factorize some necessary tasks when working with Belle2 output files.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
Type-safe access to single objects in the data store.
Class to store variables with their name which were sent to the logging service.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
const std::string c_treeNames[]
Names of trees.
std::vector< std::string > expandWordExpansions(const std::vector< std::string > &filenames)
Performs wildcard expansion using wordexp(), returns matches.
Abstract base class for different kinds of events.
Structure for background description.
Wraps a stored array/object, stored under unique (name, durability) key.
TObject * object
The pointer to the actual object.