CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DataFormats/Scalers/src/Level1TriggerRates.cc

Go to the documentation of this file.
00001 /*
00002  *   File: DataFormats/Scalers/src/Level1TriggerRates.cc   (W.Badgett)
00003  */
00004 
00005 #include "DataFormats/Scalers/interface/Level1TriggerRates.h"
00006 #include "DataFormats/Scalers/interface/Level1TriggerScalers.h"
00007 
00008 #include <iostream>
00009 #include <cstdio>
00010 
00011 Level1TriggerRates::Level1TriggerRates():
00012   version_(0),
00013   collectionTime_(0,0),
00014   deltaNS_(0),
00015   deltaT_(0.0),
00016   gtTriggersRate_(0.0),
00017   gtEventsRate_(0.0),
00018   collectionTimeLumiSeg_(0,0),
00019   triggersPhysicsGeneratedFDLRate_(0.0),
00020   triggersPhysicsLostRate_(0.0),
00021   triggersPhysicsLostBeamActiveRate_(0.0),
00022   triggersPhysicsLostBeamInactiveRate_(0.0),
00023   l1AsPhysicsRate_(0.0),
00024   l1AsRandomRate_(0.0),
00025   l1AsTestRate_(0.0),
00026   l1AsCalibrationRate_(0.0),
00027   deadtimePercent_(0.0),
00028   deadtimeBeamActivePercent_(0.0),
00029   deadtimeBeamActiveTriggerRulesPercent_(0.0),
00030   deadtimeBeamActiveCalibrationPercent_(0.0),
00031   deadtimeBeamActivePrivateOrbitPercent_(0.0),
00032   deadtimeBeamActivePartitionControllerPercent_(0.0),
00033   deadtimeBeamActiveTimeSlotPercent_(0.0),
00034   gtAlgoCountsRate_(Level1TriggerScalers::nLevel1Triggers),
00035   gtTechCountsRate_(Level1TriggerScalers::nLevel1TestTriggers)
00036 { 
00037 }
00038 
00039 Level1TriggerRates::Level1TriggerRates(Level1TriggerScalers const& s)
00040 {
00041   Level1TriggerRates(s,Level1TriggerScalers::firstShortLSRun);
00042 }
00043 
00044 Level1TriggerRates::Level1TriggerRates(Level1TriggerScalers const& s,
00045                                        int runNumber)
00046 { 
00047   Level1TriggerRates();
00048   computeRates(s,runNumber);
00049 }
00050 
00051 Level1TriggerRates::Level1TriggerRates(Level1TriggerScalers const& s1,
00052                                        Level1TriggerScalers const& s2)
00053 {
00054   Level1TriggerRates(s1,s2,Level1TriggerScalers::firstShortLSRun);
00055 }
00056 
00057 Level1TriggerRates::Level1TriggerRates(Level1TriggerScalers const& s1,
00058                                        Level1TriggerScalers const& s2,
00059                                        int runNumber)
00060 {  
00061   Level1TriggerRates();
00062   computeRates(s1,s2,runNumber);
00063 }
00064 
00065 Level1TriggerRates::~Level1TriggerRates() { } 
00066 
00067 
00068 void Level1TriggerRates::computeRates(Level1TriggerScalers const& t)
00069 { computeRates(t,Level1TriggerScalers::firstShortLSRun);}
00070 
00071 void Level1TriggerRates::computeRates(Level1TriggerScalers const& t,
00072                                       int run)
00073 {
00074   version_ = t.version();
00075 
00076   collectionTime_.set_tv_sec(static_cast<long>(t.collectionTime().tv_sec));
00077   collectionTime_.set_tv_nsec(t.collectionTime().tv_nsec);
00078 
00079   gtTriggersRate_ = t.gtTriggersRate();
00080   gtEventsRate_   = t.gtEventsRate();
00081 
00082   collectionTimeLumiSeg_.set_tv_sec(static_cast<long>(t.collectionTimeLumiSeg().tv_sec));
00083   collectionTimeLumiSeg_.set_tv_nsec(t.collectionTimeLumiSeg().tv_nsec);
00084 
00085   triggersPhysicsGeneratedFDLRate_ 
00086     = Level1TriggerScalers::rateLS(t.triggersPhysicsGeneratedFDL(),run);
00087   triggersPhysicsLostRate_ 
00088     = Level1TriggerScalers::rateLS(t.triggersPhysicsLost(),run);
00089   triggersPhysicsLostBeamActiveRate_ 
00090     = Level1TriggerScalers::rateLS(t.triggersPhysicsLostBeamActive(),run);
00091   triggersPhysicsLostBeamInactiveRate_ 
00092     = Level1TriggerScalers::rateLS(t.triggersPhysicsLostBeamInactive(),run);
00093 
00094   l1AsPhysicsRate_ = Level1TriggerScalers::rateLS(t.l1AsPhysics(),run);
00095   l1AsRandomRate_ = Level1TriggerScalers::rateLS(t.l1AsRandom(),run);
00096   l1AsTestRate_ = Level1TriggerScalers::rateLS(t.l1AsTest(),run);
00097   l1AsCalibrationRate_ = Level1TriggerScalers::rateLS(t.l1AsCalibration(),run);
00098 
00099   deadtimePercent_ = Level1TriggerScalers::percentLS(t.deadtime(),run);
00100   deadtimeBeamActivePercent_ =
00101     Level1TriggerScalers::percentLSActive(t.deadtimeBeamActive(),run);
00102   deadtimeBeamActiveTriggerRulesPercent_ =
00103     Level1TriggerScalers::percentLSActive(t.deadtimeBeamActiveTriggerRules(),run);
00104   deadtimeBeamActiveCalibrationPercent_ =
00105     Level1TriggerScalers::percentLSActive(t.deadtimeBeamActiveCalibration(),run);
00106   deadtimeBeamActivePrivateOrbitPercent_ =
00107     Level1TriggerScalers::percentLSActive(t.deadtimeBeamActivePrivateOrbit(),run);
00108   deadtimeBeamActivePartitionControllerPercent_ =
00109     Level1TriggerScalers::percentLSActive(t.deadtimeBeamActivePartitionController(),run);
00110   deadtimeBeamActiveTimeSlotPercent_ =
00111     Level1TriggerScalers::percentLSActive(t.deadtimeBeamActiveTimeSlot(),run);
00112 
00113   const std::vector<unsigned int> gtAlgoCounts = t.gtAlgoCounts();
00114   for ( std::vector<unsigned int>::const_iterator counts = gtAlgoCounts.begin();
00115         counts != gtAlgoCounts.end(); ++counts)
00116   {
00117     gtAlgoCountsRate_.push_back(Level1TriggerScalers::rateLS(*counts,run));
00118   }
00119 
00120   const std::vector<unsigned int> gtTechCounts = t.gtTechCounts();
00121   for ( std::vector<unsigned int>::const_iterator counts = gtTechCounts.begin();
00122         counts != gtTechCounts.end(); ++counts)
00123   {
00124     gtTechCountsRate_.push_back(Level1TriggerScalers::rateLS(*counts,run));
00125   }
00126 
00127   deltaNS_ = 0ULL;
00128   deltaT_ = 0.0;
00129 }
00130 
00131 void Level1TriggerRates::computeRates(Level1TriggerScalers const& t1,
00132                                       Level1TriggerScalers const& t2)
00133 {
00134   computeRates(t1,t2,Level1TriggerScalers::firstShortLSRun);
00135 }
00136 
00137 void Level1TriggerRates::computeRates(Level1TriggerScalers const& t1,
00138                                       Level1TriggerScalers const& t2,
00139                                       int run)
00140 {
00141   computeRates(t1,run);
00142 
00143   unsigned long long zeit1 = 
00144     ( (unsigned long long)t1.collectionTime().tv_sec * 1000000000ULL)| 
00145     ( (unsigned long long)t1.collectionTime().tv_nsec );
00146   unsigned long long zeit2 = 
00147     ( (unsigned long long)t2.collectionTime().tv_sec * 1000000000ULL)| 
00148     ( (unsigned long long)t2.collectionTime().tv_nsec );
00149 
00150   deltaT_  = 0.0;
00151   deltaNS_ = 0ULL;
00152   if ( zeit2 > zeit1 ) 
00153   {
00154     deltaNS_ = zeit2 - zeit1;
00155     deltaT_  = ((double)deltaNS_) / 1.0E9;
00156     gtTriggersRate_ = 
00157       ((double)(t2.gtTriggers()-t1.gtTriggers()))/deltaT_;
00158     gtEventsRate_   = 
00159       ((double)(t2.gtEvents()-t1.gtEvents()))/deltaT_;
00160   }
00161 }
00162 
00163 
00165 std::ostream& operator<<(std::ostream& s, const Level1TriggerRates& c) 
00166 {
00167   char line[128];
00168   char zeitHeaven[128];
00169   struct tm * horaHeaven;
00170 
00171   s << "Level1TriggerRates Version: " << c.version() 
00172     << " Rates in Hz, DeltaT: ";
00173 
00174   if ( c.deltaNS() > 0 )
00175   {
00176     s << c.deltaT() << " sec" << std::endl;
00177   }
00178   else
00179   {
00180     s << "n/a" << std::endl;
00181   }
00182 
00183   struct timespec secondsToHeaven = c.collectionTime();
00184   horaHeaven = gmtime(&secondsToHeaven.tv_sec);
00185   strftime(zeitHeaven, sizeof(zeitHeaven), "%Y.%m.%d %H:%M:%S", horaHeaven);
00186   sprintf(line, " CollectionTime:        %s.%9.9d" , 
00187           zeitHeaven, (int)secondsToHeaven.tv_nsec);
00188   s << line << std::endl;
00189   
00190   sprintf(line, " GtTriggersRate:                              %22.3f Hz",
00191           c.gtTriggersRate());
00192   s << line << std::endl;
00193   
00194   sprintf(line, " GtEventsRate:                                %22.3f Hz",
00195           c.gtEventsRate());
00196   s << line << std::endl;
00197 
00198   secondsToHeaven = c.collectionTimeLumiSeg();
00199   horaHeaven = gmtime(&secondsToHeaven.tv_sec);
00200   strftime(zeitHeaven, sizeof(zeitHeaven), "%Y.%m.%d %H:%M:%S", horaHeaven);
00201   sprintf(line, " CollectionTimeLumiSeg: %s.%9.9d" , 
00202           zeitHeaven, (int)secondsToHeaven.tv_nsec);
00203   s << line << std::endl;
00204   
00205   sprintf(line, " TriggersPhysicsGeneratedFDLRate:             %22.3f Hz",
00206           c.triggersPhysicsGeneratedFDLRate());
00207   s << line << std::endl;
00208 
00209   sprintf(line, " TriggersPhysicsLostRate:                     %22.3f Hz",
00210           c.triggersPhysicsLostRate());
00211   s << line << std::endl;
00212 
00213   sprintf(line, " TriggersPhysicsLostBeamActiveRate:           %22.3f Hz",
00214           c.triggersPhysicsLostBeamActiveRate());
00215   s << line << std::endl;
00216 
00217   sprintf(line, " TriggersPhysicsLostBeamInactiveRate:         %22.3f Hz",
00218           c.triggersPhysicsLostBeamInactiveRate());
00219   s << line << std::endl;
00220 
00221   sprintf(line, " L1AsPhysicsRate:                             %22.3f Hz",
00222           c.l1AsPhysicsRate());
00223   s << line << std::endl;
00224 
00225   sprintf(line, " L1AsRandomRate:                              %22.3f Hz",
00226           c.l1AsRandomRate());
00227   s << line << std::endl;
00228 
00229   sprintf(line, " L1AsTestRate:                                %22.3f Hz",
00230           c.l1AsTestRate());
00231   s << line << std::endl;
00232 
00233   sprintf(line, " L1AsCalibrationRate:                         %22.3f Hz",
00234           c.l1AsCalibrationRate());
00235   s << line << std::endl;
00236 
00237   sprintf(line, " DeadtimePercent:                             %22.3f %%",
00238           c.deadtimePercent());
00239   s << line << std::endl;
00240 
00241   sprintf(line, " DeadtimeBeamActivePercent:                   %22.3f %%",
00242           c.deadtimeBeamActivePercent());
00243   s << line << std::endl;
00244 
00245   sprintf(line, " DeadtimeBeamActiveTriggerRulesPercent:       %22.3f %%",
00246           c.deadtimeBeamActiveTriggerRulesPercent());
00247   s << line << std::endl;
00248 
00249   sprintf(line, " DeadtimeBeamActiveCalibrationPercent:        %22.3f %%",
00250           c.deadtimeBeamActiveCalibrationPercent());
00251   s << line << std::endl;
00252 
00253   sprintf(line, " DeadtimeBeamActivePrivateOrbitPercent:       %22.3f %%",
00254           c.deadtimeBeamActivePrivateOrbitPercent());
00255   s << line << std::endl;
00256 
00257   sprintf(line, " DeadtimeBeamActivePartitionControllerPercent:%22.3f %%",
00258           c.deadtimeBeamActivePartitionControllerPercent());
00259   s << line << std::endl;
00260 
00261   sprintf(line, " DeadtimeBeamActiveTimeSlotPercent:           %22.3f %%",
00262           c.deadtimeBeamActiveTimeSlotPercent());
00263   s << line << std::endl;
00264 
00265   s << "Physics GtAlgoCountsRate, Hz" << std::endl;
00266   const std::vector<double> gtAlgoCountsRate = c.gtAlgoCountsRate();
00267   int length = gtAlgoCountsRate.size() / 4;
00268   for ( int i=0; i<length; i++)
00269   {
00270     sprintf(line,
00271             " %3.3d: %12.3f  %3.3d: %12.3f  %3.3d: %12.3f  %3.3d: %12.3f",
00272             i,              gtAlgoCountsRate[i], 
00273             (i+length),     gtAlgoCountsRate[i+length], 
00274             (i+(length*2)), gtAlgoCountsRate[i+(length*2)], 
00275             (i+(length*3)), gtAlgoCountsRate[i+(length*3)]);
00276     s << line << std::endl;
00277   }
00278 
00279   s << "Test GtTechCountsRate, Hz" << std::endl;
00280   const std::vector<double> gtTechCountsRate = c.gtTechCountsRate();
00281   length = gtTechCountsRate.size() / 4;
00282   for ( int i=0; i<length; i++)
00283   {
00284     sprintf(line,
00285             " %3.3d: %12.3f  %3.3d: %12.3f  %3.3d: %12.3f  %3.3d: %12.3f",
00286             i,              gtTechCountsRate[i], 
00287             (i+length),     gtTechCountsRate[i+length], 
00288             (i+(length*2)), gtTechCountsRate[i+(length*2)], 
00289             (i+(length*3)), gtTechCountsRate[i+(length*3)]);
00290     s << line << std::endl;
00291   }
00292   return s;
00293 }