Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-08-12 02:29:05

0001 #ifndef L1TriggerScouting_Utilities_OrbitTableOutputBranches_h
0002 #define L1TriggerScouting_Utilities_OrbitTableOutputBranches_h
0003 
0004 #include <string>
0005 #include <vector>
0006 #include <TTree.h>
0007 #include "FWCore/Framework/interface/OccurrenceForOutput.h"
0008 #include "DataFormats/NanoAOD/interface/OrbitFlatTable.h"
0009 #include "DataFormats/Provenance/interface/BranchDescription.h"
0010 #include "FWCore/Utilities/interface/EDGetToken.h"
0011 
0012 class OrbitTableOutputBranches {
0013 public:
0014   OrbitTableOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken &token)
0015       : m_token(token), m_extension(DontKnowYetIfMainOrExtension), m_branchesBooked(false) {
0016     if (desc->className() != "l1ScoutingRun3::OrbitFlatTable")
0017       throw cms::Exception("Configuration",
0018                            "OrbitNanoAODOutputModule can only write out l1ScoutingRun3::OrbitFlatTable objects");
0019   }
0020 
0021   void defineBranchesFromFirstEvent(const l1ScoutingRun3::OrbitFlatTable &tab);
0022   void branch(TTree &tree);
0023 
0024   /// Fill the current table, if extensions == table.extension().
0025   /// This parameter is used so that the fill is called first for non-extensions and then for extensions
0026   void beginFill(const edm::OccurrenceForOutput &iWhatever, TTree &tree, bool extensions);
0027   bool hasBx(uint32_t bx);
0028   void fillBx(uint32_t bx);
0029   void endFill();
0030 
0031 private:
0032   edm::EDGetToken m_token;
0033   std::string m_baseName;
0034   bool m_singleton = false;
0035   enum { IsMain = 0, IsExtension = 1, DontKnowYetIfMainOrExtension = 2 } m_extension;
0036   std::string m_doc;
0037   typedef Int_t CounterType;
0038   CounterType m_counter;
0039   struct NamedBranchPtr {
0040     std::string name, title, rootTypeCode;
0041     int columnIndex;
0042     TBranch *branch;
0043     NamedBranchPtr(const std::string &aname,
0044                    const std::string &atitle,
0045                    const std::string &rootType,
0046                    int columnIndex,
0047                    TBranch *branchptr = nullptr)
0048         : name(aname), title(atitle), rootTypeCode(rootType), columnIndex(columnIndex), branch(branchptr) {}
0049   };
0050   TBranch *m_counterBranch = nullptr;
0051   std::vector<NamedBranchPtr> m_uint8Branches;
0052   std::vector<NamedBranchPtr> m_int16Branches;
0053   std::vector<NamedBranchPtr> m_uint16Branches;
0054   std::vector<NamedBranchPtr> m_int32Branches;
0055   std::vector<NamedBranchPtr> m_uint32Branches;
0056   std::vector<NamedBranchPtr> m_floatBranches;
0057   std::vector<NamedBranchPtr> m_doubleBranches;
0058   bool m_branchesBooked;
0059 
0060   edm::Handle<l1ScoutingRun3::OrbitFlatTable> m_handle;
0061   const l1ScoutingRun3::OrbitFlatTable *m_table;
0062 
0063   template <typename T>
0064   void fillColumn(NamedBranchPtr &pair, uint32_t bx) {
0065     pair.branch->SetAddress(
0066         m_counter == 0
0067             ? static_cast<T *>(nullptr)
0068             : const_cast<T *>(
0069                   &m_table->columnData<T>(pair.columnIndex, bx).front()));  // SetAddress should take a const * !
0070   }
0071 };
0072 
0073 #endif