-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgetObject.cxx
More file actions
1431 lines (1239 loc) · 58.6 KB
/
getObject.cxx
File metadata and controls
1431 lines (1239 loc) · 58.6 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <string>
#include <iostream>
#include <time.h>
#include <algorithm>
#include "QualityControl/DatabaseFactory.h"
#include "QualityControl/CcdbDatabase.h"
#include "QualityControl/MonitorObject.h"
#include "CCDB/CcdbApi.h"
#include <TBufferJSON.h>
#include <TH2.h>
#include <THnSparse.h>
#include <TFile.h>
#include <TTree.h>
#include <TSystem.h>
using namespace std;
using namespace o2::quality_control::repository;
using namespace o2::quality_control::core;
//functions to download data
string GetCorrectTS(string selrun, vector<string> runs, vector<string> timestamps);
array<string,2> GetLastRunWithTS(o2::ccdb::CcdbApi &ccdbApi, string taskname, string objname);
array<string,2> GetRunWithTS24hAgo(o2::ccdb::CcdbApi &ccdbApi, string taskname, string objname, string timestamp);
vector<string> GetGoodRunList(o2::ccdb::CcdbApi &ccdbApi, string run1, string run2, string runtype, string qcpathstart);
bool RunShifter(CcdbDatabase *ccdb, int opt, string syncasync);
bool RunExpert(CcdbDatabase *ccdb, int opt, string syncasync);
void DownloadTimestamps(CcdbDatabase *ccdb, o2::ccdb::CcdbApi &ccdbApi, string taskname, string objname, long int ts_start, long int ts_end, int lnum);
void DownloadRuns(CcdbDatabase *ccdb, o2::ccdb::CcdbApi &ccdbApi, string taskname, string objname, string run1, string run2, vector<string> goodrunlist, int lnum, vector<string> runlistfromfile);
bool GetListOfHisto(o2::ccdb::CcdbApi &ccdbApi, string taskname, string objname, vector<long int> timestamps, vector<long int> timestamps2, int lnum, bool isrunknown, bool isperstave, vector<int>runnumbers, vector<int>runnumbers2);
bool Download(int choice, CcdbDatabase* ccdb, o2::ccdb::CcdbApi &ccdbApi, string taskname, string objname, string run1, string run2, vector<string> goodrunlist, long int ts_start, long int ts_end, int lnum, vector<string> runlistfromfile);
string GetOptName(int opt);
string GetListName(int opt, int ilist);
const int nStavesInLay[7] = {12, 16, 20, 24, 30, 42, 48};
TFile *outputfile;
std::string selpassname;
//to which CCDB we have to connect
// For P2 operations put: ali-qcdb.cern.ch:8083
string ccdbport = "ali-qcdb-gpn.cern.ch:8083";
void getObject(string expOrShift, int whatToDownload)
{
int dbnum;
std::cout<<"Select the CCDB from where to download data"<<std::endl;
std::cout<<" 1. localhost:8083 (make sure to setup lxtunnel properly)"<<std::endl;
std::cout<<" 2. ali-qcdb-gpn.cern.ch:8083 (default)" << std::endl;
std::cout<<" 3. ccdb-test.cern.ch:8080" << std::endl;
std::cout<<"Enter number: ";
std::cin>>dbnum;
std::cout<<std::endl;
switch(dbnum){
case 1:
{
ccdbport = "localhost:8083";
break;
}
case 2:
{
ccdbport = "ali-qcdb-gpn.cern.ch:8083";
break;
}
case 3:
{
ccdbport = "ccdb-test.cern.ch:8080";
break;
}
default:
{
std::cout<<"Unknown number. Exiting..."<<std::endl;
exit(1);
}
}
int sa;
string syncasync;
std::cout<<std::endl;
std::cout<<"You would like to check synchronous or asynchronous QC plots? "<<std::endl;
std::cout<<" 1. Sync"<<std::endl;
std::cout<<" 2. Async"<<std::endl;
std::cout<<"Enter number: ";
cin>>sa;
std::cout<<std::endl;
switch(sa){
case 1:
{
syncasync = "sync";
break;
}
case 2:
{
syncasync = "async";
break;
}
default:
{
std::cout<<"Uknown number. Exiting ..."<<std::endl;
exit(1);
}
}
if(sa==2) {
std::cout<<"Type the pass name to download as reported in PassName field in qcdb (ex: apass3): ";
cin>>selpassname;
}
std::unique_ptr<DatabaseInterface> mydb = DatabaseFactory::create("CCDB");
if(mydb == nullptr) {
cerr << "Failed to create DatabaseInterface" << endl;
return;
}
auto* ccdb = dynamic_cast<CcdbDatabase*>(mydb.get());
if(ccdb == nullptr) {
cerr << "ccdb pointer is null" << endl;
return;
}
ccdb->connect(ccdbport.c_str(), "", "", "");
if(expOrShift == "expert") {
RunExpert(ccdb, whatToDownload, syncasync);
}
else if (expOrShift == "shifter") {
RunShifter(ccdb, whatToDownload, syncasync);
}
else {
cerr<<"The expOfShift string "<<expOrShift<<" is not recognized, please check!"<<endl;
}
ccdb->disconnect();
return;
}//end main
//
//Get Last (most recent) Run
//
array<string,2> GetLastRunWithTS(o2::ccdb::CcdbApi &ccdbApi, string taskname, string objname){
string objectlist = ccdbApi.list(taskname + "/" + objname,false,"text/plain");
stringstream ss(objectlist);
string word;
array<string,2> runts;
while(ss>>word){
if(word=="Validity:"){// take the one related to file creation
ss>>word;
runts[0] = word;
}
if(word=="RunNumber"){
ss>>word;
ss>>word;
runts[1] = word;
break;
}
}
return runts;
}
//
// Get Run 24h depending on the actual time stamp
//
array<string,2> GetRunWithTS24hAgo(o2::ccdb::CcdbApi &ccdbApi, string taskname, string objname, string timestamp){
string objectlist = ccdbApi.list(taskname + "/" + objname,false,"text/plain");
stringstream ss(objectlist);
string word;
array<string,2> runts;
bool islast = false;
long int stamp_int_actual = stol(timestamp);
long int stamp_int_24hago = stamp_int_actual - 86400000; //remove number of milliseconds in 1 day
while(ss>>word){
if(word=="Validity:"){// take the one related to file creation
ss>>word;
if(stol(word)>=stamp_int_24hago){
runts[0] = word;
}
else islast=true;
}
if(word=="RunNumber"){
ss>>word;
ss>>word;
if(islast) break;
if(stol(runts[0])>=stamp_int_24hago) runts[1] = word;
}
}
return runts;
}
//
// Shift mode
//
bool RunShifter(CcdbDatabase *ccdb, int opt, std::string syncasync){
std::string qcpathstart;
if(syncasync == "sync") {
qcpathstart = "qc/";
} else if (syncasync == "async") {
qcpathstart = "qc_async/";
}
//Choose the layer number
int layernum;
cout<<endl;
cout<<endl;
cout<<"Enter the layer number [put -1 for all IB layers]"<<endl;
cin>>layernum;
//add error and trigger-flags plot to data
bool adderrordata = true;
if(opt==2) adderrordata = false;
//taskname
string taskname[4] = {qcpathstart+"ITS/MO/ITSFHR", qcpathstart+"ITS/MO/ITSFHR", qcpathstart+"ITS/MO/ITSFHR", qcpathstart+"ITS/MO/ITSFHR"};
//set the task name
switch(opt){
case 1: {// fake-hit
taskname[0] = qcpathstart+"ITS/MO/ITSFHR";//L0T, L0B
taskname[1] = qcpathstart+"ITS/MO/ITSFHR";//L1T, L1B
taskname[2] = qcpathstart+"ITS/MO/ITSFHR"; //L2T
taskname[3] = qcpathstart+"ITS/MO/ITSFHR"; //L2B
break;
}
case 2: { //thr scan
taskname[0] = qcpathstart+"ITS/MO/ITSThresholdCalibrationTask";
taskname[1] = qcpathstart+"ITS/MO/ITSThresholdCalibrationTask";
taskname[2] = qcpathstart+"ITS/MO/ITSThresholdCalibrationTask";
taskname[3] = qcpathstart+"ITS/MO/ITSThresholdCalibrationTask";
break;
}
default: break;
}//end of switch
//CCDB api initialization
o2::ccdb::CcdbApi ccdbApi;
ccdbApi.init(ccdbport.c_str());
//set variables (run interval of timestamp interval)
array<string,2> runts1;
array<string,2> runts2;
//Decide how many different elements are needed
int nListElements = 2;
switch(opt){
case 1: nListElements = 2; break;
case 2: nListElements = 3; break;
default: nListElements = 2;
}
if(adderrordata && opt==1)
nListElements+=2;//2 because we add trigger and error plots
//Output file
string layername;
if(layernum==-1)
layername = "all-IB-layers";
else
layername = Form("Layer%d",layernum);
string suffix = "run";
string optname = GetOptName(opt);
//Download depending on the option (opt)
switch(opt){
case 1: {
//run interval definition
cout<<"Finding runs in: "<<taskname[0]<<"/Occupancy/Layer0/Layer0ChipStave"<<endl;
runts2 = GetLastRunWithTS(ccdbApi, taskname[0], "Occupancy/Layer0/Layer0ChipStave"); //take a random object name since run-list is the same.
runts1 = GetRunWithTS24hAgo(ccdbApi, taskname[0], "Occupancy/Layer0/Layer0ChipStave", runts2[0]);
cout<<"Run interval selected: "<<runts1[1]<<"-"<<runts2[1]<<endl;
cout<<"Timestamp interval selected: "<<runts1[0]<<"-"<<runts2[0]<<endl;
//output file
outputfile = new TFile(Form("Data/Output_%s_%s_from_%s%s_to_%s%s%s.root", layername.c_str(), optname.c_str(), suffix.c_str(), runts1[1].c_str(), suffix.c_str(), runts2[1].c_str(), adderrordata? "_w_error_and_trig_data":""), "RECREATE");
outputfile->cd();
if(layernum>=0){
for(int il=0; il<nListElements; il++){//loop on lists
switch(il){
case 0: {
string objname = Form("Occupancy/Layer%d/Layer%dChipStave",layernum,layernum);
cout<<"\nAll data in "<<taskname[layernum]+"/"+objname<<" between run"<<runts1[1]<<" and run"<<runts2[1]<<" are going to be downloaded."<<endl;
Download(1, ccdb, ccdbApi, taskname[layernum], objname, runts1[1], runts2[1], vector<string>(), stol(runts1[0]), stol(runts2[0]),layernum, vector<string>());
break;
}
case 1: {
for(int istave=0; istave<nStavesInLay[layernum]; istave++){
if(layernum==2){
if(istave>9){
Download(1, ccdb, ccdbApi, taskname[layernum+1], Form("Occupancy/Layer%d/Stave%d/Layer%dStave%dHITMAP",layernum,istave,layernum,istave), runts1[1], runts2[1], vector<string>(), stol(runts1[0]), stol(runts2[0]),layernum, vector<string>());
}
else{
Download(1, ccdb, ccdbApi, taskname[layernum], Form("Occupancy/Layer%d/Stave%d/Layer%dStave%dHITMAP",layernum,istave,layernum,istave), runts1[1], runts2[1], vector<string>(), stol(runts1[0]), stol(runts2[0]),layernum, vector<string>());
}
}
else {
Download(1, ccdb, ccdbApi, taskname[layernum], Form("Occupancy/Layer%d/Stave%d/Layer%dStave%dHITMAP",layernum,istave,layernum,istave), runts1[1], runts2[1], vector<string>(), stol(runts1[0]), stol(runts2[0]),layernum, vector<string>());
}
}
break;
}
case 2: {//error files
string objname = "General/ErrorVsFeeid";
cout<<"\nAll data in "<<taskname[layernum]+"/"+objname<<" between run"<<runts1[1]<<" and run"<<runts2[1]<<" are going to be downloaded."<<endl;
Download(1, ccdb, ccdbApi, taskname[layernum], objname, runts1[1], runts2[1], vector<string>(), stol(runts1[0]), stol(runts2[0]), layernum, vector<string>());
break;
}
case 3: {//error files
string objname = "General/TriggerVsFeeid";
cout<<"\nAll data in "<<taskname[layernum]+"/"+objname<<" between run"<<runts1[1]<<" and run"<<runts2[1]<<" are going to be downloaded."<<endl;
Download(1, ccdb, ccdbApi, taskname[layernum], objname, runts1[1], runts2[1], vector<string>(), stol(runts1[0]), stol(runts2[0]), layernum, vector<string>());
break;
}
}
}//end loop on lists
}//end if layernum>=0
else if(layernum==-1){
vector<string> goodrunlist = GetGoodRunList(ccdbApi, runts1[1], runts2[1], "Fhr", qcpathstart);
for(int il=0; il<nListElements; il++){//loop on lists
switch(il){
case 0: {
for(int ilay=0; ilay<=2; ilay++){
string objname = Form("Occupancy/Layer%d/Layer%dChipStave",ilay,ilay);
cout<<"\nAll data in "<<taskname[ilay]+"/"+objname<<" between run"<<runts1[1]<<" and run"<<runts2[1]<<" are going to be downloaded."<<endl;
Download(1, ccdb, ccdbApi, taskname[ilay], objname, runts1[1], runts2[1], goodrunlist, stol(runts1[0]), stol(runts2[0]),ilay,vector<string>());
}
break;
}
case 1: {
for(int ilay=0; ilay<=2; ilay++){
for(int istave=0; istave<nStavesInLay[ilay]; istave++){
if(ilay==2){
if(istave>9){
Download(1, ccdb, ccdbApi, taskname[ilay+1], Form("Occupancy/Layer%d/Stave%d/Layer%dStave%dHITMAP",ilay,istave,ilay,istave), runts1[1], runts2[1], goodrunlist, stol(runts1[0]), stol(runts2[0]),ilay,vector<string>());
}
else{
Download(1, ccdb, ccdbApi, taskname[ilay], Form("Occupancy/Layer%d/Stave%d/Layer%dStave%dHITMAP",ilay,istave,ilay,istave), runts1[1], runts2[1], goodrunlist, stol(runts1[0]), stol(runts2[0]),ilay,vector<string>());
}
}
else{
Download(1, ccdb, ccdbApi, taskname[ilay], Form("Occupancy/Layer%d/Stave%d/Layer%dStave%dHITMAP",ilay,istave,ilay,istave), runts1[1], runts2[1], goodrunlist, stol(runts1[0]), stol(runts2[0]),ilay, vector<string>());
}
}
}
break;
}
case 2: {//error files
string objname = "General/ErrorVsFeeid";
cout<<"\nAll data in "<<taskname[0]+"/"+objname<<" between run"<<runts1[1]<<" and run"<<runts2[1]<<" are going to be downloaded."<<endl;
Download(1, ccdb, ccdbApi, taskname[0], objname, runts1[1], runts2[1], goodrunlist, stol(runts1[0]), stol(runts2[0]), 0, vector<string>());
break;
}
case 3: {//trigger files
string objname = "General/TriggerVsFeeid";
cout<<"\nAll data in "<<taskname[0]+"/"+objname<<" between run"<<runts1[1]<<" and run"<<runts2[1]<<" are going to be downloaded."<<endl;
Download(1, ccdb, ccdbApi, taskname[0], objname, runts1[1], runts2[1], goodrunlist, stol(runts1[0]), stol(runts2[0]), 0, vector<string>());
break;
}
}
}//end loop on lists
}//end if layernum==-1
break;
}//end case 1
case 2: {//thresholds
cout << "THR task does not support shifter mode ";
/*
//run interval definition
cout << "Finding runs in: " << taskname[0] << "ThrNoiseChipAverageIB" << endl;
runts2 = GetLastRunWithTS(ccdbApi, taskname[0], "ThrNoiseChipAverageIB"); //take a random object name since run-list is the same.
runts1 = GetRunWithTS24hAgo(ccdbApi, taskname[0], "ThrNoiseChipAverageIB", runts2[0]);
vector<string> goodrunlist = GetGoodRunList(ccdbApi, runts1[1], runts2[1], "Thr", qcpathstart);
cout << "Run interval selected: " << runts1[1] << "-" << runts2[1] << endl;
cout << "Timestamp interval selected: " << runts1[0] << "-" << runts2[0] << endl;
outputfile = new TFile(Form("Data/Output%s_%s_from_%s%s_to_%s%s.root", layername.c_str(), optname.c_str(), suffix.c_str(), runts1[1].c_str(), suffix.c_str(), runts2[1].c_str()), "RECREATE");
outputfile->cd();
if (layernum >= 0) {
string objname = "ThrNoiseChipAverageIB";
cout << "\nAll data in " << taskname[layernum] + "/" + objname << " between run" << runts1[1] << " and run" << runts2[1] << " are going to be downloaded." << endl;
Download(1, ccdb, ccdbApi, taskname[layernum], objname, runts1[1], runts2[1], vector<string>(), stol(runts1[0]), stol(runts2[0]), layernum, vector<string>());
}//end if layernum>=0
else if (layernum == -1) {
for (int ilay = 0; ilay <= 2; ilay++) {
string objname = "ThrNoiseChipAverageIB";
cout << "\nAll data in " << taskname[ilay] + "/" + objname << " between run" << runts1[1] << " and run" << runts2[1] << " are going to be downloaded." << endl;
Download(1, ccdb, ccdbApi, taskname[ilay], objname, runts1[1], runts2[1], goodrunlist, stol(runts1[0]), stol(runts2[0]), ilay, vector<string>());
}
}//end if layernum==-1
break;
*/
}// end of case 2
}//end switch
outputfile->Close();
delete outputfile;
return 1;
}
//
// Expert mode
//
bool RunExpert(CcdbDatabase *ccdb, int opt, std::string syncasync){
std::string qcpathstart;
if(syncasync == "sync") {
qcpathstart = "qc/";
} else if (syncasync == "async") {
qcpathstart = "qc_async/";
}
int IBorOB;
int layernum;
if(opt==3) layernum=-2;
else{
//choose IB, OB or both
cout << endl;
cout << endl;
cout << "Choose beteen IB (0), OB (1) or both (2, = all layers of IB and OB)" << endl;
cin>> IBorOB;
//Choose the layer number
cout<<endl;
switch(IBorOB){
case 0: {
cout<<"Enter the layer number [put -1 for all IB layers]"<<endl;
cin >>layernum;
break;
}
case 1: {
cout<<"Enter the layer number [put -1 for all OB layers]"<<endl;
cin >>layernum;
break;
}
case 2: {
layernum=-1;
break;
}
default: break;
}
}
//taskname
string taskname[8] = {qcpathstart+"ITS/MO/FHRTask", qcpathstart+"ITS/MO/FHRTask", qcpathstart+"ITS/MO/FHRTask", qcpathstart+"ITS/MO/FHRTask", qcpathstart+"ITS/MO/FHRTask", qcpathstart+"ITS/MO/FHRTask", qcpathstart+"ITS/MO/FHRTask", qcpathstart+"ITS/MO/FHRTask"};
//set the task name
switch(IBorOB){
case 0: {//Inner Barrel
switch(opt){
case 1: {// fake-hit
taskname[0] = qcpathstart+"ITS/MO/FHRTask";//L0T, L0B
taskname[1] = qcpathstart+"ITS/MO/FHRTask";//L1T, L1B
taskname[2] = qcpathstart+"ITS/MO/FHRTask"; //L2T
taskname[3] = qcpathstart+"ITS/MO/FHRTask"; //L2B
break;
}
case 2: { //thr scan
taskname[0] = qcpathstart+"ITS/MO/ITSTHRTask0";
taskname[1] = qcpathstart+"ITS/MO/ITSTHRTask1";
taskname[2] = qcpathstart+"ITS/MO/ITSTHRTask2T";
taskname[3] = qcpathstart+"ITS/MO/ITSTHRTask2B";
break;
}
default: break;
}//end of switch
break;
}
case 1: { //Outer Barrel
switch(opt){
case 1: {// fake-hit
taskname[4] = qcpathstart+"ITS/MO/FHRTask";//L3
taskname[5] = qcpathstart+"ITS/MO/FHRTask";//L4
taskname[6] = qcpathstart+"ITS/MO/FHRTask";//L5
taskname[7] = qcpathstart+"ITS/MO/FHRTask";//L6
break;
}
case 2: { //thr scan
//path name to be changed for OB
taskname[4] = qcpathstart+"ITS/MO/ITSTHRTask0";
taskname[5] = qcpathstart+"ITS/MO/ITSTHRTask1";
taskname[6] = qcpathstart+"ITS/MO/ITSTHRTask2T";
taskname[7] = qcpathstart+"ITS/MO/ITSTHRTask2B";
break;
}
default: break;
}//end of switch
}
case 2: { //Inner and Outer Barrel
switch(opt){
case 1: {// fake-hit
taskname[0] = qcpathstart+"ITS/MO/FHRTask";//L0
taskname[1] = qcpathstart+"ITS/MO/FHRTask";//L1
taskname[2] = qcpathstart+"ITS/MO/FHRTask";//L2
taskname[3] = qcpathstart+"ITS/MO/FHRTask";//not used for FHR
taskname[4] = qcpathstart+"ITS/MO/FHRTask";//L3
taskname[5] = qcpathstart+"ITS/MO/FHRTask";//L4
taskname[6] = qcpathstart+"ITS/MO/FHRTask";//L5
taskname[7] = qcpathstart+"ITS/MO/FHRTask";//L6
break;
}
case 2: { //thr scan
// path name to be changed
taskname[0] = qcpathstart+"ITS/MO/ITSThresholdCalibrationTask";
break;
}
default: break;
}//end of switch
}
default: break;
}//end of switch
//Ask whether attach a error report to the results
bool adderrordata = false;
string erranswer = "n";
if(opt==1){//only is user selects to download FHR
cout<<endl;
cout<<"Error-flag plots needed? [y/n]"<<endl;
cin>>erranswer;
if(erranswer=="y")
adderrordata = true;
}
//Chose about run number or time interval
int choice;
cout<<endl;
cout<<"Download data - Choose an option:\n"<<endl;
cout<<"1. Enter run numbers (not possible in qc_async)"<<endl;
cout<<"2. Enter timestamps (not possible in qc_async)"<<endl;
cout<<"3. Run list as input txt file (must be in Data folder)"<<endl;
cout<<"[Type option number]: ";
cin>>choice;
//set variables (run interval of timestamp interval)
string run1="0", run2="0";
time_t ts_start=0, ts_end=0;
vector<string> nums; //can contain selected run interval or timestamp interval
vector<string> runlistfromfile;
switch(choice){
case 1: {
cout<<"\n"<<"Run interval [just run number, NO ZEROs in front]"<<endl;
cout<<"Enter first run: ";
cin>> run1;
cout<<"Enter second run: ";
cin>> run2;
nums.push_back(run1);
nums.push_back(run2);
break;
}
case 2:{
//Enter time period of the data to be downloaded
struct tm datetime_start;
struct tm datetime_end;
string day, month, hour, min, sec;
int year;
cout<<"\n"<<"Time period [format (hour 24H): DD MM YYYY HH MM SS]"<<endl;
cout<<"Enter start date and time: ";
cin>> day >> month >> year >> hour >> min >> sec;
string datetime1 = Form("%d%s%s_%s%s%s",year,month.c_str(),day.c_str(),hour.c_str(),min.c_str(),sec.c_str());
datetime_start.tm_mday = stoi(day);
datetime_start.tm_mon = stoi(month)-1;//-1 because january = 0;
datetime_start.tm_year = year-1900;
datetime_start.tm_hour = stoi(hour);
datetime_start.tm_min = stoi(min);
datetime_start.tm_sec = stoi(sec);
datetime_start.tm_isdst = -1; //-1 means DST unknown
ts_start = mktime(&datetime_start);//get timestamp start
ts_start*=1000; //convert in milliseconds
cout<<"Enter end date and time : ";
cin>> day >> month >> year >> hour >> min >> sec;
string datetime2 = Form("%d%s%s_%s%s%s",year,month.c_str(),day.c_str(),hour.c_str(),min.c_str(),sec.c_str());
datetime_end.tm_mday = stoi(day);
datetime_end.tm_mon = stoi(month)-1;//-1 because january = 0;
datetime_end.tm_year = year-1900;
datetime_end.tm_hour = stoi(hour);
datetime_end.tm_min = stoi(min);
datetime_end.tm_sec = stoi(sec);
datetime_end.tm_isdst = -1; //-1 means DST unknown
ts_end = mktime(&datetime_end);//get timestamp start
ts_end*=1000; //convert in milliseconds
printf("Timestamp start (ms): %ld\n", (long) ts_start);
printf("Timestamp end (ms): %ld\n", (long) ts_end);
nums.push_back(datetime1);
nums.push_back(datetime2);
break;
}
case 3: {
cout<<"\n"<<"Files potentially containing a run list:"<<endl;
cout<<endl;
gSystem->Exec("ls Data/*.txt -Art | tail -n 500");
string filename;
cout<<"\n"<<"Enter file name (example: my_run_list.txt): ";
cin>>filename;
ifstream inflruns(Form("Data/%s",filename.c_str()));
string runi;
while(inflruns>>runi){
runlistfromfile.push_back(runi); // run list from user
}
inflruns.close();
nums.push_back(runlistfromfile[runlistfromfile.size()-1]);
nums.push_back(runlistfromfile[0]);
run1 = runlistfromfile[runlistfromfile.size()-1];
run2 = runlistfromfile[0];
break;
}
default: break;
}
//Decide how many different elements are needed
int nListElements = 2;
switch(opt){
case 1: nListElements = 2; break;
case 2: nListElements = 3; break;
default: nListElements = 2;
}
if(adderrordata)
nListElements+=1;
//CCDB api initialization
o2::ccdb::CcdbApi ccdbApi;
ccdbApi.init(ccdbport.c_str());
//Output file
string layername;
if(layernum==-1){
if(IBorOB==0) layername = "_all-IB-layers";
else if (IBorOB==1) layername = "_all-OB-layers";
else layername = "_all-layers";
}
else if(layernum==-2) layername="";
else
layername = Form("_Layer%d",layernum);
int layernumEff=layernum;
if(IBorOB==1) layernumEff=layernum+1;
int ilayMin = 0;
int ilayMax = 2;
if (IBorOB==1) {
ilayMin = 3;
ilayMax =6;
}
else if (IBorOB==2) {
ilayMin = 0;
ilayMax =6;
}
string suffix;
switch(choice){
case 1: suffix = "run"; break;
case 2: suffix = ""; break;
case 3: suffix = "run"; break;
default: suffix="";
}
string optname = GetOptName(opt);
outputfile = new TFile(Form("Data/Output%s_%s_from_%s%s_to_%s%s.root",layername.c_str(), optname.c_str(), suffix.c_str(),nums[0].c_str(), suffix.c_str(), nums[1].c_str()), "RECREATE");
outputfile->cd();
//Download depending on the option (opt)
switch(opt){
case 1: {
if(layernum>=0){
for(int il=0; il<nListElements; il++){//loop on lists
switch(il){
case 0: {
string objname = Form("Occupancy/Layer%d/Layer%dChipStave",layernum,layernum);
cout<<"\nAll data in "<<taskname[layernumEff]+"/"+objname<<" between run"<<run1<<" and run"<<run2<<" are going to be downloaded."<<endl;
Download(choice, ccdb, ccdbApi, taskname[layernumEff], objname, run1, run2, vector<string>(), (long)ts_start, (long)ts_end,layernum, runlistfromfile);
break;
}
case 1: {
for(int istave=0; istave<nStavesInLay[layernum]; istave++){
if(layernum==2){
if(istave>9){//L2B
Download(choice, ccdb, ccdbApi, taskname[layernumEff+1], Form("Occupancy/Layer%d/Stave%d/Layer%dStave%dHITMAP",layernum,istave,layernum,istave), run1, run2, vector<string>(), (long)ts_start, (long)ts_end, layernum, runlistfromfile);
}
else{
Download(choice, ccdb, ccdbApi, taskname[layernumEff], Form("Occupancy/Layer%d/Stave%d/Layer%dStave%dHITMAP",layernum,istave,layernum,istave), run1, run2, vector<string>(), (long)ts_start, (long)ts_end, layernum, runlistfromfile);
}
}
else{
Download(choice, ccdb, ccdbApi, taskname[layernumEff], Form("Occupancy/Layer%d/Stave%d/Layer%dStave%dHITMAP",layernum,istave,layernum,istave), run1, run2, vector<string>(), (long)ts_start, (long)ts_end, layernum, runlistfromfile);
}
}
break;
}
case 2: {//error files
string objname = "General/ErrorVsFeeid";
cout<<"\nAll data in "<<taskname[layernumEff]+"/"+objname<<" between run"<<run1<<" and run"<<run2<<" are going to be downloaded."<<endl;
Download(choice, ccdb, ccdbApi, taskname[layernumEff], objname, run1, run2, vector<string>(), (long)ts_start, (long)ts_end, layernum, runlistfromfile);
break;
}
default: break;
}
}//end loop on lists
}//end if layernum>=0
else if(layernum==-1){
for(int il=0; il<nListElements; il++){//loop on lists
switch(il){
case 0: {
for(int ilay=ilayMin; ilay<=ilayMax; ilay++){
int ilayEff=ilay;
if (IBorOB==1) ilayEff=ilay+1;
else if (IBorOB==2 && ilay>=3) ilayEff=ilay+1;
string objname = Form("Occupancy/Layer%d/Layer%dChipStave",ilay,ilay);
cout<<"\nAll data in "<<taskname[ilayEff]+"/"+objname<<" between run"<<run1<<" and run"<<run2<<" are going to be downloaded."<<endl;
Download(choice, ccdb, ccdbApi, taskname[ilayEff], objname, run1, run2, vector<string>(), (long)ts_start, (long)ts_end, ilay, runlistfromfile);
}
break;
}
case 1: {
for(int ilay=ilayMin; ilay<=ilayMax; ilay++){
int ilayEff=ilay;
if (IBorOB==1) ilayEff=ilay+1;
else if (IBorOB==2 && ilay>=3) ilayEff=ilay+1;
for(int istave=0; istave<nStavesInLay[ilay]; istave++){
if(ilay==2){
if(istave>9){//L2B
Download(choice, ccdb, ccdbApi, taskname[ilayEff+1], Form("Occupancy/Layer%d/Stave%d/Layer%dStave%dHITMAP",ilay,istave,ilay,istave), run1, run2, vector<string>(), (long)ts_start, (long)ts_end, ilay, runlistfromfile);
}
else{
Download(choice, ccdb, ccdbApi, taskname[ilayEff], Form("Occupancy/Layer%d/Stave%d/Layer%dStave%dHITMAP",ilay,istave,ilay,istave), run1, run2, vector<string>(), (long)ts_start, (long)ts_end, ilay, runlistfromfile);
}
}
else{
Download(choice, ccdb, ccdbApi, taskname[ilayEff], Form("Occupancy/Layer%d/Stave%d/Layer%dStave%dHITMAP",ilay,istave,ilay,istave), run1, run2, vector<string>(), (long)ts_start, (long)ts_end, ilay, runlistfromfile);
}
}
}
break;
}
case 2: {//error files
string objname = "General/ErrorVsFeeid";
cout<<"\nAll data in "<<taskname[0]+"/"+objname<<" between run"<<run1<<" and run"<<run2<<" are going to be downloaded."<<endl;
Download(1, ccdb, ccdbApi, taskname[0], objname, run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
break;
}
default: break;
}
}//end loop on lists
}//end if layernum==-1
break;
}//end case 1
case 2: {// thresholds
string tskn = "qc/ITS/MO/ITSThresholdCalibrationTask";
string objname = "THRChipAverageIB";
cout << "\nAll data in " << tskn + "/" + objname << " between run" << run1 << " and run" << run2 << " are going to be downloaded." << endl;
Download(choice, ccdb, ccdbApi, tskn, objname, run1, run2, vector<string>(), (long)ts_start, (long)ts_end, layernum, runlistfromfile);
objname = "THRChipAverageML";
cout << "\nAll data in " << tskn + "/" + objname << " between run" << run1 << " and run" << run2 << " are going to be downloaded." << endl;
Download(choice, ccdb, ccdbApi, tskn, objname, run1, run2, vector<string>(), (long)ts_start, (long)ts_end, layernum, runlistfromfile);
objname = "THRChipAverageOL";
cout << "\nAll data in " << tskn + "/" + objname << " between run" << run1 << " and run" << run2 << " are going to be downloaded." << endl;
Download(choice, ccdb, ccdbApi, tskn, objname, run1, run2, vector<string>(), (long)ts_start, (long)ts_end, layernum, runlistfromfile);
objname = "ThrNoiseChipAverageIB";
cout << "\nAll data in " << tskn + "/" + objname << " between run" << run1 << " and run" << run2 << " are going to be downloaded." << endl;
Download(choice, ccdb, ccdbApi, tskn, objname, run1, run2, vector<string>(), (long)ts_start, (long)ts_end, layernum, runlistfromfile);
objname = "ThrNoiseChipAverageML";
cout << "\nAll data in " << tskn + "/" + objname << " between run" << run1 << " and run" << run2 << " are going to be downloaded." << endl;
Download(choice, ccdb, ccdbApi, tskn, objname, run1, run2, vector<string>(), (long)ts_start, (long)ts_end, layernum, runlistfromfile);
objname = "ThrNoiseChipAverageOL";
cout << "\nAll data in " << tskn + "/" + objname << " between run" << run1 << " and run" << run2 << " are going to be downloaded." << endl;
Download(choice, ccdb, ccdbApi, tskn, objname, run1, run2, vector<string>(), (long)ts_start, (long)ts_end, layernum, runlistfromfile);
break;
}// end of case 2
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 3: { //tracks
string trackname = (syncasync == "async") ? "Tracks" : "ITSTrackTask";
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+trackname, "AngularDistribution", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+trackname, "EtaDistribution", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+trackname, "PhiDistribution", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+trackname, "NClusters", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+trackname, "VertexZ", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+trackname, "VertexRvsZ", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+trackname, "VertexCoordinates", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+trackname, "NVertexContributors", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+trackname, "Ntracks", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+trackname, "AssociatedClusterFraction", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+trackname, "NClustersPerTrackEta", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
break;
}//end of case 3
//////////////////////////////////////////////////////////
case 4: { //FEE
cout<<"\nAll data in "<<qcpathstart+"ITS/MO/ITSFEE/LaneStatus/LaneStatusFlagError(ERROR,FAULT,WARNING)"<<" between run"<<run1<<" and run"<<run2<<" downloading..."<<endl;
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/ITSFEE","LaneStatus/laneStatusFlagERROR", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/ITSFEE","LaneStatus/laneStatusFlagFAULT", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/ITSFEE","LaneStatus/laneStatusFlagWARNING", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/ITSFEE","LaneStatus/laneStatusFlagCumulativeERROR", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/ITSFEE","LaneStatus/laneStatusFlagCumulativeFAULT", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/ITSFEE","LaneStatus/laneStatusFlagCumulativeWARNING", run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
string objname = "TriggerVsFeeid";
cout<<"\nAll data in "<<qcpathstart<< "ITS/MO/ITSFEE/"<<objname<<" between run"<<run1<<" and run"<<run2<<" are going to be downloaded."<<endl;
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/ITSFEE", objname, run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
objname = "RDHSummaryCumulative";
cout<<"\nAll data in "<<qcpathstart<< "ITS/MO/ITSFEE/"<<objname<<" between run"<<run1<<" and run"<<run2<<" are going to be downloaded."<<endl;
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/ITSFEE", objname, run1, run2, vector<string>(), (long)ts_start, (long)ts_end, 0, runlistfromfile);
break;
}//end of case 4
//////////////////////////////////////////////////////////
case 5:{ //Clusters
string cluname = (syncasync=="async") ? "Clusters":"ITSClusterTask";
if(layernum>=0){
//Cluster occupation
cout<<"\nAll data in "<< Form("%sITS/MO/%s/Layer%d/ClusterOccupation",qcpathstart.c_str(), cluname.c_str() ,layernum) << " between run" << run1 << " and run" << run2 << " are going to be downloaded." <<endl;
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+cluname, Form("Layer%d/ClusterOccupation", layernum), run1, run2, vector<string>(), (long)ts_start, (long)ts_end, layernum, runlistfromfile);
//Average cluster size
cout<<"\nAll data in "<< Form("%sITS/MO/%s/Layer%d/AverageClusterSize", qcpathstart.c_str(), cluname.c_str(), layernum) << " between run" << run1 << " and run" << run2 << " are going to be downloaded." <<endl;
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+cluname, Form("Layer%d/AverageClusterSize", layernum), run1, run2, vector<string>(), (long)ts_start, (long)ts_end, layernum, runlistfromfile);
} else if (layernum == -1){
for(int ilay = ilayMin; ilay <= ilayMax; ilay++){ // "-1" option corresponds to ALL LAYERS in OB or IB, or even for whole ITS
//Cluster occupation
cout<<"\nAll data in "<< Form("%sITS/MO/%s/Layer%d/ClusterOccupation", qcpathstart.c_str(), cluname.c_str(),ilay) << " between run" << run1 << " and run" << run2 << " are going to be downloaded." <<endl;
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+cluname, Form("Layer%d/ClusterOccupation", ilay), run1, run2, vector<string>(), (long)ts_start, (long)ts_end, ilay, runlistfromfile);
//Average cluster size
cout<<"\nAll data in "<< Form("%sITS/MO/%s/Layer%d/AverageClusterSize",qcpathstart.c_str(), cluname.c_str(), ilay) << " between run" << run1 << " and run" << run2 << " are going to be downloaded." <<endl;
Download(choice, ccdb, ccdbApi, qcpathstart+"ITS/MO/"+cluname, Form("Layer%d/AverageClusterSize", ilay), run1, run2, vector<string>(), (long)ts_start, (long)ts_end, ilay, runlistfromfile);
}
}
break;
}//end of case 5
}//end switch
outputfile->Close();
delete outputfile;
return 1;
}
//
// Return run list of GOOD runs = runs in all CCDB paths for TH2
//
vector<string> GetGoodRunList(o2::ccdb::CcdbApi &ccdbApi, string run1, string run2, string runtype, string qcpathstart){//run type can be "Thr" or "Fhr"
string objnames[3] = {"ThrNoiseChipAverageIB", "ThrNoiseChipAverageIB", "ThrNoiseChipAverageIB"};
string tasknames[3] = {qcpathstart+"ITS/MO/ITSThresholdCalibrationTask", qcpathstart+"ITS/MO/ITSThresholdCalibrationTask", qcpathstart+"ITS/MO/ITSThresholdCalibrationTask"};
//in case of FHR
if(runtype=="Fhr"){
objnames[0] = "Occupancy/Layer0/Layer0ChipStave";
objnames[1] = "Occupancy/Layer1/Layer1ChipStave";
objnames[2] = "Occupancy/Layer2/Layer2ChipStave";
tasknames[0] = qcpathstart+"ITS/MO/ITSFHR";
tasknames[1] = qcpathstart+"ITS/MO/ITSFHR";
tasknames[2] = qcpathstart+"ITS/MO/ITSFHR";
}
vector<vector<string>> runlists;
for(int i=0; i<3; i++){//get run list between run1 and run2 for all the paths defined above
string objectlist = ccdbApi.list(tasknames[i] + "/" + objnames[i],false,"text/plain");
stringstream ss(objectlist);
string word;
vector<string>runlist;
while(ss>>word){
if(word=="Validity:"){// take the one related to file creation
ss>>word;
//alltimestampsALT.push_back(word);
}
if(word=="RunNumber"){
ss>>word;
ss>>word;
if(stoi(word)>=stoi(run1) && stoi(word)<=stoi(run2)){
if(std::find(runlist.begin(), runlist.end(), word) == runlist.end())//if element doesn't exist already
runlist.push_back(word);
}
if(stoi(word)==stoi(run1)) break;
}
}
runlists.push_back(runlist);
}
//Extract runs present in all runlists
vector<string> runsfiltered;
for(int il=0; il<(int)runlists[0].size(); il++){
string run = runlists[0][il];
int cntrun = 1;
if((int)runlists[2].size()==0) cntrun++;// in case half L2 is missing
if((int)runlists[3].size()==0) cntrun++;// in case half L2 is missing
//look for this run in the other lists
for(int cntlist=1; cntlist<4; cntlist++){
for(int il2=0; il2<(int)runlists[cntlist].size(); il2++){
if(run==runlists[cntlist][il2]) {
cntrun++;
}
}
}
if(cntrun==4){
runsfiltered.push_back(run);
cout<<"Run: "<<run<<endl;
}
}
return runsfiltered;
}
//
// Download data based on timestamps
//
void DownloadTimestamps(CcdbDatabase* ccdb, o2::ccdb::CcdbApi &ccdbApi, string taskname, string objname, long int ts_start, long int ts_end, int lnum){
//Extract all the time stamps of the object
string objectlist = ccdbApi.list(taskname + "/" + objname,false,"text/plain");
stringstream ss(objectlist);
string word;
vector <string> timestamps;
while(ss>>word){
if(word=="Validity:"){// take the one related to file creation
ss>>word;
timestamps.push_back(word);
}
}
//filter all the timestamps to get the ones within start and end dates (get most recent!!)
vector <long int> timestamps_selperiod;
int counter=0;
for(int its=0; its<(int)timestamps.size()-1; its++){
if(stol(timestamps[its])>=ts_start && stol(timestamps[its])<=ts_end){
counter++;
if(counter==1) {
if(its==0)
timestamps_selperiod.push_back(stol(timestamps[its]));//the first (most recent) is taken by definition if it is really the first in the list
else if(stol(timestamps[its-1])-stol(timestamps[its])>65000) timestamps_selperiod.push_back(stol(timestamps[its]));//if not the real first, check if it is the most recent (in this way the user can insert whatever date interval)
}
if(stol(timestamps[its])-stol(timestamps[its+1])>65000) timestamps_selperiod.push_back(stol(timestamps[its+1]));
}
else if(stol(timestamps[its])>ts_end) continue;
else break;
}
cout<<"\n"<<"Selected timestamps: "<<endl;
for(int i=0; i<(int)timestamps_selperiod.size();i++){
cout<<timestamps_selperiod[i]<<endl;
}