Skip to content

Commit

Permalink
New codes for Strip O2O.
Browse files Browse the repository at this point in the history
  • Loading branch information
hqucms committed Mar 24, 2016
1 parent 4dbb9bd commit 75f1609
Show file tree
Hide file tree
Showing 23 changed files with 31,534 additions and 632 deletions.
15,148 changes: 15,148 additions & 0 deletions CalibTracker/SiStripDCS/data/StripPSUDetIDMap_FromAug2013.dat

Large diffs are not rendered by default.

15,148 changes: 15,148 additions & 0 deletions CalibTracker/SiStripDCS/data/StripPSUDetIDMap_FromFeb2016.dat

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions CalibTracker/SiStripDCS/interface/SiStripDetVOffBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class SiStripDetVOffBuilder
/** Build the SiStripDetVOff object for transfer. */
void BuildDetVOffObj();
/** Return modules Off vector of objects. */
std::vector< std::pair<SiStripDetVOff*,cond::Time_t> > getModulesVOff(const int deltaTmin = 1, const int maxIOVlength = 120) {
reduction(deltaTmin, maxIOVlength);
std::vector< std::pair<SiStripDetVOff*,cond::Time_t> > getModulesVOff() {
reduction(deltaTmin_, maxIOVlength_);
return modulesOff;
}
/** Return statistics about payloads transferred for storage in logDB. */
Expand Down Expand Up @@ -128,6 +128,7 @@ class SiStripDetVOffBuilder
bool debug_;
coral::TimeStamp tmax, tmin, tsetmin;
std::vector<int> tDefault, tmax_par, tmin_par, tset_par;
uint32_t deltaTmin_, maxIOVlength_;

std::string detIdListFile_;
std::string excludedDetIdListFile_;
Expand Down
36 changes: 0 additions & 36 deletions CalibTracker/SiStripDCS/interface/SiStripDetVOffHandler.h

This file was deleted.

10 changes: 0 additions & 10 deletions CalibTracker/SiStripDCS/plugins/SealModules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
#include "FWCore/Framework/interface/MakerMacros.h"



#include "CondCore/PopCon/interface/PopConAnalyzer.h"

#include "FWCore/ServiceRegistry/interface/ServiceMaker.h"

//ReWritten DCS O2O
#include "CalibTracker/SiStripDCS/interface/SiStripDetVOffHandler.h"
typedef popcon::PopConAnalyzer<popcon::SiStripDetVOffHandler> SiStripPopConDetVOff;
DEFINE_FWK_MODULE(SiStripPopConDetVOff);

#include "FWCore/ServiceRegistry/interface/ServiceMaker.h"
#include "CalibTracker/SiStripDCS/interface/SiStripDetVOffBuilder.h"
DEFINE_FWK_SERVICE(SiStripDetVOffBuilder);
Expand Down
135 changes: 135 additions & 0 deletions CalibTracker/SiStripDCS/plugins/SiStripDetVOffHandler.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include <iostream>
#include <sstream>

#include "CondCore/CondDB/interface/ConnectionPool.h"

#include "CalibTracker/SiStripDCS/interface/SiStripDetVOffBuilder.h"


class SiStripDetVOffHandler : public edm::EDAnalyzer {
public:
explicit SiStripDetVOffHandler(const edm::ParameterSet& iConfig );
virtual ~SiStripDetVOffHandler();
virtual void analyze( const edm::Event& evt, const edm::EventSetup& evtSetup);
virtual void endJob();

private:
cond::persistency::ConnectionPool m_connectionPool;
std::string m_condDb;
std::string m_localCondDbFile;
std::string m_targetTag;

int maxTimeBeforeNewIOV_;

std::vector< std::pair<SiStripDetVOff*,cond::Time_t> > newPayloads;
edm::Service<SiStripDetVOffBuilder> modHVBuilder;
};

SiStripDetVOffHandler::SiStripDetVOffHandler(const edm::ParameterSet& iConfig):
m_connectionPool(),
m_condDb( iConfig.getParameter< std::string >("conditionDatabase") ),
m_localCondDbFile( iConfig.getParameter< std::string >("condDbFile") ),
m_targetTag( iConfig.getParameter< std::string >("targetTag") ),
maxTimeBeforeNewIOV_( iConfig.getUntrackedParameter< int >("maxTimeBeforeNewIOV", 24) ){
m_connectionPool.setParameters( iConfig.getParameter<edm::ParameterSet>("DBParameters") );
m_connectionPool.configure();
// get last IOV from local sqlite file if "conditionDatabase" is empty
if (m_condDb.empty()) m_condDb = m_localCondDbFile;
}

SiStripDetVOffHandler::~SiStripDetVOffHandler() {
}

void SiStripDetVOffHandler::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) {
// get last payload from condDb
cond::Time_t lastIov = 0;
boost::shared_ptr<SiStripDetVOff> lastPayload;

edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
<< "Retrieve last IOV from " << m_condDb;
cond::persistency::Session condDbSession = m_connectionPool.createSession( m_condDb );
condDbSession.transaction().start( true );
if ( m_condDb.find("sqlite")==0 && (!condDbSession.existsDatabase()) ){
// Source of last IOV is empty
edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
<< "No information can be retrieved from " << m_condDb << " because the file is empty.\n"
<< "Will assume all HV/LV's are off.";
}else{
cond::persistency::IOVProxy iovProxy = condDbSession.readIov( m_targetTag );
cond::Hash lastPayloadHash = iovProxy.getLast().payloadId;
if ( !lastPayloadHash.empty() ) {
lastPayload = condDbSession.fetchPayload<SiStripDetVOff>( lastPayloadHash );
lastIov = iovProxy.getLast().since; // move to LastValidatedTime?
}
edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
<< " ... last IOV: " << lastIov << " , " << "last Payload: " << lastPayloadHash;
}
condDbSession.transaction().commit();

// build the object!
newPayloads.clear();
modHVBuilder->setLastSiStripDetVOff( lastPayload.get(), lastIov );
modHVBuilder->BuildDetVOffObj();
newPayloads = modHVBuilder->getModulesVOff();
edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
<< "Finished building " << newPayloads.size() << " new payloads.";

// write the payloads to sqlite file
edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
<< "Write new payloads to sqlite file " << m_localCondDbFile;
cond::persistency::Session localFileSession = m_connectionPool.createSession( m_localCondDbFile, true );
localFileSession.transaction().start( false );
if ( lastPayload && newPayloads.size() == 1 && *newPayloads[0].first == *lastPayload ){
// if no HV/LV transition was found in this period
edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
<< "No HV/LV transition was found from PVSS query.";
bool forceNewIOV = true;
if (maxTimeBeforeNewIOV_ < 0)
forceNewIOV = false;
else {
auto deltaT = cond::time::to_boost(newPayloads[0].second) - cond::time::to_boost(lastIov);
forceNewIOV = deltaT > boost::posix_time::hours(maxTimeBeforeNewIOV_);
}
if ( !forceNewIOV ){
newPayloads.erase(newPayloads.begin());
edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
<< " ... No payload transfered.";
}else {
edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
<< " ... The last IOV is too old. Will start a new IOV from " << newPayloads[0].second
<< "(" << boost::posix_time::to_simple_string(cond::time::to_boost(newPayloads[0].second)) << ") with the same payload.";
}
}

cond::persistency::IOVEditor iovEditor;
if (localFileSession.existsDatabase() && localFileSession.existsIov(m_targetTag)){
edm::LogWarning("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
<< "IOV of tag " << m_targetTag << " already exists in sqlite file " << m_localCondDbFile;
iovEditor = localFileSession.editIov(m_targetTag);
}else {
iovEditor = localFileSession.createIov<SiStripDetVOff>( m_targetTag, cond::timestamp );
iovEditor.setDescription( "New IOV" );
}
for (const auto &payload : newPayloads){
cond::Hash thePayloadHash = localFileSession.storePayload<SiStripDetVOff>( *payload.first );
iovEditor.insert( payload.second, thePayloadHash );
}
iovEditor.flush();
localFileSession.transaction().commit();

edm::LogInfo("SiStripDetVOffHandler") << "[SiStripDetVOffHandler::" << __func__ << "] "
<< newPayloads.size() << " payloads written to sqlite file.";

}

void SiStripDetVOffHandler::endJob() {
}

// -------------------------------------------------------
typedef SiStripDetVOffHandler SiStripO2ODetVOff;
DEFINE_FWK_MODULE(SiStripO2ODetVOff);
131 changes: 131 additions & 0 deletions CalibTracker/SiStripDCS/plugins/SiStripDetVOffTkMapPlotter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include <iostream>
#include <sstream>

#include "CondCore/CondDB/interface/ConnectionPool.h"

#include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
#include "CondFormats/SiStripObjects/interface/SiStripDetVOff.h"
#include "CondFormats/Common/interface/Time.h"
#include "CondFormats/Common/interface/TimeConversions.h"

#include "DQM/SiStripCommon/interface/TkHistoMap.h"
#include "CommonTools/TrackerMap/interface/TrackerMap.h"


class SiStripDetVOffTkMapPlotter : public edm::EDAnalyzer {
public:
explicit SiStripDetVOffTkMapPlotter(const edm::ParameterSet& iConfig );
virtual ~SiStripDetVOffTkMapPlotter();
virtual void analyze( const edm::Event& evt, const edm::EventSetup& evtSetup);
virtual void endJob();

private:
std::string formatIOV(cond::Time_t iov, std::string format="%Y-%m-%d__%H_%M_%S");

cond::persistency::ConnectionPool m_connectionPool;
std::string m_condDb;
std::string m_plotTag;

// IOV of plotting.
cond::Time_t m_IOV;
// Or use datatime string. Format: "2002-01-20 23:59:59.000". Set IOV to 0 to use this.
std::string m_Time;
// Set the plot format. Default: png.
std::string m_plotFormat;
// Specify output root file name. Leave empty if do not want to save plots in a root file.
std::string m_outputFile;

edm::Service<SiStripDetInfoFileReader> detidReader;
};

SiStripDetVOffTkMapPlotter::SiStripDetVOffTkMapPlotter(const edm::ParameterSet& iConfig):
m_connectionPool(),
m_condDb( iConfig.getParameter< std::string >("conditionDatabase") ),
m_plotTag( iConfig.getParameter< std::string >("Tag") ),
m_IOV( iConfig.getUntrackedParameter< cond::Time_t >("IOV", 0) ),
m_Time( iConfig.getUntrackedParameter< std::string >("Time", "") ),
m_plotFormat( iConfig.getUntrackedParameter< std::string >("plotFormat", "png") ),
m_outputFile( iConfig.getUntrackedParameter< std::string >("outputFile", "") ){
m_connectionPool.setParameters( iConfig.getParameter<edm::ParameterSet>("DBParameters") );
m_connectionPool.configure();
}

SiStripDetVOffTkMapPlotter::~SiStripDetVOffTkMapPlotter() {
}

void SiStripDetVOffTkMapPlotter::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) {

cond::Time_t theIov = 0;
if (m_IOV != 0){
theIov = m_IOV;
}else if (!m_Time.empty()){
theIov = cond::time::from_boost( boost::posix_time::time_from_string(m_Time) );
}else{
// Use the current time if no input. Will get the last IOV.
theIov = cond::time::from_boost( boost::posix_time::second_clock::universal_time() );
}

// open db session
edm::LogInfo("SiStripDetVOffMapPlotter") << "[SiStripDetVOffMapPlotter::" << __func__ << "] "
<< "Query the condition database " << m_condDb << " for tag " << m_plotTag;
cond::persistency::Session condDbSession = m_connectionPool.createSession( m_condDb );
condDbSession.transaction().start( true );
cond::persistency::IOVProxy iovProxy = condDbSession.readIov(m_plotTag, true);
auto iiov = iovProxy.find(theIov);
if (iiov==iovProxy.end())
throw cms::Exception("Input IOV "+std::to_string(m_IOV)+"/"+m_Time+" is invalid!");

theIov = (*iiov).since;
edm::LogInfo("SiStripDetVOffMapPlotter") << "[SiStripDetVOffMapPlotter::" << __func__ << "] "
<< "Make tkMap for IOV " << theIov << " (" << boost::posix_time::to_simple_string(cond::time::to_boost(theIov)) << ")";
auto payload = condDbSession.fetchPayload<SiStripDetVOff>( (*iiov).payloadId );

TrackerMap lvmap,hvmap;
TkHistoMap lvhisto("LV_Status","LV_Status",-1);
TkHistoMap hvhisto("HV_Status","HV_Status",-1);

auto detids = detidReader->getAllDetIds();
for (auto id : detids){
if (payload->IsModuleLVOff(id))
lvhisto.fill(id, 1); // RED
else
lvhisto.fill(id, 0.5);

if (payload->IsModuleHVOff(id))
hvhisto.fill(id, 1); // RED
else
hvhisto.fill(id, 0.5);
}

lvhisto.dumpInTkMap(&lvmap);
hvhisto.dumpInTkMap(&hvmap);
lvmap.setPalette(1);
hvmap.setPalette(1);
lvmap.save(true,0,0,"LV_tkMap_"+formatIOV(theIov)+"."+m_plotFormat);
hvmap.save(true,0,0,"HV_tkMap_"+formatIOV(theIov)+"."+m_plotFormat);

if (!m_outputFile.empty()){
lvhisto.save(m_outputFile);
hvhisto.save(m_outputFile);
}

}

void SiStripDetVOffTkMapPlotter::endJob() {
}

std::string SiStripDetVOffTkMapPlotter::formatIOV(cond::Time_t iov, std::string format) {
auto facet = new boost::posix_time::time_facet(format.c_str());
std::ostringstream stream;
stream.imbue(std::locale(stream.getloc(), facet));
stream << cond::time::to_boost(iov);
return stream.str();
}

DEFINE_FWK_MODULE(SiStripDetVOffTkMapPlotter);

0 comments on commit 75f1609

Please sign in to comment.