FairRoot/PandaRoot
Public Types | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
PndMvdMQFileSink Class Reference

#include <PndMvdMQFileSink.h>

Inheritance diagram for PndMvdMQFileSink:

Public Types

enum  { OutputFileName = FairMQDevice::Last, Last }
 

Public Member Functions

 PndMvdMQFileSink ()
 
virtual ~PndMvdMQFileSink ()
 
void SetProperty (const int key, const std::string &value)
 
void SetProperty (const int key, const int value)
 
std::string GetProperty (const int key, const std::string &default_="")
 
int GetProperty (const int key, const int default_=0)
 
void SetOutputFileName (std::string tempString)
 
void AddOutputBranch (std::string classString, std::string branchString)
 
std::string GetOutputFileName ()
 

Protected Member Functions

virtual void Init ()
 
virtual void Run ()
 

Private Attributes

std::string fFileName
 
std::string fTreeName
 
std::vector< std::string > fBranchNames
 
std::vector< std::string > fClassNames
 
std::string fFileOption
 
bool fFlowMode
 
bool fWrite
 
TFile * fOutFile
 
TTree * fTree
 
unsigned int fNObjects
 
TObject ** fOutputObjects
 
TFolder * fFolder
 

Detailed Description

PndMvdMQFileSink.h

Since
2016-03-08
Author
R. Karabowicz

Definition at line 26 of file PndMvdMQFileSink.h.

Member Enumeration Documentation

anonymous enum
Enumerator
OutputFileName 
Last 

Definition at line 29 of file PndMvdMQFileSink.h.

30  {
31  OutputFileName = FairMQDevice::Last,
32  Last
33  };

Constructor & Destructor Documentation

PndMvdMQFileSink::PndMvdMQFileSink ( )

Definition at line 37 of file PndMvdMQFileSink.cxx.

38  : FairMQDevice()
39  , fFileName()
40  , fTreeName()
41 
42  , fBranchNames()
43  , fClassNames()
44  , fFileOption()
45  , fFlowMode(false)
46  , fWrite(false)
47 
48  , fOutFile(NULL)
49  , fTree(NULL)
50  , fNObjects(0)
51  , fOutputObjects(new TObject*[1000])
52  , fFolder(NULL)
53 {
54 }
std::string fFileName
std::string fFileOption
TObject ** fOutputObjects
std::string fTreeName
std::vector< std::string > fBranchNames
unsigned int fNObjects
std::vector< std::string > fClassNames
PndMvdMQFileSink::~PndMvdMQFileSink ( )
virtual

Definition at line 175 of file PndMvdMQFileSink.cxx.

References fOutFile, and fTree.

176 {
177  if (fTree)
178  {
179  fTree->Write();
180  delete fTree;
181  }
182 
183  if (fOutFile)
184  {
185  if (fOutFile->IsOpen())
186  fOutFile->Close();
187  delete fOutFile;
188  }
189 }

Member Function Documentation

void PndMvdMQFileSink::AddOutputBranch ( std::string  classString,
std::string  branchString 
)
inline

Definition at line 44 of file PndMvdMQFileSink.h.

References fBranchNames, and fClassNames.

Referenced by main().

45  {
46  fClassNames .push_back(classString);
47  fBranchNames.push_back(branchString);
48  }
std::vector< std::string > fBranchNames
std::vector< std::string > fClassNames
std::string PndMvdMQFileSink::GetOutputFileName ( )
inline

Definition at line 49 of file PndMvdMQFileSink.h.

References fFileName.

Referenced by GetProperty().

49 { return fFileName;}
std::string fFileName
std::string PndMvdMQFileSink::GetProperty ( const int  key,
const std::string &  default_ = "" 
)

Definition at line 158 of file PndMvdMQFileSink.cxx.

References GetOutputFileName(), and OutputFileName.

159 {
160  switch (key)
161  {
162  case OutputFileName :
163  return GetOutputFileName();
164 
165  default:
166  return FairMQDevice::GetProperty(key, default_);
167  }
168 }
std::string GetOutputFileName()
int PndMvdMQFileSink::GetProperty ( const int  key,
const int  default_ = 0 
)

