/** @file CbmDigiManager.cxx ** @author Volker Friese ** @since 8 May 2007 **/ #include "CbmDigiManager.h" #include "CbmDigiBranch.h" #include "mvd/CbmMvdDigi.h" #include "sts/CbmStsDigi.h" #include "rich/CbmRichDigi.h" #include "much/CbmMuchDigi.h" #include "trd/CbmTrdDigi.h" #include "tof/CbmTofDigi.h" #include "psd/CbmPsdDigi.h" // ----- Initialisation of static variables ---------------------------- CbmDigiManager* CbmDigiManager::fgInstance = nullptr; std::vector CbmDigiManager::fBranches = std::vector(); Bool_t CbmDigiManager::fIsInitialised = kFALSE; // ------------------------------------------------------------------------- // ----- Constructor --------------------------------------------------- CbmDigiManager::CbmDigiManager() { } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- CbmDigiManager::~CbmDigiManager() { for (auto& entry : fBranches) { if ( entry ) delete entry; } } // ------------------------------------------------------------------------- // ----- Get digi branch name for a system ----------------------------- TString CbmDigiManager::BranchName(Int_t system) const { switch (system) { case kMvd: return "MvdDigi"; break; case kSts: return "StsDigi"; break; case kRich: return "RichDigi"; break; case kMuch: return "MuchDigi"; break; case kTrd: return "TrdDigi"; break; case kTof: return "TofDigi"; break; case kPsd: return "PsdDigi"; break; default: return ""; break; } } // ------------------------------------------------------------------------- // ----- Get number of digis in branch --------------------------------- Int_t CbmDigiManager::GetNofDigis(ECbmModuleId systemId) { assert( fIsInitialised ); if ( fBranches[systemId] ) return fBranches[systemId]->GetNofDigis(); LOG(info) << "Branch for system " << systemId << " not present"; return -1; } // ------------------------------------------------------------------------- // ----- Initialisation ------------------------------------------------ InitStatus CbmDigiManager::Init() { if (fIsInitialised) return kSUCCESS; fBranches.resize(kNofSystems, nullptr); LOG(info) << "Branch name for kMvd is " << BranchName(kMvd); std::cout << std::endl << std::endl; LOG(info) << "=================================================="; LOG(info) << "DigiManager: Initialising..."; SetBranch(); SetBranch(); SetBranch(); SetBranch(); SetBranch(); SetBranch(); SetBranch(); std::cout << std::endl; LOG(info) << "Present branches:"; for (auto const& branch : fBranches) { if ( branch ) LOG(info) << " " << branch->ToString(); } fIsInitialised = kTRUE; LOG(info) << "=================================================="; std::cout << std::endl << std::endl; return kSUCCESS; } // ------------------------------------------------------------------------- // ----- Set a digi branch --------------------------------------------- template void CbmDigiManager::SetBranch() { // Get system ID from digi object Digi testDigi; Int_t systemId = testDigi.GetSystemId(); // --- Catch branch already set if ( fBranches[systemId] ) { LOG(warn) << "DigiManager: branch for system " << systemId << " is already set."; return; } // --- Catch unknown system if ( BranchName(systemId).IsNull() ) { LOG(warn) << "DigiManager: Unknown system " << systemId; return; } // --- Branch name TString branchName = BranchName(systemId); // --- Add branch object and connect it to the tree CbmDigiBranchBase* branch = new CbmDigiBranch(branchName.Data()); if ( branch->ConnectToTree() ) fBranches[systemId] = branch; else delete branch; // Special case for mCBM STS if ( systemId == kSts && ! fBranches[systemId] ) { branchName = "CbmStsDigi"; branch = new CbmDigiBranch(branchName.Data()); if ( branch->ConnectToTree() ) fBranches[systemId] = branch; else delete branch; } } // ------------------------------------------------------------------------- ClassImp(CbmDigiManager)