2 #include "boost/foreach.hpp"
7 onlineDbConnectionString(pset.getParameter<std::
string>(
"onlineDB")),
8 authenticationPath(pset.getParameter<std::
string>(
"authPath")),
9 whichTable(pset.getParameter<std::
string>(
"queryType")),
10 lastValueFileName(pset.getParameter<std::
string>(
"lastValueFile")),
11 fromFile(pset.getParameter<bool>(
"lastValueFromFile")),
12 psuDetIdMapFile_(pset.getParameter<std::
string>(
"PsuDetIdMapFile")),
13 debug_(pset.getParameter<bool>(
"debugModeOn")),
15 tmax_par(pset.getParameter< std::vector<int> >(
"Tmax")),
16 tmin_par(pset.getParameter< std::vector<int> >(
"Tmin")),
17 tset_par(pset.getParameter< std::vector<int> >(
"TSetMin")),
18 detIdListFile_(pset.getParameter< std::
string >(
"DetIdListFile")),
19 excludedDetIdListFile_(pset.getParameter< std::
string >(
"ExcludedDetIdListFile")),
20 highVoltageOnThreshold_(pset.getParameter<double>(
"HighVoltageOnThreshold"))
25 edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::SiStripDetVOffBuilder] constructor" << endl;
47 edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::SiStripDetVOffBuilder] DB name has not been set properly ... Returning ...";
52 edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::SiStripDetVOffBuilder] File expected for lastValue table, but filename not specified ... Returning ...";
58 ss <<
"[SiStripDetVOffBuilder::SiStripDetVOffBuilder]\n"
62 <<
" Table to be queried: " <<
whichTable <<
"\n"
79 edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::" << __func__ <<
"]: destructing ...";
83 BOOST_FOREACH(
int val, par){
95 edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Query type is " <<
whichTable << endl;
97 if (
whichTable ==
"LASTVALUE") {
edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Use file? " << ((
fromFile) ?
"TRUE" :
"FALSE");}
99 if (
lastStoredCondObj.second > 0) {
edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: retrieved last time stamp from DB: "
156 for (
unsigned int i = 0;
i < dStruct.
detidV.size();
i++) {
160 std::vector<uint32_t> * detids = &(dStruct.
detidV[
i].first);
175 if (iovtime != saveIovTime) {
185 const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > detInfos =
reader.getAllData();
194 std::vector< std::pair<uint32_t, std::string> > excludedDetIdMap;
198 for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = detInfos.begin(); it != detInfos.end(); ++it) {
199 std::vector< std::pair<uint32_t, std::string> >::const_iterator exclIt = excludedDetIdMap.begin();
200 bool excluded =
false;
201 for( ; exclIt != excludedDetIdMap.end(); ++exclIt ) {
202 if( it->first == exclIt->first ) {
208 modV->
put( it->first, 1, 1 );
222 std::vector<uint32_t> beforeV;
233 for (
unsigned int j = 0;
j < detids->size();
j++) {
234 if(
debug_ )
cout <<
"at time = " << iovtime <<
" detid["<<
j<<
"] = " << (*detids)[
j] <<
" has hv = " << hvlv.first <<
" and lv = " << hvlv.second << endl;
235 modV->
put((*detids)[
j],hvlv.first,hvlv.second);
239 unsigned int numAdded = 0, numRemoved = 0;
240 if (iovtime == saveIovTime) {
242 numAdded = oldStats[1];
243 numRemoved = oldStats[2];
245 std::vector<uint32_t> afterV;
248 if ((afterV.size() - beforeV.size()) > 0) {
249 numAdded += afterV.size() - beforeV.size();
250 }
else if ((beforeV.size() - afterV.size()) > 0) {
251 numRemoved += beforeV.size() - afterV.size();
256 if (iovtime != saveIovTime) {
259 if (
modulesOff.empty() || !(*modV == *testV) ) {
260 modulesOff.push_back( std::make_pair(modV,iovtime) );
262 saveIovTime = iovtime;
278 std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator moIt =
modulesOff.begin();
280 std::vector< std::vector<uint32_t> >::iterator plIt =
payloadStats.begin();
289 std::vector<uint32_t> finalids;
291 std::cout <<
"Index = " <<
i <<
" Size of DetIds vector = " << finalids.size() << std::endl;
293 for (
unsigned int j = 0;
j < finalids.size();
j++) {
294 std::cout <<
"detid = " << finalids[
j] <<
" LV off = " << (
modulesOff[
i].first)->IsModuleLVOff(finalids[
j]) <<
" HV off = "
295 << (
modulesOff[
i].first)->IsModuleHVOff(finalids[j]) << std::endl;
304 std::vector<int> locations;
305 for (
unsigned int i = 0;
i < settingID.size();
i++) {
if (settingID[
i] ==
id) {locations.push_back((
int)
i);} }
308 if (locations.size() == 0) {setting = -1;}
309 else if (locations.size() == 1) {setting = locations[0];}
313 for (
unsigned int j = 0;
j < locations.size();
j++) {
314 #ifdef USING_NEW_CORAL
315 const boost::posix_time::ptime& testSec = changeDate.time();
316 const boost::posix_time::ptime& limitSec = settingDate[(
unsigned int)locations[
j]].
time();
318 long testSec = changeDate.time().ns();
319 long limitSec = settingDate[(
unsigned int)locations[
j]].
time().ns();
321 if (testSec >= limitSec) {setting = locations[
j];}
330 std::vector<int> locations;
331 for (
unsigned int i = 0;
i < settingDpname.size();
i++) {
if (settingDpname[
i] == dpname) {locations.push_back((
int)
i);} }
334 if (locations.size() == 0) {setting = -1;}
335 else if (locations.size() == 1) {setting = locations[0];}
339 for (
unsigned int j = 0;
j < locations.size();
j++) {
340 #ifdef USING_NEW_CORAL
341 const boost::posix_time::ptime& testSec = changeDate.time();
342 const boost::posix_time::ptime& limitSec = settingDate[(
unsigned int)locations[
j]].
time();
344 long testSec = changeDate.time().ns();
345 long limitSec = settingDate[(
unsigned int)locations[
j]].
time().ns();
347 if (testSec >= limitSec) {setting = locations[
j];}
356 edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::" << __func__ <<
"]: last Value file does not exist!";
363 std::vector<std::string> changeDates;
371 std::istringstream
ss(line);
375 ss >> std::skipws >> dpid >> vmon >> changeDate;
376 dpIDs.push_back(dpid);
377 vmonValues.push_back(vmon);
378 changeDates.push_back(changeDate);
383 for (
unsigned int i = 0;
i < changeDates.size();
i++) {
385 int year = atoi(part.c_str());
388 part = changeDates[
i].substr(5,2);
389 int month = atoi(part.c_str());
392 part = changeDates[
i].substr(8,2);
393 int day = atoi(part.c_str());
396 part = changeDates[
i].substr(11,2);
397 int hour = atoi(part.c_str());
400 part = changeDates[
i].substr(14,2);
401 int minute = atoi(part.c_str());
404 part = changeDates[
i].substr(17,2);
405 int second = atoi(part.c_str());
408 coral::TimeStamp date(year,month,day,hour,minute,second,0);
409 dateChange.push_back(date);
412 if (changeDates.size() != dateChange.size()) {
edm::LogError(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::" << __func__ <<
"]: date conversion failed!!";}
435 unsigned long long iovSec = iovTime >> 32;
436 uint32_t iovNanoSec = uint32_t(iovTime);
438 cout <<
"[SiStripDetVOffBuilder::getCoralTime] Converting CondTime into CoralTime: "
439 <<
" condTime = " << iovSec <<
" - " << iovNanoSec
440 <<
" getCondTime(coralTime) = " << (testTime>>32) <<
" - " << (testTime&0xFFFFFFFF) << endl;
448 std::vector<uint32_t>::iterator it = std::unique(vec.begin(),vec.end());
449 vec.resize( it - vec.begin() );
464 << (latestDate&0xFFFFFFFF)
469 for (
unsigned int i = 1;
i < coralDate.size();
i++) {
471 if (testDate > latestDate) {
472 latestDate = testDate;
479 std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator & initialIt,
480 std::vector< std::pair<SiStripDetVOff*,cond::Time_t> > & resultVec,
486 if( distance(resultVec.begin(), initialIt) == 0 ) {
490 if(
debug_ && ( it->first->getLVoffCounts() - initialIt->first->getLVoffCounts() == 0 ) && ( it->first->getHVoffCounts() - initialIt->first->getHVoffCounts() == 0 ) ) {
491 cout <<
"Same number of LV and HV at start and end of sequence: LV off = " << it->first->getLVoffCounts() <<
" HV off = " << it->first->getHVoffCounts() << endl;
495 if( ( it->first->getLVoffCounts() - initialIt->first->getLVoffCounts() > 0 ) || ( it->first->getHVoffCounts() - initialIt->first->getHVoffCounts() > 0 ) ) {
501 if(
debug_ )
cout <<
"Reducing IOV sequence (going off)" << endl;
504 else if( ( it->first->getLVoffCounts() - initialIt->first->getLVoffCounts() <= 0 ) || ( it->first->getHVoffCounts() - initialIt->first->getHVoffCounts() <= 0 ) ) {
506 discardIOVs(it, initialIt, resultVec, last, first);
507 if(
debug_ )
cout <<
"Reducing IOV sequence (going on)" << endl;
512 std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator & initialIt,
513 std::vector< std::pair<SiStripDetVOff*,cond::Time_t> > & resultVec,
514 const bool last,
const unsigned int first )
517 cout <<
"first (1->means the sequence started at the first timestamp in the query results, 0-> that it did not)= " << first << endl;
518 cout <<
"initial->first (initial SiStripDetVOff object of the IOV sequence)= " << initialIt->first <<
", second (initial timestamp of the IOV sequence) = " << initialIt->second << endl;
519 cout <<
"last (0->means that the sequence is not ending with the last item in the query results, 1-> that it DOES!)= " << last << endl;
522 resultVec.erase(initialIt+first, it+1);
524 it = resultVec.end()-2;
527 it = resultVec.erase(initialIt+first, it);
536 std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator initialIt;
539 int resultsIndex = 0;
541 if( resultVecSize > 1 ) {
542 std::vector< std::pair<SiStripDetVOff*,cond::Time_t> >::iterator it =
modulesOff.begin();
543 for( ; it !=
modulesOff.end()-1; ++it, ++resultsIndex ) {
544 unsigned long long deltaT = ((it+1)->
second - it->second) >> 32;
545 unsigned long long deltaTsequence = 0;
547 deltaTsequence = ((it+1)->
second - initialIt->second) >> 32;
550 if( (deltaT < deltaTmin) && ( (count == 0) || ( deltaTsequence < maxIOVlength ) ) ) {
559 else if( count > 1 ) {
569 if( resultsIndex == resultVecSize-2 && count != 0 ) {
609 std::vector<coral::TimeStamp> settingDate;
610 std::vector<float> settingValue;
611 std::vector<std::string> settingDpname;
612 std::vector<uint32_t> settingDpid;
614 LogDebug(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Channel settings retrieved";
615 LogDebug(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Number of PSU channels: " << settingDpname.size();
618 std::stringstream
ss;
619 for (
unsigned int j = 0;
j < tStruct.
dpname.size();
j++) {
627 ss <<
"Channel = " << tStruct.
dpname[
j] << std::endl;
630 LogDebug(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Number of channels with no setting information " <<
missing;
631 LogDebug(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Number of entries in dpname vector " << tStruct.
dpname.size();
638 LogDebug(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: File access complete \n\t Number of values read from file: " << tStruct.
dpid.size();
641 std::vector<coral::TimeStamp> settingDate;
642 std::vector<float> settingValue;
643 std::vector<std::string> settingDpname;
644 std::vector<uint32_t> settingDpid;
647 LogDebug(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Channel settings retrieved";
648 LogDebug(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff]: Number of PSU channels: " << settingDpname.size();
651 std::stringstream
ss;
654 tStruct.
dpname.resize(tStruct. dpid.size());
655 for (
unsigned int j = 0;
j < tStruct.
dpid.size();
j++) {
662 tStruct.
dpname[
j] = settingDpname[setting];
667 ss <<
"DP ID = " << tStruct.
dpid[
j] << std::endl;
670 LogDebug(
"SiStripDetVOffBuilder") <<
"Number of missing psu channels = " << missing << std::endl;
671 LogDebug(
"SiStripDetVOffBuilder") <<
"IDs are: = " << ss.str();
677 ss << comment << (condTime>> 32) <<
" - " << (condTime & 0xFFFFFFFF) << std::endl;
684 ss <<
"Starting from IOV time in the database : year = " << coralTime.year()
685 <<
", month = " << coralTime.month()
686 <<
", day = " << coralTime.day()
687 <<
", hour = " << coralTime.hour()
688 <<
", minute = " << coralTime.minute()
689 <<
", second = " << coralTime.second()
690 <<
", nanosecond = " << coralTime.nanosecond() << std::endl;
695 struct stat FileInfo;
699 Stat=stat(FileName.c_str(),&FileInfo);
717 std::cout<<
"PLEASE provide the name of a valid PSUDetIDMapFile in the cfg: currently still necessary to have a file, soon will access the info straight from the DB!"<<endl;
723 LogTrace(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::BuildDetVOff] PSU(Channel)-detID map(s) built";
731 unsigned int ch0bad = 0, ch1bad = 0, ch2bad = 0, ch3bad = 0;
732 std::vector<unsigned int> numLvBad, numHvBad;
737 std::map<std::string,bool> UnmappedState, CrosstalkingState;
739 std::map<std::string,std::vector<uint32_t> > UnmappedPSUs=map_.
getHVUnmappedMap();
741 if (
FileExists(
"HVUnmappedChannelState.dat")) {
742 std::cout<<
"File HVUnmappedChannelState.dat exists!"<<std::endl;
743 std::ifstream ifs(
"HVUnmappedChannelState.dat");
745 while( getline( ifs, line ) ) {
748 stringstream
ss(line);
754 std::string PSU=PSUChannel.substr(0,PSUChannel.size()-10);
756 std::map<std::string,std::vector<uint32_t> >::iterator
iter=UnmappedPSUs.find(PSU);
757 if (iter!=UnmappedPSUs.end()) {
758 UnmappedState[PSUChannel]=HVStatus;
761 std::cout<<
"WARNING!!! There are channels in the local file with the channel status for HVUnmapped channels, that ARE NOT CONSIDERED AS UNMAPPED in the current map!"<<std::endl;
767 bool MissingChannels=
false;
768 for (
std::map<
std::string, vector<uint32_t> >::iterator it=UnmappedPSUs.begin(); it!=UnmappedPSUs.end(); it++) {
771 std::map<std::string,bool>::iterator
iter=UnmappedState.find(chan002);
772 if (iter==UnmappedState.end()) {
773 std::cout<<
"ERROR! The local file with the channel status for HVUnmapped channels IS MISSING one of the following unmapped channel voltage status information:"<<std::endl;
775 MissingChannels=
true;
777 iter=UnmappedState.find(chan003);
778 if (iter==UnmappedState.end()) {
779 std::cout<<
"ERROR! The local file with the channel status for HVUnmapped channels IS MISSING one of the following unmapped channel voltage status information:"<<std::endl;
781 MissingChannels=
true;
785 if (MissingChannels) {
786 std::cout<<
"!!!!\n"<<
"Exiting now... please check the local HVUnmappedChannelState.dat and the mapfile you provided ("<<
psuDetIdMapFile_<<
")"<<std::endl;
792 for (
std::map<
std::string, vector<uint32_t> >::iterator it=UnmappedPSUs.begin(); it!=UnmappedPSUs.end(); it++) {
795 UnmappedState[chan002]=
false;
796 UnmappedState[chan003]=
false;
802 if (
FileExists(
"HVCrosstalkingChannelState.dat")) {
803 std::cout<<
"File HVCrosstalkingChannelState.dat exists!"<<std::endl;
804 std::ifstream ifs(
"HVCrosstalkingChannelState.dat");
806 while( getline( ifs, line ) ) {
809 stringstream
ss(line);
815 std::string PSU=PSUChannel.substr(0,PSUChannel.size()-10);
817 std::map<std::string,std::vector<uint32_t> >::iterator
iter=CrosstalkingPSUs.find(PSU);
818 if (iter!=CrosstalkingPSUs.end()) {
819 CrosstalkingState[PSUChannel]=HVStatus;
822 std::cout<<
"WARNING!!! There are channels in the local file with the channel status for HVUnmapped channels, that ARE NOT CONSIDERED AS UNMAPPED in the current map!"<<std::endl;
828 bool MissingChannels=
false;
829 for (
std::map<
std::string, vector<uint32_t> >::iterator it=CrosstalkingPSUs.begin(); it!=CrosstalkingPSUs.end(); it++) {
832 std::map<std::string,bool>::iterator
iter=CrosstalkingState.find(chan002);
833 if (iter==CrosstalkingState.end()) {
834 std::cout<<
"ERROR! The local file with the channel status for HVCrosstalking channels IS MISSING one of the following unmapped channel voltage status information:"<<std::endl;
836 MissingChannels=
true;
838 iter=CrosstalkingState.find(chan003);
839 if (iter==CrosstalkingState.end()) {
840 std::cout<<
"ERROR! The local file with the channel status for HVCrosstalking channels IS MISSING one of the following unmapped channel voltage status information:"<<std::endl;
842 MissingChannels=
true;
846 if (MissingChannels) {
847 std::cout<<
"!!!!\n"<<
"Exiting now... please check the local HVCrosstalkingChannelState.dat and the mapfile you provided ("<<
psuDetIdMapFile_<<
")"<<std::endl;
853 for (
std::map<
std::string, vector<uint32_t> >::iterator it=CrosstalkingPSUs.begin(); it!=CrosstalkingPSUs.end(); it++) {
856 CrosstalkingState[chan002]=
false;
857 CrosstalkingState[chan003]=
false;
863 std::cout<<
"Printing the UnmappedChannelState initial map:"<<std::endl;
864 std::cout<<
"PSUChannel\t\tHVON?(true or false)"<<std::endl;
865 for (std::map<std::string,bool>::iterator it=UnmappedState.begin(); it!=UnmappedState.end(); it++) {
866 std::cout<<it->first<<
"\t\t"<<it->second<<std::endl;
869 std::cout<<
"Printing the CrosstalkingChannelState initial map:"<<std::endl;
870 std::cout<<
"PSUChannel\t\tHVON?(true or false)"<<std::endl;
871 for (std::map<std::string,bool>::iterator it=CrosstalkingState.begin(); it!=CrosstalkingState.end(); it++) {
872 std::cout<<it->first<<
"\t\t"<<it->second<<std::endl;
881 for (
unsigned int dp = 0; dp < psuStruct.
dpname.size(); dp++) {
885 if (PSUChannel !=
"UNKNOWN") {
889 std::string PSU = PSUChannel.substr(0,PSUChannel.size()-10);
913 std::vector<uint32_t> ids;
920 std::vector<uint32_t> unmapped_ids,crosstalking_ids;
923 if (Channel==
"channel000" || Channel==
"channel001") {
930 map_.
getHvDetID(PSUChannel,ids,unmapped_ids,crosstalking_ids);
936 if (Channel==
"channel000" || Channel==
"channel001") {
937 cout <<
"Corresponding to LV (PSU-)matching detids: "<<endl;
938 for (
unsigned int i_detid=0;i_detid<ids.size();i_detid++) {
939 cout<< ids[i_detid] << std::endl;
943 cout <<
"Corresponding to straight HV matching detids: "<<endl;
944 for (
unsigned int i_detid=0;i_detid<ids.size();i_detid++) {
945 cout<< ids[i_detid] << std::endl;
950 if (!unmapped_ids.empty()) {
951 cout <<
"Corresponding to HV unmapped (PSU-)matching detids: "<<endl;
952 for (
unsigned int i_detid=0;i_detid<unmapped_ids.size();i_detid++) {
953 cout<< unmapped_ids[i_detid] << std::endl;
956 if (!crosstalking_ids.empty()) {
957 cout <<
"Corresponding to HV crosstalking (PSU-)matching detids: "<<endl;
958 for (
unsigned int i_detid=0;i_detid<crosstalking_ids.size();i_detid++) {
959 cout<< crosstalking_ids[i_detid] << std::endl;
987 detIdStruct.
detidV.push_back( std::make_pair(ids,psuStruct.
changeDate[dp]) );
993 numLvBad.insert(numLvBad.end(),ids.begin(),ids.end());
996 detIdStruct.
isHV.push_back(0);
999 detIdStruct.
psuName.push_back( PSUChannel );
1005 if (!ids.empty() || !unmapped_ids.empty() || !crosstalking_ids.empty()) {
1006 if (Channel==
"channel002") {
1009 else if (Channel==
"channel003") {
1014 std::vector<uint32_t> OFFids;
1015 OFFids.insert(OFFids.end(),ids.begin(),ids.end());
1016 OFFids.insert(OFFids.end(),unmapped_ids.begin(),unmapped_ids.end());
1018 if (!crosstalking_ids.empty()) {
1020 CrosstalkingState[PSUChannel]=
false;
1023 if (!CrosstalkingState[PSUChannel.substr(0,PSUChannel.size()-1)+
"2"] && !CrosstalkingState[PSUChannel.substr(0,PSUChannel.size()-1)+
"3"]) {
1024 OFFids.insert(OFFids.end(),crosstalking_ids.begin(),crosstalking_ids.end());
1026 std::cout<<
"Adding the unmapped detids corresponding to (HV1/2 cross-talking) PSU "<<PSUChannel.substr(0,PSUChannel.size()-10)<<
" to the list of detids turning OFF"<<std::endl;
1031 if (!unmapped_ids.empty()) {
1032 UnmappedState[PSUChannel]=
false;
1034 if (!OFFids.empty()) {
1043 detIdStruct.
detidV.push_back( std::make_pair(OFFids,psuStruct.
changeDate[dp]) );
1049 numHvBad.insert(numHvBad.end(),ids.begin(),ids.end());
1052 detIdStruct.
isHV.push_back(1);
1055 detIdStruct.
psuName.push_back( PSUChannel );
1072 detIdStruct.
detidV.push_back( std::make_pair(ids,psuStruct.
changeDate[dp]) );
1078 detIdStruct.
isHV.push_back(0);
1081 detIdStruct.
psuName.push_back( PSUChannel );
1087 std::vector<uint32_t> ONids;
1088 ONids.insert(ONids.end(),ids.begin(),ids.end());
1089 ONids.insert(ONids.end(),crosstalking_ids.begin(),crosstalking_ids.end());
1091 if (!unmapped_ids.empty()) {
1093 UnmappedState[PSUChannel]=
true;
1096 if (UnmappedState[PSUChannel.substr(0,PSUChannel.size()-1)+
"2"] && UnmappedState[PSUChannel.substr(0,PSUChannel.size()-1)+
"3"]) {
1097 ONids.insert(ONids.end(),unmapped_ids.begin(),unmapped_ids.end());
1099 std::cout<<
"Adding the detids corresponding to HV-unmapped PSU "<<PSUChannel.substr(0,PSUChannel.size()-10)<<
" to the list of detids turning ON"<<std::endl;
1104 if (!crosstalking_ids.empty()) {
1105 CrosstalkingState[PSUChannel]=
true;
1107 if (!ONids.empty()) {
1116 detIdStruct.
detidV.push_back( std::make_pair(ONids,psuStruct.
changeDate[dp]) );
1122 detIdStruct.
isHV.push_back(1);
1125 detIdStruct.
psuName.push_back( PSUChannel );
1138 std::ofstream ofsUnmapped(
"HVUnmappedChannelState.dat");
1139 for (std::map<std::string,bool>::iterator it=UnmappedState.begin(); it!=UnmappedState.end(); it++) {
1140 ofsUnmapped<<it->first<<
"\t"<<it->second<<std::endl;
1142 std::ofstream ofsCrosstalking(
"HVCrosstalkingChannelState.dat");
1143 for (std::map<std::string,bool>::iterator it=CrosstalkingState.begin(); it!=CrosstalkingState.end(); it++) {
1144 ofsCrosstalking<<it->first<<
"\t"<<it->second<<std::endl;
1153 std::cout <<
"Number of channels that turned OFF in this O2O interval"<<std::endl;
1154 std::cout <<
"Channel000 = " << ch0bad <<
" Channel001 = " << ch1bad << std::endl;
1155 std::cout <<
"Channel002 = " << ch2bad <<
" Channel003 = " << ch3bad << std::endl;
1156 std::cout <<
"Number of LV detIDs that turned OFF in this O2O interval = " << numLvBad.size() << std::endl;
1157 std::cout <<
"Number of HV detIDs that turned OFF in this O2O interval = " << numHvBad.size() << std::endl;
1160 LogTrace(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::" << __func__ <<
"]: Number of PSUs retrieved from DB with map information " << detIdStruct.
detidV.size();
1161 LogTrace(
"SiStripDetVOffBuilder") <<
"[SiStripDetVOffBuilder::" << __func__ <<
"]: Number of PSUs retrieved from DB with no map information " << detIdStruct.
notMatched;
1163 unsigned int dupCount = 0;
1164 for (
unsigned int t = 0;
t < numLvBad.size();
t++) {
1165 std::vector<unsigned int>::iterator
iter =
std::find(numHvBad.begin(),numHvBad.end(),numLvBad[
t]);
1166 if (iter != numHvBad.end()) {dupCount++;}
1168 if(
debug_ )
std::cout <<
"Number of channels for which LV & HV turned OFF in this O2O interval = " << dupCount << std::endl;
1174 std::vector<uint32_t> pStats(3,0);
1175 pStats.push_back(afterV);
1176 pStats.push_back(numAdded);
1177 pStats.push_back(numRemoved);
1184 int lv_off = -1, hv_off = -1;
1185 if (detIdStruct.
isHV[i] == 0) {lv_off = !(detIdStruct.
StatusGood[
i]);}
1186 if (detIdStruct.
isHV[i] == 1) {
1197 if (iChannel ==
"002" || iChannel ==
"003") {
1198 bool lastStatusOfOtherChannel =
true;
1199 for (
unsigned int j = 0;
j <
i;
j++) {
1202 if (iPsu == jPsu && iChannel != jChannel && (jChannel ==
"002" || jChannel ==
"003")) {
1204 lastStatusOfOtherChannel = detIdStruct.
StatusGood[
j];
1207 if (detIdStruct.
StatusGood[i] != lastStatusOfOtherChannel) {
1208 if(
debug_ )
cout <<
"turning off hv" << endl;
1219 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)
std::map< std::string, std::vector< uint32_t > > getHVCrosstalkingMap()
void printPar(std::stringstream &ss, const std::vector< int > &par)
void buildPSUdetIdMap(TimesAndValues &tStruct, DetIdListTimeAndStatus &dStruct)
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
std::map< std::string, std::vector< uint32_t > > getHVUnmappedMap()
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
int findSetting(uint32_t id, const coral::TimeStamp &changeDate, const std::vector< uint32_t > &settingID, const std::vector< coral::TimeStamp > &settingDate)
void removeDuplicates(std::vector< uint32_t > &vec)
std::vector< std::string > dpname
U second(std::pair< T, U > const &p)
bool FileExists(std::string filename)
unsigned long long Time_t
std::vector< uint32_t > dpid
std::string excludedDetIdListFile_
cond::Time_t getCondTime(const coral::TimeStamp &coralTime)
std::vector< bool > StatusGood
std::vector< coral::TimeStamp > changeDate
void getDetIds(std::vector< uint32_t > &DetIds_) const
std::vector< unsigned int > isHV
std::vector< uint32_t > getLvDetID(std::string psu)
void reduction(const uint32_t deltaTmin, const uint32_t maxIOVlength)
An interface class to the PVSS cond DB.
void lastValue(TimesAndValues &tStruct)
void getHvDetID(std::string psuchannel, std::vector< uint32_t > &ids, std::vector< uint32_t > &unmapped_ids, std::vector< uint32_t > &crosstalking_ids)
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)
cond::Time_t findMostRecentTimeStamp(const std::vector< coral::TimeStamp > &coralDate)
void lastValueFromFile(TimesAndValues &tStruct)
std::vector< int > tmax_par
coral::TimeStamp getCoralTime(cond::Time_t iovTime)
void setLastSiStripDetVOff(SiStripDetVOff *lastPayload, cond::Time_t lastTimeStamp)
void BuildMap(const std::string &mapFile, const bool debug)
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)
std::string onlineDbConnectionString