CMS 3D CMS Logo

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

#include <SiPixelStatusManager.h>

Public Types

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

Public Member Functions

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

Private Member Functions

void createBadComponents ()
 
void createFEDerror25 ()
 

Static Private Member Functions

static bool rankByLumi (SiPixelDetectorStatus status1, SiPixelDetectorStatus status2)
 

Private Attributes

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

Detailed Description

Author

helper class that set up IOV strcutre of SiPixelDetectorStatus

Author

Definition at line 24 of file SiPixelStatusManager.h.

Member Typedef Documentation

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

Definition at line 40 of file SiPixelStatusManager.h.

Definition at line 39 of file SiPixelStatusManager.h.

Definition at line 41 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 ( )
private

Definition at line 89 of file SiPixelStatusManager.cc.

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

Referenced by createPayloads().

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

Definition at line 237 of file SiPixelStatusManager.cc.

References FEDerror25Map_, SiPixelDetectorStatus::getFEDerror25Rocs(), and siPixelStatusVtr_.

Referenced by createPayloads().

237  {
238 
239  // initialize the first IOV and SiPixelDetector status (in the first IOV)
240  siPixelStatusVtr_iterator firstStatus = siPixelStatusVtr_.begin();
241  edm::LuminosityBlockNumber_t firstLumi = edm::LuminosityBlockNumber_t(firstStatus->getLSRange().first);
242  SiPixelDetectorStatus firstFEDerror25 = (*firstStatus);
243  FEDerror25Map_[firstLumi] = firstFEDerror25.getFEDerror25Rocs();
244 
245  siPixelStatusVtr_iterator lastStatus = siPixelStatusVtr_.end();
246 
248  bool sameAsLastIOV = true;
249  edm::LuminosityBlockNumber_t previousLumi = firstLumi;
250 
251  siPixelStatusVtr_iterator secondStatus = ++siPixelStatusVtr_.begin();
252  for (siPixelStatusVtr_iterator it = secondStatus; it != lastStatus; it++) {
253  // init for each lumi section (iterator)
254  edm::LuminosityBlockNumber_t tmpLumi = edm::LuminosityBlockNumber_t(it->getLSRange().first);
255  SiPixelDetectorStatus tmpFEDerror25 = (*it);
256 
257  std::map<int,std::vector<int> >tmpBadRocLists = tmpFEDerror25.getFEDerror25Rocs();
258 
259  std::map<int, SiPixelModuleStatus>::iterator itModEnd = tmpFEDerror25.end();
260  for (std::map<int, SiPixelModuleStatus>::iterator itMod = tmpFEDerror25.begin(); itMod != itModEnd; ++itMod)
261  {
262  int detid = itMod->first;
263  // if the badroc list differs for any detid, update the payload
264  if(tmpBadRocLists[detid]!=(FEDerror25Map_[previousLumi])[detid]){
265  sameAsLastIOV = false;
266  break; // jump out of the loop once a new payload is found
267  }
268  }
269 
270  if(sameAsLastIOV==false){
271  //only write new IOV when this Lumi is not equal to the previous one
272  FEDerror25Map_[tmpLumi] = tmpBadRocLists;
273  // and reset
274  previousLumi = tmpLumi;
275  sameAsLastIOV = true;
276 
277  }
278 
279  }
280 
281 }
std::map< int, std::vector< int > > getFEDerror25Rocs()
unsigned int LuminosityBlockNumber_t
std::vector< SiPixelDetectorStatus >::iterator siPixelStatusVtr_iterator
std::map< edm::LuminosityBlockNumber_t, std::map< int, std::vector< int > > > FEDerror25Map_
std::vector< SiPixelDetectorStatus > siPixelStatusVtr_
void SiPixelStatusManager::createPayloads ( )

Definition at line 57 of file SiPixelStatusManager.cc.

References createBadComponents(), createFEDerror25(), rankByLumi(), and siPixelStatusVtr_.

Referenced by SiPixelStatusHarvester::endRun().

57  {
58  // sort the vector according to lumi
60 
61  // create FEDerror25 ROCs and bad ROCs from PCL
64 
65  // realse the cost of siPixelStatusVtr_ since it is not needed anymore
66  siPixelStatusVtr_.clear();
67 }
std::vector< SiPixelDetectorStatus > siPixelStatusVtr_
static bool rankByLumi(SiPixelDetectorStatus status1, SiPixelDetectorStatus status2)
const std::map<edm::LuminosityBlockNumber_t,SiPixelDetectorStatus>& SiPixelStatusManager::getBadComponents ( )
inline

