ARTEMIS-CRIB
 
Loading...
Searching...
No Matches
TBranchCopyProcessor.cc
Go to the documentation of this file.
1/**
2 * @file TBranchCopyProcessor.cc
3 * @brief
4 * @author Kodai Okawa<okawa@cns.s.u-tokyo.ac.jp>
5 * @date 2023-06-13 16:06:15
6 * @note last modified: 2025-03-05 18:34:56
7 * @details
8 */
9
11#include "TProcessorUtil.h"
12
13#include <TDataObject.h>
14
15/// ROOT macro for class implementation
17
18namespace art::crib {
20 RegisterInputCollection("InputCollection", "name of the origin branch",
22 RegisterOutputCollection("OutputCollection", "output collection name",
24}
25
30
31/**
32 * @details
33 * Sets up the input and output collections by retrieving the input collection
34 * and preparing a corresponding output collection of the same class type.
35 */
36void TBranchCopyProcessor::Init(TEventCollection *col) {
38 col, fInputColName, "TClonesArray", "art::TDataObject");
39
40 if (std::holds_alternative<TString>(result)) {
41 SetStateError(std::get<TString>(result));
42 return;
43 }
44
45 fInData = std::get<TClonesArray **>(result);
46 Info("Init", "%s => %s copy", fInputColName.Data(), fOutputColName.Data());
47
48 const auto *cl = (*fInData)->GetClass();
49 if (!cl) {
50 SetStateError(Form("Failed to get TClass at branch: %s",
51 fInputColName.Data()));
52 return;
53 }
54 fOutData = new TClonesArray(cl);
55 fOutData->SetName(fOutputColName);
56 col->Add(fOutputColName, fOutData, fOutputIsTransparent);
57}
58
59/**
60 * @details
61 * Iterates over the entries in the input collection and creates a copy
62 * of each entry in the output collection using the `Copy` method of `TDataObject`.
63 */
65 fOutData->Clear("C");
66
67 for (int iData = 0; iData < (*fInData)->GetEntriesFast(); iData++) {
68 const auto *inData = static_cast<TDataObject *>((*fInData)->At(iData));
69 auto *outData = static_cast<TDataObject *>(fOutData->ConstructedAt(iData));
70
71 inData->Copy(*outData);
72 }
73}
74} // namespace art::crib
ClassImp(art::crib::TBranchCopyProcessor)
ROOT macro for class implementation.
Utility functions for handling input and parameter objects in TEventCollection.
Processor for copying data from one TClonesArray to another.
~TBranchCopyProcessor() override
Destructor.
TString fInputColName
Name of the input collection.
TClonesArray ** fInData
! Pointer to the input data
TClonesArray * fOutData
! Pointer to the output data.
TString fOutputColName
Name of the output collection.
void Process() override
Processes the data by copying from input to output collection.
void Init(TEventCollection *col) override
Initializes the processor with the given event collection.
std::enable_if_t< std::is_base_of_v< TObject, T >, std::variant< T **, TString > > GetInputObject(TEventCollection *col, const TString &name, const TString &expectedTypeName, const TString &elementTypeName="TObject")
Retrieve an object from TEventCollection with type validation.
return to the guide