BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
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
9
int
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
}
i
int i
Definition
P4_F32vec4.h:22
Int_t
int Int_t
UInt_t
unsigned int UInt_t
gSystem
R__EXTERN TSystem * gSystem
kBMNERROR
@ kBMNERROR
Error.
Definition
BmnEnums.h:95
kBMNPEDESTAL
@ kBMNPEDESTAL
pedestal event.
Definition
BmnEnums.h:144
BmnEventHeader
Definition
BmnEventHeader.h:24
BmnEventHeader::GetPeriodId
UInt_t GetPeriodId()
Get the period ID for this event.
Definition
BmnEventHeader.h:92
BmnEventHeader::SetEventType
void SetEventType(BmnEventType event_type)
Set the type for this event.
Definition
BmnEventHeader.h:160
BmnEventHeader::GetEventId
UInt_t GetEventId()
Get the event ID for this event.
Definition
BmnEventHeader.h:89
BmnEventHeader::Clear
void Clear()
Definition
BmnEventHeader.cxx:76
BmnEventHeader::GetEventTimeTS
TTimeStamp GetEventTimeTS()
Get the time for this event.
Definition
BmnEventHeader.h:95
BmnEventHeader::SetEventTimeTS
void SetEventTimeTS(TTimeStamp event_time)
Set the time for this event in.
Definition
BmnEventHeader.h:151
BmnEventHeader::SetPeriodId
void SetPeriodId(UInt_t period_id)
Set the period ID for this event.
Definition
BmnEventHeader.h:148
BmnEventHeader::GetEventType
BmnEventType GetEventType()
Get the type of this event.
Definition
BmnEventHeader.h:102
BmnEventHeader::SetEventId
void SetEventId(UInt_t event_id)
Set the event ID for this event.
Definition
BmnEventHeader.h:143
TBranch
TClonesArray
TClonesArray::GetClass
TClass * GetClass() const
TDirectoryFile::Get
T * Get(const char *namecycle)
TDirectoryFile::GetListOfKeys
TList * GetListOfKeys() const override
TDirectory::WriteObject
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)
TFile
TFile::Write
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsize=0) const override
TFile::IsOpen
virtual Bool_t IsOpen() const
TFile::Close
void Close(Option_t *option="") override
TIter
TIterator
TIterator::Reset
virtual void Reset()=0
TIterator::Next
virtual TObject * Next()=0
TKey
TList
TObjArray
TObjArray::MakeIterator
TIterator * MakeIterator(Bool_t dir=kIterForward) const override
TObject
TObject::ClassName
virtual const char * ClassName() const
TString
TString::Data
const char * Data() const
TTree
TTree::Fill
virtual Int_t Fill()
TTree::GetEntry
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
TTree::GetEntries
virtual Long64_t GetEntries() const
TTree::Write
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const override
TTree::GetListOfBranches
virtual TObjArray * GetListOfBranches()
TTree::SetBranchAddress
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
TTree::Branch
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
updateContent
int updateContent(TString fileName="", TString destName="", Int_t nPedsMax=100, TString treeName="BMN_RAW")
updateContent.C
Definition
updateContent.C:9
macro
miscellaneous
updateContent.C
Generated on
for BmnRoot by
1.17.0