Definition at line 170 of file PndMvdMQFileSink.cxx.

171 {
172  return FairMQDevice::GetProperty(key, value);
173 }
void PndMvdMQFileSink::Init ( )
protectedvirtual

Definition at line 56 of file PndMvdMQFileSink.cxx.

References fBranchNames, fClassNames, fFileName, fFileOption, fFolder, fNObjects, fOutFile, fOutputObjects, fTree, and fTreeName.

57 {
58  LOG(INFO) << "SHOULD CREATE THE FILE AND TREE";
59  // fFileName = "/Users/karabowi/fairroot/pixel9_dev/FairRoot/examples/MQ/9-PixelDetector/macros/tmpOut.root";
60  fFileOption = "RECREATE";
61  fTreeName = "pndsim";
62 
63  // fBranchNames.push_back("EventHeader.");
64  // fClassNames .push_back("FairEventHeader");
65  // fBranchNames.push_back("PixelHits");
66  // fClassNames .push_back("TClonesArray(PixelHit)");
67 
68  fOutFile = TFile::Open(fFileName.c_str(),fFileOption.c_str());
69 
70  fTree = new TTree(fTreeName.c_str(), "/cbmout");
71 
72  fFolder = new TFolder("cbmout", "Main Output Folder");
73  TFolder* foldEventHeader = fFolder->AddFolder("EvtHeader","EvtHeader");
74  TFolder* foldPixel = fFolder->AddFolder("Pixel","Pixel");
75 
76  TList* BranchNameList = new TList();
77 
78  LOG(INFO) << "PndMvdMQFileSink: " << fBranchNames.size();
79 
80  for ( fNObjects = 0 ; fNObjects < fBranchNames.size() ; fNObjects++ ) {
81  if ( fClassNames[fNObjects].find("TClonesArray(") == 0 ) {
82  fClassNames [fNObjects] = fClassNames[fNObjects].substr(13,fClassNames[fNObjects].length()-12-2);
83  fOutputObjects [fNObjects] = new TClonesArray(fClassNames[fNObjects].c_str());
84  fTree->Branch(fBranchNames[fNObjects].c_str(),"TClonesArray", &fOutputObjects[fNObjects]);
85  foldPixel->Add(fOutputObjects[fNObjects]);
86  LOG(INFO) << fNObjects << " : " << fBranchNames[fNObjects];
87  BranchNameList->AddLast(new TObjString(fBranchNames[fNObjects].c_str()));
88  }
89  else if ( fClassNames[fNObjects].find("FairEventHeader") == 0 ) {
90  fOutputObjects [fNObjects] = new FairEventHeader();
91  fTree->Branch(fBranchNames[fNObjects].c_str(),"FairEventHeader", &fOutputObjects[fNObjects]);
92  foldEventHeader->Add(fOutputObjects[fNObjects]);
93  BranchNameList->AddLast(new TObjString(fBranchNames[fNObjects].c_str()));
94  }
95  else {
96  LOG(ERROR) << "!!! Unknown output object \"" << fClassNames[fNObjects] << "\" !!!";
97  }
98  }
99 
100  fFolder->Write();
101  BranchNameList->Write("BranchList", TObject::kSingleKey);
102  BranchNameList->Delete();
103  delete BranchNameList;
104 
105 }
std::string fFileName
std::string fFileOption
TObject ** fOutputObjects
std::string fTreeName
std::vector< std::string > fBranchNames
unsigned int fNObjects
std::vector< std::string > fClassNames
void PndMvdMQFileSink::Run ( )
protectedvirtual

Definition at line 107 of file PndMvdMQFileSink.cxx.

References fBranchNames, fOutputObjects, and fTree.

