CMS 3D CMS Logo

Public Member Functions | Private Types | Private Member Functions | Private Attributes

SiStripPsuDetIdMap Class Reference

Extension to SiStripConfigDb to map PSU channels to DetIDs using DCU-PSU map and DCU-DetID map. More...

#include <SiStripPsuDetIdMap.h>

List of all members.

Public Member Functions

void BuildMap (const std::string &mapFile, const bool debug)
void BuildMap (const std::string &mapFile, std::vector< std::pair< uint32_t, std::string > > &rawmap)
void BuildMap (const std::string &mapFile, const bool debug, std::map< std::string, std::vector< uint32_t > > &LVmap, std::map< std::string, std::vector< uint32_t > > &HVmap, std::map< std::string, std::vector< uint32_t > > &HVUnmappedmap, std::map< std::string, std::vector< uint32_t > > &HVCrosstalkingmap)
 Overloaded method that does the buidling.
std::vector< uint32_t > getCcuDcuIds ()
std::vector< uint32_t > getCgDcuIds ()
std::vector< std::string > getControlDetectorLocations ()
std::vector< std::pair
< uint32_t, std::string > > 
getControlPsuDetIdMap ()
uint32_t getDcuId (std::string pvss)
uint32_t getDcuId (uint32_t detid)
std::vector< uint32_t > getDcuIds ()
std::vector< std::pair
< uint32_t, std::string > > 
getDcuPsuMap ()
std::string getDetectorLocation (uint32_t detid)
std::string getDetectorLocation (std::string pvss)
std::string getDetectorLocation (uint32_t detid, std::string group)
std::vector< std::string > getDetectorLocations ()
void getDetID (std::string pvss, bool, std::vector< uint32_t > &detids, std::vector< uint32_t > &unmapped_detids, std::vector< uint32_t > &crosstalking_detids)
std::map< std::string,
std::vector< uint32_t > > 
getHVCrosstalkingMap ()
void getHvDetID (std::string psuchannel, std::vector< uint32_t > &ids, std::vector< uint32_t > &unmapped_ids, std::vector< uint32_t > &crosstalking_ids)
std::map< std::string,
std::vector< uint32_t > > 
getHVUnmappedMap ()
std::vector< uint32_t > getLvDetID (std::string psu)
std::vector< std::pair
< uint32_t, std::string > > 
getPsuDetIdMap ()
std::string getPSUName (uint32_t detid)
std::string getPSUName (uint32_t detid, std::string group)
int IsHVChannel (std::string pvss)
void printControlMap ()
void printMap ()
void RemoveDuplicateDetIDs (std::vector< uint32_t > &detids)
 SiStripPsuDetIdMap ()
 ~SiStripPsuDetIdMap ()

Private Types

typedef edm::MapOfVectors
< std::string, TkDcuPsuMap * > 
DcuPsus
typedef DcuPsus::range DcuPsusRange
typedef std::vector
< TkDcuPsuMap * > 
DcuPsuVector
typedef std::map< std::string,
std::vector< uint32_t > > 
PsuDetIdMap

Private Member Functions

void checkMapInputValues (SiStripConfigDb::DcuDetIdsV dcuDetIds_, DcuPsuVector dcuPsus_)
void clone (DcuPsuVector &input, DcuPsuVector &output)
std::vector< uint32_t > findDcuIdFromDeviceAddress (uint32_t dcuid_)
void getDcuPsuMap (DcuPsusRange &pRange, DcuPsusRange &cRange, std::string partition)
std::vector< std::pair
< std::vector< uint16_t >
, std::vector< uint32_t > > > 
retrieveDcuDeviceAddresses (std::string partition)

Private Attributes

std::vector< uint32_t > ccuDcuIds
std::vector< uint32_t > cgDcuIds
std::vector< std::pair
< uint32_t, std::string > > 
cgMap
std::vector< std::string > controlLocations
edm::Service< SiStripConfigDbdb_
std::vector< std::pair
< std::vector< uint16_t >
, std::vector< uint32_t > > > 
dcu_device_addr_vector
std::vector< uint32_t > dcuIds
DcuPsus DcuPsuMapCG_
DcuPsus DcuPsuMapPG_
std::vector< std::string > detectorLocations
PsuDetIdMap HVCrosstalking_Map
PsuDetIdMap HVMap
PsuDetIdMap HVUnmapped_Map
PsuDetIdMap LVMap
std::vector< std::pair
< uint32_t, std::string > > 
pgMap

Detailed Description

Extension to SiStripConfigDb to map PSU channels to DetIDs using DCU-PSU map and DCU-DetID map.

Author:
J.Cole

Definition at line 33 of file SiStripPsuDetIdMap.h.


Member Typedef Documentation

typedef edm::MapOfVectors<std::string,TkDcuPsuMap*> SiStripPsuDetIdMap::DcuPsus [private]

Definition at line 115 of file SiStripPsuDetIdMap.h.

Definition at line 116 of file SiStripPsuDetIdMap.h.

typedef std::vector<TkDcuPsuMap *> SiStripPsuDetIdMap::DcuPsuVector [private]

Definition at line 113 of file SiStripPsuDetIdMap.h.

typedef std::map<std::string,std::vector<uint32_t> > SiStripPsuDetIdMap::PsuDetIdMap [private]

Definition at line 114 of file SiStripPsuDetIdMap.h.


Constructor & Destructor Documentation

SiStripPsuDetIdMap::SiStripPsuDetIdMap ( )

Constructor

Definition at line 20 of file SiStripPsuDetIdMap.cc.

References LogTrace.

{ LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] Constructing ..."; }
SiStripPsuDetIdMap::~SiStripPsuDetIdMap ( )

Destructor

