CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CalibTracker/SiPixelConnectivity/src/PixelBarrelLinkMaker.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiPixelConnectivity/interface/PixelBarrelLinkMaker.h"
00002 #include "DataFormats/SiPixelDetId/interface/PixelModuleName.h"
00003 #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
00004 #include "CondFormats/SiPixelObjects/interface/PixelROC.h"
00005 
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 
00008 #include <ostream>
00009 using namespace std;
00010 using namespace sipixelobjects;
00011 
00012 bool PixelBarrelLinkMaker::Order::operator() 
00013     (const Item &u1, const Item& u2) const
00014 {
00015   const PixelBarrelName & n1 = *u1.name;
00016   const PixelBarrelName & n2 = *u2.name;
00017 
00018   bool res = false;
00019 
00020        if ( n1.layerName() < n2.layerName() ) res = true;
00021   else if ( n1.layerName() > n2.layerName() ) res = false;
00022   else if ( n1.ladderName() < n2.ladderName() ) res = true;
00023   else if ( n1.ladderName() > n2.ladderName() ) res = false;
00024   else if ( abs(n1.moduleName()) < abs(n2.moduleName()) ) res =  true;
00025   else if ( abs(n1.moduleName()) > abs(n2.moduleName()) ) res =  false;
00026   else if ( u1.rocIds.min() < u2.rocIds.min() ) res = true;
00027   else if ( u1.rocIds.min() > u2.rocIds.min() ) res = false;
00028 
00029   return res;
00030 }
00031 
00032 PixelBarrelLinkMaker::Links PixelBarrelLinkMaker::links( 
00033     const Names & n, const DetUnits & u) const
00034 {
00035 
00036   Links result;
00037   typedef Names::const_iterator CIN;
00038 
00039   //
00040   // construct link items from names. 
00041   // the item is equivalent to name for layer=3.
00042   // for layer=1,2 each module has 2 links
00043   //
00044   vector<Item> linkItems;
00045   typedef vector<Item>::const_iterator CIU;
00046 
00047   for(unsigned int idx = 0; idx < n.size(); idx++) {
00048     Item item;
00049     PixelBarrelName * b = dynamic_cast<PixelBarrelName * >(n[idx]);
00050     uint32_t d = u[idx];
00051     item.name = b;
00052     item.unit = d;
00053 
00054     if ( b->isHalfModule()) {
00055       item.rocIds = Range(0,7);      // half modules 
00056       linkItems.push_back(item);
00057     } else if(b->layerName() <= 2) {
00058       item.rocIds = Range(0,7);      // first link for modules in Layer=1,2
00059       linkItems.push_back(item);
00060       item.rocIds = Range(8,15);     // second link for modules in Layer=1,2
00061       linkItems.push_back(item);
00062     } else {
00063       item.rocIds = Range(0,15);    // one module per link 
00064       linkItems.push_back(item);     
00065     }
00066   }
00067 
00068 
00069 
00070   //
00071   // sort link items to get the order as in links
00072   //
00073   
00074   Order myLess;
00075   sort( linkItems.begin(), linkItems.end(), myLess );
00076 
00077   //
00078   // DEBUG
00079   //
00080   ostringstream str;
00081   for (CIU it = linkItems.begin(); it != linkItems.end(); it++) {
00082     str << (*it).name->name() <<" r="<< (*it).rocIds << endl;
00083   }
00084   LogDebug(" sorted BARREL links: ") << str.str();
00085 
00086 
00087   //
00088   // create corresponding PixelROC and link
00089   //
00090   int idLink = 0;
00091   result.reserve(linkItems.size());
00092   for (CIU it = linkItems.begin(); it != linkItems.end(); it++) {
00093     PixelFEDLink::ROCs rocs; 
00094     PixelFEDLink link(++idLink);
00095     int idRoc = 0;
00096     for (int id = (*it).rocIds.min(); id <= (*it).rocIds.max(); id++) {
00097       idRoc++;
00098       rocs.push_back( PixelROC( it->unit, id, idRoc) ); 
00099     }
00100     link.add(rocs);
00101     result.push_back(link); 
00102   }
00103 
00104   return result;
00105 }