-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetFromDatabase.cxx
201 lines (160 loc) · 7.02 KB
/
GetFromDatabase.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <ctime>
#include "../new-alpide-software/DataBaseSrc/DBHelpers.h"
#include "../new-alpide-software/DataBaseSrc/AlpideDB.h"
#include "../new-alpide-software/DataBaseSrc/AlpideDBEndPoints.h"
#include "paths/pathstaverec.h"
#include "paths/pathstaveqt.h"
using namespace std;
using namespace std::chrono;
//Function to replace white spaces in a string with _
std::string space2underscore(std::string text) {
for(std::string::iterator it = text.begin(); it != text.end(); ++it) {
if(*it == ' ') {
*it = '_';
}
}
return text;
}
//Function that checks if file exist in /eos/...
int IsFileExisting(string path){
if(path.find("Threshold")==string::npos) return -1;
FILE *filein;
filein = fopen (path.c_str(), "r");
if(filein!=NULL){
fclose(filein);
return 1;
}
return 0;
}
//Bubble sort for strings
void bubbleSort(std::vector<string> &arr1, std::vector<int> &arr2, std::vector<string> &arr3, int n)
{
for (int j=0; j<n-1; j++)
{
for (int i=j+1; i<n; i++)
{
if (arr1[j]<arr1[i])
{
std::swap(arr1[i], arr1[j]);
std::swap(arr2[i], arr2[j]);
std::swap(arr3[i], arr3[j]);
}
}
}
}
//Function to write vector into file
void WriteToFile(std::vector<string> name, std::vector<int> wc, std::vector<string> date, string fname){
ofstream fileout (fname.c_str());
for(int i=0; i<(int)name.size(); i++){
fileout<<name[i]<<" "<<date[i].substr(0,8)<<" "<<wc[i]<<endl;
}
fileout<<"-------------------------------------- ------------------------------------ -1"<<endl;
fileout.close();
}
void GetFromDatabase(){
//THicType hicType = HIC_OB;
//vector to contain activity name and file paths
std::vector<string> fpathHS, fpathStave, fpathStaveCern, hsAname, staveAname, staveAnamecern;
std::vector<string> dateHS, dateStave, dateCern;
std::vector<int> wcHS, wcStave, wcCern;
//vector for string editing
std::vector<string> testcity = {"TestB","TestT","TestA", "TestD", "TestF"};
std::vector<string> testcityund = {"Test_B","Test_T","Test_A", "Test_D", "Test_F"};
//Initialize DB
AlpideDB *db;
db = new AlpideDB(0);
//Get list of HICs into the DB
int componentTypeId;
componentTypeId = DbGetComponentTypeId (db, "Outer Barrel HIC Module");
ComponentDB *componentDB = new ComponentDB(db);
std::vector<ComponentDB::componentShort> componentList;//list
componentDB->GetListByType(db->GetProjectId(), componentTypeId, &componentList);
//Loop on all components
std::vector<ComponentDB::compActivity> tests;
std::vector<ComponentDB::componentShort>::iterator iComp;
for (iComp = componentList.begin(); iComp != componentList.end(); iComp++) {
ComponentDB::componentShort comp = *iComp;
DbGetAllTests (db, comp.ID, tests, STThreshold, true);
//Loop on all activities
std::vector<ComponentDB::compActivity>::iterator it;
ActivityDB *activityDB = new ActivityDB(db);
for(it = tests.begin(); it != tests.end(); it++) {
ComponentDB::compActivity act = *it;
ActivityDB::activityLong actLong;
activityDB->Read(act.ID, &actLong);
//EOS path
//string eosPathSingle = GetEosPath(actLong, hicType, false);
//string eosPathDouble = GetEosPath(actLong, hicType, true);//for old HICs where HIC name appear twice
//string dataName, resultName;
//GetThresholdFileName(actLong, 0, false, 0, dataName, resultName);//take tuned thr scan at 0V BB
//Get the paramenter "Number of Working Chips"
float nworkch;
bool isparamexist;
isparamexist = DbFindParamValue(actLong.Parameters, "Number of Working Chips", nworkch);
if(!isparamexist) nworkch = -1.;
//Get start date
string qualdatehuman;
qualdatehuman.resize(20);
time_t qualdatetimeunix = actLong.StartDate;
strftime(&qualdatehuman[0], qualdatehuman.size(), "%Y%m%d %H:%M:%S", localtime(&qualdatetimeunix));
//cout<<actLong.Name<<" "<<qualdatehuman<<endl;
/*std::tm* t = std::gmtime(&qualdatetime);
std::stringstream ss; // or if you're going to print, just input directly into the output stream
ss << std::put_time(t, "%d/%m/%Y %I:%M:%S %p");
string output = ss.str();
cout<<actLong.Name<<" "<<output<<endl;*/
//string fpathSingle = eosPathSingle + "/" + resultName;
//string fpathDouble = eosPathDouble + "/" + resultName;
//Check which file really exist in eos
//int fexistSingle = IsFileExisting(fpathSingle);
//string fpathreal;
//if(fexistSingle==-1) continue;
//else if(fexistSingle) fpathreal=fpathSingle;
//else fpathreal=fpathDouble;
//Remove a strange [1558583984] number from activity name, remove "Retest", replace Test<city> with Test_city-> problem for alphabetic order
if(actLong.Name.find("[") != string::npos)
actLong.Name.replace(actLong.Name.find("[")-1, 13, "");
if(actLong.Name.find("Retest") != string::npos)
actLong.Name.replace(actLong.Name.find("Retest")-1, 9, "");
for(int i=0; i<(int)testcity.size(); i++)
if(actLong.Name.find(testcity[i].c_str()) != string::npos)
actLong.Name.replace(actLong.Name.find(testcity[i].c_str()), 5, testcityund[i].c_str());
//Save activity names, test date, #work-chips into vector (alphabetically unordered here!)
if(actLong.Type.Name.find("Stave") == string::npos) {wcHS.push_back(nworkch); dateHS.push_back(qualdatehuman); hsAname.push_back(space2underscore(actLong.Name));}
if(actLong.Type.Name.find("Reception") == string::npos && actLong.Type.Name.find("HS Qualification")==string::npos){
dateStave.push_back(qualdatehuman);
wcStave.push_back(nworkch);
staveAname.push_back(space2underscore(actLong.Name));
}
if(actLong.Type.Name.find("Reception") != string::npos) {wcCern.push_back(nworkch); dateCern.push_back(qualdatehuman); staveAnamecern.push_back(space2underscore(actLong.Name));}
}
delete activityDB;
}
//Add paths manually
/*for(int i=0; i<(int)pathStaveRec.size(); i++){
fpathStaveCern.push_back(pathStaveRec[i].substr(pathStaveRec[i].find("/eos"),pathStaveRec[i].size()));
staveAnamecern.push_back(pathStaveRec[i].substr(0, pathStaveRec[i].find("/eos")-1));
}
for(int i=0; i<(int)pathStaveQt.size(); i++){
fpathStave.push_back(pathStaveQt[i].substr(pathStaveQt[i].find("/eos"),pathStaveQt[i].size()));
staveAname.push_back(pathStaveQt[i].substr(0, pathStaveQt[i].find("/eos")-1));
}*/
//Alphabetical ordering of the vector
bubbleSort(hsAname, wcHS, dateHS, (int)hsAname.size());
bubbleSort(staveAname, wcStave, dateStave, (int)staveAname.size());
bubbleSort(staveAnamecern, wcCern, dateCern, (int)staveAnamecern.size());
//Write vector into file (alphabetically ordered!!)
WriteToFile(hsAname, wcHS, dateHS, "hsfiles.dat");
WriteToFile(staveAname, wcStave, dateStave, "stavefiles.dat");
WriteToFile(staveAnamecern, wcCern, dateCern, "stavefiles_rec.dat");
}
int main(){
GetFromDatabase();
return 0;
}