QwAnalysis
QwControl.cc
Go to the documentation of this file.
1 #include "QwControl.h"
2 
3 // Standard C and C++ headers
4 #include <iostream>
5 #include <cstdlib>
6 using std::cout; using std::endl;
7 
8 // ROOT headers
9 #include "TROOT.h"
10 #include "TBenchmark.h"
11 
12 // Qweak headers
13 #include "VQwSystem.h"
14 
15 // Qweak analyzers
16 #include "VQwAnalyzer.h"
17 #include "QwTrackingAnalyzer.h"
18 
19 // Qweak dataservers
20 #include "VQwDataserver.h"
21 #include "QwTrackingDataserver.h"
22 
23 
25 
26 
27 void* QwRunThread (void* arg)
28 {
29  // Threaded running of the analyzer
30  // so that other tasks may be performed
31 
32  if (! ((TObject*) arg)->InheritsFrom("QwControl")) {
33  TThread::Printf(" Error...QwControl base class not supplied\n");
34  return NULL;;
35  }
36  QwControl* qr = (QwControl*) arg;
37  qr->Run();
38  return NULL;
39 }
40 
41 //---------------------------------------------------------------------------
43 {
44  // Run online or offline analysis
45  // Offline handles ascii file(s)
46 
47  gBenchmark = new TBenchmark();
48  gBenchmark->Start("QwControlRunThread");
49 
50  // Set up analysis
51  //fAnalysis->FileConfig (fAnalysisSetup);
52 
53  // Online
54  if (fIsOnline) {
55  // Connect to data stream
56  // if (data stream) data loop;
57 
58  // Offline
59  } else {
60  OfflineLoop();
61  }
62  gBenchmark->Show("QwControlRunThread");
63  fIsFinished = true;
64 }
65 
66 //-----------------------------------------------------------------------------
68 {
69  // Start the analysis thread. This will run in the background
70  // but will produce to occasional warning or info message
71 
72  if (fRunThread) {
73  printf(" Warning...deleting old RunThread and starting new one,\n");
74  fRunThread->Delete();
75  }
76  printf(" Starting new RunThread.\n");
77  fRunThread = new TThread("QwRunThread",
78  (void(*) (void*))&(QwRunThread),
79  (void*) this);
80  fRunThread->Run();
81  return;
82 }
83 
84 //-----------------------------------------------------------------------------
86 {
87  // Loop while online data
88 
89  // Wait until buffer ready
90 
91  // Process event
92 
93  // Finish
94 }
95 
96 //-----------------------------------------------------------------------------
98 {
99  // Loop over the offline data sources (ascii files, ntuples from geant)
100 
101  // Setup file name
102 
103  int nEvent = 0; // number of processed events
104  int nEventMax = 10; // maximum number of events
105 
106  while (nEvent < nEventMax) {
107  // Get next event from dataserver
110 
111  // Process this event
112  fAnalyzer->Process();
113 
114  nEvent++;
115  }
116 }
117 
118 //-----------------------------------------------------------------------------
120 {
121  if (strcmp (name, "QwTrackingAnalyzer") == 0) {
122  VQwAnalyzer* analyzer = new QwTrackingAnalyzer (name);
123  return analyzer;
124  }
125  return 0;
126 }
127 //-----------------------------------------------------------------------------
129 {
130 // TODO (wdc) Why doesn't this work? (and in SetDataserver below)
131 // if (! analyzer->InheritsFrom("VQwAnalyzer")) {
132 // std::cout << "Error: analysis has to inherit from VQwAnalyzer!" << std::endl;
133 // return;
134 // }
135  fAnalyzer = analyzer;
136  return;
137 }
138 
139 //-----------------------------------------------------------------------------
141 {
142  if (strcmp (name, "QwTrackingDataserver") == 0) {
143  VQwDataserver* dataserver = new QwTrackingDataserver (name);
144  return dataserver;
145  }
146  return 0;
147 }
148 //-----------------------------------------------------------------------------
150 {
151 // if (! dataserver->InheritsFrom("VQwDataserver")) {
152 // std::cout << "Error: dataserver has to inherit from VQwDataserver!" << std::endl;
153 // return;
154 // }
155  fDataserver = dataserver;
156  return;
157 }
bool fIsFinished
Definition: QwControl.h:21
VQwDataserver * fDataserver
Definition: QwControl.h:18
bool fIsOnline
Definition: QwControl.h:20
virtual void NextEvent()
Definition: VQwDataserver.h:19
void * QwRunThread(void *)
Definition: QwControl.cc:27
TThread * fRunThread
Definition: QwControl.h:15
void SetDataserver(VQwDataserver *dataserver)
Definition: QwControl.cc:149
void SetAnalyzer(VQwAnalyzer *analyzer)
Definition: QwControl.cc:128
void Start()
Definition: QwControl.cc:67
virtual QwHitContainer * GetHitList()
Definition: VQwDataserver.h:24
void OfflineLoop()
Definition: QwControl.cc:97
void OnlineLoop()
Definition: QwControl.cc:85
virtual void Process()
Definition: VQwAnalyzer.h:23
VQwAnalyzer * CreateAnalyzer(const char *name)
Definition: QwControl.cc:119
ClassImp(QwF1TDC)
void Run()
Definition: QwControl.cc:42
VQwDataserver * CreateDataserver(const char *name)
Definition: QwControl.cc:140
virtual void SetHitList(QwHitContainer *hitlist)
Definition: VQwAnalyzer.h:19
VQwAnalyzer * fAnalyzer
Definition: QwControl.h:17