CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/CalibTracker/SiStripDCS/interface/SiStripDetVOffBuilder.h

Go to the documentation of this file.
00001 #ifndef SISTRIPDETVOFF_SRC_BUILDER_H
00002 #define SISTRIPDETVOFF_SRC_BUILDER_H
00003 #define USING_NEW_CORAL
00004 
00005 
00006 #include "FWCore/ServiceRegistry/interface/Service.h"
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 
00012 #include "CondFormats/SiStripObjects/interface/SiStripDetVOff.h"
00013 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
00014 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00015 
00016 #include "CalibTracker/SiStripDCS/interface/SiStripCoralIface.h"
00017 #include "CalibTracker/SiStripDCS/interface/SiStripPsuDetIdMap.h"
00018 // #include "CalibTracker/SiStripDCS/interface/SiStripPsuDetIdMapFromFile.h"
00019 
00020 #include "CoralBase/TimeStamp.h"
00021 #include "CondFormats/Common/interface/Time.h"
00022 #include "CondFormats/Common/interface/TimeConversions.h"
00023 //#include "DataFormats/Provenance/interface/Timestamp.h"
00024 
00025 
00026 #include <fstream>
00027 #include <iostream>
00028 #include <memory>
00029 
00036 class SiStripDetVOffBuilder
00037 {
00038  public:
00040   ~SiStripDetVOffBuilder();
00042   SiStripDetVOffBuilder(const edm::ParameterSet&,const edm::ActivityRegistry&);
00044   void BuildDetVOffObj();
00046   std::vector< std::pair<SiStripDetVOff*,cond::Time_t> > getModulesVOff(const int deltaTmin = 1, const int maxIOVlength = 120) {
00047     reduction(deltaTmin, maxIOVlength);
00048     return modulesOff;
00049   }
00051   std::vector< std::vector<uint32_t> > getPayloadStats() {return payloadStats;}
00054   void setLastSiStripDetVOff( SiStripDetVOff * lastPayload, cond::Time_t lastTimeStamp );
00055 
00057   void reduce( std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator & it,
00058                std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator & initialIt,
00059                std::vector< std::pair<SiStripDetVOff*,cond::Time_t> > & resultVec,
00060                const bool last = false);
00061 
00062   void reduction(const uint32_t deltaTmin, const uint32_t maxIOVlength);
00063 
00065   void discardIOVs( std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator & it,
00066                     std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator & initialIt,
00067                     std::vector< std::pair<SiStripDetVOff*,cond::Time_t> > & resultVec,
00068                     const bool last, const unsigned int first );
00069   bool FileExists(std::string filename);
00070  private:
00071   // typedefs
00072   typedef std::vector< std::pair< std::vector<uint32_t>,coral::TimeStamp> > DetIdTimeStampVector;
00073   
00074 
00075   bool whichQuery;
00076 
00077 
00078   void printPar(std::stringstream& ss, const std::vector<int>& par);
00079 
00080   std::string timeToStream(const coral::TimeStamp & coralTime, const string & comment = "");
00081   std::string timeToStream(const cond::Time_t & condTime, const string & comment = "");
00082 
00084   int findSetting(uint32_t id, 
00085                   coral::TimeStamp changeDate, 
00086                   std::vector<uint32_t> settingID, 
00087                   std::vector<coral::TimeStamp> settingDate);
00088 
00090   int findSetting(std::string dpname, 
00091                   coral::TimeStamp changeDate, 
00092                   std::vector<std::string> settingDpname, 
00093                   std::vector<coral::TimeStamp> settingDate);
00094 
00096   void readLastValueFromFile(std::vector<uint32_t> &dpIDs,
00097                              std::vector<float> &vmonValues, 
00098                              std::vector<coral::TimeStamp> &dateChange);
00099 
00101   cond::Time_t getCondTime(coral::TimeStamp coralTime);
00102 
00104   coral::TimeStamp getCoralTime(cond::Time_t iovTime);
00105 
00107   void removeDuplicates( std::vector<uint32_t> & vec );
00109   cond::Time_t findMostRecentTimeStamp( std::vector<coral::TimeStamp> coralDate );
00110   
00111   // member data
00112   std::vector< std::vector<uint32_t> > payloadStats;
00113   std::vector< std::pair<SiStripDetVOff*,cond::Time_t> > modulesOff;
00114   std::pair<SiStripDetVOff *, cond::Time_t> lastStoredCondObj;
00115   
00116   // configurable parameters
00117   std::string onlineDbConnectionString;
00118   std::string authenticationPath;
00119   std::string whichTable;
00120   std::string lastValueFileName;
00121   bool fromFile;
00122   std::string psuDetIdMapFile_;
00123   bool debug_;
00124   coral::TimeStamp tmax, tmin, tsetmin;
00125   std::vector<int> tDefault, tmax_par, tmin_par, tset_par;
00126 
00127   std::string detIdListFile_;
00128   std::string excludedDetIdListFile_;
00129   // Threshold to consider a high voltage channel on
00130   double highVoltageOnThreshold_;
00131 
00132   // Structure used to store variables needed when building the database objects
00133   struct TimesAndValues
00134   {
00135     TimesAndValues() :
00136       latestTime(0)
00137     {}
00138     std::vector<coral::TimeStamp> changeDate;    // used by both
00139     std::vector<std::string>      dpname;        // only used by DB access, not file access
00140     std::vector<float>            actualValue;   // only used by DB access, not file access
00141     std::vector<uint32_t>         dpid;          // only used by file access
00142     std::vector<int>              actualStatus;  // filled using actualValue info
00143     cond::Time_t                  latestTime;    // used for timestamp when using lastValue from file
00144   };
00145   
00146   struct DetIdListTimeAndStatus
00147   {
00148     DetIdListTimeAndStatus() :
00149       notMatched(0)
00150     {}
00151     DetIdTimeStampVector detidV;
00152     std::vector<bool> StatusGood;
00153     unsigned int notMatched;
00154     std::vector<std::string> psuName;
00155     std::vector<unsigned int> isHV;
00156   };
00157 
00158   void statusChange( cond::Time_t & lastTime, TimesAndValues & tStruct );
00159   void lastValue( TimesAndValues & tStruct );
00160   void lastValueFromFile( TimesAndValues & tStruct );
00161 
00162   void buildPSUdetIdMap(TimesAndValues & tStruct, DetIdListTimeAndStatus & dStruct);
00163 
00164   void setPayloadStats(const uint32_t afterV, const uint32_t numAdded, const uint32_t numRemoved);
00165   std::pair<int, int> extractDetIdVector(const unsigned int i, SiStripDetVOff * modV, DetIdListTimeAndStatus & detIdStruct);
00166 
00167   std::auto_ptr<SiStripCoralIface> coralInterface;
00168 
00169 };
00170 #endif