CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/Geometry/TrackerNumberingBuilder/plugins/TrackerGeometricDetExtraESModule.cc

Go to the documentation of this file.
00001 #include "Geometry/TrackerNumberingBuilder/plugins/TrackerGeometricDetExtraESModule.h"
00002 #include "Geometry/TrackerNumberingBuilder/plugins/DDDCmsTrackerContruction.h"
00003 #include "CondFormats/GeometryObjects/interface/PGeometricDet.h"
00004 #include "CondFormats/GeometryObjects/interface/PGeometricDetExtra.h"
00005 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00006 #include "Geometry/Records/interface/PGeometricDetExtraRcd.h"
00007 #include "DetectorDescription/Core/interface/DDCompactView.h"
00008 #include "DetectorDescription/Core/interface/DDSolid.h"
00009 #include "DetectorDescription/Core/interface/DDMaterial.h"
00010 #include "ExtractStringFromDDD.h"
00011 #include "CondDBCmsTrackerConstruction.h"
00012 
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 #include "FWCore/Framework/interface/ESTransientHandle.h"
00016 #include "FWCore/Framework/interface/ModuleFactory.h"
00017 #include "FWCore/Framework/interface/ESProducer.h"
00018 
00019 
00020 #include <memory>
00021 
00022 using namespace edm;
00023 
00024 TrackerGeometricDetExtraESModule::TrackerGeometricDetExtraESModule(const edm::ParameterSet & p) 
00025   : fromDDD_(p.getParameter<bool>("fromDDD")) 
00026 {
00027   setWhatProduced(this);
00028 }
00029 
00030 TrackerGeometricDetExtraESModule::~TrackerGeometricDetExtraESModule() {}
00031 
00032 boost::shared_ptr<std::vector<GeometricDetExtra> >
00033 TrackerGeometricDetExtraESModule::produce(const IdealGeometryRecord & iRecord) {
00034   boost::shared_ptr<std::vector<GeometricDetExtra> > gde (new std::vector<GeometricDetExtra>);
00035   // get the GeometricDet which has a nav_type
00036   edm::ESHandle<GeometricDet> gd;
00037   iRecord.get ( gd );
00038   if (fromDDD_) {
00039   // traverse all components from the tracker down;
00040   // read the DD if from DD
00041     const GeometricDet* tracker = &(*gd);
00042     edm::ESTransientHandle<DDCompactView> cpv;
00043     iRecord.get( cpv );
00044     DDExpandedView ev(*cpv);
00045     ev.goTo(tracker->navType());
00046     putOne((*gde), tracker, ev, 0);
00047     std::vector<const GeometricDet*> tc = tracker->components();
00048     std::vector<const GeometricDet*>::const_iterator git = tc.begin();
00049     std::vector<const GeometricDet*>::const_iterator egit = tc.end();
00050     int count=0;
00051     int lev = 1;
00052     //  CmsTrackerStringToEnum ctst
00053     gde->reserve(tracker->deepComponents().size());
00054     for (; git!= egit; ++git) {  // one level below "tracker"
00055       ev.goTo((*git)->navType());
00056       putOne((*gde), *git, ev, lev);
00057       std::vector<const GeometricDet*> inone = (*git)->components();
00058       //    std::cout << lev << " type " << (*git)->type() << " " << int((*git)->geographicalId()) << std::endl; // << " has " << inone.size() << " components." << std::endl;
00059       if ( inone.size() == 0 )  ++count;
00060       std::vector<const GeometricDet*>::const_iterator git2 = inone.begin();
00061       std::vector<const GeometricDet*>::const_iterator egit2 = inone.end();
00062       ++lev;
00063       for (; git2 != egit2; ++git2) { // level 2
00064         ev.goTo((*git2)->navType());
00065         putOne((*gde), *git2, ev, lev);
00066         std::vector<const GeometricDet*> intwo= (*git2)->components();
00067         //      std::cout << lev << "\ttype " << (*git2)->type() << " " << int((*git2)->geographicalId()) << std::endl; // << " has " << intwo.size() << " components." << std::endl;
00068         if ( intwo.size() == 0 )  ++count;
00069         std::vector<const GeometricDet*>::const_iterator git3 = intwo.begin();
00070         std::vector<const GeometricDet*>::const_iterator egit3 = intwo.end();
00071         ++lev;
00072         for (; git3 != egit3; ++git3) { // level 3
00073           ev.goTo((*git3)->navType());
00074           putOne((*gde), *git3, ev, lev);
00075           std::vector<const GeometricDet*> inthree= (*git3)->components();
00076           //std::cout << lev << "\t\ttype " << (*git3)->type() << " " << int((*git3)->geographicalId()) << std::endl; // << " has " << inthree.size() << " components." << std::endl;
00077           if ( inthree.size() == 0 )  ++count;
00078           std::vector<const GeometricDet*>::const_iterator git4 = inthree.begin();
00079           std::vector<const GeometricDet*>::const_iterator egit4 = inthree.end();
00080           ++lev;
00081           for (; git4 != egit4; ++git4) { //level 4
00082             ev.goTo((*git4)->navType());
00083             putOne((*gde), *git4, ev, lev);
00084             std::vector<const GeometricDet*> infour= (*git4)->components();
00085             //  std::cout << lev << "\t\t\ttype " << (*git4)->type() << " " << int((*git4)->geographicalId()) << std::endl; // << " has " << infour.size() << " components." << std::endl;
00086             if ( infour.size() == 0 )  ++count;
00087             std::vector<const GeometricDet*>::const_iterator git5 = infour.begin();
00088             std::vector<const GeometricDet*>::const_iterator egit5 = infour.end();
00089             ++lev;
00090             for (; git5 != egit5; ++git5) { // level 5
00091               ev.goTo((*git5)->navType());
00092               putOne((*gde), *git5, ev, lev);
00093               std::vector<const GeometricDet*> infive= (*git5)->components();
00094               //    std::cout << lev << "\t\t\t\ttype " << (*git5)->type() << " " << int((*git5)->geographicalId()) << std::endl; // << " has " << infive.size() << " components." << std::endl;
00095               if ( infive.size() == 0 )  ++count;
00096               std::vector<const GeometricDet*>::const_iterator git6 = infive.begin();
00097               std::vector<const GeometricDet*>::const_iterator egit6 = infive.end();
00098               ++lev;
00099               for (; git6 != egit6; ++git6) { //level 6
00100                 ev.goTo((*git6)->navType());
00101                 putOne((*gde), *git6, ev, lev);
00102                 std::vector<const GeometricDet*> insix= (*git6)->components();
00103                 //      std::cout << lev << "\t\t\t\t\ttype " << (*git6)->type() << " " << int((*git6)->geographicalId()) << std::endl; // << " has " << insix.size() << " components." << std::endl;
00104                 if ( insix.size() == 0 ){
00105                   ++count;
00106                 } else {
00107                   edm::LogError("GeometricDetExtra") << "Hierarchy has exceeded hard-coded level 6 for Tracker " ;
00108                 }
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   }else{
00121     // if it is not from the DD, then just get the GDE from ES and match w/ GD.
00122     edm::ESHandle<PGeometricDetExtra> pgde;
00123     iRecord.getRecord<PGeometricDetExtraRcd>().get(pgde);
00124     std::map<uint32_t, const GeometricDet*> helperMap;
00125     const GeometricDet* tracker = &(*gd);
00126     helperMap[gd->geographicalID()] = tracker;
00127     std::vector<const GeometricDet*> tc = tracker->components();
00128     std::vector<const GeometricDet*>::const_iterator git = tc.begin();
00129     std::vector<const GeometricDet*>::const_iterator egit = tc.end();
00130     for (; git!= egit; ++git) {  // one level below "tracker"
00131       helperMap[(*git)->geographicalID()] = (*git);
00132       std::vector<const GeometricDet*> inone = (*git)->components();
00133       std::vector<const GeometricDet*>::const_iterator git2 = inone.begin();
00134       std::vector<const GeometricDet*>::const_iterator egit2 = inone.end();
00135       for (; git2 != egit2; ++git2) { // level 2
00136         helperMap[(*git2)->geographicalID()] = (*git2);
00137         std::vector<const GeometricDet*> intwo= (*git2)->components();
00138         std::vector<const GeometricDet*>::const_iterator git3 = intwo.begin();
00139         std::vector<const GeometricDet*>::const_iterator egit3 = intwo.end();
00140         for (; git3 != egit3; ++git3) { // level 3
00141           helperMap[(*git3)->geographicalID()] = (*git3);
00142           std::vector<const GeometricDet*> inthree= (*git3)->components();
00143           std::vector<const GeometricDet*>::const_iterator git4 = inthree.begin();
00144           std::vector<const GeometricDet*>::const_iterator egit4 = inthree.end();
00145           for (; git4 != egit4; ++git4) { //level 4
00146             helperMap[(*git4)->geographicalID()] = (*git4);
00147             std::vector<const GeometricDet*> infour= (*git4)->components();
00148             std::vector<const GeometricDet*>::const_iterator git5 = infour.begin();
00149             std::vector<const GeometricDet*>::const_iterator egit5 = infour.end();
00150             for (; git5 != egit5; ++git5) { // level 5
00151               helperMap[(*git5)->geographicalID()] = (*git5);
00152               std::vector<const GeometricDet*> infive= (*git5)->components();
00153               std::vector<const GeometricDet*>::const_iterator git6 = infive.begin();
00154               std::vector<const GeometricDet*>::const_iterator egit6 = infive.end();
00155               for (; git6 != egit6; ++git6) { //level 6
00156                 helperMap[(*git6)->geographicalID()] = (*git6);
00157                 if ( (*git6)->components().size() != 0 ){
00158                   edm::LogError("GeometricDetExtra") << "Hierarchy has exceeded hard-coded level of 6 for Tracker " ;
00159                 }
00160               } // level 6
00161             } // level 5
00162           } // level 4
00163         } //level 3
00164       } // level 2
00165     }
00166   
00167     const std::vector<PGeometricDetExtra::Item>& pgdes = pgde->pgdes_;
00168     gde->reserve(pgdes.size());
00169     std::vector<DDExpandedNode> evs; //EMPTY
00170     std::string nm; //EMPTY
00171     for (unsigned int i = 0; i < pgdes.size(); ++i) {
00172         //   GeometricDetExtra( GeometricDet const *gd, DetId id, GeoHistory& gh,  double vol, double dens, double wgt, double cpy, const std::string& mat, const std::string& name, bool dd=false );
00173       gde->push_back( GeometricDetExtra(helperMap[pgdes[i]._geographicalId], pgdes[i]._geographicalId, evs
00174                                        , pgdes[i]._volume, pgdes[i]._density, pgdes[i]._weight, pgdes[i]._copy
00175                                        , pgdes[i]._material, nm));
00176     }
00177   }
00178   return boost::shared_ptr<std::vector<GeometricDetExtra> >(gde);
00179 }
00180 
00181 void TrackerGeometricDetExtraESModule::putOne(std::vector<GeometricDetExtra> & gde, const GeometricDet* gd, const DDExpandedView& ev, int lev ) {
00182   std::string matname = ((ev.logicalPart()).material()).name().fullname();
00183   std::string lpname = ((ev.logicalPart()).name().fullname());
00184   std::vector<DDExpandedNode> evs = GeometricDetExtra::GeoHistory(ev.geoHistory().begin(),ev.geoHistory().end());
00185   gde.push_back(GeometricDetExtra( gd, gd->geographicalId(), evs,
00186                                    ((ev.logicalPart()).solid()).volume(), ((ev.logicalPart()).material()).density(),
00187                                    ((ev.logicalPart()).material()).density() * ( ((ev.logicalPart()).solid()).volume() / 1000.),                                                                       
00188                                    ev.copyno(), matname, lpname, true ));
00189 }
00190 
00191 DEFINE_FWK_EVENTSETUP_MODULE(TrackerGeometricDetExtraESModule);