00001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00002 #include "CondFormats/SiStripObjects/interface/SiStripPerformanceSummary.h"
00003
00004
00005 SiStripPerformanceSummary::SiStripPerformanceSummary(): runNr_(0), timeValue_(0){}
00006 SiStripPerformanceSummary::~SiStripPerformanceSummary(){ edm::LogInfo("Destructor")<<" SiStripPerformanceSummary destructor called."; }
00007
00008
00009 SiStripPerformanceSummary::SiStripPerformanceSummary(const SiStripPerformanceSummary& rhs){
00010 runNr_ = rhs.getRunNr();
00011 timeValue_ = rhs.getTimeValue();
00012 vDetSummary_ = rhs.getWholeSummary();
00013 }
00014
00015
00016 std::pair<bool, std::vector<SiStripPerformanceSummary::DetSummary>::iterator> SiStripPerformanceSummary::setDet(const uint32_t input_detid, const std::vector<float>& input_values){
00017 std::vector<DetSummary>::iterator ivDet = vDetSummary_.end();
00018
00019 if(input_values.size() != kDetSummarySize) {
00020 edm::LogError("FillError")<<"wrong input size "<<input_values.size()<<". Can only add "<<kDetSummarySize<<" values. Not adding to SiStripPerformanceSummary";
00021 return std::make_pair(false, ivDet);
00022 }
00023
00024 ivDet = std::lower_bound(vDetSummary_.begin(),vDetSummary_.end(),input_detid,SiStripPerformanceSummary::StrictWeakOrdering());
00025 if (ivDet!=vDetSummary_.end() && ivDet->detId==input_detid){
00026 return std::make_pair(false, ivDet);
00027 }
00028
00029 DetSummary detSummary;
00030 detSummary.detId=input_detid;
00031 detSummary.performanceValues = input_values;
00032
00033 return std::make_pair(true, vDetSummary_.insert(ivDet, detSummary));
00034 }
00035
00036
00037 std::pair<bool, std::vector<SiStripPerformanceSummary::DetSummary>::iterator> SiStripPerformanceSummary::initDet(const uint32_t input_detid){
00038 std::vector<float> input_values; for(int i = 0; i<kDetSummarySize; ++i) input_values.push_back(kNonsenseValue);
00039 return setDet(input_detid, input_values);
00040 }
00041
00042
00043 bool SiStripPerformanceSummary::setTwoValues(uint32_t input_detid, float val1, float val2, int index1, int index2){
00044 if(index1>kDetSummarySize || index2>kDetSummarySize){
00045 edm::LogError("SetError")<<" Could not set values for such indeces index1="<<index1<<" index2="<<index2<<" Maximum index is "<<kDetSummarySize;
00046 return false;
00047 }
00048 std::pair<bool, std::vector<DetSummary>::iterator> init_result = initDet(input_detid);
00049 if (init_result.first == true || init_result.second != vDetSummary_.end() ){
00050 init_result.second->performanceValues[index1] = val1;
00051 init_result.second->performanceValues[index2] = val2;
00052 return true;
00053 }else{
00054 edm::LogError("SetError")<<" Could not set values, new entry could not be created for detid="<<input_detid;
00055 return false;
00056 }
00057 return true;
00058 }
00059
00060
00061 bool SiStripPerformanceSummary::setOneValue(uint32_t input_detid, float val1, int index1){
00062 if(index1>kDetSummarySize){
00063 edm::LogError("SetError")<<" Could not set values for such index index1="<<index1<<" Maximum index is "<<kDetSummarySize;
00064 return false;
00065 }
00066 std::pair<bool, std::vector<DetSummary>::iterator> init_result = initDet(input_detid);
00067 if (init_result.first == true || init_result.second != vDetSummary_.end() ){
00068 init_result.second->performanceValues[index1] = val1;
00069 return true;
00070 }else{
00071 edm::LogError("SetError")<<" Could not set values, new entry could not be created for detid="<<input_detid;
00072 return false;
00073 }
00074 return true;
00075 }
00076
00077
00078 float SiStripPerformanceSummary::getOneValue(uint32_t input_detid, int index1){
00079 if(index1>kDetSummarySize){
00080 edm::LogError("GetError")<<" Could not get values for such index index1="<<index1<<" Maximum index is "<<kDetSummarySize;
00081 return kNonsenseValue;
00082 }
00083 std::vector<float> voutput; voutput.clear();
00084 getSummary(input_detid, voutput);
00085 if(voutput.size()==kDetSummarySize){
00086 return voutput[index1];
00087 }else{
00088 return kNonsenseValue;
00089 }
00090 }
00091
00092
00093 void SiStripPerformanceSummary::getDetIds(std::vector<uint32_t>& vdetids) const {
00094 std::vector<DetSummary>::const_iterator begin = vDetSummary_.begin();
00095 std::vector<DetSummary>::const_iterator end = vDetSummary_.end();
00096 for (std::vector<DetSummary>::const_iterator perf=begin; perf != end; ++perf) {
00097 vdetids.push_back(perf->detId);
00098 }
00099 }
00100
00101
00102 void SiStripPerformanceSummary::print() const{
00103 edm::LogInfo("print")<<"Nr. of elements in SiStripPerformanceSummary object is "<< vDetSummary_.size()<<" RunNr="<<runNr_<<" timeValue="<<timeValue_<<std::endl;
00104 }
00105
00106
00107 void SiStripPerformanceSummary::print(const uint32_t input_detid) const{
00108 DetSummary dummy; dummy.detId = input_detid;
00109 std::vector<DetSummary>::const_iterator ivDet = std::find_if(vDetSummary_.begin(),vDetSummary_.end(), MatchDetSummaryDetId(input_detid));
00110 if( ivDet==vDetSummary_.end() ){
00111 edm::LogError("print")<<"Cannot find any DetSummary for DetId="<<input_detid;
00112 }else{
00113 edm::LogInfo("print")<<"Input detid="<<input_detid<<" DetSummary for DetId="<<ivDet->detId;
00114 print(ivDet->performanceValues);
00115 }
00116 }
00117
00118
00119 void SiStripPerformanceSummary::getSummary(const uint32_t input_detid, std::vector<float>& voutput) const{
00120 DetSummary dummy; dummy.detId = input_detid;
00121 std::vector<DetSummary>::const_iterator ivDet = std::find_if(vDetSummary_.begin(),vDetSummary_.end(), MatchDetSummaryDetId(input_detid));
00122 if( ivDet==vDetSummary_.end() ){
00123 edm::LogError("get")<<"Cannot find any DetSummary for DetId="<<input_detid;
00124 }else{
00125 voutput = ivDet->performanceValues;
00126 }
00127 }
00128
00129
00130 void SiStripPerformanceSummary::printall() const{
00131 print();
00132 std::vector<DetSummary>::const_iterator begin = vDetSummary_.begin();
00133 std::vector<DetSummary>::const_iterator end = vDetSummary_.end();
00134 for (std::vector<DetSummary>::const_iterator perf=begin; perf != end; ++perf) {
00135 std::cout<<" detid = "<<perf->detId;
00136 print(perf->performanceValues);
00137 }
00138 }
00139
00140
00141 void SiStripPerformanceSummary::print(const std::vector<float>& pvec) const{
00142 for(std::vector<float>::const_iterator ip = pvec.begin(); ip != pvec.end(); ++ip) std::cout<<" "<<*ip;
00143 std::cout<<std::endl;
00144 }
00145