Definition at line 22 of file SiStripPsuDetIdMap.cc.

References LogTrace.

{LogTrace("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] Destructing ..."; }

Member Function Documentation

void SiStripPsuDetIdMap::BuildMap ( const std::string &  mapFile,
const bool  debug 
)

Main routine that accesses the DB and builds the PSU-DETID map. Build the map from given file. ATTENTION: this will only build the pgMap, not the cgMap.

Definition at line 25 of file SiStripPsuDetIdMap.cc.

Referenced by SiStripDetVOffBuilder::BuildDetVOffObj(), and SiStripDetVOffBuilder::buildPSUdetIdMap().

void SiStripPsuDetIdMap::BuildMap ( const std::string &  mapFile,
std::vector< std::pair< uint32_t, std::string > > &  rawmap 
)

Definition at line 30 of file SiStripPsuDetIdMap.cc.

References mergeVDriftHistosByStation::file, and geometryCSVtoXML::line.

                                                                                                              {
  //This method is a remnant of the old method, that provided a vector type of map, based on the 
  //raw reading of a file, with no processing.
  //FIXME:
  //This is not currently used, but I think we could slim this down to just a vector with 
  //the detIDs since the PSUChannel part of the excludedlist (if it ever is in a file) is never used!
  edm::FileInPath file(mapFile.c_str());
  ifstream ifs( file.fullPath().c_str() );
  string line;
  while( getline( ifs, line ) ) {
    if( line != "" ) {
      // split the line and insert in the map
      stringstream ss(line);
      string PSUChannel;
      uint32_t detId;
      ss >> detId;
      ss >> PSUChannel;
      rawmap.push_back(std::make_pair(detId, PSUChannel) );
    }
  }
}
void SiStripPsuDetIdMap::BuildMap ( const std::string &  mapFile,
const bool  debug,
std::map< std::string, std::vector< uint32_t > > &  LVmap,
std::map< std::string, std::vector< uint32_t > > &  HVmap,
std::map< std::string, std::vector< uint32_t > > &  HVUnmappedmap,
std::map< std::string, std::vector< uint32_t > > &  HVCrosstalkingmap 
)

Overloaded method that does the buidling.

Definition at line 53 of file SiStripPsuDetIdMap.cc.

References gather_cfg::cout, mergeVDriftHistosByStation::file, i, and geometryCSVtoXML::line.

{
  //This method reads the map from the mapfile indicated in the cfg
  //It populates the 4 maps (private data members of the SiStripPSUDetIdMap in question) (all maps are std::map<std::string,uint32_t > ):
  //LVMap
  //HVMap
  //HVUnmapped_Map
  //HVCrosstalking_Map
  //These maps are accessed, based on the LV/HV case, to extract the detIDs connected to a given PSUChannel... 
  //see the getDetIDs method...
  edm::FileInPath file(mapFile.c_str());
  ifstream ifs( file.fullPath().c_str() );
  string line;
  while( getline( ifs, line ) ) {
    if( line != "" ) {
      // split the line and insert in the map
      stringstream ss(line);
      string PSUChannel;
      uint32_t detId;
      ss >> detId;
      ss >> PSUChannel;
      //Old "vector of pairs" map!
      //map.push_back( std::make_pair(detId, dpName) );//This "map" is normally the pgMap of the map of which we are executing BuildMap()...
      //Using a map to make the look-up easy and avoid lots of lookup loops.
      std::string PSU=PSUChannel.substr(0,PSUChannel.size()-10);
      std::string Channel=PSUChannel.substr(PSUChannel.size()-10);
      LVmap[PSU].push_back(detId); // LVmap uses simply the PSU since there is no channel distinction necessary
      if (Channel=="channel000") {
        HVUnmappedmap[PSU].push_back(detId); //Populate HV Unmapped map, by PSU listing all detids unmapped in that PSU (not necessarily all will be unmapped)
      }
      else if (Channel=="channel999") {
        HVCrosstalkingmap[PSU].push_back(detId); //Populate HV Crosstalking map, by PSU listing all detids crosstalking in that PSU (usually all will be unmapped)
      }
      else {
        HVmap[PSUChannel].push_back(detId); //HV map for HV mapped channels, populated by PSU channel!
      }
    }
  }
  
  //Remove duplicates for all 4 maps
  for (PsuDetIdMap::iterator psu = LVMap.begin(); psu != LVMap.end(); psu++) {
    RemoveDuplicateDetIDs(psu->second);
  }
  for (PsuDetIdMap::iterator psuchan = HVMap.begin(); psuchan != HVMap.end(); psuchan++) {
    RemoveDuplicateDetIDs(psuchan->second);
  }
  for (PsuDetIdMap::iterator psu = HVUnmapped_Map.begin(); psu != HVUnmapped_Map.end(); psu++) {
    RemoveDuplicateDetIDs(psu->second);
  }
  for (PsuDetIdMap::iterator psu = HVCrosstalking_Map.begin(); psu != HVCrosstalking_Map.end(); psu++) {
    RemoveDuplicateDetIDs(psu->second);
  }
  if (debug) {
    //Print out all the 4 maps:
    std::cout<<"Dumping the LV map"<<std::endl;
    std::cout<<"PSU->detids"<<std::endl;
    for (PsuDetIdMap::iterator psu = LVMap.begin(); psu != LVMap.end(); psu++) {
      std::cout<<psu->first<<" corresponds to following detids"<<endl;
      for (unsigned int i=0; i<psu->second.size(); i++) {
        std::cout<<"\t\t"<<psu->second[i]<<std::endl;
      }
    }
    std::cout<<"Dumping the HV map for HV mapped channels"<<std::endl;
    std::cout<<"PSUChannel->detids"<<std::endl;
    for (PsuDetIdMap::iterator psuchan = HVMap.begin(); psuchan != HVMap.end(); psuchan++) {
      std::cout<<psuchan->first<<" corresponds to following detids"<<endl;
      for (unsigned int i=0; i<psuchan->second.size(); i++) {
        std::cout<<"\t\t"<<psuchan->second[i]<<std::endl;
      }
    }
    std::cout<<"Dumping the HV map for HV UNmapped channels"<<std::endl;
    std::cout<<"PSU->detids"<<std::endl;
    for (PsuDetIdMap::iterator psu = HVUnmapped_Map.begin(); psu != HVUnmapped_Map.end(); psu++) {
      std::cout<<psu->first<<" corresponds to following detids"<<endl;
      for (unsigned int i=0; i<psu->second.size(); i++) {
        std::cout<<"\t\t"<<psu->second[i]<<std::endl;
      }
    }
    std::cout<<"Dumping the HV map for HV Crosstalking channels"<<std::endl;
    std::cout<<"PSU->detids"<<std::endl;
    for (PsuDetIdMap::iterator psu = HVCrosstalking_Map.begin(); psu != HVCrosstalking_Map.end(); psu++) {
      std::cout<<psu->first<<" corresponds to following detids"<<endl;
      for (unsigned int i=0; i<psu->second.size(); i++) {
        std::cout<<"\t\t"<<psu->second[i]<<std::endl;
      }
    }
    //Could add here consistency checks against the list of detIDs for Strip or Pixels
    //Number of total detIDs LVMapped, HV Mapped, HVunmapped, HV crosstalking... 
  }
}
void SiStripPsuDetIdMap::checkMapInputValues ( SiStripConfigDb::DcuDetIdsV  dcuDetIds_,
DcuPsuVector  dcuPsus_ 
) [private]

Produces a detailed debug of the input values.

Definition at line 469 of file SiStripPsuDetIdMap.cc.

References gather_cfg::cout, and createTree::dd.

                                                                                                        {
  std::cout << "Number of entries in DCU-PSU map:    " << dcuPsus_.size() << std::endl;
  std::cout << "Number of entries in DCU-DETID map:  " << dcuDetIds_.size() << std::endl;
  std::cout << std::endl;
  
  std::vector<bool> ddUsed(dcuDetIds_.size(),false);
  std::vector<bool> dpUsed(dcuPsus_.size(),false);

  for (unsigned int dp = 0; dp < dcuPsus_.size(); dp++) {
    for (unsigned int dd = 0; dd < dcuDetIds_.size(); dd++) {
      if (dcuPsus_[dp]->getDcuHardId() == dcuDetIds_[dd].second->getDcuHardId()) {
        dpUsed[dp] = true;
        ddUsed[dd] = true;
      }
    }
  }
  unsigned int numDpUsed = 0, numDpNotUsed = 0;
  for (unsigned int dp = 0; dp < dpUsed.size(); dp++) {
    if (dpUsed[dp]) { numDpUsed++; }
    else { numDpNotUsed++; }
  }

  std::cout << "Number of used DCU-PSU entries:   " << numDpUsed << std::endl;
  std::cout << "Number of unused DCU-PSU entries: " << numDpNotUsed << std::endl;

  unsigned int numDdUsed = 0, numDdNotUsed = 0;
  for (unsigned int dd = 0; dd < ddUsed.size(); dd++) {
    if (ddUsed[dd]) { numDdUsed++; }
    else { numDdNotUsed++; }
  }

  std::cout << "Number of used DCU-DETID entries:   " << numDdUsed << std::endl;
  std::cout << "Number of unused DCU-DETID entries: " << numDdNotUsed << std::endl;
  std::cout << std::endl;
  std::cout << "Size of PSU-DETID map:              " << pgMap.size() << std::endl;
  std::cout << "Size of detectorLocations:          " << detectorLocations.size() << std::endl;
}
void SiStripPsuDetIdMap::clone ( DcuPsuVector input,
DcuPsuVector output 
) [private]

Utility to clone a DCU-PSU map.

Definition at line 436 of file SiStripPsuDetIdMap.cc.

References i.

                                                                        {
  output.clear();
  for (unsigned int i = 0; i < input.size(); i++) {
    output.push_back(new TkDcuPsuMap(*(input[i])));
  }
}
std::vector< uint32_t > SiStripPsuDetIdMap::findDcuIdFromDeviceAddress ( uint32_t  dcuid_) [private]

Searches the DCU device descriptions for the specified DCU ID. Needed for control groups.

Definition at line 576 of file SiStripPsuDetIdMap.cc.

References gather_cfg::cout, spr::find(), and i.

                                                                                  {
  std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > >::iterator iter = dcu_device_addr_vector.begin();
  std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > >::iterator res_iter = dcu_device_addr_vector.end();
  std::vector<uint32_t> pgDcu;

  for ( ; iter != dcu_device_addr_vector.end(); iter++) {
    std::vector<uint32_t> dcuids = iter->second;
    std::vector<uint32_t>::iterator dcu_iter = std::find(dcuids.begin(),dcuids.end(),dcuid_);
    bool alreadyFound = false;
    if (res_iter != dcu_device_addr_vector.end()) {alreadyFound = true;}
    if (dcu_iter != dcuids.end()) {
      res_iter = iter;
      if (!alreadyFound) {
        for (unsigned int i = 0; i < dcuids.size(); i++) {
          if (dcuids[i] != dcuid_) {pgDcu.push_back(dcuids[i]);}
        }
      } else {
        std::cout << "Oh oh ... we have a duplicate :-(" << std::endl;
      }
    }
  }
  return pgDcu;
}
std::vector<uint32_t> SiStripPsuDetIdMap::getCcuDcuIds ( ) [inline]

Return the CCU DCU IDs associated to the CG map.

Definition at line 85 of file SiStripPsuDetIdMap.h.

References ccuDcuIds.

{return ccuDcuIds;}
std::vector<uint32_t> SiStripPsuDetIdMap::getCgDcuIds ( ) [inline]

Return the module DCU IDs associated to the CG map.

Definition at line 83 of file SiStripPsuDetIdMap.h.

References cgDcuIds.

{return cgDcuIds;}
std::vector<std::string> SiStripPsuDetIdMap::getControlDetectorLocations ( ) [inline]

Return the CG detector locations as a vector - one-to-one correspondance with the contents of the PSU-DetID map vector.

Definition at line 81 of file SiStripPsuDetIdMap.h.

References controlLocations.

{return controlLocations;}
std::vector< std::pair<uint32_t, std::string> > SiStripPsuDetIdMap::getControlPsuDetIdMap ( ) [inline]

Return the CG PSU-DETID map as a vector.

Definition at line 79 of file SiStripPsuDetIdMap.h.

References cgMap.

{return cgMap;}
uint32_t SiStripPsuDetIdMap::getDcuId ( uint32_t  detid)

Returns the DCU ID associated to the specified Det ID. NB. This checks power groups only, by definition.

Definition at line 407 of file SiStripPsuDetIdMap.cc.

References first, and i.

                                                    {
  for (unsigned int i = 0; i < pgMap.size(); i++) {
    if (pgMap[i].first == detid) {return dcuIds[i];}
  }
  return 0;
}
uint32_t SiStripPsuDetIdMap::getDcuId ( std::string  pvss)

Returns the DCU ID for the specified PSU channel - checks power and control groups.

Definition at line 397 of file SiStripPsuDetIdMap.cc.

References i, and edm::second().

                                                          {
  for (unsigned int i = 0; i < pgMap.size(); i++) {
    if (pgMap[i].second == PSUChannel) {return dcuIds[i];}
  }
  for (unsigned int i = 0; i < cgMap.size(); i++) {
    if (cgMap[i].second == PSUChannel) {return cgDcuIds[i];}
  }
  return 0;
}
std::vector<uint32_t> SiStripPsuDetIdMap::getDcuIds ( ) [inline]

Return the DCU IDs associated to the PG map.

Definition at line 77 of file SiStripPsuDetIdMap.h.

References dcuIds.

{return dcuIds;}
std::vector< std::pair< uint32_t, std::string > > SiStripPsuDetIdMap::getDcuPsuMap ( )

Returns the DCU-PSU map as a vector.

Definition at line 463 of file SiStripPsuDetIdMap.cc.

                                                                           {
  if (pgMap.size() != 0) { return pgMap; }
  std::vector< std::pair<uint32_t, std::string> > emptyVec;
  return emptyVec;
}
void SiStripPsuDetIdMap::getDcuPsuMap ( DcuPsusRange pRange,
DcuPsusRange cRange,
std::string  partition 
) [private]

Extracts the DCU-PSU map from the DB.

std::string SiStripPsuDetIdMap::getDetectorLocation ( uint32_t  detid,
std::string  group 
)

Returns the detector location for the specified Det ID and specified group type (PG or CG).

Definition at line 371 of file SiStripPsuDetIdMap.cc.

References first, and i.

                                                                                 {
  if (group == "PG") {
    for (unsigned int i = 0; i < pgMap.size(); i++) {
      if (pgMap[i].first == detid) {return detectorLocations[i];}
    }
  }
  if (group == "CG") {
    for (unsigned int i = 0; i < cgMap.size(); i++) {
      if (cgMap[i].first == detid) {return controlLocations[i];}
    }
  }
  return "UNKNOWN";
}
std::string SiStripPsuDetIdMap::getDetectorLocation ( uint32_t  detid)

Returns the detector location for the specified Det ID, for power groups only.

Definition at line 363 of file SiStripPsuDetIdMap.cc.

References first, and i.

                                                                {
  for (unsigned int i = 0; i < pgMap.size(); i++) {
    if (pgMap[i].first == detid) {return detectorLocations[i];}
  }
  return "UNKNOWN";
}
std::string SiStripPsuDetIdMap::getDetectorLocation ( std::string  pvss)

Returns the detector location for the specified PSU channel.

Definition at line 386 of file SiStripPsuDetIdMap.cc.

References i, and edm::second().

                                                                      {
  for (unsigned int i = 0; i < pgMap.size(); i++) {
    if (pgMap[i].second == PSUChannel) {return detectorLocations[i];}
  }
  for (unsigned int i = 0; i < cgMap.size(); i++) {
    if (cgMap[i].second == PSUChannel) {return controlLocations[i];}
  }
  return "UNKNOWN";
}
std::vector<std::string> SiStripPsuDetIdMap::getDetectorLocations ( ) [inline]

Return the PG detector locations as a vector - one-to-one correspondance with the contents of the PSU-DetID map vector.

Definition at line 75 of file SiStripPsuDetIdMap.h.

References detectorLocations.

void SiStripPsuDetIdMap::getDetID ( std::string  pvss,
bool  debug,
std::vector< uint32_t > &  detids,
std::vector< uint32_t > &  unmapped_detids,
std::vector< uint32_t > &  crosstalking_detids 
)

Definition at line 184 of file SiStripPsuDetIdMap.cc.

References gather_cfg::cout.

                                                                                                                                                                                     {
  //This function takes as argument the PSUChannel (i.e. the dpname as it comes from the PVSS query, e.g. cms_trk_dcs_02:CAEN/CMS_TRACKER_SY1527_2/branchController05/easyCrate0/easyBoard12/channel001)
  //And it returns 3 vectors:
  //1-detids->all the detids positively matching the PSUChannel in question
  //2-unmapped_detids->the detids that are matching the PSU in question but that are not HV mapped
  //3-crosstalking_detids->the detids that are matching the PSU in question but exhibit the HV channel cross-talking behavior (they are ON as long as ANY of the 2 HV channels of the supply is ON, so they only go OFF when both channels are OFF)
  //The second and third vectors are only relevant for the HV case, when unmapped and cross-talking channels need further processing before being turned ON and OFF.
  
  std::string PSUChannelFromQuery = PSUChannel;

  //Get the channel to see if it is LV or HV, they will be treated differently
  std::string ChannelFromQuery=PSUChannelFromQuery.substr(PSUChannelFromQuery.size()-10);
  //Get the PSU from Query, to be used for LVMap and for the HVUnmapped and HVCrosstalking maps:
  std::string PSUFromQuery=PSUChannelFromQuery.substr(0,PSUChannelFromQuery.size()-10);
  if (debug) {
    //FIXME:
    //Should handle all the couts with MessageLogger!
    std::cout << "DPNAME from QUERY: "<<PSUChannelFromQuery<<", Channel: "<<ChannelFromQuery<<"PSU: "<<PSUFromQuery<<std::endl;
  }

  //First prepare the strings needed to do the matching of the PSUChannel from the query to the ones in the map

  //Handle the LV case first:
  if (ChannelFromQuery=="channel000" or ChannelFromQuery=="channel001") {
    //For LV channels we need to look for any detID that is reported either as channel000 (not HV mapped)
    //but also as channel002 and channel003 (if they are HV mapped), or as channel999 (if they are in a crosstalking PSU)
    //Get the PSU to do a PSU-only matching to get all detIDs connected to the LV channel:
    //Now loop over the map!
    //for (PsuDetIdMap::iterator iter = pgMap.begin(); iter != pgMap.end(); iter++) {
    //  std::string PSUFromMap = iter->second.substr(0,iter->second.size()-10);
    //  //Careful if you uncomment this cout: it prints 15148 lines when checking for 1 psu name match! (meant for debugging of course)
    //  //std::cout<<"Truncated DPNAME from MAP: "<<PSUFromMap<<std::endl;
    //  if (PSUFromQuery == PSUFromMap) {
    //    detids.push_back(iter->first); //And fill the detids vector with the all detids matching the PSU from the query!
    //  }
    //}
    //No need to loop over if we use an actual map!
    
    if (LVMap.find(PSUFromQuery)!=LVMap.end()) {
      detids=LVMap[PSUFromQuery];
    }
  }
  //Handle the HV case too:
  else if (ChannelFromQuery=="channel002" or ChannelFromQuery=="channel003") {
    //For the HV channel we need to look at the actual positive matching detIDs, 
    //but also to the unmapped one (channel000) and the crosstalking ones (channel999).
    //Assemble the corresponding channel000 (unmapped channels) replacing the last character in PSUChannelFromQuery:
    //  std::string ZeroedPSUChannelFromQuery= PSUChannelFromQuery;
    //  ZeroedPSUChannelFromQuery.replace(ZeroedPSUChannelFromQuery.size()-1,1,"0");
    //  //Same for channel999 for the crosstalking channels:
    //  //std::string NineNineNine='999';
    //  std::string NinedPSUChannelFromQuery= PSUChannelFromQuery;
    //  NinedPSUChannelFromQuery.replace(NinedPSUChannelFromQuery.size()-3,3,"999");
    //  //std::string NinedPSUChannelFromQuery= PSUChannelFromQuery.substr(0,PSUChannelFromQuery.size()-3);// + '999';
    //  //Now loop over the map!
    //  for (PsuDetIdMap::iterator iter = pgMap.begin(); iter != pgMap.end(); iter++) {
    //    std::string PSUChannelFromMap = iter->second;
    //    //Careful if you uncomment this cout: it prints 15148 lines when checking for 1 psu name match! (meant for debugging of course)
    //    //std::cout<<"Truncated DPNAME from MAP: "<<PSUFromMap<<std::endl;
    //    if (PSUChannelFromMap==PSUChannelFromQuery)  {
    //      detids.push_back(iter->first); //Fill the detids vector with the all detids matching the PSUChannel from the query!
    //    }
    //    if (PSUChannelFromMap==ZeroedPSUChannelFromQuery) {
    //          unmapped_detids.push_back(iter->first); //Fill the unmapped_detids vector with the all detids matching the channel000 for the PSU from the query!
    //          if (debug) { //BEWARE: this debug printouts can become very heavy! 1 print out per detID matched!
    //            std::cout<<"Matched one of the HV-UNMAPPED channels: "<<ZeroedPSUChannelFromQuery<<std::endl;
    //            std::cout<<"Corresponding to detID: "<<iter->first<<std::endl;
    //            //for (unsigned int i_nohvmap_detid=0;i_nohvmap_detid < iter->first.size();i_nohvmap_detid++) {
    //            //  cout<< iter->first[i_nohvmap_detid] << std::endl;
    //          }
    //    }
    //    if (PSUChannelFromMap==NinedPSUChannelFromQuery) {
    //          crosstalking_detids.push_back(iter->first); //Fill the crosstalking_detids vector with the all detids matching the channel999 for the PSU from the query!
    //    }
    //  }
    if (HVMap.find(PSUChannelFromQuery)!=HVMap.end()) {
      detids=HVMap[PSUChannelFromQuery];
    }
    else if (HVUnmapped_Map.find(PSUFromQuery)!=HVUnmapped_Map.end()) {
      unmapped_detids=HVUnmapped_Map[PSUFromQuery];
    }
    else if (HVCrosstalking_Map.find(PSUFromQuery)!=HVCrosstalking_Map.end()) {
      crosstalking_detids=HVCrosstalking_Map[PSUFromQuery];
    }
  }
  //  
  //  
  //  //With the new code above that makes use of the channel00X information in the map
  //  //we should no more need to remove duplicates by construction.
  //  //The following code was used when there was no channel information in the map, 
  //  //to elegantly eliminate duplicates.
  //  //We can now use it as a cross-check (still removing duplicates in case they happen, but writing a message out)
  //  
  //  // remove duplicates
  //  
  //  //First sort detIDs vector, so that duplicates will be consecutive
  //  if (!detids.empty()) {
  //    std::sort(detids.begin(),detids.end());
  //    //Then use the forward iterator unique from STD that basically removes all consecutive duplicates from the vector
  //    //and reports a forward iterator pointing to the new end of the sequence
  //    std::vector<uint32_t>::iterator it = std::unique(detids.begin(),detids.end());
  //    if (it!=detids.end()) {
  //      std::cout<<"ARGH! It seems we found duplicate detIDs in the map corresponding to this PSUChannel: "<<PSUChannelFromQuery<<std::endl;
  //      detids.resize( it - detids.begin() );
  //    }
  //    if (debug) {
  //      std::cout<<"Matched the following detIDs to PSU channel from query "<<PSUChannelFromQuery <<":"<<std::endl;
  //      for (std::vector<uint32_t>::iterator i_detid=detids.begin();i_detid!=detids.end(); i_detid++) {
  //    std::cout<<*i_detid<<std::endl;;
  //      }
  //    }
  //  }
  //  //Same for unmapped detIDs:
  //  if (!unmapped_detids.empty()) {
  //    std::sort(unmapped_detids.begin(),unmapped_detids.end());
  //    //Then use the forward iterator unique from STD that basically removes all consecutive duplicates from the vector
  //    //and reports a forward iterator pointing to the new end of the sequence
  //    std::vector<uint32_t>::iterator it = std::unique(unmapped_detids.begin(),unmapped_detids.end());
  //    if (it!=unmapped_detids.end()) {
  //      std::cout<<"ARGH! It seems we found duplicate unmapped_detids in the map corresponding to this PSUChannel: "<<PSUChannelFromQuery<<std::endl;
  //      unmapped_detids.resize( it - unmapped_detids.begin() );
  //    }
  //    if (debug) {
  //      std::cout<<"Matched the following unmapped_detids to PSU channel from query "<<PSUChannelFromQuery <<":"<<std::endl;
  //      for (std::vector<uint32_t>::iterator i_detid=unmapped_detids.begin();i_detid!=unmapped_detids.end(); i_detid++) {
  //    std::cout<<*i_detid<<std::endl;;
  //      }
  //    }
  //  }
  //  //Finally, same for crosstalking detIDs:
  //  if (!crosstalking_detids.empty()) {
  //    std::sort(crosstalking_detids.begin(),crosstalking_detids.end());
  //    //Then use the forward iterator unique from STD that basically removes all consecutive duplicates from the vector
  //    //and reports a forward iterator pointing to the new end of the sequence
  //    std::vector<uint32_t>::iterator it = std::unique(crosstalking_detids.begin(),crosstalking_detids.end());
  //    if (it!=crosstalking_detids.end()) {
  //      std::cout<<"ARGH! It seems we found duplicate crosstalking_detids in the map corresponding to this PSUChannel: "<<PSUChannelFromQuery<<std::endl;
  //      crosstalking_detids.resize( it - crosstalking_detids.begin() );
  //    }
  //    if (debug) {
  //      std::cout<<"Matched the following crosstalking_detids to PSU channel from query "<<PSUChannelFromQuery <<":"<<std::endl;
  //      for (std::vector<uint32_t>::iterator i_detid=crosstalking_detids.begin();i_detid!=crosstalking_detids.end(); i_detid++) {
  //    std::cout<<*i_detid<<std::endl;;
  //      }
  //    }
  //  }
  //  
  //  //Using reference parameters since we are returning multiple objects.
  //  //return detids;

}
std::map<std::string,std::vector<uint32_t> > SiStripPsuDetIdMap::getHVCrosstalkingMap ( ) [inline]

Definition at line 67 of file SiStripPsuDetIdMap.h.

References HVCrosstalking_Map.

Referenced by SiStripDetVOffBuilder::buildPSUdetIdMap().

void SiStripPsuDetIdMap::getHvDetID ( std::string  psuchannel,
std::vector< uint32_t > &  ids,
std::vector< uint32_t > &  unmapped_ids,
std::vector< uint32_t > &  crosstalking_ids 
)

Definition at line 165 of file SiStripPsuDetIdMap.cc.

Referenced by SiStripDetVOffBuilder::buildPSUdetIdMap().

                                                                                                                                                                {
  //Function that (via reference parameters) populates ids, unmapped_ids, crosstalking_ids vectors of detids associated with a given PSU *HV* channel.
  if (HVMap.find(PSUChannel)!=HVMap.end()) {
    ids=HVMap[PSUChannel];
  }
  //Extract the PSU to check the unmapped and crosstalking maps too corresponding to this channel
  std::string PSU = PSUChannel.substr(0,PSUChannel.size()-10);
  if (HVUnmapped_Map.find(PSU)!=HVUnmapped_Map.end()) {
    unmapped_ids=HVUnmapped_Map[PSU];
  }
  if (HVCrosstalking_Map.find(PSU)!=HVCrosstalking_Map.end()) {
    crosstalking_ids=HVCrosstalking_Map[PSU];
  }
}
std::map<std::string,std::vector<uint32_t> > SiStripPsuDetIdMap::getHVUnmappedMap ( ) [inline]

Definition at line 65 of file SiStripPsuDetIdMap.h.

References HVUnmapped_Map.

Referenced by SiStripDetVOffBuilder::buildPSUdetIdMap().

{return HVUnmapped_Map;}
std::vector< uint32_t > SiStripPsuDetIdMap::getLvDetID ( std::string  psu)

Definition at line 153 of file SiStripPsuDetIdMap.cc.

Referenced by SiStripDetVOffBuilder::buildPSUdetIdMap().

                                                                {
  //Function that returns a vector with all detids associated with a PSU 
  //(no channel information is saved in the map since it is not relevant for LV!)
  if (LVMap.find(PSU)!=LVMap.end()) {
    return LVMap[PSU];
  }
  else {
    std::vector<uint32_t> detids;
    return detids;
  }
}
std::vector< std::pair<uint32_t, std::string> > SiStripPsuDetIdMap::getPsuDetIdMap ( ) [inline]

Return the PG PSU-DETID map as a vector.

Definition at line 73 of file SiStripPsuDetIdMap.h.

References pgMap.

{return pgMap;}
std::string SiStripPsuDetIdMap::getPSUName ( uint32_t  detid)

Returns the PSU channel name for the specified Det ID, for power groups only.

Definition at line 337 of file SiStripPsuDetIdMap.cc.

                                                       {
  std::vector< std::pair<uint32_t, std::string> >::iterator iter;
  for (iter = pgMap.begin(); iter != pgMap.end(); iter++) {
    if (iter->first && iter->first == detid) {return iter->second;}
  }
  // if we reach here, then we didn't find the detid in the map
  return "UNKNOWN";
}
std::string SiStripPsuDetIdMap::getPSUName ( uint32_t  detid,
std::string  group 
)

Returns the PSU channel name for the specified Det ID.

Definition at line 346 of file SiStripPsuDetIdMap.cc.

                                                                        {
  std::vector< std::pair<uint32_t, std::string> >::iterator iter;
  if (group == "PG") {
    for (iter = pgMap.begin(); iter != pgMap.end(); iter++) {
      if (iter->first && iter->first == detid) {return iter->second;}
    }
  }
  if (group == "CG") {
    for (iter = cgMap.begin(); iter != cgMap.end(); iter++) {
      if (iter->first && iter->first == detid) {return iter->second;}
    }
  }
  // if we reach here, then we didn't find the detid in the map
  return "UNKNOWN";
}
int SiStripPsuDetIdMap::IsHVChannel ( std::string  pvss)

Returns 1 if the specified PSU channel is a HV channel, 0 if it is a LV channel. -1 means error.

Definition at line 415 of file SiStripPsuDetIdMap.cc.

                                                        {
  // isHV = 0 means LV, = 1 means HV, = -1 means error
  int isHV = 0;
  std::string::size_type loc = PSUChannel.find( "channel", 0 );
  if (loc != std::string::npos) {
    std::string chNumber = PSUChannel.substr(loc+7,3);
    if (chNumber == "002" || chNumber == "003") {
      isHV = 1;
    } else if (chNumber == "000" || chNumber == "001") {
      isHV = 0;
    } else {
      edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] channel number of unexpected format, setting error flag!";
      isHV = -1;
    }
  } else {
    edm::LogWarning("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] channel number not located in PSU channel name, setting error flag!";
    isHV = -1;
  }
  return isHV;
}
void SiStripPsuDetIdMap::printControlMap ( )

Produces a formatted printout of the control PSU-DETID map.

Definition at line 453 of file SiStripPsuDetIdMap.cc.

References AlCaHLTBitMon_ParallelJobs::p.

                                         {
  stringstream cg;
  cg << "Map of control power supplies to DET IDs: " << std::endl
     << "-- PSU name --                -- Det Id --" << std::endl;
  for (unsigned int p = 0; p < cgMap.size(); p++) {
    cg << cgMap[p].first << "         " << cgMap[p].second << std::endl;
  }
  edm::LogInfo("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << cg.str();
}
void SiStripPsuDetIdMap::printMap ( )

Produces a formatted printout of the PSU-DETID map.

Definition at line 443 of file SiStripPsuDetIdMap.cc.

References AlCaHLTBitMon_ParallelJobs::p.

Referenced by SiStripDetVOffBuilder::buildPSUdetIdMap().

                                  {
  stringstream pg;
  pg << "Map of power supplies to DET IDs: " << std::endl
     << "-- PSU name --          -- Det Id --" << std::endl;
  for (unsigned int p = 0; p < pgMap.size(); p++) {
    pg << pgMap[p].first << "         " << pgMap[p].second << std::endl;
  }
  edm::LogInfo("SiStripPsuDetIdMap") << "[SiStripPsuDetIdMap::" << __func__ << "] " << pg.str();
}
void SiStripPsuDetIdMap::RemoveDuplicateDetIDs ( std::vector< uint32_t > &  detids)

Definition at line 144 of file SiStripPsuDetIdMap.cc.

References python::multivaluedict::sort().

                                                                           {
  //Function to remove duplicates from a vector of detids
  if (!detids.empty()) { //Leave empty vector alone ;)
    std::sort(detids.begin(),detids.end());
    std::vector<uint32_t>::iterator it = std::unique(detids.begin(),detids.end());
    detids.resize( it - detids.begin() );
  }
}
std::vector< std::pair< std::vector< uint16_t >, std::vector< uint32_t > > > SiStripPsuDetIdMap::retrieveDcuDeviceAddresses ( std::string  partition) [private]

Extracts the DCU device descriptions and stores them for further use. Only used for control groups.

Definition at line 508 of file SiStripPsuDetIdMap.cc.

References begin, SiStripPartition::defaultPartitionName_, end, first, i, SiStripDbParams::partitions(), and python::multivaluedict::sort().

                                                                                                                                    {
  // get the DB parameters
  SiStripDbParams dbParams_ = db_->dbParams();
  SiStripDbParams::SiStripPartitions::const_iterator iter;
  
  std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> > resultVec;
  
  SiStripConfigDb::DeviceDescriptionsV dcuDevices_;
  SiStripConfigDb::DeviceType device_ = DCU;
  
  for (iter = dbParams_.partitions().begin(); iter != dbParams_.partitions().end(); ++iter) {
    if ( partition == "" || partition == iter->second.partitionName() ) {
      if ( iter->second.partitionName() == SiStripPartition::defaultPartitionName_ ) { continue; }
      if (iter->second.dcuVersion().first > 0 && iter->second.fecVersion().first > 0) {
        SiStripConfigDb::DeviceDescriptionsRange range = db_->getDeviceDescriptions(device_,iter->second.partitionName());
        if (!range.empty()) {
          SiStripConfigDb::DeviceDescriptionsV nextVec( range.begin(), range.end() );
          for (unsigned int i = 0; i < nextVec.size(); i++) {
            dcuDescription * desc = dynamic_cast<dcuDescription *>(nextVec[i]);
            resultVec.push_back( std::make_pair( desc->getDcuHardId(), db_->deviceAddress(*(nextVec[i])) ) );
          }
        }
      }
    }
  }

  std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > > testVec;
  std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> >::iterator reorg_iter = resultVec.begin();

  for ( ; reorg_iter != resultVec.end(); reorg_iter++) {
    std::vector<uint16_t> fecInfo(4,0);
    fecInfo[0] = reorg_iter->second.fecCrate_;
    fecInfo[1] = reorg_iter->second.fecSlot_;
    fecInfo[2] = reorg_iter->second.fecRing_;
    fecInfo[3] = reorg_iter->second.ccuAddr_;
    std::vector<uint32_t> dcuids;
    std::vector< std::pair<uint32_t, SiStripConfigDb::DeviceAddress> >::iterator jter = reorg_iter;
    for ( ; jter != resultVec.end(); jter++) {
      if (reorg_iter->second.fecCrate_ == jter->second.fecCrate_ &&
          reorg_iter->second.fecSlot_ == jter->second.fecSlot_ &&
          reorg_iter->second.fecRing_ == jter->second.fecRing_ &&
          reorg_iter->second.ccuAddr_ == jter->second.ccuAddr_) {
        dcuids.push_back(jter->first);
      }
    }
    // handle duplicates
    bool isDup = false;
    for (unsigned int i = 0; i < testVec.size(); i++) {
      if (fecInfo == testVec[i].first) {
        isDup = true;
        dcuids.insert(dcuids.end(), (testVec[i].second).begin(), (testVec[i].second).end() );
        std::sort(dcuids.begin(),dcuids.end());
        std::vector<uint32_t>::iterator it = std::unique(dcuids.begin(),dcuids.end());
        dcuids.resize( it - dcuids.begin() );
        testVec[i].second = dcuids;
      }
    }
    if (!isDup) {
      std::sort(dcuids.begin(),dcuids.end());
      std::vector<uint32_t>::iterator it = std::unique(dcuids.begin(),dcuids.end());
      dcuids.resize( it - dcuids.begin() );
      testVec.push_back(std::make_pair(fecInfo,dcuids));
    }
  }
  //  return resultVec;
  return testVec;
}

Member Data Documentation

std::vector<uint32_t> SiStripPsuDetIdMap::ccuDcuIds [private]

Definition at line 135 of file SiStripPsuDetIdMap.h.

Referenced by getCcuDcuIds().

std::vector<uint32_t> SiStripPsuDetIdMap::cgDcuIds [private]

Definition at line 135 of file SiStripPsuDetIdMap.h.

Referenced by getCgDcuIds().

std::vector< std::pair<uint32_t, std::string> > SiStripPsuDetIdMap::cgMap [private]

Definition at line 133 of file SiStripPsuDetIdMap.h.

Referenced by getControlPsuDetIdMap().

std::vector<std::string> SiStripPsuDetIdMap::controlLocations [private]

Definition at line 134 of file SiStripPsuDetIdMap.h.

Referenced by getControlDetectorLocations().

Definition at line 131 of file SiStripPsuDetIdMap.h.

std::vector< std::pair< std::vector<uint16_t> , std::vector<uint32_t> > > SiStripPsuDetIdMap::dcu_device_addr_vector [private]

Definition at line 138 of file SiStripPsuDetIdMap.h.

std::vector<uint32_t> SiStripPsuDetIdMap::dcuIds [private]

Definition at line 135 of file SiStripPsuDetIdMap.h.

Referenced by getDcuIds().

Definition at line 136 of file SiStripPsuDetIdMap.h.

Definition at line 136 of file SiStripPsuDetIdMap.h.

std::vector<std::string> SiStripPsuDetIdMap::detectorLocations [private]

Definition at line 134 of file SiStripPsuDetIdMap.h.

Referenced by getDetectorLocations().

Definition at line 132 of file SiStripPsuDetIdMap.h.

Referenced by getHVCrosstalkingMap().

Definition at line 132 of file SiStripPsuDetIdMap.h.

Definition at line 132 of file SiStripPsuDetIdMap.h.

Referenced by getHVUnmappedMap().

Definition at line 132 of file SiStripPsuDetIdMap.h.

std::vector< std::pair<uint32_t, std::string> > SiStripPsuDetIdMap::pgMap [private]

Definition at line 133 of file SiStripPsuDetIdMap.h.

Referenced by getPsuDetIdMap().