Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:37

0001 /* \file testCSCMapping.cc
0002  *
0003  * \author Tim Cox
0004  * Based on template from S. Argiro & N. Amapane
0005  */
0006 
0007 #include <cppunit/extensions/HelperMacros.h>
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 #include "FWCore/Utilities/interface/FileInPath.h"
0010 #include "CondFormats/CSCObjects/interface/CSCReadoutMappingFromFile.h"
0011 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0012 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
0013 #include <iostream>
0014 #include <cstdlib>
0015 
0016 std::string releasetop(getenv("CMSSW_BASE"));
0017 //std::string mappingFilePath= releasetop + "/src/CondFormats/CSCObjects/test/";
0018 
0019 class testCSCMapping : public CppUnit::TestFixture {
0020   CPPUNIT_TEST_SUITE(testCSCMapping);
0021 
0022   CPPUNIT_TEST(testRead);
0023 
0024   CPPUNIT_TEST_SUITE_END();
0025 
0026 public:
0027   testCSCMapping() : myName_("testCSCMapping"), dashedLineWidth(104), dashedLine(std::string(dashedLineWidth, '-')) {}
0028 
0029   void setUp() {
0030     char* ret = getenv("CMSSW_BASE");
0031     if (!ret) {
0032       std::cerr << "env variable SCRAMRT_LOCALRT not set, try eval `scramv1 runt -sh`" << std::endl;
0033       exit(1);
0034     } else {
0035       std::cout << "CMSSW_BASE set to " << ret << std::endl;
0036     }
0037 
0038     ret = getenv("CMSSW_SEARCH_PATH");
0039     if (!ret) {
0040       std::cerr << "env variable SCRAMRT_LOCALRT not set, try eval `scramv1 runt -sh`" << std::endl;
0041       exit(1);
0042     } else {
0043       std::cout << "CMSSW_SEARCH_PATH set to " << ret << std::endl;
0044     }
0045   }
0046 
0047   void tearDown() {}
0048 
0049   void testRead();
0050 
0051 private:
0052   const std::string myName_;
0053   const int dashedLineWidth;
0054   std::string dashedLine;
0055 };
0056 
0057 void testCSCMapping::testRead() {
0058   edm::FileInPath fip("CondFormats/CSCObjects/data/csc_slice_test_map.txt");
0059   std::cout << "Attempt to set FileInPath to " << fip.fullPath() << std::endl;
0060 
0061   std::cout << myName_ << ": --- t e s t C S C M a p p i n g  ---" << std::endl;
0062   std::cout << "start " << dashedLine << std::endl;
0063 
0064   CSCReadoutMappingFromFile theMapping(fip.fullPath());
0065 
0066   // The following labels are irrelevant to hardware in slice test
0067   int tmb = -1;
0068   int iendcap = -1;
0069   int istation = -1;
0070 
0071   // Loop over all possible crates and dmb slots in slice test
0072   // TEST CSCReadoutMapping::chamber(...)
0073 
0074   int numberOfVmeCrates = 4;
0075   int numberOfDmbSlots = 10;
0076   int missingDmbSlot = 6;
0077 
0078   for (int i = 0; i < numberOfVmeCrates; ++i) {
0079     int vmecrate = i;
0080     for (int j = 1; j <= numberOfDmbSlots; ++j) {
0081       if (j == missingDmbSlot)
0082         continue;  // ***There is no slot 6***
0083       int dmb = j;
0084 
0085       std::cout << "\n"
0086                 << myName_ << ": search for sw id for hw labels, endcap= " << iendcap << ", station=" << istation
0087                 << ", vmecrate=" << vmecrate << ", dmb=" << dmb << ", tmb= " << tmb << std::endl;
0088       int id = theMapping.chamber(iendcap, istation, vmecrate, dmb, tmb);
0089 
0090       std::cout << myName_ << ": found chamber rawId = " << id << std::endl;
0091 
0092       CSCDetId cid(id);
0093 
0094       // We can now find real endcap & station labels
0095       int endcap = cid.endcap();
0096       int station = cid.station();
0097 
0098       std::cout << myName_ << ": from CSCDetId for this chamber, endcap= " << cid.endcap()
0099                 << ", station=" << cid.station() << ", ring=" << cid.ring() << ", chamber=" << cid.chamber()
0100                 << std::endl;
0101 
0102       // Now try direct mapping for specific layers & cfebs (now MUST have correct endcap & station labels!)
0103       // TEST CSCReadoutMapping::detId(...)
0104       for (int cfeb = 0; cfeb != 5; ++cfeb) {
0105         for (int layer = 1; layer <= 6; ++layer) {
0106           std::cout << myName_ << ": map layer with hw labels, endcap= " << endcap << ", station=" << station
0107                     << ", vmecrate=" << vmecrate << ", dmb=" << dmb << ", tmb= " << tmb << ", cfeb= " << cfeb
0108                     << ", layer=" << layer << std::endl;
0109 
0110           CSCDetId lid = theMapping.detId(endcap, station, vmecrate, dmb, tmb, cfeb, layer);
0111 
0112           // And check what we've actually selected...
0113           std::cout << myName_ << ": from CSCDetId for this layer, endcap= " << lid.endcap()
0114                     << ", station=" << lid.station() << ", ring=" << lid.ring() << ", chamber=" << lid.chamber()
0115                     << ", layer=" << lid.layer() << std::endl;
0116         }
0117 
0118         std::cout << std::endl;
0119 
0120       }  // end loop over cfebs
0121     }  // end loop over dmbs
0122   }  // end loop over vmes
0123   std::cout << dashedLine << " end" << std::endl;
0124 }
0125 
0126 ///registration of the test so that the runner can find it
0127 CPPUNIT_TEST_SUITE_REGISTRATION(testCSCMapping);