CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/CalibTracker/SiPixelConnectivity/src/PixelEndcapLinkMaker.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiPixelConnectivity/interface/PixelEndcapLinkMaker.h"
00002 #include "DataFormats/SiPixelDetId/interface/PixelModuleName.h"
00003 #include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"
00004 #include "CondFormats/SiPixelObjects/interface/PixelROC.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include <ostream>
00007 
00008 using namespace std;
00009 using namespace sipixelobjects;
00010 
00011 bool PixelEndcapLinkMaker::Order::operator()
00012     (const Item &u1, const Item& u2) const
00013 {
00014   bool res = true;
00015   const PixelEndcapName & n1 = *u1.name;
00016   const PixelEndcapName & n2 = *u2.name;
00017 
00018   if (n1.halfCylinder() < n2.halfCylinder() ) res = true;
00019   else if(n1.halfCylinder() > n2.halfCylinder() ) res = false;
00020   else if (n1.diskName() < n2.diskName() ) res =  true;
00021   else if (n1.diskName() > n2.diskName() ) res =  false;
00022   else if (n1.bladeName() < n2.bladeName() ) res =  true;
00023   else if (n1.bladeName() > n2.bladeName() ) res =  false;
00024   else if (n1.pannelName() < n2.pannelName() ) res =  true;
00025   else if (n1.pannelName() > n2.pannelName() ) res =  false;
00026   else if (n1.plaquetteName() < n2.plaquetteName() ) res =  true;
00027   else if (n1.plaquetteName() > n2.plaquetteName() ) res =  false;
00028 
00029   return res;
00030 }
00031 
00032 PixelEndcapLinkMaker::Links PixelEndcapLinkMaker::links(
00033     const Names & n, const DetUnits & u) const
00034 {
00035     
00036   Links result; 
00037   typedef Names::const_iterator CIN;
00038 
00039   //
00040   // split names to links
00041   //
00042   vector<Item> linkItems;
00043   typedef vector<Item>::const_iterator CIU;
00044 
00045 
00046   for(unsigned int idx = 0; idx < n.size(); idx++) {
00047     Item item;
00048     PixelEndcapName * e = dynamic_cast<PixelEndcapName * >(n[idx]);
00049     uint32_t d = u[idx];
00050     item.name = e;
00051     item.unit = d;
00052     Range rocIds(-1,-1);
00053     PixelModuleName::ModuleType type = e->moduleType(); 
00054     switch (type) {
00055       case(PixelModuleName::v1x2) : { rocIds = Range(0,1); break; }
00056       case(PixelModuleName::v1x5) : { rocIds = Range(0,4); break; }
00057       case(PixelModuleName::v2x3) : { rocIds = Range(0,5); break; }
00058       case(PixelModuleName::v2x4) : { rocIds = Range(0,7); break; }
00059       case(PixelModuleName::v2x5) : { rocIds = Range(0,9); break; }
00060       default:
00061         edm::LogError("PixelEndcapLinkMaker")<< " *** UNEXPECTED roc: " << e->name() ;
00062     };
00063     item.rocIds = rocIds;
00064     linkItems.push_back(item);
00065   }
00066   //
00067   // sort names to get the order as in links
00068   //
00069 
00070   sort( linkItems.begin(), linkItems.end(), Order() );
00071 
00072   //
00073   // DEBUG
00074   //
00075   ostringstream str;
00076   for (CIU it = linkItems.begin(); it != linkItems.end(); it++) {
00077     str << (*it).name->name() <<" r="<< (*it).rocIds << endl;
00078   }
00079   LogDebug(" sorted ENDCAP links: ") << str.str();
00080 
00081   result.reserve(36);
00082   int lastPannelId = -1;
00083   int idLink = 0;
00084   int idRoc = 0;
00085   PixelFEDLink link(idLink); // dummy object, id=0
00086 
00087   for (CIU it = linkItems.begin(); it != linkItems.end(); it++) {
00088     PixelFEDLink::ROCs rocs;
00089     int pannelId = it->name->pannelName();
00090 
00091     if ( pannelId != lastPannelId ) {
00092       lastPannelId = pannelId;
00093       if (idLink > 0) result.push_back(link);
00094       idRoc = 0;
00095       link = PixelFEDLink(++idLink); // real link, to be filled
00096     }
00097 
00098     for (int id = (*it).rocIds.min(); id <= (*it).rocIds.max(); id++) { 
00099      ++idRoc;
00100      rocs.push_back( PixelROC( it->unit, id, idRoc ) );
00101     }
00102 
00103     link.add( rocs);
00104   }
00105 
00106   if (idLink > 0) result.push_back(link);
00107   return result;
00108 }
00109 
00110 
00111