CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
SiPixelStatusManager Class Reference

#include <SiPixelStatusManager.h>

Public Types

typedef std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatus >::iterator siPixelStatusMap_iterator
 
typedef std::map< edm::LuminosityBlockNumber_t, std::map< int, std::vector< int > > >::iterator stuckTBMsMap_iterator
 

Public Member Functions

void createBadComponents ()
 
void createPayloads ()
 
void createStuckTBMs ()
 
const std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatus > & getBadComponents ()
 
const std::map< edm::LuminosityBlockNumber_t, std::map< int, std::vector< int > > > & getStuckTBMsRocs ()
 
void readLumi (const edm::LuminosityBlock &)
 
void reset ()
 
 SiPixelStatusManager ()
 
 SiPixelStatusManager (const edm::ParameterSet &, edm::ConsumesCollector &&)
 
virtual ~SiPixelStatusManager ()
 

Private Attributes

int aveDigiOcc_
 
std::string label_
 
std::string moduleName_
 
int nLumi_
 
std::string outputBase_
 
std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatussiPixelStatusMap_
 
edm::EDGetTokenT< SiPixelDetectorStatussiPixelStatusToken_
 
std::map< edm::LuminosityBlockNumber_t, std::map< int, std::vector< int > > > stuckTBMsMap_
 

Detailed Description

Author

helper class that set up IOV strcutre of SiPixelDetectorStatus

Author

Definition at line 22 of file SiPixelStatusManager.h.

Member Typedef Documentation

Definition at line 43 of file SiPixelStatusManager.h.

typedef std::map<edm::LuminosityBlockNumber_t,std::map<int, std::vector<int> > >::iterator SiPixelStatusManager::stuckTBMsMap_iterator

Definition at line 44 of file SiPixelStatusManager.h.

Constructor & Destructor Documentation

SiPixelStatusManager::SiPixelStatusManager ( )

Definition at line 21 of file SiPixelStatusManager.cc.

21  {
22 }
SiPixelStatusManager::SiPixelStatusManager ( const edm::ParameterSet iConfig,
edm::ConsumesCollector &&  iC 
)

Definition at line 25 of file SiPixelStatusManager.cc.

References edm::InLumi, label_, moduleName_, outputBase_, reset(), and siPixelStatusToken_.

