CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FastMonitoringService.h
Go to the documentation of this file.
1 #ifndef EvFFastMonitoringService_H
2 #define EvFFastMonitoringService_H 1
3 
4 
12 
13 #include "boost/filesystem.hpp"
14 
16 #include "FastMonitoringThread.h"
17 
18 #include <string>
19 #include <vector>
20 
21 #include <sstream>
22 #include <unordered_map>
23 
24 /*Description
25  this is an evolution of the MicroStateService intended to be run standalone in cmsRun or similar
26  As such, it has to independently create a monitoring thread and run it in each forked process, which needs
27  to be arranged following the standard CMSSW procedure.
28  We try to use boost threads for uniformity with the rest of the framework, even if they suck a bit.
29  A legenda for use by the monitoring process in the DAQ needs to be generated as soon as convenient - since
30  no access to the EventProcessor is granted, this needs to wait until after beginJob is executed.
31  At the same time, we try to spare time in the monitoring by avoiding even a single string lookup and using the
32  moduledesc pointer to key into the map instead.
33  As a bonus, we can now add to the monitored status the current path (and possibly associate modules to a path...)
34  this intermediate info will be called "ministate" :D
35  The general counters and status variables (event number, number of processed events, number of passed and stored
36  events, luminosity section etc. are also monitored here.
37 
38  NOTA BENE!!! with respect to the MicroStateService, no string or string pointers are used for the microstates.
39  NOTA BENE!!! the state of the edm::EventProcessor cannot be monitored directly from within a service, so a
40  different solution must be identified for that (especially one needs to identify error states).
41  NOTA BENE!!! to keep backward compatibility with the MicroStateService, a common base class with abstract interface,
42  exposing the single method to be used by all other packages (except EventFilter/Processor,
43  which should continue to use the concrete class interface) will be defined
44 
45 */
46 
47 namespace evf{
48 
50  {
51  struct Encoding
52  {
53  Encoding(unsigned int res): reserved_(res), current_(reserved_), currentReserved_(0)
54  {
56  // completeReservedWithDummies();
57  }
58  //trick: only encode state when sending it over (i.e. every sec)
59  int encode(const void *add){
60  std::map<const void *, int>::const_iterator it=quickReference_.find(add);
61  return (it!=quickReference_.end()) ? (*it).second : 0;
62  }
63  const void* decode(unsigned int index){return decoder_[index];}
64  void fillReserved(void* add, unsigned int i){
65  // translation_[*name]=current_;
67  if(decoder_.size()<=i)
68  decoder_.push_back(add);
69  else
71  }
72  void updateReserved(void* add){
75  }
77  {
78  for(unsigned int i = currentReserved_; i<reserved_; i++)
80  }
81  void update(void* add){
82  // translation_[*name]=current_;
84  decoder_.push_back(add);
85  current_++;
86  }
87  std::map<const void *,int> quickReference_;
88  std::vector<const void *> decoder_;
89  unsigned int reserved_;
90  int current_;
93  };
94  public:
95 
96 
97  // the names of the states - some of them are never reached in an online app
99  // Reserved names for microstates
100  // moved into base class in EventFilter/Utilities for compatibility with MicroStateServiceClassic
101  static const std::string nopath_;
104 
107  void preModuleBeginJob(const edm::ModuleDescription& desc);
108 
109  void prePathBeginRun(const std::string& pathName);
110  void postBeginRun(edm::Run const&, edm::EventSetup const&);
111 
112  void postBeginJob();
113  void postEndJob();
114 
115  void preBeginLumi(edm::LuminosityBlockID const& iID, edm::Timestamp const& iTime);
116  void preEndLumi(edm::LuminosityBlockID const& iID, edm::Timestamp const& iTime);
117  void preProcessPath(const std::string& pathName);
118  void preEventProcessing(const edm::EventID&, const edm::Timestamp&);
119  void postEventProcessing(const edm::Event&, const edm::EventSetup&);
120 
123 
124  void preModule(const edm::ModuleDescription&);
125  void postModule(const edm::ModuleDescription&);
126 
127  void jobFailure();
128 
129  void setMicroState(Microstate); // this is still needed for use in special functions like DQM which are in turn framework services. - the string pointer needs to be interpreted at each call.
130  void accummulateFileSize(unsigned long fileSize);
131  void startedLookingForFile();
132  void stoppedLookingForFile();
133  unsigned int getEventsProcessedForLumi(unsigned int lumi);
135  std::string getRunDirName() const { return runDirectory_.stem().string(); }
136 
137  private:
138  void dowork() { // the function to be called in the thread. Thread completes when function returns.
139  while (!fmt_.m_stoprequest) {
140  std::cout << "Current states: Ms=" << fmt_.m_data.macrostate_
141  << " ms=" << encPath_.encode(fmt_.m_data.ministate_)
142  << " us=" << encModule_.encode(fmt_.m_data.microstate_)
143  << std::endl;
144 
145  // lock the monitor
146  fmt_.monlock_.lock();
151 
152  fmt_.m_data.jsonMonitor_->snap(true, fastPath_);
153  fmt_.monlock_.unlock();
154 
155  //::sleep(1);
156  ::sleep(sleepTime_);
157  }
158  }
159 
160  //the actual monitoring thread is held by a separate class object for ease of maintenance
164 
166  string /*rootDirectory_,*/ microstateDefPath_, outputDefPath_;
170  std::vector<double> leadTimes_;
171  std::unordered_map<unsigned int, int> processedEventsPerLumi_;
173  };
174 
175 }
176 
177 #endif
int i
Definition: DBlmapReader.cc:9
void preBeginLumi(edm::LuminosityBlockID const &iID, edm::Timestamp const &iTime)
boost::filesystem::path runDirectory_
std::string getRunDirName() const
tuple lumi
Definition: fjr2json.py:35
void preEventProcessing(const edm::EventID &, const edm::Timestamp &)
std::string getOutputDefPath() const
std::map< const void *, int > quickReference_
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
std::unordered_map< unsigned int, int > processedEventsPerLumi_
void prePathBeginRun(const std::string &pathName)
unsigned int getEventsProcessedForLumi(unsigned int lumi)
void preEndLumi(edm::LuminosityBlockID const &iID, edm::Timestamp const &iTime)
boost::shared_ptr< FastMonitor > jsonMonitor_
static const std::string nopath_
void postBeginRun(edm::Run const &, edm::EventSetup const &)
std::vector< const void * > decoder_
static const std::string macroStateNames[FastMonitoringThread::MCOUNT]
void preProcessPath(const std::string &pathName)
void preModule(const edm::ModuleDescription &)
std::vector< double > leadTimes_
void postModule(const edm::ModuleDescription &)
void preModuleBeginJob(const edm::ModuleDescription &desc)
boost::filesystem::path workingDirectory_
tuple cout
Definition: gather_cfg.py:121
const void * decode(unsigned int index)
void postEventProcessing(const edm::Event &, const edm::EventSetup &)
void accummulateFileSize(unsigned long fileSize)
edm::ModuleDescription * dummiesForReserved_
FastMonitoringService(const edm::ParameterSet &, edm::ActivityRegistry &)
Definition: Run.h:41
void fillReserved(void *add, unsigned int i)