CheckTrueDate.C
Go to the documentation of this file.
1 #include <fstream>
2 #include <TH1F.h>
3 #include <TTree.h>
4 #include <TFile.h>
5 #include <TStyle.h>
6 #include <TSystem.h>
7 #include <TDatime.h>
8 
9 void CheckTrueDate(int idet, int timeOpt) {
10 
11  std::cout << "\n\nChecking Actual Dates for new files...\n\n";
12 
13  TDatime *TNowGMT = new TDatime; // current GMT time
14  TDatime *TNow = new TDatime; // current local time
15  TDatime *SRtime = new TDatime;
16  int XNowGMT = TNowGMT->Convert(kTRUE);
17  int XNow = TNow ->Convert(kFALSE);
18  int GMToffset = XNowGMT - XNow;
19 
20  XNow = XNow - GMToffset;
21 
22  int XDayAgo = XNow - 60*60*24;
23  int X4DyAgo = XNow - 60*60*24*4;
24  int XWekAgo = XNow - 60*60*24*7;
25  int X2HrAgo = XNow - 60*60*2;
26  int X8HrAgo = XNow - 60*60*8;
27  int Xsrtime = 0;
28 
29  unsigned int year = 0;
30  unsigned short int month = 0;
31  unsigned short int day = 0;
32  double Hour = 0.0;
33  double Min = 0.0;
34  int hour = 0;
35  int min = 0;
36  int sec = 0;
37 
38  unsigned int run = 0;
39  unsigned int subrun = 0;
40  UInt_t par = 0;
41 
42  unsigned int LastRun = 0;
43  unsigned int LastSR = 0;
44 
45  unsigned int yearEnd = 0;
46  unsigned short int monthEnd = 0;
47  unsigned short int dayEnd = 0;
48  double HourEnd = 0.0;
49  double SRdur = 0;
50 
51  // Root is stupid and you have to make it think that it is in a different time zone so that it will draw any
52  // plots with time on the X-axis correctly.
53  gSystem->Setenv("TZ","UTC");
54  gStyle->SetTimeOffset(0);
55 
56  const unsigned int Npoint = 1440;
57  double time = 0.0;
58 
59  //
60  // Check date in files
61  //
62  std::ifstream inDay;
63  std::ofstream out_file;
64  if(idet==1){
65  inDay.open("NewFarDetFiles.txt");
66  out_file.open ("NewFarDetOnMonFiles.txt");
67  }
68  else if(idet==2){
69  inDay.open("NewNearDetFiles.txt");
70  out_file.open ("NewNearDetOnMonFiles.txt");
71  }
72  else cout << " invalid detector type in CheckTrueDate " << endl;
73  while(inDay.good()) {
74 
75  char filenameD[256];
76  inDay >> filenameD;
77  TFile fileD(filenameD);
78 
79  TTree *header = (TTree*)fileD.Get("Header");
80  if(header != 0) {
81  header->SetBranchAddress("StartYear", &year);
82  header->SetBranchAddress("StartMonth", &month);
83  header->SetBranchAddress("StartDay", &day);
84  header->SetBranchAddress("StartHour", &Hour);
85  header->SetBranchAddress("EndYear", &yearEnd);
86  header->SetBranchAddress("EndMonth", &monthEnd);
87  header->SetBranchAddress("EndDay", &dayEnd);
88  header->SetBranchAddress("EndHour", &HourEnd);
89  header->SetBranchAddress("Run", &run);
90  header->SetBranchAddress("Subrun", &subrun);
91  header->GetEntry(0);
92 
93  hour = Hour;
94  Min = (Hour-hour)*60.0;
95  min = (Hour-hour)*60.0;
96  sec = (Min-min)*60.0;
97 
98  // OnMon/DAQ keeps track of GMT time, so convert to local time
99  SRtime->Set(year,month,day,hour,min,sec);
100  Xsrtime = SRtime->Convert() - GMToffset;
101 
102  if(timeOpt == 0 && Xsrtime > XDayAgo) out_file << filenameD << std::endl;
103  if(timeOpt == 1 && Xsrtime > X2HrAgo) out_file << filenameD << std::endl;
104  if(timeOpt == 2 && Xsrtime > X8HrAgo) out_file << filenameD << std::endl;
105  if(timeOpt == 3 && Xsrtime > XWekAgo) out_file << filenameD << std::endl;
106  if(timeOpt == 4 && Xsrtime > X4DyAgo) out_file << filenameD << std::endl;
107  }
108  }
109 
110 } // End making day plots.
111 
112 
UInt_t LastSR
Definition: AnaPlotMaker.h:50
TDatime * TNow
Definition: AnaPlotMaker.h:41
void CheckTrueDate(int idet, int timeOpt)
Definition: CheckTrueDate.C:9
Int_t par
Definition: SimpleIterate.C:24
TDatime * SRtime
Definition: AnaPlotMaker.h:42
out_file
Append EOF lines.
Definition: modifyFHiCL.py:113
UInt_t LastRun
Definition: AnaPlotMaker.h:49
Definition: run.py:1
TDatime * TNowGMT
Definition: AnaPlotMaker.h:40
OStream cout
Definition: OStream.cxx:6
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
Int_t GMToffset
Definition: AnaPlotMaker.h:43
static constexpr Double_t year
Definition: Munits.h:185