25  :
26  outputBase_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters").getUntrackedParameter<std::string>("outputBase")),
27  aveDigiOcc_(iConfig.getParameter<edm::ParameterSet>("SiPixelStatusManagerParameters").getUntrackedParameter<int>("aveDigiOcc")),
28  nLumi_(iConfig.getParameter<edm::ParameterSet>("SiPixelStatusManagerParameters").getUntrackedParameter<int>("resetEveryNLumi")),
29  moduleName_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters").getUntrackedParameter<std::string>("moduleName")),
30  label_ (iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters").getUntrackedParameter<std::string>("label"))
31 {
32 
33  edm::InputTag siPixelStatusTag_(moduleName_, label_);
35 
36  LogInfo("SiPixelStatusManager")
37  << "Output base: " << outputBase_
38  << std::endl;
39  reset();
40 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< SiPixelDetectorStatus > siPixelStatusToken_
SiPixelStatusManager::~SiPixelStatusManager ( )
virtual

Definition at line 43 of file SiPixelStatusManager.cc.

43  {
44 }

Member Function Documentation

void SiPixelStatusManager::createBadComponents ( )

Definition at line 72 of file SiPixelStatusManager.cc.

References aveDigiOcc_, SiPixelDetectorStatus::end(), nLumi_, outputBase_, SiPixelDetectorStatus::perRocDigiOcc(), siPixelStatusMap_, and SiPixelDetectorStatus::updateDetectorStatus().

Referenced by createPayloads().

72  {
73 
74  siPixelStatusMap_iterator firstStatus = siPixelStatusMap_.begin();
76 
77  std::map<LuminosityBlockNumber_t,SiPixelDetectorStatus> tmpSiPixelStatusMap_;
78 
79  if(outputBase_ == "nLumibased" && nLumi_>1){ // doesn't work for nLumi_=1 cos any integer can be completely divided by 1
80 
81  // if the total number of Lumi Blocks can't be completely divided by nLumi_,
82  // the residual Lumi Blocks will be as the last IOV
83  int iterationLumi = 0;
84 
86  SiPixelDetectorStatus tmpSiPixelStatus;
87  for (siPixelStatusMap_iterator it = firstStatus; it != lastStatus; it++) {
88 
89  // this is the begining of an IOV
90  if(iterationLumi%nLumi_==0){
91  tmpLumi = it->first;
92  tmpSiPixelStatus = it->second;
93  }
94 
95  // keep update detector status up to nLumi_ lumi sections
96  if(iterationLumi%nLumi_>0){
97  tmpSiPixelStatus.updateDetectorStatus(it->second);
98  }
99 
100  siPixelStatusMap_iterator currentIt = it;
101  siPixelStatusMap_iterator nextIt = (++currentIt);
102  // wirte out if current lumi is the last lumi-section in the IOV
103  if(iterationLumi%nLumi_==nLumi_-1 || nextIt==lastStatus)
104  {
105  // fill it into a new map (with IOV structured)
106  tmpSiPixelStatusMap_[tmpLumi] = tmpSiPixelStatus;
107  }
108 
109  iterationLumi=iterationLumi+1;
110  }
111 
112  // check whether there is not enough number of Lumi in the last IOV
113  // (only when siPixelStatusMap_.size() > nLumi_ or equivalently tmpSiPixelStatusMap_.size()>1
114  // (otherwise there will be only one IOV, and not previous IOV before the last IOV)
115  // and the number of lumi can not be completely divided by the nLumi_.
116  // (then the number of lumis in the last IOV is equal to the residual, which is less than nLumi_)
117  // if it is, combine last IOV with the IOV before it
118  if(siPixelStatusMap_.size()%nLumi_!=0 && tmpSiPixelStatusMap_.size()>1){
119 
120  // start from the iterator of the end of std::map
121  siPixelStatusMap_iterator iterEnd = tmpSiPixelStatusMap_.end();
122  // the last IOV
123  siPixelStatusMap_iterator iterLastIOV = std::prev(iterEnd);
124  // the IOV before the last IOV
125  siPixelStatusMap_iterator iterBeforeLastIOV = std::prev(iterLastIOV);
126 
127  // combine the last IOV data to the IOV before the last IOV
128  (iterBeforeLastIOV->second).updateDetectorStatus(iterLastIOV->second);
129  // delete the last IOV, so the IOV before the last IOV becomes the new last IOV
130  tmpSiPixelStatusMap_.erase(iterLastIOV);
131 
132  }
133 
134  siPixelStatusMap_.clear();
135  siPixelStatusMap_ = tmpSiPixelStatusMap_;
136 
137  }
138  else if(outputBase_ == "dynamicLumibased"){
139 
140  double aveDigiOcc = 1.0*aveDigiOcc_;
141 
142  LuminosityBlockNumber_t tmpLumi;
143  SiPixelDetectorStatus tmpSiPixelStatus;
144  bool isNewIOV = true;
145 
146  int counter = 0;
147  for (siPixelStatusMap_iterator it = firstStatus; it != lastStatus; it++) {
148 
149  if(isNewIOV){ // if it is new IOV, init with the current data
150  tmpLumi = it->first;
151  tmpSiPixelStatus = it->second;
152  }
153  else{ // if it is not new IOV, append current data
154  tmpSiPixelStatus.updateDetectorStatus(it->second);
155  }
156 
157  // if reaching the end of data, write the last IOV to the map whatsoevec
158  siPixelStatusMap_iterator currentIt = it;
159  siPixelStatusMap_iterator nextIt = (++currentIt);
160  if(tmpSiPixelStatus.perRocDigiOcc()<aveDigiOcc && nextIt!=lastStatus){
161  isNewIOV = false; // if digi occ is not enough, next data will not belong to new IOV
162  }
163  else{ // if (accunumated) digi occ is enough, write the data to the map
164  isNewIOV = true;
165  tmpSiPixelStatusMap_[tmpLumi]=tmpSiPixelStatus;
166  // so next loop is the begining of a new IOV
167  }
168  counter++;
169 
170  } // end of siPixelStatusMap
171 
172  // check whether last IOV has enough statistics
173  // (ONLY when there are more than oneIOV(otherwise there is NO previous IOV before the last IOV) )
174  // if not, combine with previous IOV
175  if(tmpSiPixelStatusMap_.size()>1){
176 
177  // start from the end iterator of the std::map
178  siPixelStatusMap_iterator iterEnd = tmpSiPixelStatusMap_.end();
179  // the last IOV
180  siPixelStatusMap_iterator iterLastIOV = std::prev(iterEnd);
181  // if the statistics of the last IOV is not enough
182  if((iterLastIOV->second).perRocDigiOcc()<aveDigiOcc){
183  // the IOV before the last IOV of the map
184  siPixelStatusMap_iterator iterBeforeLastIOV = std::prev(iterLastIOV);
185  // combine the last IOV data to the IOV before the last IOV
186  (iterBeforeLastIOV->second).updateDetectorStatus(iterLastIOV->second);
187  // erase the last IOV, so the IOV before the last IOV becomes the new last IOV
188  tmpSiPixelStatusMap_.erase(iterLastIOV);
189  }
190 
191  }
192 
193  siPixelStatusMap_.clear();
194  siPixelStatusMap_ = tmpSiPixelStatusMap_;
195 
196  }
197  else if(outputBase_ == "runbased" || ( (int(siPixelStatusMap_.size()) <= nLumi_ && outputBase_ == "nLumibased")) ){
198 
199  siPixelStatusMap_iterator firstStatus = siPixelStatusMap_.begin();
200  siPixelStatusMap_iterator lastStatus = siPixelStatusMap_.end();
201 
202  LuminosityBlockNumber_t tmpLumi = firstStatus->first;
203  SiPixelDetectorStatus tmpSiPixelStatus = firstStatus->second;
204 
205  siPixelStatusMap_iterator nextStatus = ++siPixelStatusMap_.begin();
206  for (siPixelStatusMap_iterator it = nextStatus; it != lastStatus; it++) {
207  tmpSiPixelStatus.updateDetectorStatus(it->second);
208  }
209 
210  siPixelStatusMap_.clear();
211  siPixelStatusMap_[tmpLumi] = tmpSiPixelStatus;
212 
213  }
214  else{
215  LogInfo("SiPixelStatusManager")
216  << "Unrecognized payload outputBase parameter: " << outputBase_
217  << endl;
218  }
219 
220 
221 }
void updateDetectorStatus(SiPixelDetectorStatus newData)
unsigned int LuminosityBlockNumber_t
std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatus > siPixelStatusMap_
std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatus >::iterator siPixelStatusMap_iterator
void SiPixelStatusManager::createPayloads ( )
inline
void SiPixelStatusManager::createStuckTBMs ( )

Definition at line 224 of file SiPixelStatusManager.cc.

References SiPixelDetectorStatus::begin(), SiPixelDetectorStatus::end(), SiPixelDetectorStatus::getStuckTBMsRocs(), siPixelStatusMap_, and stuckTBMsMap_.

Referenced by createPayloads().

224  {
225 
226  // initialize the first IOV and SiPixelDetector status (in the first IOV)
227  siPixelStatusMap_iterator firstStatus = siPixelStatusMap_.begin();
228  LuminosityBlockNumber_t firstLumi = firstStatus->first;
229  SiPixelDetectorStatus firstStuckTBMs = firstStatus->second;
230  stuckTBMsMap_[firstLumi] = firstStuckTBMs.getStuckTBMsRocs();
231 
232  siPixelStatusMap_iterator lastStatus = siPixelStatusMap_.end();
233 
235  bool sameAsLastIOV = true;
236  LuminosityBlockNumber_t previousLumi = firstLumi;
237  siPixelStatusMap_iterator secondStatus = ++siPixelStatusMap_.begin();
238  for (siPixelStatusMap_iterator it = secondStatus; it != lastStatus; it++) {
239 
240  LuminosityBlockNumber_t tmpLumi = it->first;
241  SiPixelDetectorStatus tmpStuckTBMs = it->second;
242  std::map<int,std::vector<int> >tmpBadRocLists = tmpStuckTBMs.getStuckTBMsRocs();
243 
244  std::map<int, SiPixelModuleStatus>::iterator itModEnd = tmpStuckTBMs.end();
245  for (std::map<int, SiPixelModuleStatus>::iterator itMod = tmpStuckTBMs.begin(); itMod != itModEnd; ++itMod)
246  {
247  int detid = itMod->first;
248  // if the badroc list differs for any detid, update the payload
249  if(tmpBadRocLists[detid]!=(stuckTBMsMap_[previousLumi])[detid]){
250  sameAsLastIOV = false;
251  return;
252  }
253  }
254 
255  if(sameAsLastIOV==false){
256  //only write new IOV when this Lumi is not equal to the previous one
257 
258  stuckTBMsMap_[tmpLumi] = tmpBadRocLists;
259  previousLumi = tmpLumi;
260 
261  }
262 
263  }
264 
265 }
unsigned int LuminosityBlockNumber_t
std::map< edm::LuminosityBlockNumber_t, std::map< int, std::vector< int > > > stuckTBMsMap_
std::map< int, std::vector< int > > getStuckTBMsRocs()
std::map< int, SiPixelModuleStatus >::iterator begin()
std::map< int, SiPixelModuleStatus >::iterator end()
std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatus > siPixelStatusMap_
std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatus >::iterator siPixelStatusMap_iterator
const std::map<edm::LuminosityBlockNumber_t,SiPixelDetectorStatus>& SiPixelStatusManager::getBadComponents ( )
inline

Definition at line 40 of file SiPixelStatusManager.h.

References siPixelStatusMap_.

Referenced by SiPixelStatusHarvester::endRun().

40 {return siPixelStatusMap_; }
std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatus > siPixelStatusMap_
const std::map<edm::LuminosityBlockNumber_t,std::map<int, std::vector<int> > >& SiPixelStatusManager::getStuckTBMsRocs ( )
inline

Definition at line 41 of file SiPixelStatusManager.h.

References stuckTBMsMap_.

Referenced by SiPixelStatusHarvester::endRun().

41 {return stuckTBMsMap_;}
std::map< edm::LuminosityBlockNumber_t, std::map< int, std::vector< int > > > stuckTBMsMap_
void SiPixelStatusManager::readLumi ( const edm::LuminosityBlock iLumi)

Definition at line 52 of file SiPixelStatusManager.cc.

References edm::LuminosityBlock::getByToken(), edm::HandleBase::isValid(), edm::LuminosityBlockBase::luminosityBlock(), siPixelStatusMap_, and siPixelStatusToken_.

Referenced by SiPixelStatusHarvester::endLuminosityBlock().

52  {
53 
54  edm::Handle<SiPixelDetectorStatus> siPixelStatusHandle;
55  iLumi.getByToken(siPixelStatusToken_, siPixelStatusHandle);
56 
57  if(siPixelStatusHandle.isValid()) { // check the product
58  siPixelStatusMap_[iLumi.luminosityBlock()] = *siPixelStatusHandle;
59  }
60  else {
61  LogInfo("SiPixelStatusManager")
62  << "Lumi: " << iLumi.luminosityBlock() << std::endl;
63  LogInfo("SiPixelStatusManager")
64  << " SiPixelDetectorStatus is not valid!" << std::endl;
65  }
66 
67 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::EDGetTokenT< SiPixelDetectorStatus > siPixelStatusToken_
LuminosityBlockNumber_t luminosityBlock() const
bool isValid() const
Definition: HandleBase.h:74
std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatus > siPixelStatusMap_
void SiPixelStatusManager::reset ( void  )

Definition at line 47 of file SiPixelStatusManager.cc.

References siPixelStatusMap_.

Referenced by MatrixReader.MatrixReader::__init__(), SiPixelStatusHarvester::beginRun(), data_sources.json_list::next(), MatrixReader.MatrixReader::showRaw(), and SiPixelStatusManager().

47  {
48  siPixelStatusMap_.clear();
49 }
std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatus > siPixelStatusMap_

Member Data Documentation

int SiPixelStatusManager::aveDigiOcc_
private

Definition at line 52 of file SiPixelStatusManager.h.

Referenced by createBadComponents().

std::string SiPixelStatusManager::label_
private
std::string SiPixelStatusManager::moduleName_
private

Definition at line 54 of file SiPixelStatusManager.h.

Referenced by SiPixelStatusManager().

int SiPixelStatusManager::nLumi_
private

Definition at line 53 of file SiPixelStatusManager.h.

Referenced by createBadComponents().

std::string SiPixelStatusManager::outputBase_
private

Definition at line 51 of file SiPixelStatusManager.h.

Referenced by createBadComponents(), and SiPixelStatusManager().

std::map<edm::LuminosityBlockNumber_t, SiPixelDetectorStatus> SiPixelStatusManager::siPixelStatusMap_
private
edm::EDGetTokenT<SiPixelDetectorStatus> SiPixelStatusManager::siPixelStatusToken_
private

Definition at line 57 of file SiPixelStatusManager.h.

Referenced by readLumi(), and SiPixelStatusManager().

std::map<edm::LuminosityBlockNumber_t, std::map<int, std::vector<int> > > SiPixelStatusManager::stuckTBMsMap_
private

Definition at line 49 of file SiPixelStatusManager.h.

Referenced by createStuckTBMs(), and getStuckTBMsRocs().