00001 #include "RunTimes.h"
00002 #include <fstream>
00003
00004
00005 RunTimes::RunTimes()
00006 : fFilename("emc_runtimes_initfromfile.tmp.txt"),
00007 fInit(false),
00008 fMinRunNumber(0)
00009 {
00010
00011
00012
00013 }
00014
00015
00016 RunTimes::~RunTimes()
00017 {
00018 std::map<int, RunLite*>::iterator it;
00019 for ( it = fTimes.begin(); it != fTimes.end(); it++)
00020 {
00021 delete it->second;
00022 it->second = 0;
00023 }
00024 }
00025
00026
00027 void
00028 RunTimes::MinRunNumber(int n)
00029 {
00030 fMinRunNumber=n;
00031 }
00032
00033
00034 void
00035 RunTimes::Output()
00036 {
00037 if ( !fInit )
00038 {
00039 Init();
00040 }
00041
00042 std::cout << "RunTimes::Writing " << fFilename
00043 << " file " << std::endl;
00044
00045
00046 std::ofstream out(fFilename.c_str());
00047
00048 std::map<int, RunLite* >::iterator it;
00049
00050 for ( it = fTimes.begin(); it != fTimes.end(); it++ )
00051 {
00052 RunLite* rl = it->second;
00053 out << rl->Number() << "," << rl->Start() << "," << rl->End()
00054 << std::endl;
00055 }
00056
00057 out.close();
00058 }
00059
00060
00061 void
00062 RunTimes::Reset(void)
00063 {
00064 std::map<int, RunLite*>::iterator it;
00065 for ( it = fTimes.begin(); it != fTimes.end(); it++)
00066 {
00067 delete it->second;
00068 it->second = 0;
00069 }
00070
00071 fTimes.clear();
00072 }
00073
00074
00075 const PHTimeStamp
00076 RunTimes::RunEnd(int runNumber)
00077 {
00078 if (!fInit)
00079 {
00080 Init();
00081 }
00082
00083 static PHTimeStamp zero(0);
00084
00085 std::map<int, RunLite* >::iterator it;
00086
00087 it = fTimes.find(runNumber);
00088
00089 if ( it == fTimes.end() )
00090 {
00091 return PHTimeStamp(0);
00092 }
00093
00094 return it->second->End();
00095 }
00096
00097
00098 void
00099 RunTimes::RunList(const PHTimeStamp& t1, const PHTimeStamp& t2,
00100 std::vector<int>& runnumbers)
00101 {
00102 if (!fInit)
00103 {
00104 Init();
00105 }
00106
00107 runnumbers.clear();
00108
00109 std::map<int, RunLite* >::iterator it;
00110
00111 for ( it = fTimes.begin(); it != fTimes.end(); it++ )
00112 {
00113 RunLite* rl = it->second;
00114 PHTimeStamp start = rl->Start();
00115 PHTimeStamp end = rl->End();
00116
00117 if ( start >= t1 && start <= t2 &&
00118 end <= t2 )
00119 {
00120 runnumbers.push_back(it->first);
00121 }
00122 }
00123 }
00124
00125
00126 int
00127 RunTimes::RunNumber(const PHTimeStamp& ts)
00128 {
00129 if (!fInit)
00130 {
00131 Init();
00132 }
00133
00134 std::map<int, RunLite* >::iterator it;
00135 int run = 0;
00136
00137 for ( it = fTimes.begin(); it != fTimes.end() && run == 0; it++ )
00138 {
00139 RunLite* rl = it->second;
00140 if ( ts >= rl->Start() && ts <= rl->End() )
00141 {
00142 run = it->first;
00143 }
00144 }
00145 return run;
00146 }
00147
00148
00149 const PHTimeStamp
00150 RunTimes::RunStart(int runNumber)
00151 {
00152 if (!fInit)
00153 {
00154 Init();
00155 }
00156
00157 std::map<int, RunLite* >::iterator it;
00158
00159 it = fTimes.find(runNumber);
00160
00161 if ( it == fTimes.end() )
00162 {
00163 return PHTimeStamp(0);
00164 }
00165 return it->second->Start();
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175 RunTimes::RunLite::RunLite(int number,
00176 const PHTimeStamp& start,
00177 const PHTimeStamp& end)
00178 {
00179 Set(number, start, end);
00180 }
00181
00182
00183 void
00184 RunTimes::RunLite::Print(void) const
00185 {
00186 std::cout << "Run " << fNumber << " Start " << fStart
00187 << " End " << fEnd << std::endl;
00188 }
00189
00190
00191 void
00192 RunTimes::RunLite::Set(int number,
00193 const PHTimeStamp& start,
00194 const PHTimeStamp& end)
00195 {
00196 fStart = start;
00197 fEnd = end;
00198 fNumber = number;
00199 }