CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DQMServices/XdaqCollector/src/XmasToDQMEventInfo.cc

Go to the documentation of this file.
00001 /*
00002  * \file DQMEventInfo.cc
00003  * \author M. Zanetti - CERN PH
00004  * Last Update:
00005  * $Date: 2010/07/20 02:58:28 $
00006  * $Revision: 1.4 $
00007  * $Author: wmtan $
00008  *
00009  */
00010 
00011 #include "DQMServices/XdaqCollector/interface/XmasToDQMEventInfo.h"
00012 #include <TSystem.h>
00013 
00014 // Framework
00015 
00016 #include "FWCore/Version/interface/GetReleaseVersion.h"
00017 
00018 #include <stdio.h>
00019 #include <sstream>
00020 #include <math.h>
00021 
00022 using namespace edm;
00023 using namespace std;
00024 
00025 XmasToDQMEventInfo::XmasToDQMEventInfo(const ParameterSet& ps){
00026 
00027  cout << "Constructor of XmasToDQMEventInfo called...." << endl;
00028   
00029   parameters_ = ps;
00030   pEvent_ = 0;
00031   evtRateCount_ = 0;
00032   gettimeofday(&currentTime_,NULL);
00033   lastAvgTime_ = currentTime_;
00034   
00035   dbe_ = edm::Service<DQMStore>().operator->();
00036 
00037   string eventinfofolder = parameters_.getUntrackedParameter<string>("eventInfoFolder", "EventInfo") ;
00038   string subsystemname = parameters_.getUntrackedParameter<string>("subSystemFolder", "YourSubsystem") ;
00039   string currentfolder = subsystemname + "/" +  eventinfofolder ;
00040   cout << "currentfolder " << currentfolder << endl;
00041 
00042   evtRateWindow_ = parameters_.getUntrackedParameter<double>("eventRateWindow", 0.5);
00043   if(evtRateWindow_<=0.15) evtRateWindow_=0.15;
00044   cout << "Event Rate averaged over " << evtRateWindow_ << " minutes" << endl;
00045 
00046   dbe_->setCurrentFolder(currentfolder) ;
00047 
00048   //Event specific contents
00049   runId_     = dbe_->bookInt("iRun");
00050   lumisecId_ = dbe_->bookInt("iLumiSection");
00051   eventId_   = dbe_->bookInt("iEvent");
00052   eventTimeStamp_ = dbe_->bookFloat("eventTimeStamp");
00053   
00054   dbe_->setCurrentFolder(currentfolder) ;
00055   //Process specific contents
00056   processTimeStamp_ = dbe_->bookFloat("processTimeStamp");
00057   processTimeStamp_->Fill(getUTCtime(&currentTime_));
00058   processLatency_ = dbe_->bookFloat("processLatency");
00059   processTimeStamp_->Fill(-1);
00060   processEvents_ = dbe_->bookInt("processedEvents");
00061   processEvents_->Fill(pEvent_);
00062   processEventRate_ = dbe_->bookFloat("processEventRate");
00063   processEventRate_->Fill(-1); 
00064   nUpdates_= dbe_->bookInt("processUpdates");
00065   nUpdates_->Fill(-1);
00066 
00067   //Static Contents
00068   processId_= dbe_->bookInt("processID"); 
00069   processId_->Fill(gSystem->GetPid());
00070   processStartTimeStamp_ = dbe_->bookFloat("processStartTimeStamp");
00071   processStartTimeStamp_->Fill(getUTCtime(&currentTime_));
00072   runStartTimeStamp_ = dbe_->bookFloat("runStartTimeStamp");
00073   hostName_= dbe_->bookString("hostName",gSystem->HostName());
00074   processName_= dbe_->bookString("processName",subsystemname);
00075   workingDir_= dbe_->bookString("workingDir",gSystem->pwd());
00076   cmsswVer_= dbe_->bookString("CMSSW_Version",edm::getReleaseVersion());
00077 //  dqmPatch_= dbe_->bookString("DQM_Patch",dbe_->getDQMPatchVersion());
00078  
00079   // Folder to be populated by sub-systems' code
00080   string subfolder = currentfolder + "/reportSummaryContents" ;
00081   dbe_->setCurrentFolder(subfolder);
00082 
00083 }
00084 
00085 XmasToDQMEventInfo::~XmasToDQMEventInfo(){
00086 
00087   cout<<"[XmasToDQMEventInfo]: destructor"<<endl;
00088 
00089 }
00090 
00091 void XmasToDQMEventInfo::beginRun(const edm::Run& r, const edm::EventSetup &c ) {
00092   
00093   const edm::Timestamp time = r.beginTime();
00094 
00095   float sec = time.value() >> 32; 
00096   float usec = 0xFFFFFFFF & time.value() ; 
00097 
00098   // cout << " begin Run " << r.run() << " " << time.value() << endl;
00099   // cout << setprecision(16) << getUTCtime(&currentTime_) << endl;
00100   // cout << sec+usec/1000000. << endl;
00101 
00102   runStartTimeStamp_->Fill(sec+usec/1000000.);
00103   
00104 } 
00105 
00106 void XmasToDQMEventInfo::analyze(const Event& e, const EventSetup& c){
00107  
00108   static int icalls = 1;
00109   cout << "XmasToDQMEventInfo::analyze call = " << icalls << std::endl;
00110   
00111   //runId_->Fill(e.id().run());
00112   std::string runNumber;
00113   
00114   //xmas2dqm::wse::ToDqm::instance()->BSem_.take();
00115   runNumber = xmas2dqm::wse::ToDqm::instance()->runNumber_.toString();
00116   std::cout << "EventInfo runNumber ... = " << runNumber << std::endl;
00117   //xmas2dqm::wse::ToDqm::instance()->BSem_.give();
00118   
00119   std::istringstream istrfloat(runNumber);
00120   float runNumber_value;
00121   istrfloat >> runNumber_value;
00122   runId_->Fill(runNumber_value);
00123   
00124   lumisecId_->Fill(e.luminosityBlock());
00125   eventId_->Fill(e.id().event());
00126   eventTimeStamp_->Fill(e.time().value()/(double)0xffffffff);
00127 
00128   pEvent_++;
00129   evtRateCount_++;
00130   processEvents_->Fill(pEvent_);
00131 
00132   lastUpdateTime_=currentTime_;
00133   gettimeofday(&currentTime_,NULL);  
00134   processTimeStamp_->Fill(getUTCtime(&currentTime_));
00135   processLatency_->Fill(getUTCtime(&lastUpdateTime_,&currentTime_));
00136 
00137   float time = getUTCtime(&lastAvgTime_,&currentTime_);
00138   if(time>=(evtRateWindow_*60.0)){
00139     processEventRate_->Fill((float)evtRateCount_/time);
00140     evtRateCount_ = 0;
00141     lastAvgTime_ = currentTime_;    
00142   }
00143 
00144   icalls++;
00145   return;
00146 }
00147 
00148 double XmasToDQMEventInfo::getUTCtime(timeval* a, timeval* b){
00149   double deltaT=(*a).tv_sec*1000.0+(*a).tv_usec/1000.0;
00150   if(b!=NULL) deltaT=(*b).tv_sec*1000.0+(*b).tv_usec/1000.0 - deltaT;
00151   return deltaT/1000.0;
00152 }