CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
WriteOneGeometryFromXML.cc
Go to the documentation of this file.
2 
6 
15 #include <DetectorDescription/PersistentDDDObjects/interface/DDDToPersFactory.h>
16 
18 
19 #include <iostream>
20 #include <string>
21 #include <vector>
22 #include <map>
23 
25 {
26  std::cout<<"WriteOneGeometryFromXML::WriteOneGeometryFromXML"<<std::endl;
27  rotNumSeed_ = iConfig.getParameter<int>("rotNumSeed");
28 }
29 
31 {
32  std::cout<<"WriteOneGeometryFromXML::~WriteOneGeometryFromXML"<<std::endl;
33 }
34 
35 void
37 {
38  std::cout<<"WriteOneGeometryFromXML::beginRun"<<std::endl;
39  PIdealGeometry* pgeom = new PIdealGeometry;
41  if( !mydbservice.isAvailable() ){
42  std::cout<<"PoolDBOutputService unavailable"<<std::endl;
43  return;
44  }
45 
46  // std::cout << "About to do... size_t callbackToken=mydbservice->callbackToken(\"PIdealGeometry\");" << std::endl;
47  // size_t callbackToken=mydbservice->callbackToken("PIdealGeometry");
48  // std::cout << "Got back token " << callbackToken << std::endl;
50 
51  es.get<IdealGeometryRecord>().get(label_, pDD );
52  if (pDD.isValid())
53  std::cout << "DD is Valid" << std::endl;
54 
55  DDCompactView::DDCompactView::graph_type gra = pDD->graph();
56 
57  DDDToPersFactory dddFact;
58  DDMaterial::iterator<DDMaterial> it(DDMaterial::begin()), ed(DDMaterial::end());
59  PMaterial* pm;
60  for (; it != ed; ++it) {
61  if (! it->isDefined().second) continue;
62  pm = dddFact.material ( *it );
63  pgeom->pMaterials.push_back ( *pm );
64  delete pm;
65  }
66 
67  DDRotation::iterator<DDRotation> rit(DDRotation::begin()), red(DDRotation::end());
68  PRotation* pr;
69  DDRotation rotn(DDName("IDENTITYDB","generatedForDB"));
70  if ( !rotn.isDefined().second ) {
71  DDRotationMatrix* rotID = new DDRotationMatrix();
72  DDRotation mydr = DDrot (DDName("IDENTITYDB","generatedForDB"), rotID);
73  pr = dddFact.rotation ( mydr );
74  pgeom->pRotations.push_back ( *pr );
75  }
76  for (; rit != red; ++rit) {
77  if (! rit->isDefined().second) continue;
78  // if it is the identity...
79  if ( *(rit->matrix()) == *(rotn.matrix()) ) continue;
80  pr = dddFact.rotation( *rit );
81  pgeom->pRotations.push_back ( *pr );
82  }
83 
84 
85  DDSolid::iterator<DDSolid> sit(DDSolid::begin()), sed(DDSolid::end());
86  PSolid* ps;
87  for (; sit != sed; ++sit) {
88  if (! sit->isDefined().second) continue;
89  ps = dddFact.solid( *sit );
90  pgeom->pSolids.push_back( *ps );
91  delete ps;
92  }
93 
94  // Discovered during validation: If a user declares
95  // a LogicalPart in the DDD XML and does not position it
96  // in the graph, it will NOT be stored to the database
97  // subsequently SpecPars (see below) that use wildcards
98  // that may have selected the orphaned LogicalPart node
99  // will be read into the DDD from the DB (not by this
100  // code, but in the system) and so DDSpecifics will
101  // throw a DDException.
102  typedef DDCompactView::graph_type::const_adj_iterator adjl_iterator;
103  adjl_iterator git = gra.begin();
104  adjl_iterator gend = gra.end();
105 
107  PLogicalPart* plp;
108  for (; git != gend; ++git)
109  {
110  const DDLogicalPart & ddLP = gra.nodeData(git);
111  // std::cout << ddLP << std::endl;
112  plp = dddFact.logicalPart ( ddLP );
113  pgeom->pLogicalParts.push_back( *plp );
114  delete plp;
115  ++i;
116  if (git->size())
117  {
118  // ask for children of ddLP
119  DDCompactView::graph_type::edge_list::const_iterator cit = git->begin();
120  DDCompactView::graph_type::edge_list::const_iterator cend = git->end();
121  PPosPart* ppp;
122  for (; cit != cend; ++cit)
123  {
124  const DDLogicalPart & ddcurLP = gra.nodeData(cit->first);
125  ppp = dddFact.position ( ddLP, ddcurLP, gra.edgeData(cit->second), *pgeom, rotNumSeed_ );
126  // std::cout << "okay after the factory..." << std::endl;
127  pgeom->pPosParts.push_back( *ppp );
128  // std::cout << "okay after the push_back" << std::endl;
129  delete ppp;
130  // std::cout << "okay after the delete..." << std::endl;
131  } // iterate over children
132  } // if (children)
133  } // iterate over graph nodes
134 
135  std::vector<std::string> partSelections;
136  std::map<std::string, std::vector<std::pair<std::string, double> > > values;
137  std::map<std::string, int> isEvaluated;
138 
139  PSpecPar* psp;
140 
141  DDSpecifics::iterator<DDSpecifics> spit(DDSpecifics::begin()), spend(DDSpecifics::end());
142 
143  // ======= For each DDSpecific...
144  for (; spit != spend; ++spit) {
145  if ( !spit->isDefined().second ) continue;
146  psp = dddFact.specpar( *spit );
147  pgeom->pSpecPars.push_back( *psp );
148  delete psp;
149  }
150  std::cout <<" did the static work? is there a size to this string storage? " << std::endl;
151  std::cout << " dddFact.pstrs.pStrings.size() = " << dddFact.pstrs.pStrings.size() << std::endl;
152  pgeom->pStrings = dddFact.pstrs.pStrings;
153  pgeom->pStartNode = DDRootDef::instance().root().toString();
154 
155  if ( mydbservice->isNewTagRequest("IdealGeometryRecord") ) {
156  // mydbservice->newValidityForNewPayload<PIdealGeometry>(pgeom, mydbservice->endOfTime(), callbackToken);
157  mydbservice->createNewIOV<PIdealGeometry>(pgeom
158  , mydbservice->beginOfTime()
159  , mydbservice->endOfTime()
160  , "IdealGeometryRecord");
161  } else {
162  std::cout << "Tag is already present." << std::endl;
163  }
164 }
165 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
def_type isDefined() const
Definition: DDBase.h:115
virtual void beginRun(const edm::Run &, edm::EventSetup const &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:18
std::vector< double >::size_type index_type
Definition: adjgraph.h:15
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:66
static value_type & instance()
bool isNewTagRequest(const std::string &recordName)
WriteOneGeometryFromXML(const edm::ParameterSet &iConfig)
bool isAvailable() const
Definition: Service.h:47
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:88
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
DDRotation DDrot(const DDName &name, DDRotationMatrix *rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:93
const T & get() const
Definition: EventSetup.h:55
adj_list::const_iterator const_adj_iterator
Definition: adjgraph.h:125
static DDI::Store< DDName, DDI::Material * >::iterator begin()
Definition: DDBase.h:70
tuple cout
Definition: gather_cfg.py:121
static DDI::Store< DDName, DDI::Material * >::iterator end()
Definition: DDBase.h:69
DDRotationMatrix * matrix()
Definition: DDTransform.h:94
bool isValid() const
Definition: ESHandle.h:37
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
Definition: Run.h:33