BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
updateContent.C
Go to the documentation of this file.
1/**
2 * updateContent.C
3 *
4 * An example macro how to copy raw root data and make first events
5 * as pedestal ones
6 *
7 */
8
9int updateContent(TString fileName = "", TString destName = "", Int_t nPedsMax = 100, TString treeName = "BMN_RAW")
10{
11 const TString EHDigiName = "BmnEventHeader.";
12 vector<TString> digiNamesOther;
13 vector<TClass*> digiClassesOther;
14 vector<TClonesArray*> digiBaseArsOther;
15 vector<TClonesArray*> digiDestArsOther;
16 if (fileName == "") {
17 cout << "ERROR: File path was not specified" << endl;
18 return -1;
19 }
20
21 gSystem->ExpandPathName(fileName);
22
23 /*****************************/
24 /** Open input base digits **/
25 /*****************************/
26 TFile* rootFile = new TFile(fileName.Data(), "READ");
27 if (!rootFile) {
28 cout << "ERROR: File was not found: " << fileName << endl;
29 return -2;
30 }
31 // get objects outside trees
32 TList* keys = rootFile->GetListOfKeys();
33 // get input tree
34 TTree* fInTreeBase = (TTree*)rootFile->Get(treeName.Data());
35 if (!fInTreeBase) {
36 cout << "ERROR: Tree was not found: " << treeName << endl;
37 return -3;
38 }
39 UInt_t fNEventSource = fInTreeBase->GetEntries();
40 TObjArray* digiBaseBrsFull = fInTreeBase->GetListOfBranches();
41 TIterator* it = digiBaseBrsFull->MakeIterator();
42 it->Reset();
43 TBranch* b = NULL;
44 while ((b = (TBranch*)it->Next())) {
45 if (strcmp(b->GetName(), EHDigiName.Data()) == 0)
46 continue;
47 TClonesArray* arDigi = nullptr;
48 fInTreeBase->SetBranchAddress(b->GetName(), &arDigi);
49 digiNamesOther.push_back(TString(b->GetName()));
50 digiBaseArsOther.push_back(arDigi);
51 digiClassesOther.push_back(arDigi->GetClass());
52 }
53 BmnEventHeader* baseEH = nullptr;
54 fInTreeBase->SetBranchAddress(EHDigiName.Data(), &baseEH);
55
56 /*****************************/
57 /** Open dest digits **/
58 /*****************************/
59 TFile* fDestHitsFile = new TFile(destName, "RECREATE");
60 if (fDestHitsFile->IsOpen() == false) {
61 printf("\n!!!!\ncannot open file %s !\n", destName.Data());
62 return kBMNERROR;
63 }
64 printf("\n DEST FILE: ");
65 printf("%s\n", destName.Data());
66
67 TIter next(keys);
68 TKey* key;
69 while ((key = (TKey*)next())) {
70 TObject* obj = key->ReadObj();
71 if (treeName == TString(key->GetName()))
72 continue;
73 std::cout << "Cloning object : " << key->GetName() << "; obj->ClassName() : " << obj->ClassName() << std::endl;
74 fDestHitsFile->WriteObject(obj, key->GetName());
75 }
76
77 TTree* fDestTree = new TTree(treeName.Data(), treeName.Data());
78 for (Int_t i = 0; i < digiBaseArsOther.size(); i++) {
79 TClonesArray* arDigi = new TClonesArray(digiClassesOther[i]);
80 fDestTree->Branch(digiNamesOther[i], &arDigi);
81 digiDestArsOther.push_back(arDigi);
82 }
83 BmnEventHeader* destEH = new BmnEventHeader();
84 fDestTree->Branch("BmnEventHeader.", &destEH);
85 UInt_t fNArs = digiNamesOther.size();
86
87 // fill events
88 Int_t nPedsAdded = 0;
89 for (UInt_t iEv = 0; iEv < fNEventSource; ++iEv) {
90 if (iEv % 5000 == 0)
91 cout << "Cloned event #" << iEv << endl;
92
93 fInTreeBase->GetEntry(iEv);
94 destEH->Clear();
95 for (UInt_t iBr = 0; iBr < digiDestArsOther.size(); iBr++) {
96 digiDestArsOther[iBr]->Clear("C");
97 digiDestArsOther[iBr]->AbsorbObjects(digiBaseArsOther[iBr]);
98 }
99 destEH->Clear();
100 destEH->SetEventId(baseEH->GetEventId());
101 destEH->SetEventTime(baseEH->GetEventTime());
102 destEH->SetEventTimeTS(baseEH->GetEventTimeTS());
103 if (nPedsAdded++ < nPedsMax)
104 destEH->SetEventTime(kBMNPEDESTAL);
105 else
106 destEH->SetEventType(baseEH->GetEventType());
107 destEH->SetPeriodId(baseEH->GetPeriodId());
108 destEH->SetRunId(baseEH->GetRunId());
109 fDestTree->Fill();
110 }
111 fDestTree->Write();
112 // fDestHitsFile->WriteObject(rhBase, RHDigiName.Data());
113 fDestHitsFile->Write();
114 if (fDestHitsFile)
115 fDestHitsFile->Close();
116
117 rootFile->Close();
118 delete rootFile;
119 return 0;
120}
int i
Definition P4_F32vec4.h:22
int Int_t
unsigned int UInt_t
R__EXTERN TSystem * gSystem
@ kBMNERROR
Error.
Definition BmnEnums.h:95
@ kBMNPEDESTAL
pedestal event.
Definition BmnEnums.h:144
UInt_t GetPeriodId()
Get the period ID for this event.
void SetEventType(BmnEventType event_type)
Set the type for this event.
UInt_t GetEventId()
Get the event ID for this event.
TTimeStamp GetEventTimeTS()
Get the time for this event.
void SetEventTimeTS(TTimeStamp event_time)
Set the time for this event in.
void SetPeriodId(UInt_t period_id)
Set the period ID for this event.
BmnEventType GetEventType()
Get the type of this event.
void SetEventId(UInt_t event_id)
Set the event ID for this event.
TClass * GetClass() const
T * Get(const char *namecycle)
TList * GetListOfKeys() const override
std::enable_if_t<!std::is_base_of< TObject, T >::value, Int_t > WriteObject(const T *obj, const char *name, Option_t *option="", Int_t bufsize=0)
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) const override
virtual Bool_t IsOpen() const
void Close(Option_t *option="") override
virtual void Reset()=0
virtual TObject * Next()=0
TIterator * MakeIterator(Bool_t dir=kIterForward) const override
virtual const char * ClassName() const
const char * Data() const
virtual Int_t Fill()
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
virtual Long64_t GetEntries() const
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const override
virtual TObjArray * GetListOfBranches()
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
int updateContent(TString fileName="", TString destName="", Int_t nPedsMax=100, TString treeName="BMN_RAW")
updateContent.C