CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/Geometry/TrackerNumberingBuilder/bin/stubs/GeometricDetLoader.cc

Go to the documentation of this file.
00001 #include "GeometricDetLoader.h"
00002 
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00007 #include "FWCore/Framework/interface/EventSetup.h"
00008 #include "FWCore/Framework/interface/ESHandle.h"
00009 #include "CondFormats/GeometryObjects/interface/PGeometricDet.h"
00010 
00011 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00012 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00013 #include <DetectorDescription/Core/interface/DDCompactView.h>
00014 #include <DetectorDescription/Core/interface/DDExpandedView.h>
00015 
00016 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00017 
00018 #include <iostream>
00019 #include <string>
00020 #include <vector>
00021 //#include <map>
00022 //#include <sstream>
00023 //#include <algorithm>
00024 
00025 // just a reminder to self... beware errors caused by levels.  Look
00026 // at how tracker is built and how GeometricSearchTracker.h is built 
00027 // up from the hierarchy.
00028 
00029 GeometricDetLoader::GeometricDetLoader(const edm::ParameterSet& iConfig)
00030 {
00031   std::cout<<"GeometricDetLoader::GeometricDetLoader"<<std::endl;
00032 }
00033 
00034 GeometricDetLoader::~GeometricDetLoader()
00035 {
00036   std::cout<<"GeometricDetLoader::~GeometricDetLoader"<<std::endl;
00037 }
00038 
00039 void
00040 GeometricDetLoader::beginJob( edm::EventSetup const& es) 
00041 {
00042   std::cout<<"GeometricDetLoader::beginJob"<<std::endl;
00043   PGeometricDet* pgd = new PGeometricDet;
00044   edm::Service<cond::service::PoolDBOutputService> mydbservice;
00045   if( !mydbservice.isAvailable() ){
00046     std::cout<<"PoolDBOutputService unavailable"<<std::endl;
00047     return;
00048   }
00049   edm::ESHandle<DDCompactView> pDD;
00050   edm::ESHandle<GeometricDet> rDD;
00051   es.get<IdealGeometryRecord>().get( pDD );
00052   es.get<IdealGeometryRecord>().get( rDD );
00053   const GeometricDet* tracker = &(*rDD);
00054 
00055   // so now I have the tracker itself. loop over all its components to store them.
00056   putOne(tracker, pgd, 0);
00057   std::vector<const GeometricDet*> tc = tracker->components();
00058   std::cout <<"Tracker has " << tc.size() << " components." << std::endl; //, lets go through them." << std::endl;
00059   std::vector<const GeometricDet*>::const_iterator git = tc.begin();
00060   std::vector<const GeometricDet*>::const_iterator egit = tc.end();
00061   int count=0;
00062   int lev = 1;
00063   for (; git!= egit; ++git) {  // one level below "tracker"
00064     putOne(*git, pgd, lev);
00065     std::vector<const GeometricDet*> inone = (*git)->components();
00066     //    << ctste.name((*git)->type())
00067     //    std::cout << lev << " type " << (*git)->type() << " " << int((*git)->geographicalId()) << std::endl; // << " has " << inone.size() << " components." << std::endl;
00068     if ( inone.size() == 0 )  ++count;
00069     std::vector<const GeometricDet*>::const_iterator git2 = inone.begin();
00070     std::vector<const GeometricDet*>::const_iterator egit2 = inone.end();
00071     ++lev;
00072     for (; git2 != egit2; ++git2) { // level 2
00073       putOne(*git2, pgd, lev);
00074       std::vector<const GeometricDet*> intwo= (*git2)->components();
00075       //      std::cout << lev << "\ttype " << (*git2)->type() << " " << int((*git2)->geographicalId()) << std::endl; // << " has " << intwo.size() << " components." << std::endl;
00076       if ( intwo.size() == 0 )  ++count;
00077       std::vector<const GeometricDet*>::const_iterator git3 = intwo.begin();
00078       std::vector<const GeometricDet*>::const_iterator egit3 = intwo.end();
00079       ++lev;
00080       for (; git3 != egit3; ++git3) { // level 3
00081         putOne(*git3, pgd, lev);
00082         std::vector<const GeometricDet*> inthree= (*git3)->components();
00083         //      std::cout << lev << "\t\ttype " << (*git3)->type() << " " << int((*git3)->geographicalId()) << std::endl; // << " has " << inthree.size() << " components." << std::endl;
00084         if ( inthree.size() == 0 )  ++count;
00085         std::vector<const GeometricDet*>::const_iterator git4 = inthree.begin();
00086         std::vector<const GeometricDet*>::const_iterator egit4 = inthree.end();
00087         ++lev;
00088         for (; git4 != egit4; ++git4) { //level 4
00089           putOne(*git4, pgd, lev);
00090           std::vector<const GeometricDet*> infour= (*git4)->components();
00091           //      std::cout << lev << "\t\t\ttype " << (*git4)->type() << " " << int((*git4)->geographicalId()) << std::endl; // << " has " << infour.size() << " components." << std::endl;
00092           if ( infour.size() == 0 )  ++count;
00093           std::vector<const GeometricDet*>::const_iterator git5 = infour.begin();
00094           std::vector<const GeometricDet*>::const_iterator egit5 = infour.end();
00095           ++lev;
00096           for (; git5 != egit5; ++git5) { // level 5
00097             putOne(*git5, pgd, lev);
00098             std::vector<const GeometricDet*> infive= (*git5)->components();
00099             //      std::cout << lev << "\t\t\t\ttype " << (*git5)->type() << " " << int((*git5)->geographicalId()) << std::endl; // << " has " << infive.size() << " components." << std::endl;
00100             if ( infive.size() == 0 )  ++count;
00101             std::vector<const GeometricDet*>::const_iterator git6 = infive.begin();
00102             std::vector<const GeometricDet*>::const_iterator egit6 = infive.end();
00103             ++lev;
00104             for (; git6 != egit6; ++git6) { //level 6
00105               putOne(*git6, pgd, lev);
00106               std::vector<const GeometricDet*> insix= (*git6)->components();
00107               //              std::cout << lev << "\t\t\t\t\ttype " << (*git6)->type() << " " << int((*git6)->geographicalId()) << std::endl; // << " has " << insix.size() << " components." << std::endl;
00108               if ( insix.size() == 0 )  ++count;
00109             } // level 6
00110             --lev;
00111           } // level 5
00112           --lev;
00113         } // level 4
00114         --lev;
00115       } //level 3
00116       --lev;
00117     } // level 2
00118     --lev;
00119   }
00120   std::vector<const GeometricDet*> modules =  tracker->deepComponents();
00121   std::cout << " No. of Tracker components \"deepComponents\" = " << modules.size() << std::endl;
00122   std::cout << " Counted # of lowest \"leaves\" = " << count << std::endl; 
00123   if ( mydbservice->isNewTagRequest("PGeometricDetRcd") ) {
00124     mydbservice->createNewIOV<PGeometricDet>( pgd
00125                                               , mydbservice->beginOfTime()
00126                                               , mydbservice->endOfTime()
00127                                               , "PGeometricDetRcd");
00128   } else {
00129     std::cout << "PGeometricDetRcd Tag is already present." << std::endl;
00130   }
00131 }
00132   
00133 void GeometricDetLoader::putOne ( const GeometricDet* gd, PGeometricDet* pgd, int lev ) {
00134 
00135 //   std::cout << "putting name: " << gd->name().name();
00136 //   std::cout << " gid: " << gd->geographicalID();
00137 //   std::cout << " type: " << gd->type() << std::endl;
00138 //  std::cout << "shape = " << gd->shape()<<"; name = "<<gd->name().name()<<"; parameter number = "<<gd->params().size()<<std::endl;
00139   PGeometricDet::Item item;
00140   DDTranslation tran = gd->translation();
00141   DDRotationMatrix rot = gd->rotation();
00142   DD3Vector x, y, z;
00143   rot.GetComponents(x, y, z);
00144   item._name           = gd->name().name();
00145   item._level          = lev;
00146   item._x              = tran.X();
00147   item._y              = tran.Y();
00148   item._z              = tran.Z();
00149   item._phi            = gd->phi();
00150   item._rho            = gd->rho();
00151   item._a11            = x.X();
00152   item._a12            = y.X();
00153   item._a13            = z.X();
00154   item._a21            = x.Y();
00155   item._a22            = y.Y();
00156   item._a23            = z.Y();
00157   item._a31            = x.Z();
00158   item._a32            = y.Z();
00159   item._a33            = z.Z();
00160   item._shape          = gd->shape();
00161   item._type           = gd->type();
00162   if(gd->shape()==1){
00163     item._params0=gd->params()[0];
00164     item._params1=gd->params()[1];
00165     item._params2=gd->params()[2];
00166     item._params3=0;
00167     item._params4=0;
00168     item._params5=0;
00169     item._params6=0;
00170     item._params7=0;
00171     item._params8=0;
00172     item._params9=0;
00173     item._params10=0;
00174   }else if(gd->shape()==3){
00175     item._params0=gd->params()[0];
00176     item._params1=gd->params()[1];
00177     item._params2=gd->params()[2];
00178     item._params3=gd->params()[3];
00179     item._params4=gd->params()[4];
00180     item._params5=gd->params()[5];
00181     item._params6=gd->params()[6];
00182     item._params7=gd->params()[7];
00183     item._params8=gd->params()[8];
00184     item._params9=gd->params()[9];
00185     item._params10=gd->params()[10];
00186   }else{
00187     item._params0=0;
00188     item._params1=0;
00189     item._params2=0;
00190     item._params3=0;
00191     item._params4=0;
00192     item._params5=0;
00193     item._params6=0;
00194     item._params7=0;
00195     item._params8=0;
00196     item._params9=0;
00197     item._params10=0;
00198   } 
00199   item._geographicalID = gd->geographicalID();
00200   // FIXME: These are moved to PGeometricDetExtra:
00201   //item._volume         = gd->volume();
00202   //item._density        = gd->density();
00203   //item._weight         = gd->weight();
00204   //item._copy           = gd->copyno();
00205   //item._material       = gd->material();
00206   item._radLength      = gd->radLength();
00207   item._xi             = gd->xi();
00208   item._pixROCRows     = gd->pixROCRows();
00209   item._pixROCCols     = gd->pixROCCols();
00210   item._pixROCx        = gd->pixROCx();
00211   item._pixROCy        = gd->pixROCy();
00212   item._stereo         = gd->stereo();
00213   item._siliconAPVNum = gd->siliconAPVNum();
00214   pgd->pgeomdets_.push_back ( item );
00215 }
00216 
00217 #include "FWCore/Framework/interface/MakerMacros.h"
00218 DEFINE_FWK_MODULE(GeometricDetLoader);