Subversion Repositories f9daq

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
326 f9daq 1
 
2
#include <stdio.h>
3
#include <stdlib.h>
4
#include <sys/stat.h>
5
#include <TROOT.h>
6
#include <TSystem.h>
7
#include <TFile.h>
8
#include <TDirectory.h>
9
#include <TCanvas.h>
10
#include <TH2D.h>
11
 
12
#include <algorithm>
13
#include <iostream>
14
#include <fstream>
15
#include <string>
16
#include <sstream>
17
#include <vector>
18
#include <cctype>
19
 
20
 
21
 
22
#include "base.h"
23
 
24
std::string serialNumberOut;
25
 
26
const char * getSN(int runNumber){
27
  char rNum[0xF];
28
  sprintf(rNum,"%04d",runNumber);
29
  std::string rNumber = rNum;
30
 
31
  const char * serialNumberFromGraph;
32
  std::string serialNumberTemp;
33
 
34
  const char * serialNumberFromGraphHEX;
35
  std::string serialNumberTempHEX;
36
 
37
  std::string delimiter;
38
  size_t pos = 0;
39
 
40
  TH2D * sum_hxy = (TH2D *) gDirectory->Get("hxy0_sum_0");
41
  // TH2D * sum_hxy = (TH2D *) gDirectory->Get("hxy1_sum_0"); // Za rune od 113 - 117, kjer je bil modul 0 izklopljen
42
  TH2D * h2d = (TH2D *) gDirectory->Get("h2d_0");
43
 
44
  if(!sum_hxy) {
45
    printf("Ni naloženega dokumenta!\n");
46
    return (char*) "NoFILE";
47
  }
48
 
49
  serialNumberFromGraph = sum_hxy->GetTitle(); // you get something like: HAPD=ZJ5859/021,ZJ5862/023,ZJ5858/022,ZJ5865/025
50
  serialNumberTemp = serialNumberFromGraph;
51
  delimiter = "=";
52
  pos = serialNumberTemp.find(delimiter);
53
  serialNumberTemp.erase(0, pos + delimiter.length()); // you get something like: ZJ5859/021,ZJ5862/023,ZJ5858/022,ZJ5865/025
54
  //std::cout << "Vrstica 1 " << serialNumberTemp << std::endl;
55
  serialNumberOut = serialNumberTemp;
56
  if(h2d){
57
    serialNumberFromGraphHEX = h2d->GetTitle()+1; // you get something like: FEB0=0x11354161 FEB1=0x11354161 FEB2=0x11354161 FEB3=0x11354161
58
                                                  // there is a whitespace at the beginning of title you want to remove, so you set pointer to +1.
59
    serialNumberTempHEX = serialNumberFromGraphHEX; // you duplicate string
60
    //std::cout << "Vrstica 2 " << serialNumberTempHEX << std::endl;
61
 
62
    std::string SNtemp, FEBsnHEX, output;
63
 
64
    delimiter = ",";
65
      //int iteration=0;
66
    while (serialNumberTemp.length()!=0) {
67
        //std::cout << iteration << std::endl;
68
        //iteration++;
69
      if((pos = serialNumberTemp.find(delimiter))!=std::string::npos) SNtemp = serialNumberTemp.substr(0, pos);
70
      else SNtemp = serialNumberTemp.substr(0, serialNumberTemp.length());
71
        //std::cout << "Vrstica 3 " << SNtemp << std::endl;
72
        //std::cout << "Vrstica 3a " << SNtemp.substr(0,SNtemp.find("/")) << " " << SNtemp.substr(SNtemp.find("/")+1) << std::endl;
73
      if(pos!=std::string::npos) serialNumberTemp.erase(0, pos + delimiter.length());
74
      else serialNumberTemp.erase(0, serialNumberTemp.length());
75
        //std::cout << "Vrstica 4 " << serialNumberTemp << std::endl;
76
      if(!SNtemp.compare("noserial")) continue;
77
      FEBsnHEX = serialNumberTempHEX.substr(serialNumberTempHEX.find("=")+1,serialNumberTempHEX.find(" ")-serialNumberTempHEX.find("=")-1);
78
        //std::cout << "Vrstica 5 " << FEBsnHEX << std::endl;
79
      output = rNumber + " " + SNtemp.substr(0,SNtemp.find("/")) + " "  + SNtemp.substr(SNtemp.find("/")+1) + " "  + FEBsnHEX;
80
      WriteSN(output);
81
        //std::cout << output << std::endl;
82
      serialNumberTempHEX.erase(0,serialNumberTempHEX.find(" ")+1);
83
    }
84
  }
85
  printf("base.c output: %s\n", serialNumberOut.c_str());
86
  return serialNumberOut.c_str();
87
}
88
 
