00001
00002
00003
00004 #include <sstream>
00005 #include <iostream>
00006 #include <map>
00007 #include <string>
00008 #include <set>
00009 #include <sstream>
00010
00011 #include "tools/MicroException.hh"
00012 #include "tools/Toolbox.hh"
00013 #include "tools/Log.hh"
00014
00015
00016 using namespace std;
00017
00018
00019 Toolbox::Toolbox()
00020 {
00021 }
00022
00023
00024 Toolbox::~Toolbox()
00025 {
00026 }
00027
00028
00029 void Toolbox::printRepere ( bool xRotation, bool yRotation, int zRotation )
00030 {
00031 cout <<" \n ------------- ROTATIONS" << endl;
00032
00033 int result = (xRotation== false) ? 0 : 180;
00034 cout << "### xRotation " << result << " degree." << endl;
00035
00036 result = (yRotation== false) ? 0 : 180;
00037 cout << "### yRotation " << result << " degree." << endl;
00038
00039 cout << "### zRotation " << zRotation << " degree." << endl;
00040
00041
00042 cout << endl << "### Nous utilisons un repere irthonorme directe ###" <<endl;
00043 cout << "" << endl;
00044 cout << " X" << endl;
00045 cout << " " << endl;
00046 cout << " ^" << endl;
00047 cout << " / \\ " << endl;
00048 cout << " |" << endl;
00049 cout << " |" << endl;
00050 cout << " |" << endl;
00051 cout << " |" << endl;
00052 cout << " |" << endl;
00053 cout << " |" << endl;
00054 cout << "SYSTEM de COORDONNEES: (0,0) au centre ----X----------> Y " << endl;
00055 cout << " Z rentrant. |" << endl;
00056 cout << " |" << endl;
00057 cout << " |" << endl;
00058 cout << " |" << endl;
00059
00060 }
00061
00062
00063
00064
00065
00066 unsigned short Toolbox::bigTolittle ( short value )
00067 {
00068
00069 unsigned short lsb = value & MASK_LSB ;
00070 lsb = lsb << 8 ;
00071
00072 unsigned short msb = value & MASK_MSB;
00073 msb = msb >> 8 ;
00074
00075
00076
00077 unsigned short result = lsb + msb;
00078 return result;
00079 }
00080
00081
00082 void Toolbox::addFloatToString(std::string& chaine, float value)
00083 {
00084
00085 std::string s;
00086 std::stringstream out;
00087 out << value;
00088 s = out.str();
00089 chaine = chaine.append(s);
00090 }
00091
00092 void Toolbox::addIntToString(std::string& chaine, int value)
00093 {
00094
00095 std::string s;
00096 std::stringstream out;
00097 out << value;
00098 s = out.str();
00099 chaine = chaine.append(s);
00100 }
00101
00102
00103 void Toolbox::readSteerFile(string steerName , bool debug = false)
00104 {
00105
00106 FILE *steerFile;
00107
00108
00109
00110 cout << "Steering File: " << steerName << endl;
00111
00112
00113 steerFile=fopen(steerName.data(),"r");
00114
00115
00116 int nbOfFile = 0;
00117 fscanf (steerFile, "%d", &nbOfFile);
00118 if ( debug ) cout << "Nb input data file(s)\t" << nbOfFile << endl;
00119
00120
00121 string fileNam[nbOfFile];
00122 for ( int i = 0 ; i < nbOfFile ; i++ )
00123 {
00124 fscanf (steerFile, "%s",fileNam[i].data());
00125 if ( debug ) cout << "input data file " << i << " \t" << fileNam[i].data() << endl;
00126 }
00127
00128
00129 string rootFileName;
00130 fscanf (steerFile, "%s", rootFileName.data());
00131 if ( debug ) cout << "root file name \t\t" << rootFileName.data() << endl;
00132
00133
00134 string verbose;
00135 fscanf (steerFile, "%s",verbose.data());
00136 if ( debug ) cout << "verbose Mode\t\t" << verbose.data() << endl;
00137
00138
00139 int Nmicro = 0;
00140 fscanf (steerFile, "%d", &Nmicro);
00141 if ( debug ) cout << "Nb of MicroMegas Chambers " <<Nmicro<< endl;
00142
00143
00144 int NGplex[Nmicro];
00145
00146 int NTotGplex = 0;
00147 for ( int i = 0 ; i < Nmicro ; i++ )
00148 {
00149 fscanf (steerFile, "%d", &NGplex[i]);
00150 if ( debug ) cout << "Nb of Gassiplex Cards for MicroMegas no="<<i<< " " <<NGplex[i]<< endl;
00151 if ( debug ) cout << "Nb of Channels for MicroMegas no="<<i<< " " <<NGplex[i]*96<< endl;
00152 NTotGplex += NGplex[i]; }
00153 if ( debug ) cout << "TOTAL Nb of Gassiplex Cards " << NTotGplex << endl;
00154
00155
00156 unsigned int Nchamber[NTotGplex];
00157 int GplCount=-1;
00158 for ( int i = 0 ; i < Nmicro ; i++ )
00159 {
00160 for ( int j = 0 ; j < NGplex[i] ; j++ )
00161 {
00162 GplCount++;
00163 Nchamber[GplCount]=i;
00164 if ( debug ) cout << "ID of MicroMegas for gassiplex nb" << GplCount << " : " << Nchamber[GplCount]<<endl;
00165 }
00166 }
00167
00168
00169 fclose (steerFile);
00170 float d=3;
00171 int nBeta2=0;
00172 int nBeta24=0;
00173 for(int i=0;i<Nmicro;i++){if(NGplex[i]==1){nBeta2++;}else{nBeta24++;}}
00174 if ( debug ) cout<<nBeta2<<" chambres beta 2\n"
00175 <<nBeta24<<" chambres beta 2.4\n";
00176
00177 if ( strcmp(verbose.data(),"-v") == 0 ) { verbose = true; }
00178 if ( debug ) cout << "Verbose mode\t\t\t\t" << verbose << endl;
00179
00180
00181
00182 }
00183
00184
00185
00186
00187 std::ostream& operator <<(std::ostream &out, const BinOut& x) {
00188
00189
00190 for (unsigned int digit = x._Digits; digit > 0; digit--) {
00191 if ((digit != x._Digits) && (digit % 4 == 0))
00192 out << " ";
00193 out << ((x._Num >> (digit - 1)) & 0x1);
00194 }
00195 return(out);
00196 }
00197
00198
00199