Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CDFMonitoringModule.cxx

Go to the documentation of this file.
00001 #include "CDFMonitoringModule.h"
00002 
00003 #include <CDFMonitoringFwk/TConsumerInfo.h>
00004 #include <CDFMonitoringFwk/ConsumerExport.h>
00005 
00006 #include <MessageService/MsgService.h>
00007 #include <JobControl/JobCModuleRegistry.h>
00008 #include <JobControl/JobCResult.h>
00009 
00010 #include <HistMan/HistMan.h>
00011 
00012 #include <TROOT.h>
00013 #include <TFolder.h>
00014 
00015 // for spew()
00016 #include <DataUtil/GetRecords.h>
00017 #include <RawData/RawRecord.h>
00018 #include <string>
00019 #include <vector>
00020 
00021 #include <TStyle.h>
00022 
00023 using namespace std;
00024 
00025 CVSID("$Id: CDFMonitoringModule.cxx,v 1.8 2007/01/29 23:00:37 gmieg Exp $");
00026 JOBMODULE(CDFMonitoringModule,"CDFMonitoring","Talk to the CDFMonitoringFwk");
00027 
00028 
00029 const int CDFMonitoringModule::default_port = 9050;
00030 const char* CDFMonitoringModule::default_folder = "Monitoring";
00031 const int CDFMonitoringModule::default_refresh = 1;
00032 
00033 class CDFMonitoringModuleImp {
00034     ConsumerExport fConsExp;
00035     TConsumerInfo fConsInfo;
00036     const char* fPath;
00037     int fCount, fRefreshPeriod;
00038 
00039     map<string,TObject*> fObjectMap;
00040 
00041 
00042 public:
00043     CDFMonitoringModuleImp(int port, const char* name, int refresh);
00044     ~CDFMonitoringModuleImp();
00045 
00046     // Push objects to the ConsumerExport if refresh period has
00047     // passed.
00048     void Update();      
00049 
00050     // Add the given object to be monitored at the given path.
00051     // TFolders will be recursively traversed and will have all
00052     // objects added.
00053     void AddObject(TObject* o, string path=""); 
00054 };
00055 
00056 CDFMonitoringModuleImp::CDFMonitoringModuleImp(int port, const char* name,
00057                                                int refresh)
00058     : fConsExp(port)
00059     , fConsInfo(name,0)
00060     , fPath(name)
00061     , fCount(0)
00062     , fRefreshPeriod(refresh)
00063 {
00064 }
00065 CDFMonitoringModuleImp::~CDFMonitoringModuleImp()
00066 {
00067 }
00068 
00069 void CDFMonitoringModuleImp::AddObject(TObject* o, string path)
00070 {
00071     TFolder* f = dynamic_cast<TFolder*>(o);
00072 
00073     if (f) {                    // it's a folder
00074 
00075         if (string("private") == f->GetName()) {
00076             MSG("BD",Msg::kVerbose) << "skipping private folder\n";
00077             return;
00078         }
00079 
00080         TCollection* sf = f->GetListOfFolders();
00081         if (!sf) return;                // empty
00082 
00083         if (path != "") path += "/";
00084         path += f->GetName();
00085 
00086         MSG("BD",Msg::kVerbose)
00087             << "iterating on folder \"" << f->GetName() << "\"\n";
00088 
00089         TIter it(sf->MakeIterator());
00090         TObject* obj=0;
00091         while ( (obj=it()) ) this->AddObject(obj,path);
00092         return;
00093     }
00094 
00095     // not a folder
00096 
00097     string objpath = path;
00098     if (objpath != "") objpath += "/";
00099     objpath += o->GetName();
00100     TObject* other = fObjectMap[objpath];
00101 
00102     if (! other) {              // haven't seen it yet
00103         fObjectMap[objpath] = o;
00104         fConsInfo.addObject(o->GetName(), path.c_str(), 0, o);
00105         MSG("BD",Msg::kDebug)
00106             << "adding object \"" << o->GetName() << "\" of type \"" <<
00107             o->Class_Name() << "\" to \""
00108             << path << "\" and saving  at \"" << objpath << "\"\n";
00109         return;
00110     }
00111     if (other != o) {   // exists but differs
00112         MSG("BD",Msg::kWarning)
00113             << "pre-existing object at " << objpath << endl;
00114         return;
00115     }
00116     return;                     // already added and is same
00117 }
00118 
00119 void CDFMonitoringModuleImp::Update()
00120 {
00121     if (fCount < fRefreshPeriod && fCount % fRefreshPeriod) return;
00122     MSG("BD",Msg::kVerbose)
00123         << "refreshing at " << fCount << " with period " << fRefreshPeriod << endl;
00124 
00125     HistMan hm(fPath);
00126 
00127     TFolder& f = hm.BaseFolder();
00128     TFolder* folder = dynamic_cast<TFolder*>(f.FindObject(fPath));
00129     if (!folder) {
00130         MSG("BD",Msg::kWarning)
00131             << "Failed to find folder " << fPath << endl;
00132     }
00133 
00134     this->AddObject(folder);
00135 
00136     fConsExp.send(&fConsInfo);
00137 }
00138 
00139 
00140 
00141 //-------------------------//
00142 
00143 
00144 
00145 CDFMonitoringModule::CDFMonitoringModule()
00146     : fImp(0)
00147 {
00148     fImp = new CDFMonitoringModuleImp(9050,"Monitoring",1);
00149 }
00150 CDFMonitoringModule::~CDFMonitoringModule()
00151 {
00152     if (fImp) delete fImp; fImp=0;
00153 }
00154 
00155 void CDFMonitoringModule::BeginJob()
00156 {
00157     return;
00158 
00159     int port = default_port, refresh = default_refresh;
00160     const char* folder = default_folder;
00161 
00162     Registry& cfg = this->GetConfig();
00163     cfg.Get("port",port);
00164     cfg.Get("refresh",refresh);
00165     cfg.Get("folder",folder);
00166 
00167     if (fImp) delete fImp;
00168     fImp = new CDFMonitoringModuleImp(port,folder,refresh);
00169     MSG("BD",Msg::kDebug) << "Created connection to port " << port
00170                           << " using path \"" << folder << "\"\n";
00171 
00172 }
00173 void CDFMonitoringModule::EndJob()
00174 {
00175     MSG("BD",Msg::kDebug)
00176         << "EndJob" << endl;
00177     if (fImp) delete fImp; fImp = 0;
00178 }
00179 
00180 void CDFMonitoringModule::BeginFile()
00181 {
00182     MSG("BD",Msg::kInfo)
00183         << "Begin file" << endl;
00184 }
00185 
00186 void CDFMonitoringModule::EndFile()
00187 {
00188     MSG("BD",Msg::kInfo)
00189         << "End file" << endl;
00190 }
00191 #if 0
00192 static void spew(const MomNavigator* mom)
00193 {
00194     vector<const RawRecord*> rrv = DataUtil::GetRecords<const RawRecord>(mom);
00195     for (size_t ind=0; ind<rrv.size(); ++ind) {
00196         const RawRecord* rr = rrv[ind];
00197         string stream_name = rr->GetTempTags().GetCharString("stream");
00198         cerr << rr->GetTempTags() << endl;
00199     }
00200 }
00201 #endif
00202 JobCResult CDFMonitoringModule::Ana(const MomNavigator */*mom*/)
00203 {
00204   gStyle->SetAxisColor(1, "xyz");
00205 gStyle->SetCanvasColor(0);
00206 gStyle->SetFrameFillColor(0);
00207 gStyle->SetFrameLineColor(1);
00208 gStyle->SetHistFillColor(0);
00209 gStyle->SetHistLineColor(1);
00210 gStyle->SetPadColor(1);
00211 gStyle->SetStatColor(0);
00212 gStyle->SetStatTextColor(1);
00213 gStyle->SetTitleColor(1);
00214 gStyle->SetTitleTextColor(1);
00215 gStyle->SetLabelColor(1,"xyz");
00216  gStyle->SetTitleOffset(1.2,"y"); 
00217 gStyle->SetOptStat(1110);
00218 gROOT->ForceStyle();
00219 
00220 
00221     if (!fImp) {
00222         MSG("BD",Msg::kError)
00223             << "No implementation! Ana() called w/out a BeginJob()\n";
00224         return JobCResult::kError;
00225     }
00226     fImp->Update();
00227     //spew(mom);
00228     return JobCResult::kAOK;
00229 }
00230 const Registry& CDFMonitoringModule::DefaultConfig() const
00231 {
00232     static Registry cfg;
00233     if (cfg.Size() == 0) {
00234         cfg.Set("port",default_port);
00235         cfg.Set("refresh",default_refresh);
00236         cfg.Set("folder",default_folder);
00237     }
00238     return cfg;
00239 }

Generated on Mon Feb 15 11:06:30 2010 for loon by  doxygen 1.3.9.1