Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "TGo4DabcPlayer.h"
00016
00017 #include "TFolder.h"
00018 #include "TCollection.h"
00019 #include "TTimer.h"
00020 #include "Riostream.h"
00021
00022 #include "TGo4Sniffer.h"
00023
00024 #include "TGo4AnalysisImp.h"
00025 #include "TGo4AnalysisObjectManager.h"
00026 #include "TGo4Ratemeter.h"
00027 #include "TGo4Log.h"
00028 #include "TGo4LockGuard.h"
00029
00030 #include "dabc/Hierarchy.h"
00031
00032 #include "dabc/Factory.h"
00033
00034
00035 class TGo4DabcFactory : public dabc::Factory {
00036 public:
00037 TGo4DabcFactory(const std::string& name) : dabc::Factory(name) {}
00038
00039 virtual dabc::Reference CreateObject(const std::string& classname, const std::string& objname, dabc::Command cmd)
00040 {
00041 if (classname=="TGo4DabcPlayer")
00042 return new TGo4DabcPlayer(objname, cmd);
00043
00044 return dabc::Factory::CreateObject(classname, objname, cmd);
00045 }
00046 };
00047
00048
00049 dabc::FactoryPlugin go4dabc_factory(new TGo4DabcFactory("go4"));
00050
00051
00052 TGo4DabcPlayer::TGo4DabcPlayer(const std::string& name, dabc::Command cmd) :
00053 root::Monitor(name, cmd),
00054 TGo4AnalysisSniffer("dabc_sniffer")
00055 {
00056 if (TGo4Analysis::Instance()!=0)
00057 TGo4Analysis::Instance()->SetSniffer(this);
00058
00059
00060
00061 TGo4Log::SetSniffer(this);
00062 }
00063
00064 TGo4DabcPlayer::~TGo4DabcPlayer()
00065 {
00066 if (TGo4Analysis::Instance()!=0)
00067 TGo4Analysis::Instance()->SetSniffer(0);
00068
00069 TGo4Log::SetSniffer(0);
00070 }
00071
00072 void TGo4DabcPlayer::InitializeHierarchy()
00073 {
00074 dabc::LockGuard lock(fHierarchy.GetHMutex());
00075
00076 dabc::Hierarchy sub = fHierarchy.CreateHChild("Status");
00077 sub.SetPermanent();
00078
00079 sub.CreateHChild("Message").SetField(dabc::prop_kind, "log");
00080
00081 sub.CreateHChild("EventRate").SetField(dabc::prop_kind, "rate");
00082
00083 sub.CreateHChild("AverRate").SetField(dabc::prop_kind, "rate");
00084
00085 sub.CreateHChild("EventCount").SetField(dabc::prop_kind, "log");
00086 sub.CreateHChild("RunTime").SetField(dabc::prop_kind, "log");
00087
00088 sub.CreateHChild("DebugOutput").SetField(dabc::prop_kind, "log");
00089
00090 sub.CreateHChild("CmdClear").SetField(dabc::prop_kind, "DABC.Command");
00091 sub.CreateHChild("CmdStart").SetField(dabc::prop_kind, "DABC.Command");
00092 sub.CreateHChild("CmdStop").SetField(dabc::prop_kind, "DABC.Command");
00093
00094 sub.EnableHistory(200, true);
00095 }
00096
00097
00098 void TGo4DabcPlayer::RatemeterUpdate(TGo4Ratemeter* r)
00099 {
00100 dabc::LockGuard lock(fHierarchy.GetHMutex());
00101
00102 fHierarchy.GetHChild("Status/EventRate").SetField("value", r->GetRate());
00103 fHierarchy.GetHChild("Status/EventRate").SetFieldModified("value");
00104
00105 fHierarchy.GetHChild("Status/AverRate").SetField("value", r->GetAvRate());
00106 fHierarchy.GetHChild("Status/AverRate").SetFieldModified("value");
00107
00108 fHierarchy.GetHChild("Status/EventCount").SetField("value", dabc::format("%lu", (long unsigned) r->GetCurrentCount()));
00109
00110 fHierarchy.GetHChild("Status/RunTime").SetField("value", dabc::format("%3.1f", r->GetTime()));
00111
00112 fHierarchy.MarkChangedItems();
00113 }
00114
00115 void TGo4DabcPlayer::StatusMessage(int level, const TString& msg)
00116 {
00117 dabc::LockGuard lock(fHierarchy.GetHMutex());
00118
00119 dabc::Hierarchy item = fHierarchy.GetHChild("Status/Message");
00120 item.SetField("value", msg.Data());
00121 item.SetFieldModified("value");
00122 item.SetField("level", level);
00123
00124 fHierarchy.GetHChild("Status").MarkChangedItems();
00125 }
00126
00127 void TGo4DabcPlayer::SetTitle(const char* title)
00128 {
00129 dabc::LockGuard lock(fHierarchy.GetHMutex());
00130
00131 fHierarchy.GetHChild("Status/DebugOutput").SetField("value", title ? title : "");
00132
00133 fHierarchy.GetHChild("Status").MarkChangedItems();
00134 }
00135
00136
00137 int TGo4DabcPlayer::ProcessGetBinary(TRootSniffer* sniff, dabc::Command cmd)
00138 {
00139 TGo4Analysis* an = TGo4Analysis::Instance();
00140 TGo4AnalysisClient* cli = an ? an->GetAnalysisClient() : 0;
00141
00142
00143 if (cli!=0) {
00144 TGo4LockGuard mainlock;
00145 return root::Monitor::ProcessGetBinary(sniff, cmd);
00146 } else {
00147 return root::Monitor::ProcessGetBinary(sniff, cmd);
00148 }
00149 }
00150
00151 bool TGo4DabcPlayer::ProcessHCommand(const std::string& cmdname, dabc::Command)
00152 {
00153 TGo4Analysis* an = TGo4Analysis::Instance();
00154
00155 if (cmdname == "Status/CmdClear") {
00156 if (an) {
00157 an->ClearObjects("Histograms");
00158 StatusMessage(0, "Clear Histograms folder");
00159 std::cout << "web: Clear Histograms folder" << std::endl;
00160 }
00161 return true;
00162 }
00163 if (cmdname == "Status/CmdStart") {
00164 if (an) {
00165 an->StartAnalysis();
00166 StatusMessage(0, "Resume analysis loop");
00167 std::cout << "web: Resume analysis loop" << std::endl;
00168 }
00169 return true;
00170 }
00171 if (cmdname == "Status/CmdStop") {
00172 if (an) {
00173 an->StopAnalysis();
00174 StatusMessage(0, "Suspend analysis loop");
00175 std::cout << "web: Suspend analysis loop" << std::endl;
00176 }
00177 return true;
00178 }
00179 return false;
00180 }
00181