CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/CondTools/DT/plugins/DTHVCheckWithHysteresis.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2010/09/14 14:30:26 $
00005  *  $Revision: 1.2 $
00006  *  \author Paolo Ronchese INFN Padova
00007  *
00008  */
00009 
00010 //-----------------------
00011 // This Class' Header --
00012 //-----------------------
00013 #include "CondTools/DT/plugins/DTHVCheckWithHysteresis.h"
00014 
00015 //-------------------------------
00016 // Collaborating Class Headers --
00017 //-------------------------------
00018 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00019 #include "FWCore/PluginManager/interface/ModuleDef.h"
00020 #include "FWCore/ServiceRegistry/interface/ServiceMaker.h"
00021 
00022 //---------------
00023 // C++ Headers --
00024 //---------------
00025 #include <iostream>
00026 
00027 namespace cond { namespace service {
00028 
00029 //-------------------
00030 // Initializations --
00031 //-------------------
00032 
00033 
00034 //----------------
00035 // Constructors --
00036 //----------------
00037 DTHVCheckWithHysteresis::DTHVCheckWithHysteresis(
00038                            const edm::ParameterSet & iConfig, 
00039                            edm::ActivityRegistry & iAR ) {
00040   if ( instance == 0 ) {
00041     std::cout << "create DTHVCheckWithHysteresis" << std::endl;
00042     minHVl = new float[4];
00043     minHVh = new float[4];
00044     maxHV = new float[4];
00045     minHVl[0] = 3000.0;
00046     minHVl[1] = 3000.0;
00047     minHVl[2] = 1200.0;
00048     minHVl[3] =  600.0;
00049     minHVh[0] = 3500.0;
00050     minHVh[1] = 3500.0;
00051     minHVh[2] = 1700.0;
00052     minHVh[3] = 1100.0;
00053     maxHV[0] = 4000.0;
00054     maxHV[1] = 4000.0;
00055     maxHV[2] = 2200.0;
00056     maxHV[3] = 1600.0;
00057     maxCurrent = 30.0;
00058     oldStatusA = new std::map<int,int>;
00059     oldStatusC = new std::map<int,int>;
00060     oldStatusS = new std::map<int,int>;
00061     instance = this;
00062   }
00063 }
00064 
00065 //--------------
00066 // Destructor --
00067 //--------------
00068 DTHVCheckWithHysteresis::~DTHVCheckWithHysteresis() {
00069 }
00070 
00071 //--------------
00072 // Operations --
00073 //--------------
00074 //int DTHVCheckWithHysteresis::checkCurrentStatus(
00075 DTHVAbstractCheck::flag DTHVCheckWithHysteresis::checkCurrentStatus(
00076                         int rawId, int type,
00077                         float valueA, float valueC, float valueS,
00078                         const std::map<int,timedMeasurement>& snapshotValues,
00079                         const std::map<int,int>& aliasMap,
00080                         const std::map<int,int>& layerMap ) {
00081 
00082 // find all values for this channel
00083 //  ind dpid = 0;
00084 //  std::map<int,int>::const_iterator lpartIter;
00085 //  std::map<int,int>::const_iterator lpartIend = layerMap.end();
00086 //  if ( ( layerIter = layerMap.find( chp0 ) ) != layerIend ) 
00087 //      dpid = layerIter.second;
00088 //  std::map<int,timedMeasurement>::const_iterator snapIter;
00089 //  std::map<int,timedMeasurement>::const_iterator snapIend =
00090 //                                                 snapshotValues.end();
00091 //  float val1 = -999999.0;
00092 //  float val2 = -999999.0;
00093 //  int chan = dpId * 10;
00094 //  if ( ( snapIter = snapshotValues.find( chan + 1 ) ) != snapIend )
00095 //      val1 = snapIter->second.second;
00096 //  if ( ( snapIter = snapshotValues.find( chan + 2 ) ) != snapIend )
00097 //      val2 = snapIter->second.second;
00098 
00099 // find dp identifier for all channels in this layer
00100 //  DTLayerId lay = chlId.layerId();
00101 //  int chp0 = DTWireId( lay, 10 ).rawId();
00102 //  int chp1 = DTWireId( lay, 11 ).rawId();
00103 //  int chp2 = DTWireId( lay, 12 ).rawId();
00104 //  int chp3 = DTWireId( lay, 13 ).rawId();
00105 //  ind dpi0 = 0;
00106 //  ind dpi1 = 0;
00107 //  ind dpi2 = 0;
00108 //  ind dpi3 = 0;
00109 //  std::map<int,int>::const_iterator layerIter;
00110 //  std::map<int,int>::const_iterator layerIend = layerMap.end();
00111 //  if ( ( layerIter = layerMap.find( chp0 ) ) != layerIend ) 
00112 //      dpi0 = layerIter.second;
00113 //  if ( ( layerIter = layerMap.find( chp1 ) ) != layerIend ) 
00114 //      dpi1 = layerIter.second;
00115 //  if ( ( layerIter = layerMap.find( chp2 ) ) != layerIend ) 
00116 //      dpi2 = layerIter.second;
00117 //  if ( ( layerIter = layerMap.find( chp3 ) ) != layerIend ) 
00118 //      dpi3 = layerIter.second;
00119 
00120   float minHV[4];
00121 //  DTLayerId lay = chlId.layerId();
00122 //  int chp0 = DTWireId( lay, 10 ).rawId();
00123 //  int chp1 = DTWireId( lay, 11 ).rawId();
00124 //  int chp2 = DTWireId( lay, 12 ).rawId();
00125 //  int chp3 = DTWireId( lay, 13 ).rawId();
00126 
00127   DTWireId chlId( rawId );
00128   int part = chlId.wire() - 10;
00129   DTHVAbstractCheck::flag flag;
00130   flag.a = flag.c = flag.s = 0;
00131 
00132   std::map<int,int>::iterator chanIter;
00133   if ( ( ( chanIter = oldStatusA->find( rawId ) ) != oldStatusA->end() ) &&
00134        (   chanIter->second % 2 ) ) minHV[part] = minHVh[part];
00135   else                              minHV[part] = minHVl[part];
00136   if ( ( ( chanIter = oldStatusS->find( rawId ) ) != oldStatusS->end() ) &&
00137        (   chanIter->second % 2 ) ) minHV[   2] = minHVh[   2];
00138   else                              minHV[   2] = minHVl[   2];
00139   if ( ( ( chanIter = oldStatusC->find( rawId ) ) != oldStatusC->end() ) &&
00140        (   chanIter->second % 2 ) ) minHV[   3] = minHVh[   3];
00141   else                              minHV[   3] = minHVl[   3];
00142 
00143   if ( type == 1 ) {
00144     if ( valueA < minHV[part] ) flag.a = 1;
00145     if ( valueA > maxHV[part] ) flag.a = 2;
00146     if ( valueS < minHV[   2] ) flag.s = 1;
00147     if ( valueS > maxHV[   2] ) flag.s = 2;
00148     if ( valueC < minHV[   3] ) flag.c = 1;
00149     if ( valueC > maxHV[   3] ) flag.c = 2;
00150     if ( ( chanIter = oldStatusA->find( rawId ) ) == oldStatusA->end() )
00151          oldStatusA->insert( std::pair<int,int>( rawId, flag.a ) );
00152     else chanIter->second = flag.a;
00153     if ( ( chanIter = oldStatusC->find( rawId ) ) == oldStatusC->end() )
00154          oldStatusC->insert( std::pair<int,int>( rawId, flag.c ) );
00155     else chanIter->second = flag.c;
00156     if ( ( chanIter = oldStatusS->find( rawId ) ) == oldStatusS->end() )
00157          oldStatusS->insert( std::pair<int,int>( rawId, flag.s ) );
00158     else chanIter->second = flag.s;
00159   }
00160   if ( type == 2 ) {
00161     float voltA = 0.0;
00162     float voltS = 0.0;
00163     float voltC = 0.0;
00164     DTLayerId lay = chlId.layerId();
00165     int l_p = chlId.wire();
00166     DTWireId chA( lay, l_p );
00167     DTWireId chS( lay, 12 );
00168     DTWireId chC( lay, 13 );
00169 
00170     std::map<int,int>::const_iterator layerIter;
00171     std::map<int,int>::const_iterator layerIend = layerMap.end();
00172     std::map<int,timedMeasurement>::const_iterator snapIter;
00173     std::map<int,timedMeasurement>::const_iterator snapIend =
00174                                                    snapshotValues.end();
00175     int chan;
00176     if ( ( layerIter = layerMap.find( chA.rawId() ) ) != layerIend ) {
00177       chan = ( layerIter->second * 10 ) + l_p;
00178       if ( ( snapIter = snapshotValues.find( chan ) ) != snapIend ) {
00179         voltA = snapIter->second.second;
00180       }
00181     }
00182     if ( ( layerIter = layerMap.find( chS.rawId() ) ) != layerIend ) {
00183       chan = ( layerIter->second * 10 ) + 2;
00184       if ( ( snapIter = snapshotValues.find( chan ) ) != snapIend ) {
00185         voltS = snapIter->second.second;
00186       }
00187     }
00188     if ( ( layerIter = layerMap.find( chC.rawId() ) ) != layerIend ) {
00189       chan = ( layerIter->second * 10 ) + 3;
00190       if ( ( snapIter = snapshotValues.find( chan ) ) != snapIend ) {
00191         voltC = snapIter->second.second;
00192       }
00193     }
00194     if ( ( valueA > maxCurrent  ) &&
00195          ( voltA >= minHV[part] ) ) flag.a = 4;
00196     if ( ( valueS > maxCurrent  ) &&
00197          ( voltS >= minHV[   2] ) ) flag.s = 4;
00198     if ( ( valueC > maxCurrent  ) &&
00199          ( voltC >= minHV[   3] ) ) flag.c = 4;
00200   }
00201 
00202   return flag;
00203 
00204 }
00205 
00206 
00207 void DTHVCheckWithHysteresis::setStatus(
00208                         int rawId,
00209                         int flagA, int flagC, int flagS,
00210                         const std::map<int,timedMeasurement>& snapshotValues,
00211                         const std::map<int,int>& aliasMap,
00212                         const std::map<int,int>& layerMap ) {
00213 //  std::cout << "set status " << rawId << " "
00214 //            << flagA << " " << flagC << " " << flagS << std::endl;
00215   std::map<int,int>::iterator chanIter;
00216   if ( ( chanIter = oldStatusA->find( rawId ) ) == oldStatusA->end() )
00217        oldStatusA->insert( std::pair<int,int>( rawId, flagA ) );
00218   else chanIter->second = flagA;
00219   if ( ( chanIter = oldStatusC->find( rawId ) ) == oldStatusA->end() )
00220        oldStatusC->insert( std::pair<int,int>( rawId, flagC ) );
00221   else chanIter->second = flagC;
00222   if ( ( chanIter = oldStatusS->find( rawId ) ) == oldStatusA->end() )
00223        oldStatusS->insert( std::pair<int,int>( rawId, flagS ) );
00224   else chanIter->second = flagS;
00225   return;
00226 }
00227 
00228 
00229 DEFINE_FWK_SERVICE( DTHVCheckWithHysteresis );
00230 } }
00231 
00232