Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:47:47

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  $Date: 2010/04/02 14:10:27 $
0005  *  $Revision: 1.3 $
0006  *  \author Paolo Ronchese INFN Padova
0007  *
0008  */
0009 
0010 //-----------------------
0011 // This Class' Header --
0012 //-----------------------
0013 #include "CondTools/DT/plugins/DTHVCheckWithHysteresis.h"
0014 
0015 //-------------------------------
0016 // Collaborating Class Headers --
0017 //-------------------------------
0018 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0019 #include "FWCore/PluginManager/interface/ModuleDef.h"
0020 #include "FWCore/ServiceRegistry/interface/ServiceMaker.h"
0021 
0022 //---------------
0023 // C++ Headers --
0024 //---------------
0025 #include <iostream>
0026 
0027 namespace cond {
0028   namespace service {
0029 
0030     //-------------------
0031     // Initializations --
0032     //-------------------
0033 
0034     //----------------
0035     // Constructors --
0036     //----------------
0037     DTHVCheckWithHysteresis::DTHVCheckWithHysteresis(const edm::ParameterSet& iConfig, edm::ActivityRegistry& iAR) {
0038       if (instance == nullptr) {
0039         std::cout << "create DTHVCheckWithHysteresis" << std::endl;
0040         minHVl = new float[4];
0041         minHVh = new float[4];
0042         maxHV = new float[4];
0043         minHVl[0] = 3000.0;
0044         minHVl[1] = 3000.0;
0045         minHVl[2] = 1200.0;
0046         minHVl[3] = 600.0;
0047         minHVh[0] = 3500.0;
0048         minHVh[1] = 3500.0;
0049         minHVh[2] = 1700.0;
0050         minHVh[3] = 1100.0;
0051         maxHV[0] = 4000.0;
0052         maxHV[1] = 4000.0;
0053         maxHV[2] = 2200.0;
0054         maxHV[3] = 1600.0;
0055         maxCurrent = 30.0;
0056         oldStatusA = new std::map<int, int>;
0057         oldStatusC = new std::map<int, int>;
0058         oldStatusS = new std::map<int, int>;
0059         instance = this;
0060       }
0061     }
0062 
0063     //--------------
0064     // Destructor --
0065     //--------------
0066     DTHVCheckWithHysteresis::~DTHVCheckWithHysteresis() {}
0067 
0068     //--------------
0069     // Operations --
0070     //--------------
0071     //int DTHVCheckWithHysteresis::checkCurrentStatus(
0072     DTHVAbstractCheck::flag DTHVCheckWithHysteresis::checkCurrentStatus(
0073         int rawId,
0074         int type,
0075         float valueA,
0076         float valueC,
0077         float valueS,
0078         const std::map<int, timedMeasurement>& snapshotValues,
0079         const std::map<int, int>& aliasMap,
0080         const std::map<int, int>& layerMap) {
0081       // find all values for this channel
0082       //  ind dpid = 0;
0083       //  std::map<int,int>::const_iterator lpartIter;
0084       //  std::map<int,int>::const_iterator lpartIend = layerMap.end();
0085       //  if ( ( layerIter = layerMap.find( chp0 ) ) != layerIend )
0086       //      dpid = layerIter.second;
0087       //  std::map<int,timedMeasurement>::const_iterator snapIter;
0088       //  std::map<int,timedMeasurement>::const_iterator snapIend =
0089       //                                                 snapshotValues.end();
0090       //  float val1 = -999999.0;
0091       //  float val2 = -999999.0;
0092       //  int chan = dpId * 10;
0093       //  if ( ( snapIter = snapshotValues.find( chan + 1 ) ) != snapIend )
0094       //      val1 = snapIter->second.second;
0095       //  if ( ( snapIter = snapshotValues.find( chan + 2 ) ) != snapIend )
0096       //      val2 = snapIter->second.second;
0097 
0098       // find dp identifier for all channels in this layer
0099       //  DTLayerId lay = chlId.layerId();
0100       //  int chp0 = DTWireId( lay, 10 ).rawId();
0101       //  int chp1 = DTWireId( lay, 11 ).rawId();
0102       //  int chp2 = DTWireId( lay, 12 ).rawId();
0103       //  int chp3 = DTWireId( lay, 13 ).rawId();
0104       //  ind dpi0 = 0;
0105       //  ind dpi1 = 0;
0106       //  ind dpi2 = 0;
0107       //  ind dpi3 = 0;
0108       //  std::map<int,int>::const_iterator layerIter;
0109       //  std::map<int,int>::const_iterator layerIend = layerMap.end();
0110       //  if ( ( layerIter = layerMap.find( chp0 ) ) != layerIend )
0111       //      dpi0 = layerIter.second;
0112       //  if ( ( layerIter = layerMap.find( chp1 ) ) != layerIend )
0113       //      dpi1 = layerIter.second;
0114       //  if ( ( layerIter = layerMap.find( chp2 ) ) != layerIend )
0115       //      dpi2 = layerIter.second;
0116       //  if ( ( layerIter = layerMap.find( chp3 ) ) != layerIend )
0117       //      dpi3 = layerIter.second;
0118 
0119       float minHV[4];
0120       //  DTLayerId lay = chlId.layerId();
0121       //  int chp0 = DTWireId( lay, 10 ).rawId();
0122       //  int chp1 = DTWireId( lay, 11 ).rawId();
0123       //  int chp2 = DTWireId( lay, 12 ).rawId();
0124       //  int chp3 = DTWireId( lay, 13 ).rawId();
0125 
0126       DTWireId chlId(rawId);
0127       int part = chlId.wire() - 10;
0128       DTHVAbstractCheck::flag flag;
0129       flag.a = flag.c = flag.s = 0;
0130 
0131       std::map<int, int>::iterator chanIter;
0132       if (((chanIter = oldStatusA->find(rawId)) != oldStatusA->end()) && (chanIter->second % 2))
0133         minHV[part] = minHVh[part];
0134       else
0135         minHV[part] = minHVl[part];
0136       if (((chanIter = oldStatusS->find(rawId)) != oldStatusS->end()) && (chanIter->second % 2))
0137         minHV[2] = minHVh[2];
0138       else
0139         minHV[2] = minHVl[2];
0140       if (((chanIter = oldStatusC->find(rawId)) != oldStatusC->end()) && (chanIter->second % 2))
0141         minHV[3] = minHVh[3];
0142       else
0143         minHV[3] = minHVl[3];
0144 
0145       if (type == 1) {
0146         if (valueA < minHV[part])
0147           flag.a = 1;
0148         if (valueA > maxHV[part])
0149           flag.a = 2;
0150         if (valueS < minHV[2])
0151           flag.s = 1;
0152         if (valueS > maxHV[2])
0153           flag.s = 2;
0154         if (valueC < minHV[3])
0155           flag.c = 1;
0156         if (valueC > maxHV[3])
0157           flag.c = 2;
0158         if ((chanIter = oldStatusA->find(rawId)) == oldStatusA->end())
0159           oldStatusA->insert(std::pair<int, int>(rawId, flag.a));
0160         else
0161           chanIter->second = flag.a;
0162         if ((chanIter = oldStatusC->find(rawId)) == oldStatusC->end())
0163           oldStatusC->insert(std::pair<int, int>(rawId, flag.c));
0164         else
0165           chanIter->second = flag.c;
0166         if ((chanIter = oldStatusS->find(rawId)) == oldStatusS->end())
0167           oldStatusS->insert(std::pair<int, int>(rawId, flag.s));
0168         else
0169           chanIter->second = flag.s;
0170       }
0171       if (type == 2) {
0172         float voltA = 0.0;
0173         float voltS = 0.0;
0174         float voltC = 0.0;
0175         DTLayerId lay = chlId.layerId();
0176         int l_p = chlId.wire();
0177         DTWireId chA(lay, l_p);
0178         DTWireId chS(lay, 12);
0179         DTWireId chC(lay, 13);
0180 
0181         std::map<int, int>::const_iterator layerIter;
0182         std::map<int, int>::const_iterator layerIend = layerMap.end();
0183         std::map<int, timedMeasurement>::const_iterator snapIter;
0184         std::map<int, timedMeasurement>::const_iterator snapIend = snapshotValues.end();
0185         int chan;
0186         if ((layerIter = layerMap.find(chA.rawId())) != layerIend) {
0187           chan = (layerIter->second * 10) + l_p;
0188           if ((snapIter = snapshotValues.find(chan)) != snapIend) {
0189             voltA = snapIter->second.second;
0190           }
0191         }
0192         if ((layerIter = layerMap.find(chS.rawId())) != layerIend) {
0193           chan = (layerIter->second * 10) + 2;
0194           if ((snapIter = snapshotValues.find(chan)) != snapIend) {
0195             voltS = snapIter->second.second;
0196           }
0197         }
0198         if ((layerIter = layerMap.find(chC.rawId())) != layerIend) {
0199           chan = (layerIter->second * 10) + 3;
0200           if ((snapIter = snapshotValues.find(chan)) != snapIend) {
0201             voltC = snapIter->second.second;
0202           }
0203         }
0204         if ((valueA > maxCurrent) && (voltA >= minHV[part]))
0205           flag.a = 4;
0206         if ((valueS > maxCurrent) && (voltS >= minHV[2]))
0207           flag.s = 4;
0208         if ((valueC > maxCurrent) && (voltC >= minHV[3]))
0209           flag.c = 4;
0210       }
0211 
0212       return flag;
0213     }
0214 
0215     void DTHVCheckWithHysteresis::setStatus(int rawId,
0216                                             int flagA,
0217                                             int flagC,
0218                                             int flagS,
0219                                             const std::map<int, timedMeasurement>& snapshotValues,
0220                                             const std::map<int, int>& aliasMap,
0221                                             const std::map<int, int>& layerMap) {
0222       //  std::cout << "set status " << rawId << " "
0223       //            << flagA << " " << flagC << " " << flagS << std::endl;
0224       std::map<int, int>::iterator chanIter;
0225       if ((chanIter = oldStatusA->find(rawId)) == oldStatusA->end())
0226         oldStatusA->insert(std::pair<int, int>(rawId, flagA));
0227       else
0228         chanIter->second = flagA;
0229       if ((chanIter = oldStatusC->find(rawId)) == oldStatusA->end())
0230         oldStatusC->insert(std::pair<int, int>(rawId, flagC));
0231       else
0232         chanIter->second = flagC;
0233       if ((chanIter = oldStatusS->find(rawId)) == oldStatusA->end())
0234         oldStatusS->insert(std::pair<int, int>(rawId, flagS));
0235       else
0236         chanIter->second = flagS;
0237       return;
0238     }
0239 
0240     DEFINE_FWK_SERVICE(DTHVCheckWithHysteresis);
0241   }  // namespace service
0242 }  // namespace cond