Definition at line 36 of file SiPixelStatusManager.h.

References siPixelStatusMap_.

Referenced by SiPixelStatusHarvester::endRun().

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

Definition at line 37 of file SiPixelStatusManager.h.

References FEDerror25Map_.

Referenced by SiPixelStatusHarvester::endRun().

37 {return FEDerror25Map_;}
std::map< edm::LuminosityBlockNumber_t, std::map< int, std::vector< int > > > FEDerror25Map_
bool SiPixelStatusManager::rankByLumi ( SiPixelDetectorStatus  status1,
SiPixelDetectorStatus  status2 
)
staticprivate

Definition at line 53 of file SiPixelStatusManager.cc.

References SiPixelDetectorStatus::getLSRange().

Referenced by createPayloads().

54 { return (status1.getLSRange().first < status2.getLSRange().first); }
std::pair< int, int > getLSRange()
void SiPixelStatusManager::readLumi ( const edm::LuminosityBlock iLumi)

Definition at line 70 of file SiPixelStatusManager.cc.

References SiPixelDetectorStatus::digiOccDET(), edm::LuminosityBlock::getByToken(), edm::HandleBase::isValid(), edm::LuminosityBlockBase::luminosityBlock(), edm::LuminosityBlockBase::run(), siPixelStatusToken_, and siPixelStatusVtr_.

Referenced by SiPixelStatusHarvester::endLuminosityBlock().

70  {
71 
72  edm::Handle<SiPixelDetectorStatus> siPixelStatusHandle;
73  iLumi.getByToken(siPixelStatusToken_, siPixelStatusHandle);
74 
75  if(siPixelStatusHandle.isValid()) { // check the product
76  SiPixelDetectorStatus tmpStatus = (*siPixelStatusHandle);
77  if(tmpStatus.digiOccDET()>0){ // only put in SiPixelDetectorStatus with non zero digi (pixel hit)
78  siPixelStatusVtr_.push_back(tmpStatus);
79  }
80  }
81  else {
82  edm::LogWarning("SiPixelStatusManager")
83  << " SiPixelDetectorStatus is not valid for run "<<iLumi.run()<<" lumi "<<iLumi.luminosityBlock()<< std::endl;
84  }
85 
86 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
unsigned long int digiOccDET()
edm::EDGetTokenT< SiPixelDetectorStatus > siPixelStatusToken_
LuminosityBlockNumber_t luminosityBlock() const
RunNumber_t run() const
bool isValid() const
Definition: HandleBase.h:74
std::vector< SiPixelDetectorStatus > siPixelStatusVtr_
void SiPixelStatusManager::reset ( void  )

Definition at line 47 of file SiPixelStatusManager.cc.

References siPixelStatusMap_, and siPixelStatusVtr_.

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

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

Member Data Documentation

int SiPixelStatusManager::aveDigiOcc_
private

Definition at line 54 of file SiPixelStatusManager.h.

Referenced by createBadComponents().

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

Definition at line 51 of file SiPixelStatusManager.h.

Referenced by createFEDerror25(), and getFEDerror25Rocs().

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

Definition at line 56 of file SiPixelStatusManager.h.

Referenced by SiPixelStatusManager().

int SiPixelStatusManager::nLumi_
private

Definition at line 55 of file SiPixelStatusManager.h.

Referenced by createBadComponents().

std::string SiPixelStatusManager::outputBase_
private

Definition at line 53 of file SiPixelStatusManager.h.

Referenced by createBadComponents(), and SiPixelStatusManager().

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

Definition at line 50 of file SiPixelStatusManager.h.

Referenced by createBadComponents(), getBadComponents(), and reset().

edm::EDGetTokenT<SiPixelDetectorStatus> SiPixelStatusManager::siPixelStatusToken_
private

Definition at line 59 of file SiPixelStatusManager.h.

Referenced by readLumi(), and SiPixelStatusManager().

std::vector<SiPixelDetectorStatus> SiPixelStatusManager::siPixelStatusVtr_
private