Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
/** \file
 *
 *  \author S. Bolognesi - INFN To 
 */

#include "DTGeometryParserFromDDD.h"
#include "DataFormats/MuonDetId/interface/DTLayerId.h"

using namespace std;

DTGeometryParserFromDDD::DTGeometryParserFromDDD(
    const DDCompactView* cview,
    const MuonGeometryConstants& muonConstants,
    map<DTLayerId, std::pair<unsigned int, unsigned int> >& theLayerIdWiresMap) {
  try {
    std::string attribute = "MuStructure";
    std::string value = "MuonBarrelDT";

    // Asking only for the Muon DTs
    DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)};
    DDFilteredView fview(*cview, filter);

    parseGeometry(fview, muonConstants, theLayerIdWiresMap);
  } catch (const cms::Exception& e) {
    std::cerr << "DTGeometryParserFromDDD::build() : DDD Exception: something went wrong during XML parsing!"
              << std::endl
              << "  Message: " << e << std::endl;
    throw;
  } catch (const exception& e) {
    std::cerr << "DTGeometryParserFromDDD::build() : an unexpected exception occured: " << e.what() << std::endl;
    throw;
  } catch (...) {
    std::cerr << "DTGeometryParserFromDDD::build() : An unexpected exception occured!" << std::endl;
    throw;
  }
}

DTGeometryParserFromDDD::~DTGeometryParserFromDDD() {}

void DTGeometryParserFromDDD::parseGeometry(DDFilteredView& fv,
                                            const MuonGeometryConstants& muonConstants,
                                            map<DTLayerId, std::pair<unsigned int, unsigned int> >& theLayerIdWiresMap) {
  bool doChamber = fv.firstChild();

  // Loop on chambers
  while (doChamber) {
    // Loop on SLs
    bool doSL = fv.firstChild();
    while (doSL) {
      bool doL = fv.firstChild();
      // Loop on SLs
      while (doL) {
        //DTLayer* layer =
        buildLayer(fv, muonConstants, theLayerIdWiresMap);

        fv.parent();
        doL = fv.nextSibling();  // go to next layer
      }  // layers

      fv.parent();
      doSL = fv.nextSibling();  // go to next SL
    }  // sls

    fv.parent();
    doChamber = fv.nextSibling();  // go to next chamber
  }  // chambers
}

void DTGeometryParserFromDDD::buildLayer(DDFilteredView& fv,
                                         const MuonGeometryConstants& muonConstants,
                                         map<DTLayerId, std::pair<unsigned int, unsigned int> >& theLayerIdWiresMap) {
  MuonGeometryNumbering mdddnum(muonConstants);
  DTNumberingScheme dtnum(muonConstants);
  int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
  DTLayerId layId(rawid);

  // Loop on wires
  bool doWire = fv.firstChild();
  int WCounter = 0;
  int firstWire = fv.copyno();
  while (doWire) {
    WCounter++;
    doWire = fv.nextSibling();  // next wire
  }
  theLayerIdWiresMap[layId] = (make_pair(firstWire, WCounter));
}