108 {
109  while (CheckCurrentState(RUNNING))
110  {
111  FairMQParts parts;
112 
113  if (Receive(parts, "data-in") >= 0)
114  {
115 
116  TObject* tempObjects[10];
117  for ( int ipart = 0 ; ipart < parts.Size() ; ipart++ )
118  {
119  Ex9TMessage tm(parts.At(ipart)->GetData(), parts.At(ipart)->GetSize());
120  tempObjects[ipart] = (TObject*)tm.ReadObject(tm.GetClass());
121  for ( unsigned int ibr = 0 ; ibr < fBranchNames.size() ; ibr++ )
122  {
123  if ( strcmp(tempObjects[ipart]->GetName(),fBranchNames[ibr].c_str()) == 0 )
124  {
125  fOutputObjects[ibr] = tempObjects[ipart];
126  fTree->SetBranchAddress(fBranchNames[ibr].c_str(),&fOutputObjects[ibr]);
127  }
128  }
129  }
130  fTree->Fill();
131  }
132  else
133  {
134  LOG(INFO) << "oops!";
135  }
136  }
137 }
TObject ** fOutputObjects
std::vector< std::string > fBranchNames
void PndMvdMQFileSink::SetOutputFileName ( std::string  tempString)
inline

Definition at line 43 of file PndMvdMQFileSink.h.

References fFileName.

Referenced by SetProperty().

43 { fFileName = tempString; }
std::string fFileName
void PndMvdMQFileSink::SetProperty ( const int  key,
const std::string &  value 
)

Definition at line 139 of file PndMvdMQFileSink.cxx.

References OutputFileName, and SetOutputFileName().

Referenced by main().

140 {
141  switch (key)
142  {
143  case OutputFileName :
144  SetOutputFileName(value);
145  break;
146 
147  default:
148  FairMQDevice::SetProperty(key, value);
149  break;
150  }
151 }
void SetOutputFileName(std::string tempString)
void PndMvdMQFileSink::SetProperty ( const int  key,
const int  value 
)

Definition at line 153 of file PndMvdMQFileSink.cxx.

154 {
155  FairMQDevice::SetProperty(key, value);
156 }

Member Data Documentation

std::vector<std::string> PndMvdMQFileSink::fBranchNames
private

Definition at line 59 of file PndMvdMQFileSink.h.

Referenced by AddOutputBranch(), Init(), and Run().

std::vector<std::string> PndMvdMQFileSink::fClassNames
private

Definition at line 60 of file PndMvdMQFileSink.h.

Referenced by AddOutputBranch(), and Init().

std::string PndMvdMQFileSink::fFileName
private

Definition at line 56 of file PndMvdMQFileSink.h.

Referenced by GetOutputFileName(), Init(), and SetOutputFileName().

std::string PndMvdMQFileSink::fFileOption
private

Definition at line 62 of file PndMvdMQFileSink.h.

Referenced by Init().

bool PndMvdMQFileSink::fFlowMode
private

Definition at line 63 of file PndMvdMQFileSink.h.

TFolder* PndMvdMQFileSink::fFolder
private

Definition at line 72 of file PndMvdMQFileSink.h.

Referenced by Init().

unsigned int PndMvdMQFileSink::fNObjects
private

Definition at line 68 of file PndMvdMQFileSink.h.

Referenced by Init().

TFile* PndMvdMQFileSink::fOutFile
private

Definition at line 66 of file PndMvdMQFileSink.h.

Referenced by Init(), and ~PndMvdMQFileSink().

TObject** PndMvdMQFileSink::fOutputObjects
private

Definition at line 69 of file PndMvdMQFileSink.h.

Referenced by Init(), and Run().

TTree* PndMvdMQFileSink::fTree
private

Definition at line 67 of file PndMvdMQFileSink.h.

Referenced by Init(), Run(), and ~PndMvdMQFileSink().

std::string PndMvdMQFileSink::fTreeName
private

Definition at line 57 of file PndMvdMQFileSink.h.

Referenced by Init().

bool PndMvdMQFileSink::fWrite
private

Definition at line 64 of file PndMvdMQFileSink.h.


The documentation for this class was generated from the following files: