CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/CalibMuon/DTCalibration/plugins/DTMapGenerator.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2008/01/22 19:00:29 $
00005  *  $Revision: 1.2 $
00006  *  \author G. Cerminara, S. Bolognesi - INFN Torino
00007  */
00008 
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 
00011 #include "DTMapGenerator.h"
00012 
00013 #include <iostream>
00014 #include <fstream>
00015 #include <sstream>
00016 
00017 using namespace edm;
00018 using namespace std;
00019 
00020 DTMapGenerator::DTMapGenerator(const ParameterSet& pset) {
00021   // The output file with the map
00022   outputMapName = pset.getUntrackedParameter<string>("outputFileName","output.map");
00023   // The input file with the base map (DDU ROS -> Wheel, Station, Sector)
00024   inputMapName = pset.getUntrackedParameter<string>("inputFileName","basemap.txt");
00025   //The ros type: ROS8 for commissioning, ROS25 otherwise
00026   rosType =  pset.getUntrackedParameter<int>("rosType",25);
00027   if(rosType != 8 && rosType != 25){
00028     cout<<"[DTMapGenerator]: wrong ros type (8 for commissioning, 25 otherwise)"<<endl;
00029     abort();
00030   }
00031 }
00032 
00033 DTMapGenerator::~DTMapGenerator(){}
00034 
00035 void DTMapGenerator::endJob() {
00036 
00037   cout << "DTMapGenerator: Output Map: " << outputMapName << " ROS Type: " << rosType << endl;
00038 
00039   // Read the existing wires
00040   ifstream existingChannels("/afs/cern.ch/cms/Physics/muon/CMSSW/DT/channelsMaps/existing_channels.txt");
00041   
00042   set<DTWireId> wireMap; //FIXME:MAYBE YOU NEED THE > and == operators to use set?
00043 
00044   // Read the map between DDU - ROS and Chambers
00045   string lineMap;
00046   while (getline(existingChannels,lineMap)) {
00047     if( lineMap == "" || lineMap[0] == '#' ) continue; // Skip comments and empty lines
00048     stringstream linestr;
00049     linestr << lineMap;
00050     int wheelEx, stationEx, sectorEx, slEx, layerEx, wireEx;
00051     linestr >> wheelEx >> sectorEx >> stationEx >> slEx >> layerEx >> wireEx;
00052     DTWireId wireIdEx(wheelEx, stationEx, sectorEx, slEx, layerEx, wireEx);
00053     wireMap.insert(wireIdEx);
00054   }
00055   cout << "Map size: " << wireMap.size() << endl;
00056 
00057   // The map between DDU - ROS and Chambers
00058   ifstream skeletonMap(inputMapName.c_str());
00059   
00060   // The output map in the CMSSW format
00061   ofstream outputMap(outputMapName.c_str());
00062 
00063   // Read the map between DDU - ROS and Chambers
00064   string line;
00065   while (getline(skeletonMap,line)) {
00066     if( line == "" || line[0] == '#' ) continue; // Skip comments and empty lines
00067     stringstream linestr;
00068     linestr << line;
00069     int ddu, ros, wheel, station, sector;
00070     linestr >> ddu >> ros >> wheel >> station >> sector;
00071     cout << "DDU: " << ddu << endl
00072          << "ROS: " << ros << endl
00073          << "Connected to chamber in Wh: " << wheel << " St: " << station << " Sec: " << sector << endl;
00074 
00075     int previousROB = -1;
00076     int robCounter = -1;
00077     // The chamber map in ORCA commissioning format    
00078     string fileName;
00079     stringstream nameTmp;
00080     nameTmp << "/afs/cern.ch/cms/Physics/muon/CMSSW/DT/channelsMaps/templates/MB" << station << "_" <<  sector << ".map";
00081     nameTmp >> fileName;
00082     ifstream chamberMap(fileName.c_str());
00083 
00084     string lineChamberMap;
00085     while (getline(chamberMap,lineChamberMap)) {
00086       if( lineChamberMap == "" || lineChamberMap[0] == '#' ) continue; // Skip comments and empty lines
00087       stringstream chamberMapStr;
00088       chamberMapStr << lineChamberMap;
00089       
00090       int rob, tdc, tdcChannel, sl, layer, wire;
00091       int unusedRos, unusedChamberCode;
00092       int outRob = -1;
00093       chamberMapStr >> unusedRos  >> rob >> tdc >> tdcChannel >> unusedChamberCode >> sl >> layer >> wire;
00094       
00095       // Check if the channel really exists
00096       if(!checkWireExist(wireMap, wheel, station, sector, sl, layer, wire))
00097         continue;
00098 
00099       if(rob > previousROB) {
00100         previousROB = rob;
00101         robCounter++;
00102       } else if(rob < previousROB) {
00103         cout << "Error: ROB number is not uniformly increasing!" << endl;
00104         abort();
00105       }
00106       // Set the ROB id within the ros
00107       if(rosType == 25) {
00108         if(station == 1) {//MB1
00109           outRob = robCounter;
00110         } else if(station == 2) {//MB2
00111           outRob = robCounter + 6;
00112         } else if(station == 3) {//MB3
00113           if(robCounter < 3) 
00114             outRob = robCounter + 12;
00115           else if(robCounter == 3)
00116             outRob = 24;
00117           else if(robCounter > 3)
00118             outRob = robCounter + 11;
00119         } else if(station == 4) {//MB4
00120           if(sector == 14)  {
00121             if(robCounter == 3) {
00122               continue;
00123             }
00124             outRob = robCounter + 18;
00125           } else if(sector == 10) {
00126             if(robCounter == 3) {
00127               continue;
00128             } else if(robCounter == 0) {
00129               outRob = 21;
00130             } else {
00131               outRob = robCounter + 21;
00132             }
00133           }
00134           if(sector == 4 )  {
00135             if(robCounter == 3 || robCounter == 4 ) {
00136               continue;
00137             }
00138             outRob = robCounter + 18;
00139           } else if(sector == 13) {
00140             if(robCounter == 3 || robCounter == 4) {
00141               continue;
00142             } else if(robCounter == 0) {
00143               outRob = 21;
00144             } else {
00145               outRob = robCounter + 21;
00146             }
00147           } else if(sector == 11 || sector == 9) {
00148             outRob = robCounter + 18;
00149             if(robCounter == 3) {
00150               continue;
00151             }
00152           }
00153           //else if(sector==12 || sector == 8 || sector == 7 || sector == 6 || sector == 5 ||  sector == 3 || sector == 2 ||sector == 1 ){
00154           else{
00155             outRob = robCounter + 18;
00156           }
00157         }
00158       } else {
00159         outRob = rob;
00160       }
00161       outputMap << ddu << " "
00162                 << ros << " "
00163                 << outRob << " "
00164                 << tdc << " "
00165                 << tdcChannel << " "
00166                 << wheel << " "
00167                 << station << " "
00168                 << sector << " "
00169                 << sl << " "
00170                 << layer << " "
00171                 << wire << endl;
00172     }
00173   }
00174 }
00175 
00176 bool DTMapGenerator::checkWireExist(const set<DTWireId>& wireMap, int wheel, int station, int sector, int sl, int layer, int wire) {
00177   DTWireId wireId(wheel, station, sector, sl, layer, wire);
00178   if(wireMap.find(wireId) == wireMap.end()) {
00179     cout << "Skipping channel: Wh: " << wheel
00180          << ", st: " << station
00181          << ", sec: " << sector
00182          << ", sl: " << sl
00183          << ", lay: " << layer
00184          << ", wire: " << wire << endl;
00185     return false;
00186   }
00187   
00188   return true;
00189 }
00190 
00191