2 #include "boost/foreach.hpp"
6 onlineDbConnectionString(pset.getParameter<std::string>(
"onlineDB")),
7 authenticationPath(pset.getParameter<std::string>(
"authPath")),
8 whichTable(pset.getParameter<std::string>(
"queryType")),
9 lastValueFileName(pset.getParameter<std::string>(
"lastValueFile")),
10 fromFile(pset.getParameter<bool>(
"lastValueFromFile")),
11 psuDetIdMapFile_(pset.getParameter<std::string>(
"PsuDetIdMapFile")),
12 debug_(pset.getParameter<bool>(
"debugModeOn")),
14 tmax_par(pset.getParameter< std::vector<int> >(
"Tmax")),
15 tmin_par(pset.getParameter< std::vector<int> >(
"Tmin")),
16 tset_par(pset.getParameter< std::vector<int> >(
"TSetMin")),
17 detIdListFile_(pset.getParameter< std::string >(
"DetIdListFile")),
18 excludedDetIdListFile_(pset.getParameter< std::string >(
"ExcludedDetIdListFile")),
19 highVoltageOnThreshold_(pset.getParameter<double>(
"HighVoltageOnThreshold"))
24 edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::SiStripDetVOffBuilder] constructor" << endl;
46 edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::SiStripDetVOffBuilder] DB name has not been set properly ... Returning ...";
51 edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::SiStripDetVOffBuilder] File expected for lastValue table, but filename not specified ... Returning ...";
57 ss <<
"[SiStripDetVOffBuilder::SiStripDetVOffBuilder]\n"
61 <<
" Table to be queried: " <<
whichTable <<
"\n";
68 if (whichTable ==
"LASTVALUE"){
77 edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::" << __func__ <<
"]: destructing ...";
81 BOOST_FOREACH(
int val, par){
93 edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Query type is " <<
whichTable << endl;
95 if (
whichTable ==
"LASTVALUE") {
edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Use file? " << ((
fromFile) ?
"TRUE" :
"FALSE");}
97 if (
lastStoredCondObj.second > 0) {
edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: retrieved last time stamp from DB: "
146 for (
unsigned int i = 0;
i < dStruct.
detidV.size();
i++) {
150 std::vector<uint32_t> * detids = &(dStruct.
detidV[
i].first);
165 if (iovtime != saveIovTime) {
175 const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > detInfos = reader.
getAllData();
180 std::vector< std::pair<uint32_t, std::string> > excludedDetIdMap;
184 for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = detInfos.begin(); it != detInfos.end(); ++it) {
185 std::vector< std::pair<uint32_t, std::string> >::const_iterator exclIt = excludedDetIdMap.begin();
186 bool excluded =
false;
187 for( ; exclIt != excludedDetIdMap.end(); ++exclIt ) {
188 if( it->first == exclIt->first ) {
194 modV->
put( it->first, 1, 1 );
208 std::vector<uint32_t> beforeV;
213 for (
unsigned int j = 0;
j < detids->size();
j++) {
214 if(
debug_ )
cout <<
"at time = " << iovtime <<
" detid["<<
j<<
"] = " << (*detids)[
j] <<
" has hv = " << hvlv.first <<
" and lv = " << hvlv.second << endl;
215 modV->
put((*detids)[
j],hvlv.first,hvlv.second);
219 unsigned int numAdded = 0, numRemoved = 0;
220 if (iovtime == saveIovTime) {
222 numAdded = oldStats[1];
223 numRemoved = oldStats[2];
225 std::vector<uint32_t> afterV;
228 if ((afterV.size() - beforeV.size()) > 0) {
229 numAdded += afterV.size() - beforeV.size();
230 }
else if ((beforeV.size() - afterV.size()) > 0) {
231 numRemoved += beforeV.size() - afterV.size();
236 if (iovtime != saveIovTime) {
239 if (
modulesOff.empty() || !(*modV == *testV) ) {
240 modulesOff.push_back( std::make_pair(modV,iovtime) );
242 saveIovTime = iovtime;
258 std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator moIt =
modulesOff.begin();
260 std::vector< std::vector<uint32_t> >::iterator plIt =
payloadStats.begin();
269 std::vector<uint32_t> finalids;
271 std::cout <<
"Index = " <<
i <<
" Size of DetIds vector = " << finalids.size() << std::endl;
273 for (
unsigned int j = 0;
j < finalids.size();
j++) {
274 std::cout <<
"detid = " << finalids[
j] <<
" LV off = " << (
modulesOff[
i].first)->IsModuleLVOff(finalids[
j]) <<
" HV off = "
275 << (
modulesOff[
i].first)->IsModuleHVOff(finalids[j]) << std::endl;
284 std::vector<int> locations;
285 for (
unsigned int i = 0;
i < settingID.size();
i++) {
if (settingID[
i] ==
id) {locations.push_back((
int)
i);} }
288 if (locations.size() == 0) {setting = -1;}
289 else if (locations.size() == 1) {setting = locations[0];}
293 for (
unsigned int j = 0;
j < locations.size();
j++) {
294 #ifdef USING_NEW_CORAL
295 const boost::posix_time::ptime& testSec = changeDate.time();
296 const boost::posix_time::ptime& limitSec = settingDate[(
unsigned int)locations[
j]].
time();
298 long testSec = changeDate.time().ns();
299 long limitSec = settingDate[(
unsigned int)locations[
j]].
time().ns();
301 if (testSec >= limitSec) {setting = locations[
j];}
310 std::vector<int> locations;
311 for (
unsigned int i = 0;
i < settingDpname.size();
i++) {
if (settingDpname[
i] == dpname) {locations.push_back((
int)
i);} }
314 if (locations.size() == 0) {setting = -1;}
315 else if (locations.size() == 1) {setting = locations[0];}
319 for (
unsigned int j = 0;
j < locations.size();
j++) {
320 #ifdef USING_NEW_CORAL
321 const boost::posix_time::ptime& testSec = changeDate.time();
322 const boost::posix_time::ptime& limitSec = settingDate[(
unsigned int)locations[
j]].
time();
324 long testSec = changeDate.time().ns();
325 long limitSec = settingDate[(
unsigned int)locations[
j]].
time().ns();
327 if (testSec >= limitSec) {setting = locations[
j];}
336 edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::" << __func__ <<
"]: last Value file does not exist!";
343 std::vector<std::string> changeDates;
351 std::istringstream ss(line);
354 std::string changeDate;
355 ss >> std::skipws >> dpid >> vmon >> changeDate;
356 dpIDs.push_back(dpid);
357 vmonValues.push_back(vmon);
358 changeDates.push_back(changeDate);
363 for (
unsigned int i = 0;
i < changeDates.size();
i++) {
364 std::string
part = changeDates[
i].substr(0,4);
365 int year = atoi(part.c_str());
368 part = changeDates[
i].substr(5,2);
369 int month = atoi(part.c_str());
372 part = changeDates[
i].substr(8,2);
373 int day = atoi(part.c_str());
376 part = changeDates[
i].substr(11,2);
377 int hour = atoi(part.c_str());
380 part = changeDates[
i].substr(14,2);
381 int minute = atoi(part.c_str());
384 part = changeDates[
i].substr(17,2);
385 int second = atoi(part.c_str());
388 coral::TimeStamp
date(year,month,day,hour,minute,second,0);
389 dateChange.push_back(date);
392 if (changeDates.size() != dateChange.size()) {
edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::" << __func__ <<
"]: date conversion failed!!";}
415 unsigned long long iovSec = iovTime >> 32;
416 uint32_t iovNanoSec = uint32_t(iovTime);
418 cout <<
"[SiStripDetVOffBuilder::getCoralTime] Converting CondTime into CoralTime: "
419 <<
" condTime = " << iovSec <<
" - " << iovNanoSec
420 <<
" getCondTime(coralTime) = " << (testTime>>32) <<
" - " << (testTime&0xFFFFFFFF) << endl;
428 std::vector<uint32_t>::iterator it = std::unique(vec.begin(),vec.end());
429 vec.resize( it - vec.begin() );
444 << (latestDate&0xFFFFFFFF)
449 for (
unsigned int i = 1;
i < coralDate.size();
i++) {
451 if (testDate > latestDate) {
452 latestDate = testDate;
459 std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator & initialIt,
460 std::vector< std::pair<SiStripDetVOff*,cond::Time_t> > & resultVec,
465 if( distance(resultVec.begin(), initialIt) == 0 ) {
469 if(
debug_ && ( it->first->getLVoffCounts() - initialIt->first->getLVoffCounts() == 0 ) && ( it->first->getHVoffCounts() - initialIt->first->getHVoffCounts() == 0 ) ) {
470 cout <<
"Same number of LV and HV at start and end of sequence: LV off = " << it->first->getLVoffCounts() <<
" HV off = " << it->first->getHVoffCounts() << endl;
474 if( ( it->first->getLVoffCounts() - initialIt->first->getLVoffCounts() > 0 ) || ( it->first->getHVoffCounts() - initialIt->first->getHVoffCounts() > 0 ) ) {
482 else if( ( it->first->getLVoffCounts() - initialIt->first->getLVoffCounts() <= 0 ) || ( it->first->getHVoffCounts() - initialIt->first->getHVoffCounts() <= 0 ) ) {
484 discardIOVs(it, initialIt, resultVec, last, first);
490 std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator & initialIt,
491 std::vector< std::pair<SiStripDetVOff*,cond::Time_t> > & resultVec,
492 const bool last,
const unsigned int first )
495 cout <<
"first = " << first << endl;
496 cout <<
"initial->first = " << initialIt->first <<
", second = " << initialIt->second << endl;
497 cout <<
"last = " << last << endl;
500 resultVec.erase(initialIt+first, it+1);
502 it = resultVec.end()-2;
505 it = resultVec.erase(initialIt+first, it);
512 std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator initialIt;
515 int resultsIndex = 0;
517 if( resultVecSize > 1 ) {
518 std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator it =
modulesOff.begin();
519 for( ; it !=
modulesOff.end()-1; ++it, ++resultsIndex ) {
520 unsigned long long deltaT = ((it+1)->
second - it->second) >> 32;
521 unsigned long long deltaTsequence = 0;
523 deltaTsequence = ((it+1)->
second - initialIt->second) >> 32;
526 if( (deltaT < deltaTmin) && ( (count == 0) || ( deltaTsequence < maxIOVlength ) ) ) {
535 else if( count > 1 ) {
545 if( resultsIndex == resultVecSize-2 && count != 0 ) {
580 std::vector<coral::TimeStamp> settingDate;
581 std::vector<float> settingValue;
582 std::vector<std::string> settingDpname;
583 std::vector<uint32_t> settingDpid;
585 LogDebug(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Channel settings retrieved";
586 LogDebug(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Number of PSU channels: " << settingDpname.size();
589 std::stringstream ss;
590 for (
unsigned int j = 0;
j < tStruct.
dpname.size();
j++) {
598 ss <<
"Channel = " << tStruct.
dpname[
j] << std::endl;
601 LogDebug(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Number of channels with no setting information " <<
missing;
602 LogDebug(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Number of entries in dpname vector " << tStruct.
dpname.size();
609 LogDebug(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: File access complete \n\t Number of values read from file: " << tStruct.
dpid.size();
612 std::vector<coral::TimeStamp> settingDate;
613 std::vector<float> settingValue;
614 std::vector<std::string> settingDpname;
615 std::vector<uint32_t> settingDpid;
618 LogDebug(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Channel settings retrieved";
619 LogDebug(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Number of PSU channels: " << settingDpname.size();
622 std::stringstream ss;
625 tStruct.
dpname.resize(tStruct. dpid.size());
626 for (
unsigned int j = 0;
j < tStruct.
dpid.size();
j++) {
633 tStruct.
dpname[
j] = settingDpname[setting];
638 ss <<
"DP ID = " << tStruct.
dpid[
j] << std::endl;
641 LogDebug(
"SiStripDetVOffBuilder") <<
"Number of missing psu channels = " << missing << std::endl;
642 LogDebug(
"SiStripDetVOffBuilder") <<
"IDs are: = " << ss.str();
648 ss << comment << (condTime>> 32) <<
" - " << (condTime & 0xFFFFFFFF) << std::endl;
655 ss <<
"Starting from IOV time in the database : year = " << coralTime.year()
656 <<
", month = " << coralTime.month()
657 <<
", day = " << coralTime.day()
658 <<
", hour = " << coralTime.hour()
659 <<
", minute = " << coralTime.minute()
660 <<
", second = " << coralTime.second()
661 <<
", nanosecond = " << coralTime.nanosecond() << std::endl;
674 LogTrace(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff] DCU-DET ID map built";
680 unsigned int ch0bad = 0, ch1bad = 0, ch2bad = 0, ch3bad = 0;
681 std::vector<unsigned int> numLvBad, numHvBad;
683 for (
unsigned int dp = 0; dp < psuStruct.
dpname.size(); dp++) {
684 if (psuStruct.
dpname[dp] !=
"UNKNOWN") {
687 std::string board = psuStruct.
dpname[dp];
699 if (board ==
"channel000") {
700 detIdStruct.
detidV.push_back( std::make_pair(ids,psuStruct.
changeDate[dp]) );
707 numLvBad.insert(numLvBad.end(),ids.begin(),ids.end());
712 detIdStruct.
isHV.push_back(0);
715 else if( board ==
"channel002" || board ==
"channel003" ) {
716 detIdStruct.
detidV.push_back( std::make_pair(ids,psuStruct.
changeDate[dp]) );
719 if (board ==
"channel002") {ch2bad++;}
720 if (board ==
"channel003") {ch3bad++;}
722 numHvBad.insert(numHvBad.end(),ids.begin(),ids.end());
727 detIdStruct.
isHV.push_back(1);
731 if (board !=
"channel001") {
732 LogTrace(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::" << __func__ <<
"] channel name not recognised! " << board;
746 std::cout <<
"Bad 000 = " << ch0bad <<
" Bad 001 = " << ch1bad << std::endl;
747 std::cout <<
"Bad 002 = " << ch0bad <<
" Bad 003 = " << ch1bad << std::endl;
748 std::cout <<
"Number of bad LV detIDs = " << numLvBad.size() << std::endl;
749 std::cout <<
"Number of bad HV detIDs = " << numHvBad.size() << std::endl;
752 LogTrace(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::" << __func__ <<
"]: Number of PSUs retrieved from DB with map information " << detIdStruct.
detidV.size();
753 LogTrace(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::" << __func__ <<
"]: Number of PSUs retrieved from DB with no map information " << detIdStruct.
notMatched;
755 unsigned int dupCount = 0;
756 for (
unsigned int t = 0;
t < numLvBad.size();
t++) {
757 std::vector<unsigned int>::iterator iter =
std::find(numHvBad.begin(),numHvBad.end(),numLvBad[
t]);
758 if (iter != numHvBad.end()) {dupCount++;}
760 if(
debug_ )
std::cout <<
"Number of channels with LV & HV bad = " << dupCount << std::endl;
765 std::vector<uint32_t> pStats(3,0);
766 pStats.push_back(afterV);
767 pStats.push_back(numAdded);
768 pStats.push_back(numRemoved);
775 int lv_off = -1, hv_off = -1;
777 if (detIdStruct.
isHV[i] == 1) {
786 std::string iChannel = detIdStruct.
psuName[
i].substr( (detIdStruct.
psuName[i].size()-3) );
787 std::string iPsu = detIdStruct.
psuName[
i].substr(0, (detIdStruct.
psuName[i].size()-3) );
788 if (iChannel ==
"002" || iChannel ==
"003") {
789 bool lastStatusOfOtherChannel =
true;
790 for (
unsigned int j = 0;
j <
i;
j++) {
791 std::string jPsu = detIdStruct.
psuName[
j].substr(0, (detIdStruct.
psuName[
j].size()-3) );
792 std::string jChannel = detIdStruct.
psuName[
j].substr( (detIdStruct.
psuName[
j].size()-3) );
793 if (iPsu == jPsu && iChannel != jChannel && (jChannel ==
"002" || jChannel ==
"003")) {
795 lastStatusOfOtherChannel = detIdStruct.
StatusGood[
j];
798 if (detIdStruct.
StatusGood[i] != lastStatusOfOtherChannel) {
799 if(
debug_ )
cout <<
"turning off hv" << endl;
810 return make_pair(hv_off, lv_off);
SiStripDetVOffBuilder(const edm::ParameterSet &, const edm::ActivityRegistry &)
std::string lastValueFileName
std::vector< int > actualStatus
std::string authenticationPath
void discardIOVs(std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &it, std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &initialIt, std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > &resultVec, const bool last, const unsigned int first)
Removes IOVs as dictated by reduction.
std::pair< int, int > extractDetIdVector(const unsigned int i, SiStripDetVOff *modV, DetIdListTimeAndStatus &detIdStruct)
void printPar(std::stringstream &ss, const std::vector< int > &par)
void buildPSUdetIdMap(TimesAndValues &tStruct, DetIdListTimeAndStatus &dStruct)
std::vector< uint32_t > getDetID(std::string pvss)
std::string psuDetIdMapFile_
Extension to SiStripConfigDb to map PSU channels to DetIDs using DCU-PSU map and DCU-DetID map...
bool put(const uint32_t DetId, const int HVoff, const int LVoff)
Insert information for a single detId.
DetIdTimeStampVector detidV
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
double highVoltageOnThreshold_
std::string detIdListFile_
std::auto_ptr< SiStripCoralIface > coralInterface
void removeDuplicates(std::vector< uint32_t > &vec)
std::vector< std::string > dpname
U second(std::pair< T, U > const &p)
const std::map< uint32_t, DetInfo > & getAllData() const
unsigned long long Time_t
std::vector< uint32_t > dpid
std::string excludedDetIdListFile_
std::vector< bool > StatusGood
std::vector< coral::TimeStamp > changeDate
void getDetIds(std::vector< uint32_t > &DetIds_) const
std::vector< unsigned int > isHV
void reduction(const uint32_t deltaTmin, const uint32_t maxIOVlength)
An interface class to the PVSS cond DB.
void lastValue(TimesAndValues &tStruct)
Time_t from_boost(boost::posix_time::ptime bt)
void readLastValueFromFile(std::vector< uint32_t > &dpIDs, std::vector< float > &vmonValues, std::vector< coral::TimeStamp > &dateChange)
void lastValueFromFile(TimesAndValues &tStruct)
cond::Time_t findMostRecentTimeStamp(std::vector< coral::TimeStamp > coralDate)
std::vector< int > tmax_par
coral::TimeStamp getCoralTime(cond::Time_t iovTime)
cond::Time_t getCondTime(coral::TimeStamp coralTime)
void setLastSiStripDetVOff(SiStripDetVOff *lastPayload, cond::Time_t lastTimeStamp)
std::vector< int > tmin_par
std::vector< std::vector< uint32_t > > payloadStats
void setPayloadStats(const uint32_t afterV, const uint32_t numAdded, const uint32_t numRemoved)
std::vector< float > actualValue
void reduce(std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &it, std::vector< std::pair< SiStripDetVOff *, cond::Time_t > >::iterator &initialIt, std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > &resultVec, const bool last=false)
Operates the reduction of the fast sequences of ramping up and down of the voltages.
std::string fullPath() const
std::vector< std::string > psuName
std::vector< std::pair< SiStripDetVOff *, cond::Time_t > > modulesOff
void statusChange(cond::Time_t &lastTime, TimesAndValues &tStruct)
std::pair< SiStripDetVOff *, cond::Time_t > lastStoredCondObj
std::string timeToStream(const coral::TimeStamp &coralTime, const string &comment="")
std::vector< int > tset_par
boost::posix_time::ptime to_boost(Time_t iValue)
int findSetting(uint32_t id, coral::TimeStamp changeDate, std::vector< uint32_t > settingID, std::vector< coral::TimeStamp > settingDate)
std::string onlineDbConnectionString
const double par[8 *NPar][4]