89
int WriteSN(std::string compareLine){
90
  const char * filename = "FEBserial.txt";
91
  std::string line;
92
 
93
  std::fstream file;
94
  file.open(filename, std::fstream::in);
95
  if (file.is_open()){
96
    while (std::getline(file,line)){
97
      //std::cout << line << std::endl;
98
      if(!line.compare(compareLine)) return 0;
99
    }
100
    file.close();
101
  }
102
 
103
  file.open(filename, std::fstream::app);
104
  if (file.is_open()){
105
    file << compareLine << endl;
106
 
107
    std::cout << "Add into " << filename << ": " << compareLine << std::endl;
108
 
109
    file.close();
110
  }
111
 
112
  return 1;
113
}
114
 
115
int file_exists(char * fileName){
116
  struct stat fbuf;
117
  int i = stat (fileName, &fbuf);
118
  if (i==0) return 1; //File found
119
  else return 0;
120
}
121
 
122
GRID mapping(){
123
  int f[6];
124
  int ndim = 400;
125
  char line[400];
126
  GRID m;
127
  FILE * fp = fopen("mapNEW.map","r");
128
 
129
  /*
130
  Stolpec 0: ASIC
131
  Stolpec 1: Kanal na ASICU
132
  Stolpec 2: x (iz sprednje strani)
133
  Stolpec 3: y (iz sprednje strani)
134
  ...
135
  */
136
  while (fgets(line,ndim,fp) != NULL) {
137
    sscanf(line,"%d%d%d%d%d%d",&f[0],&f[1],&f[2],&f[3],&f[4],&f[5]);
138
    //m.koordinatniSistem[f[2]][f[3]] = f[0]*36+f[1];
139
    m.koordinatniSistem[11-f[2]][11-f[3]] = f[0]*36+f[1];
140
    m.pozicijaPixla[f[0]*36+f[1]] = f[4];
141
    m.pozicijaPixlaNaCipu[f[0]*36+f[1]] = f[5];
142
  }
143
  fclose(fp);
144
  return m;
145
}
146
 
147
int CreateFEBsnFile(){
148
  /*
149
  you have to manualy save:
150
  http://www-f9.ijs.si/~f9daq/aerorich/febtest/lvhvbit/xsltproc.php?xml=febps.xml&xsl=febsnmap.xsl
151
  and then leave in this file only 1 line that contains info
152
  (21 0x0130ADFFC6E95A64<br/>22 0x013D3048229681BE<br/> ..........)
153
  */
154
  std::string line;
155
 
156
  size_t pos = 0;
157
  std::string token;
158
 
159
  ifstream inputFile("xsltproc.html");
160
  ofstream outpuFile;
161
  outpuFile.open ("FEBserial.txt");
162
 
163
  if (inputFile.is_open()){
164
    while (std::getline(inputFile,line)){
165
      std::cout << line << std::endl;
166
    }
167
    inputFile.close();
168
  }
169
  else std::cout << "Unable to open file" << std::endl;
170
 
171
  std::string delimiter = "<br/>";
172
 
173
  while ((pos = line.find(delimiter)) != std::string::npos) {
174
    token = line.substr(0, pos);
175
    if (token.length()>3) token = token.erase(token.find(" ")+3,1); // removes the first number after 0x... in 
176
    std::cout << token << std::endl;
177
    outpuFile << token << std::endl;
178
    line.erase(0, pos + delimiter.length());
179
  }
180
 
181
  std::cout << line << std::endl;
182
  outpuFile << line;
183
 
184
  outpuFile.close();
185
 
186
  return 0;
187
 
188
}
189
 
190
int FEBsn(char * searchFEBserial){
191
  FILE * fp = fopen("FEBserial.txt","r");
192
  int FEBserialINT;
193
  char FEBserialHEX[0xFF];
194
  int ndim = 400;
195
  char line[400];
196
  while (fgets(line,ndim,fp) != NULL) {
197
    sprintf(FEBserialHEX,"");
198
    sscanf(line,"%d%s",&FEBserialINT,FEBserialHEX);
199
    //printf("%d \t %s\n",FEBserialINT, FEBserialHEX);
200
    if(!strcmp(FEBserialHEX,searchFEBserial)) return FEBserialINT;
201
  }
202
  return -1;
203
}