Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:13:57

0001 #include <string>
0002 #include <vector>
0003 #include <math.h>
0004 #include <iostream>
0005 #include <stdlib.h>
0006 #include <stdio.h>
0007 
0008 class CCAmap {
0009 public:
0010   void map(int rbx, int rm, int card, int cca, int ccaq,
0011        int& ieta, int& iphi, int& depth, int& det,int& spigot, int& fiber, int& crate, int& fiber_chan, int& G_Dcc, int& H_slot, int& TB);
0012   //};
0013 
0014   CCAmap(const char* fname);
0015 
0016 private:
0017   struct DataMap{
0018         
0019     int m_side; 
0020     int m_eta;
0021     int m_phi;
0022     int m_depth;
0023     int m_det;
0024     int m_rbx;
0025     int m_rm;
0026     int m_qie;
0027     int m_adc;
0028     int m_fi_ch;
0029     int m_crate;
0030     int m_htr;
0031     int m_fpga;
0032     int m_htr_fi;
0033     int m_spigo;
0034     int m_dcc;
0035     
0036    
0037   } v;
0038   
0039   std::vector<DataMap> vm;
0040   
0041 
0042   DataMap DataMapMaker(std::vector<std::string>& Words);
0043 
0044   void convert(const char* lineData, std::vector<std::string>& chunkWords);  
0045 
0046 
0047 };
0048 void CCAmap::map(int rbx, int rm, int card, int cca, int ccaq,
0049          int& ieta, int& iphi, int& depth, int& det, int& spigot, int& fiber, int& crate, int& fiber_chan, int& G_Dcc, int& H_slot, int& TB) {
0050   
0051     
0052   
0053   std::vector<DataMap>::const_iterator i;
0054   int sad;
0055 
0056 for (i=vm.begin();i!=vm.end();i++){
0057   
0058     if ((rbx==i->m_rbx)&&(rm==i->m_rm)&&(card==i->m_qie)&&(cca*2+ccaq==i->m_adc)){
0059       break;
0060     }
0061   }//end of i loop
0062  if (i!=vm.end()){
0063    sad=i->m_rbx;
0064    ieta=i->m_eta*i->m_side;
0065    iphi=i->m_phi;
0066    depth=i->m_depth;
0067    det=i->m_det;
0068    spigot=i->m_spigo;
0069    fiber=i->m_htr_fi;
0070    crate =i->m_crate;
0071    fiber_chan=i->m_fi_ch;
0072    G_Dcc=i->m_dcc;
0073    H_slot=i->m_htr;
0074    TB=i->m_fpga;
0075    
0076 
0077  }
0078 
0079 }
0080 
0081 
0082 CCAmap::DataMap CCAmap::DataMapMaker(std::vector<std::string>& Words){
0083 
0084 
0085   int k_side=atoi (Words[0].c_str());
0086   int k_eta=atoi (Words[1].c_str());
0087   int k_phi=atoi (Words[2].c_str());
0088   int k_depth=atoi (Words[3].c_str());
0089   int k_rm=atoi (Words[7].c_str());
0090   int k_qie=atoi (Words[9].c_str());
0091   int k_adc=atoi (Words[10].c_str());
0092   int k_fi_ch=atoi (Words[12].c_str());
0093   int k_crate=atoi (Words[13].c_str());
0094   int k_htr=atoi (Words[14].c_str());
0095   int k_htr_fi=atoi (Words[16].c_str());
0096   int k_spigo=atoi (Words[18].c_str());
0097   int k_dcc=atoi (Words[19].c_str());
0098   std::string k_det= Words[4];
0099   std::string k_rbx= Words[5];
0100   std::string k_fpga= Words[15];
0101   
0102    
0103   DataMap dM;
0104 
0105   dM.m_side=k_side;
0106     
0107   dM.m_eta=k_eta;
0108   dM.m_phi=k_phi;
0109   dM.m_depth=k_depth;
0110   if(k_det=="HB"){dM.m_det=1;}
0111   else if(k_det=="HE"){dM.m_det=2;}
0112   else if(k_det=="HF"){dM.m_det=4;}
0113   else if(k_det=="HO"){dM.m_det=3;}
0114 
0115   
0116   int rbxsign;  
0117   int z_zero;
0118   
0119   if (dM.m_det==3){
0120     if(k_side==1){ 
0121       rbxsign=1;
0122       z_zero=0;
0123     }
0124     else if(k_side==-1){ 
0125       rbxsign=0;
0126       z_zero=0;
0127     }
0128     else if(k_side==0){ //temporary until map of HO is done
0129       rbxsign=1;
0130       z_zero=12;
0131     }
0132 
0133   } else {//not HO
0134     z_zero=0;
0135     if(k_side==1){ rbxsign=1;}
0136     else if(k_side==-1){ rbxsign=0;}
0137   
0138 }
0139   
0140 
0141   int det_num;
0142   std::string rbxnum = k_rbx.substr(3);  
0143   if(k_det=="HB"){det_num=1;}
0144   else if(k_det=="HE"){det_num=2;}
0145   else if(k_det=="HF"){det_num=3;}
0146   else if(k_det=="HO"){det_num=4;}
0147   
0148   dM.m_rbx=(det_num-1)*18+rbxsign*90+z_zero+(atoi (rbxnum.c_str()));
0149    
0150   dM.m_rm=k_rm;
0151   dM.m_qie=k_qie;//RM_card
0152   dM.m_adc=k_adc;//RM_chan
0153   dM.m_fi_ch=k_fi_ch;
0154   dM.m_crate=k_crate;
0155   dM.m_htr=k_htr;
0156   if (k_fpga=="top"){dM.m_fpga=1;}
0157   else if (k_fpga=="bot"){dM.m_fpga=0;}
0158   dM.m_htr_fi=k_htr_fi;//fiber
0159   dM.m_spigo=k_spigo;
0160   //FED id
0161   if ((k_crate==4)&&(k_dcc==1)){
0162     dM.m_dcc=0;}
0163   if ((k_crate==4)&&(k_dcc==2)){
0164     dM.m_dcc=1;}
0165   if ((k_crate==0)&&(k_dcc==1)){
0166     dM.m_dcc=2;}
0167   if ((k_crate==0)&&(k_dcc==2)){
0168     dM.m_dcc=3;}
0169   if ((k_crate==1)&&(k_dcc==1)){
0170     dM.m_dcc=4;}
0171   if ((k_crate==1)&&(k_dcc==2)){
0172     dM.m_dcc=5;}
0173   if ((k_crate==5)&&(k_dcc==1)){
0174     dM.m_dcc=6;}
0175   if ((k_crate==5)&&(k_dcc==2)){
0176     dM.m_dcc=7;}
0177   if ((k_crate==11)&&(k_dcc==1)){
0178     dM.m_dcc=8;}
0179   if ((k_crate==11)&&(k_dcc==2)){
0180     dM.m_dcc=9;}
0181   if ((k_crate==15)&&(k_dcc==1)){
0182     dM.m_dcc=10;}
0183   if ((k_crate==15)&&(k_dcc==2)){
0184     dM.m_dcc=11;}
0185   if ((k_crate==17)&&(k_dcc==1)){
0186     dM.m_dcc=12;}
0187   if ((k_crate==17)&&(k_dcc==2)){
0188     dM.m_dcc=13;}
0189   if ((k_crate==14)&&(k_dcc==1)){
0190     dM.m_dcc=14;}
0191   if ((k_crate==14)&&(k_dcc==2)){
0192     dM.m_dcc=15;}
0193   if ((k_crate==10)&&(k_dcc==1)){
0194     dM.m_dcc=16;}
0195   if ((k_crate==10)&&(k_dcc==2)){
0196     dM.m_dcc=17;}
0197   if ((k_crate==2)&&(k_dcc==1)){
0198     dM.m_dcc=18;}
0199   if ((k_crate==2)&&(k_dcc==2)){
0200     dM.m_dcc=19;}
0201   if ((k_crate==9)&&(k_dcc==1)){
0202     dM.m_dcc=20;}
0203   if ((k_crate==9)&&(k_dcc==2)){
0204     dM.m_dcc=21;}
0205   if ((k_crate==12)&&(k_dcc==1)){
0206     dM.m_dcc=22;}
0207   if ((k_crate==12)&&(k_dcc==2)){
0208     dM.m_dcc=23;}
0209   if ((k_crate==3)&&(k_dcc==1)){
0210     dM.m_dcc=24;}
0211   if ((k_crate==3)&&(k_dcc==2)){
0212     dM.m_dcc=25;}
0213   if ((k_crate==7)&&(k_dcc==1)){
0214     dM.m_dcc=26;}
0215   if ((k_crate==7)&&(k_dcc==2)){
0216     dM.m_dcc=27;}
0217   if ((k_crate==6)&&(k_dcc==1)){
0218     dM.m_dcc=28;}
0219   if ((k_crate==6)&&(k_dcc==2)){
0220     dM.m_dcc=29;}
0221   if ((k_crate==13)&&(k_dcc==1)){
0222     dM.m_dcc=30;}
0223   if ((k_crate==13)&&(k_dcc==2)){
0224     dM.m_dcc=31;}
0225   return dM;  
0226 
0227 }
0228 
0229 void CCAmap::convert(const char* lineData, std::vector<std::string>& chunkWords) {
0230   std::string chunk;
0231   chunkWords.clear();
0232   for (int i=0; lineData[i]!=0; ++i) {
0233     if (isspace(lineData[i])) {
0234       if (!chunk.empty()) {
0235     chunkWords.push_back(chunk);
0236     chunk.clear();
0237       }
0238     } else {
0239       chunk+=lineData[i];
0240     }
0241     
0242   }
0243   if (!chunk.empty()) chunkWords.push_back(chunk);
0244 }//end of convert
0245 
0246 CCAmap::CCAmap(const char* fname){
0247 
0248   
0249   FILE* fp;
0250   char instr[3024];
0251   fp=fopen(fname,"r");
0252   std::vector<std::string> WordChunks;
0253 
0254 
0255   if(fp==NULL){printf("file not found,%s\n",fname);exit(1);}
0256   while (!feof(fp) ){
0257     fgets(instr,3024,fp);
0258     if (instr[0]=='#')continue;
0259    
0260     convert(instr,WordChunks);    
0261     if (WordChunks.size()>20) {
0262       v=DataMapMaker(WordChunks);
0263       vm.push_back(v);
0264     }
0265     
0266     
0267   }
0268   if (fp!=NULL) fclose(fp);
0269 }
0270 
0271 
0272 
0273 class CCApatternmaker {
0274 public:
0275   void makePattern(int rbx,const char* fname);
0276 private:
0277   void packPair(unsigned char q0, unsigned char q1, unsigned char& b0, unsigned char& b1);
0278   std::vector<unsigned char> packCCA(int rbx, int rm, int card, int cca);
0279   std::vector<unsigned char> makeSequence(int rbx, int rm, int card, int cca, int ccaq);
0280   int rmCode(int rbx, int rm,int card);
0281   CCAmap* theMap;
0282 };
0283 
0284 
0285 int CCApatternmaker::rmCode(int rbx, int rm,int card) {
0286   if(((rbx>0)&&(rbx<19))||((rbx>90)&&(rbx<109))) {// this is valid for HB
0287     switch (rm) {
0288     case(1):return 16;
0289     case(2):return 8;
0290     case(3):return 2;
0291     case(4):return 1;
0292     default: return 0;
0293     }
0294   }
0295   
0296   if(((rbx>18)&&(rbx<37))||((rbx>108)&&(rbx<127))) {// this is valid for HE
0297     switch (rm) {
0298     case(1):return 32;
0299     case(2):return 16;
0300     case(3):return 2;
0301     case(4):return 1;
0302     default: return 0;
0303     }
0304   }
0305   
0306   if(((rbx>54)&&(rbx<67))||((rbx>143)&&(rbx<168))) {// this is valid for HO
0307     switch (rm) {
0308     case(1):return 16;
0309     case(2):return 8;
0310     case(3):return 2;
0311     case(4):return 1;
0312     default: return 0;
0313     }
0314   }
0315   
0316 
0317   if(((rbx>36)&&(rbx<49))||((rbx>126)&&(rbx<139))) {//HF,assuming simplest map, unverified
0318     if((rm==1)&&(card==1)){
0319       return 2;}
0320     else if((rm==1)&&(card>1)){
0321       return 4;}
0322     else if((rm==2)&&(card<3)){
0323       return 8;}
0324     else if((rm==2)&&(card>2)){
0325       return 16;}
0326     else if((rm==3)&&(card==1)){
0327       return 16;}
0328     else if((rm==3)&&(card>1)){
0329       return 32;} else return 0;
0330   }
0331 }
0332 
0333 void CCApatternmaker::makePattern(int rbx,const char* fname){
0334   theMap=new CCAmap(fname);
0335   int rm_mx,card_mx;
0336   bool in_he = false;
0337   bool in_hb = false;
0338   bool in_hf = false;
0339   bool in_ho = false;
0340   time_t Now=time(0);
0341   std::cout <<"; RBX:" <<rbx <<" "<< ctime(&Now)<<std::endl;
0342   if(((rbx>0)&&(rbx<19))||((rbx>90)&&(rbx<109))) {// this is valid for HB
0343     rm_mx=4;
0344     card_mx=3;in_hb=true;}
0345 
0346   else if(((rbx>18)&&(rbx<37))||((rbx>108)&&(rbx<127))) {//this is valid for HE
0347     rm_mx=4;card_mx=3;in_he=true;}
0348   else if(((rbx>36)&&(rbx<49))||((rbx>126)&&(rbx<139))) {//HF
0349     rm_mx=3;card_mx=4;in_hf=true;}
0350   else if(((rbx>54)&&(rbx<67))||((rbx>143)&&(rbx<168))) {// this is valid for HO
0351     rm_mx=4;card_mx=3;in_ho=true;}//not verified
0352 
0353   for (int rm=1; rm<=rm_mx; rm++) {
0354     std::cout << "; rm " << rm << std::endl;
0355     for (int card=1; card<=card_mx; card++) {
0356       for (int cca=0; cca<3; cca++) {
0357     std::vector<unsigned char> ccadata=packCCA(rbx,rm,card,cca);
0358     
0359     
0360     std::cout << "w 0 " << rmCode(rbx,rm,card) << " 10 ";
0361     int dev;
0362     if(!in_hf){
0363       dev=cca;
0364       if (card==2) dev+=16;
0365       if (card==3) dev+=32;
0366     }else {
0367       
0368       if(((card==2)&&((rm==1)||(rm==3)))||((rm==2)&&((card==1)||(card==3)))){dev=cca;}
0369       if(((card==3)&&((rm==1)||(rm==3)))||((rm==2)&&((card==2)||(card==4)))){dev=cca+16;}
0370       if(((rm==1)||(rm==3))&&((card==1)||(card==4))){dev=cca+32;}
0371     }   
0372     std::cout << dev << " 0x8";
0373     for (int i=0; i<10; i++)
0374       std::cout << ' ' << (int)ccadata[i];
0375     std::cout << std::endl;
0376     
0377     std::cout << "w 0 " << rmCode(rbx,rm,card) << " 10 ";
0378     std::cout << dev << " 0x12";
0379     
0380     for (int i=10; i<20; i++)
0381       std::cout << ' ' << (int)ccadata[i];
0382     std::cout << std::endl;
0383       }
0384     }
0385     //set test pattern enable bit
0386     std::cout<<std::endl;
0387     std::cout << "; set test pattern enable bit"<<std::endl;
0388     if (in_hb){
0389       if (rm==1){
0390     std::cout << "w 0 16 1 0 0 2"<<std::endl;
0391     std::cout << "w 0 16 1 1 0 2"<<std::endl;
0392     std::cout << "w 0 16 1 2 0 2"<<std::endl;
0393     std::cout << "w 0 16 1 16 0 2"<<std::endl;
0394     std::cout << "w 0 16 1 17 0 2"<<std::endl;
0395     std::cout << "w 0 16 1 18 0 2"<<std::endl;
0396     std::cout << "w 0 16 1 32 0 2"<<std::endl;
0397     std::cout << "w 0 16 1 33 0 2"<<std::endl;
0398     std::cout << "w 0 16 1 34 0 2"<<std::endl;
0399     
0400       }else if (rm==2){
0401             std::cout << "w 0 1 1 0 0 2"<<std::endl;
0402     std::cout << "w 0 8 1 1 0 2"<<std::endl;
0403     std::cout << "w 0 8 1 2 0 2"<<std::endl;
0404     std::cout << "w 0 8 1 16 0 2"<<std::endl;
0405     std::cout << "w 0 8 1 17 0 2"<<std::endl;
0406     std::cout << "w 0 8 1 18 0 2"<<std::endl;
0407     std::cout << "w 0 8 1 32 0 2"<<std::endl;
0408     std::cout << "w 0 8 1 33 0 2"<<std::endl;
0409     std::cout << "w 0 8 1 34 0 2"<<std::endl;
0410       }else if (rm==3){
0411     std::cout << "w 0 2 1 0 0 2"<<std::endl;
0412     std::cout << "w 0 2 1 1 0 2"<<std::endl;
0413     std::cout << "w 0 2 1 2 0 2"<<std::endl;
0414     std::cout << "w 0 2 1 16 0 2"<<std::endl;
0415     std::cout << "w 0 2 1 17 0 2"<<std::endl;
0416     std::cout << "w 0 2 1 18 0 2"<<std::endl;
0417     std::cout << "w 0 2 1 32 0 2"<<std::endl;
0418     std::cout << "w 0 2 1 33 0 2"<<std::endl;
0419     std::cout << "w 0 2 1 34 0 2"<<std::endl;
0420       }else if (rm==4){
0421     std::cout << "w 0 1 1 0 0 2"<<std::endl;
0422     std::cout << "w 0 1 1 1 0 2"<<std::endl;
0423     std::cout << "w 0 1 1 2 0 2"<<std::endl;
0424     std::cout << "w 0 1 1 16 0 2"<<std::endl;
0425     std::cout << "w 0 1 1 17 0 2"<<std::endl;
0426     std::cout << "w 0 1 1 18 0 2"<<std::endl;
0427     std::cout << "w 0 1 1 32 0 2"<<std::endl;
0428     std::cout << "w 0 1 1 33 0 2"<<std::endl;
0429     std::cout << "w 0 1 1 34 0 2"<<std::endl;
0430       }
0431     
0432     }else if (in_he){
0433       if (rm==1){
0434     std::cout << "w 0 32 1 0 0 2"<<std::endl;
0435     std::cout << "w 0 32 1 1 0 2"<<std::endl;
0436     std::cout << "w 0 32 1 2 0 2"<<std::endl;
0437     std::cout << "w 0 32 1 16 0 2"<<std::endl;
0438     std::cout << "w 0 32 1 17 0 2"<<std::endl;
0439     std::cout << "w 0 32 1 18 0 2"<<std::endl;
0440     std::cout << "w 0 32 1 32 0 2"<<std::endl;
0441     std::cout << "w 0 32 1 33 0 2"<<std::endl;
0442     std::cout << "w 0 32 1 34 0 2"<<std::endl;
0443       }else if (rm==2){
0444             std::cout << "w 0 1 1 0 0 2"<<std::endl;
0445     std::cout << "w 0 16 1 1 0 2"<<std::endl;
0446     std::cout << "w 0 16 1 2 0 2"<<std::endl;
0447     std::cout << "w 0 16 1 16 0 2"<<std::endl;
0448     std::cout << "w 0 16 1 17 0 2"<<std::endl;
0449     std::cout << "w 0 16 1 18 0 2"<<std::endl;
0450     std::cout << "w 0 16 1 32 0 2"<<std::endl;
0451     std::cout << "w 0 16 1 33 0 2"<<std::endl;
0452     std::cout << "w 0 16 1 34 0 2"<<std::endl;
0453       }else if (rm==3){
0454     std::cout << "w 0 2 1 0 0 2"<<std::endl;
0455     std::cout << "w 0 2 1 1 0 2"<<std::endl;
0456     std::cout << "w 0 2 1 2 0 2"<<std::endl;
0457     std::cout << "w 0 2 1 16 0 2"<<std::endl;
0458     std::cout << "w 0 2 1 17 0 2"<<std::endl;
0459     std::cout << "w 0 2 1 18 0 2"<<std::endl;
0460     std::cout << "w 0 2 1 32 0 2"<<std::endl;
0461     std::cout << "w 0 2 1 33 0 2"<<std::endl;
0462     std::cout << "w 0 2 1 34 0 2"<<std::endl;
0463       }else if (rm==4){
0464     std::cout << "w 0 1 1 0 0 2"<<std::endl;
0465     std::cout << "w 0 1 1 1 0 2"<<std::endl;
0466     std::cout << "w 0 1 1 2 0 2"<<std::endl;
0467     std::cout << "w 0 1 1 16 0 2"<<std::endl;
0468     std::cout << "w 0 1 1 17 0 2"<<std::endl;
0469     std::cout << "w 0 1 1 18 0 2"<<std::endl;
0470     std::cout << "w 0 1 1 32 0 2"<<std::endl;
0471     std::cout << "w 0 1 1 33 0 2"<<std::endl;
0472     std::cout << "w 0 1 1 34 0 2"<<std::endl;
0473       }
0474 
0475     }else if(in_hf){//unverified
0476       if (rm==1){
0477     std::cout << "w 0 2 1 32 0 2"<<std::endl;
0478     std::cout << "w 0 2 1 33 0 2"<<std::endl;
0479     std::cout << "w 0 2 1 34 0 2"<<std::endl;
0480     std::cout << "w 0 4 1 0 0 2"<<std::endl;
0481     std::cout << "w 0 4 1 1 0 2"<<std::endl;
0482     std::cout << "w 0 4 1 2 0 2"<<std::endl;
0483     std::cout << "w 0 4 1 16 0 2"<<std::endl;
0484     std::cout << "w 0 4 1 17 0 2"<<std::endl;
0485     std::cout << "w 0 4 1 18 0 2"<<std::endl;
0486     std::cout << "w 0 4 1 32 0 2"<<std::endl;
0487     std::cout << "w 0 4 1 33 0 2"<<std::endl;
0488     std::cout << "w 0 4 1 34 0 2"<<std::endl;
0489       }else if (rm==2){
0490         std::cout << "w 0 8 1 0 0 2"<<std::endl;
0491     std::cout << "w 0 8 1 1 0 2"<<std::endl;
0492     std::cout << "w 0 8 1 2 0 2"<<std::endl;
0493     std::cout << "w 0 8 1 16 0 2"<<std::endl;
0494     std::cout << "w 0 8 1 17 0 2"<<std::endl;
0495     std::cout << "w 0 8 1 18 0 2"<<std::endl;
0496     std::cout << "w 0 16 1 0 0 2"<<std::endl;
0497     std::cout << "w 0 16 1 1 0 2"<<std::endl;
0498     std::cout << "w 0 16 1 2 0 2"<<std::endl;
0499     std::cout << "w 0 16 1 16 0 2"<<std::endl;
0500     std::cout << "w 0 16 1 17 0 2"<<std::endl;
0501     std::cout << "w 0 16 1 18 0 2"<<std::endl;
0502       }else if (rm==3){
0503         std::cout << "w 0 16 1 32 0 2"<<std::endl;
0504     std::cout << "w 0 16 1 33 0 2"<<std::endl;
0505     std::cout << "w 0 16 1 34 0 2"<<std::endl;
0506     std::cout << "w 0 32 1 0 0 2"<<std::endl;
0507     std::cout << "w 0 32 1 1 0 2"<<std::endl;
0508     std::cout << "w 0 32 1 2 0 2"<<std::endl;
0509     std::cout << "w 0 32 1 16 0 2"<<std::endl;
0510     std::cout << "w 0 32 1 17 0 2"<<std::endl;
0511     std::cout << "w 0 32 1 18 0 2"<<std::endl;
0512     std::cout << "w 0 32 1 32 0 2"<<std::endl;
0513     std::cout << "w 0 32 1 33 0 2"<<std::endl;
0514     std::cout << "w 0 32 1 34 0 2"<<std::endl;
0515       }
0516     }//else if(in_ho){} //map unmade
0517     
0518     std::cout<<std::endl;
0519     
0520   }
0521   std::cout<<std::endl;
0522   std::cout << "get 0; do a read for a delay"<<std::endl;
0523   std::cout << "get 1; do a read for a delay"<<std::endl;
0524   std::cout << "put 63 12; Write to Control Register issue a QIE Reset & Leave clock to backplane Enabled"<<std::endl;
0525   std::cout << "get 0; do a read for a delay"<<std::endl;
0526   std::cout << "get 1; do a read for a delay"<<std::endl;
0527   std::cout << "put 61 1 ; enable B0 from TTC"<<std::endl;
0528   
0529 }
0530 std::vector<unsigned char> CCApatternmaker::packCCA(int rbx, int rm, int card, int cca) {
0531   std::vector<unsigned char> q0=makeSequence(rbx,rm,card,cca,0);
0532   std::vector<unsigned char> q1=makeSequence(rbx,rm,card,cca,1);
0533   std::vector<unsigned char> data;
0534   for (int i=0; i<10; i++) {
0535     unsigned char b0,b1;
0536     packPair(q0[i],q1[i],b0,b1);
0537     data.push_back(b0);
0538     data.push_back(b1);
0539  }
0540   return data;
0541 }
0542 
0543 void CCApatternmaker::packPair(unsigned char q0, unsigned char q1, unsigned char& b0, unsigned char& b1) {
0544 
0545   b0 = 0;
0546   if (q0&0x01){ b0|=0x40;}
0547   if (q0&0x02){ b0|=0x20;}
0548   if (q0&0x04){ b0|=0x10;}
0549   if (q0&0x08){ b0|=0x08;}
0550   if (q0&0x10){ b0|=0x04;}
0551   if (q0&0x20){ b0|=0x02;}
0552   if (q0&0x40){ b0|=0x01;}
0553 
0554 
0555  b1 = 0;
0556   if (q1&0x01){ b1|=0x80;}
0557   if (q1&0x02){ b1|=0x40;}
0558   if (q1&0x04){ b1|=0x20;}
0559   if (q1&0x08){ b1|=0x10;}
0560   if (q1&0x10){ b1|=0x08;}
0561   if (q1&0x20){ b1|=0x04;}
0562   if (q1&0x40){ b1|=0x02;}
0563 }
0564 
0565 
0566 
0567 std::vector<unsigned char> CCApatternmaker::makeSequence(int rbx, int rm, int card, int cca, int ccaq) {
0568   
0569   int ieta,iphi,depth,det,spigot, fiber, crate, fiber_chan, G_Dcc, H_slot, TB;
0570   theMap->map(rbx,rm,card,cca,ccaq,ieta,iphi,depth,det,spigot, fiber, crate, fiber_chan, G_Dcc, H_slot, TB);
0571 
0572   
0573 std::vector<unsigned char> cc;
0574   const int header = 0x75;
0575   cc.push_back(((header&0x7F)<<0));
0576   cc.push_back(((abs(ieta)&0x3F)<<0)|((ieta>0)?(0x40):(0x0)));
0577   cc.push_back(((iphi&0x7F)<<0));
0578   cc.push_back(((depth&0x7)<<0)|((det&0xF)<<3));
0579   cc.push_back(((spigot&0xF)<<0)|(((fiber-1)&0x7)<<4));
0580   cc.push_back(((crate&0x1F)<<0)|((fiber_chan&0x3)<<5));
0581   cc.push_back(((G_Dcc&0x3F)<<0));
0582   cc.push_back(((H_slot&0x1F)<<0)|((TB&0x1)<<5)|(((rbx&0x80)>>7)<<6));
0583   cc.push_back(((rbx&0x7F)<<0));
0584   cc.push_back((((rm-1)&0x3)<<0)|(((card-1)&0x3)<<2)|(((cca*2+ccaq)&0x7)<<4));
0585   
0586   
0587   
0588   return cc;
0589 }
0590 
0591 int main(int argc, char* argv[]) {
0592   if (argc<3) {
0593     std::cout << "Usage: " << argv[0] << " [rbx] [filename]\n";
0594     return 1;
0595   }
0596   CCApatternmaker maker;
0597   maker.makePattern(atoi(argv[1]), argv[2]);
0598   
0599   return 0;
0600 }