10 #include "StarClassLibrary/StTimer.hh"
12 #include "StMessMgr.h"
13 #include "StMuDebug.h"
14 #include "StMuIOMaker.h"
16 #include "StMuEvent.h"
21 #include "TClonesArray.h"
53 StMuIOMaker::~StMuIOMaker() {
55 if(
mMuSave && !mBadInFile && !mCloseWrite) closeMuWrite();
72 TDataSet *muDstSet = AddObj(mStMuDst,
".const");
73 if (muDstSet ) muDstSet ->SetName(
"MuDst");
89 if (iret!=
kStErr && ntry--)
break;
90 Warning(
"Make",
"%d *** ReadError ***\n",ntry);
117 DEBUGVALUE3(mNumberOfEvents);
120 if (!mChain)
return kStEOF;
123 LOG_WARN <<
"#### " <<
fFile.Data() <<
" could not read event " << index
124 <<
", TTree::GetEntry returned " << bytes << endm;
129 if(
mMuSave) { mOutTree->Fill(); THack::IsTreeWritable(mOutTree); }
145 int index = mChain->GetEntryNumberWithIndex(major,minor);
153 int index = mChain->GetEntryNumberWithIndex(key.GetRunId(),key.GetEventId());
162 LOG_INFO <<
"###### StMuIOMaker read " << mEventCounter <<
" events" << endm;
163 if(
mMuSave && !mBadInFile && !mCloseWrite) {
164 if (mOutTree) mOutTree->AutoSave();
167 DEBUGMESSAGE3(
"out");
174 Int_t StMuIOMaker:: MakeRead(
const StUKey &key) {
187 DEBUGMESSAGE(
"BadFile");
194 Int_t StMuIOMaker::Open(
const char*) {
198 int iret = openRead();
208 void StMuIOMaker::Close(Option_t *) {
210 if(
mMuSave && !mBadInFile && !mCloseWrite) closeMuWrite();
212 DEBUGMESSAGE3(
"out");
218 int StMuIOMaker::openRead() {
220 DEBUGVALUE(
fFile.Data());
221 mChain =
new TChain(
"MuDst");
223 mChain->Add(
fFile.Data());
226 mNumberOfEvents = (int)mChain->GetEntries();
228 if(mNumberOfEvents == 1234567890) {
229 LOG_WARN <<
"#### " <<
fFile.Data() <<
" Corrupted!" << endm;
239 setBranchAddresses(mChain);
240 mChain->BuildIndex(
"MuEvent.mEventInfo.mRunId",
"MuEvent.mEventInfo.mId");
242 LOG_INFO <<
" Index of " << mNumberOfEvents <<
" events buit in "
243 << timer.elapsedTime() <<
" seconds " << endm;
247 DEBUGMESSAGE3(
"out");
253 void StMuIOMaker::openMuWrite() {
255 mOutFileName =
fFile.Data();
256 while (mOutFileName.find(
"/")!=string::npos) {
257 int pos = mOutFileName.find(
"/");
258 mOutFileName.erase(0,pos+1);
260 int pos = mOutFileName.find(
"MuDst");
261 mOutFileName = mOutFileName.insert(pos,
"Sel.");
262 DEBUGVALUE(mOutFileName.c_str());
264 mOutFile =
new TFile(mOutFileName.c_str(),
"RECREATE",
"StMuDst");
265 if (mOutFile->IsZombie()) {
266 LOG_FATAL <<
"StMuIOMaker::openMuWrite" <<
" Can not create TFile object for "
267 << mOutFileName.c_str() <<
" file" << endm;
270 mOutFile->SetCompressionLevel(mCompression);
272 TTree *
tree = mChain->GetTree();
273 mOutTree =
new TTree(
"MuDst",
"StMuDst", mSplit);
274 #if ROOT_VERSION_CODE < ROOT_VERSION(5,26,0)
275 Long64_t MAXLONG=100000000000LL;
276 LOG_INFO <<
"Tree size MAX will be " << (float) MAXLONG/1000/1000/1000 <<
" GB " << endm;
277 mOutTree->SetMaxTreeSize(MAXLONG);
279 mOutTree = tree->CloneTree(0);
281 DEBUGMESSAGE3(
"out");
285 void StMuIOMaker::closeMuWrite(){
287 LOG_INFO << __PRETTY_FUNCTION__ << endm;
288 if (mOutTree && mOutFile) {
289 LOG_INFO <<
" ##### " << __PRETTY_FUNCTION__ <<
" "
290 <<
" ##### " << endm;
291 LOG_INFO <<
" ##### File=" << mOutFile->GetName() <<
" "
292 <<
" ##### " << endm;
293 LOG_INFO <<
" ##### NumberOfEvents= " << mOutTree->GetEntries() <<
" "
294 <<
" ##### " << endm;
300 if(mOutTree) mOutTree->Write();
302 if(mOutFile) mOutFile->Close();
306 LOG_INFO <<
" Writing took " << timer.elapsedTime() <<
" seconds " << endm;
308 DEBUGMESSAGE3(
"out");
TTree * tree()
Returns pointer to the current TTree, the top level io structure that holds the event, track, v0, etc. information in branches of that tree.
static void set(StMuDstMaker *maker)
set the pointers to the TClonesArrays
TString fTreeName
r=read,w=write,u=update
static void collectVertexTracks()
Helper function to collect tracks for the current prim vertex.
int mCurrentIndex
holds the # of events in the current chain (file)
bool mMuSave
holds the index of the last event read