VldValidate Class Reference

#include <VldValidate.h>

List of all members.

Public Member Functions

 VldValidate ()
virtual ~VldValidate ()
Bool_t RunAllTests ()
Bool_t TestTimeStamp (void)
Bool_t TestContext (void)
Bool_t TestRange (void)
Bool_t TestFileIO (void)

Protected Member Functions

Bool_t CompareTimeStamps (const char *label, VldTimeStamp &test, VldTimeStamp &std)

Detailed Description

Definition at line 18 of file VldValidate.h.


Constructor & Destructor Documentation

VldValidate::VldValidate (  ) 

Definition at line 30 of file VldValidate.cxx.

References MsgService::GetStream(), MsgService::Instance(), Msg::kVerbose, MsgStream::SetFormat(), and MsgStream::SetLogLevel().

00031 {
00032    // Default constructor
00033 
00034 
00035    MsgService* msvc = MsgService::Instance();
00036    MsgStream*  mstr = msvc->GetStream("Vld");
00037    
00038    mstr->SetLogLevel(Msg::kVerbose); // spew out everything for debugging
00039    mstr->SetFormat(Msg::kVerbose,0xffff);
00040 
00041 }

VldValidate::~VldValidate (  )  [virtual]

Definition at line 44 of file VldValidate.cxx.

00045 {
00046    // delete all the owned sub-objects
00047 
00048 }


Member Function Documentation

Bool_t VldValidate::CompareTimeStamps ( const char *  label,
VldTimeStamp test,
VldTimeStamp std 
) [protected]

Definition at line 234 of file VldValidate.cxx.

References VldTimeStamp::AsString(), Msg::kInfo, and MSG.

Referenced by TestTimeStamp().

00236 {
00237    if (test == std) {
00238       MSG("Vld",Msg::kInfo) << label << "    exact match " << endl;
00239       return kTRUE;
00240    }
00241    else {
00242       MSG("Vld",Msg::kInfo) << label << " ** mismatch ** " << endl;
00243       MSG("Vld",Msg::kInfo) << "            " << test.AsString() << endl;
00244       MSG("Vld",Msg::kInfo) << "            " << std.AsString() << endl;
00245       return kFALSE;
00246    }
00247 }

Bool_t VldValidate::RunAllTests ( void   ) 

Definition at line 51 of file VldValidate.cxx.

References Msg::kInfo, MSG, TestContext(), TestFileIO(), TestRange(), and TestTimeStamp().

00052 {
00053    Int_t fail  = 0;
00054    Int_t tests = 0;
00055 
00056    tests++;
00057    if (!TestTimeStamp()) fail++;
00058 
00059    tests++;
00060    if (!TestContext()) fail++;
00061 
00062    tests++;
00063    if (!TestRange()) fail++;
00064 
00065    tests++;
00066    if (!TestFileIO()) fail++;
00067 
00068    MSG("Vld",Msg::kInfo)
00069       << "VldValidate::RunAllTests had " << fail
00070       << " failures in " << tests << " tests"
00071       << endl << endl;
00072   
00073    return (!fail);
00074   
00075 }

Bool_t VldValidate::TestContext ( void   ) 

Definition at line 250 of file VldValidate.cxx.

References VldContext::AsString(), det, Msg::kInfo, and MSG.

Referenced by RunAllTests().

00251 {
00252    // Test VldContext
00253 
00254    cout << "Test VldContext" << endl << endl;
00255 
00256    Int_t fail = 0;
00257 
00258    map<VldContext,long> vldc_map;
00259    long int entry = 0;
00260 
00261    VldContext defctor;
00262    MSG("Vld",Msg::kInfo) << "VldContext default ctor: " 
00263                          << defctor.AsString("") << endl;
00264    vldc_map[defctor] = entry++;
00265 //   gSystem->Sleep(2000); // sleep for 2 sec so timestamp advances
00266 
00267    VldContext defctor2;
00268    vldc_map[defctor2] = entry++;
00269 //   gSystem->Sleep(2000); // sleep for 2 sec so timestamp advances
00270 
00271    // for the same timestamp try different combinations of detector & simflag
00272    // in the expected order that it will sort 
00273    // (detector primary over simflag --> detector in outer loop)
00274    MSG("Vld",Msg::kInfo) << endl
00275                          << "VldContext test map<VldContext,long>" << endl;
00276    VldTimeStamp now;
00277    for (Int_t ibit_det = 0; ibit_det<3; ibit_det++) {
00278       Detector::Detector_t det = 
00279          (Detector::Detector_t) (1<<ibit_det);
00280       for (Int_t ibit_sim = 0; ibit_sim<4; ibit_sim++) {
00281          SimFlag::SimFlag_t sim = (SimFlag::SimFlag_t) (1<<ibit_sim);
00282 
00283          VldContext vldc(det,sim,now);
00284 //         MSG("Vld",Msg::kInfo) 
00285 //            << " entry " << setw(2) << entry << " : " 
00286 //            << vldc.AsString() 
00287 //            << endl;
00288          vldc_map[vldc] = entry++;
00289 
00290       }
00291    }
00292    typedef map<VldContext,long>::const_iterator vcl_itr;
00293    int expect = 0;
00294    bool pass  = true;
00295    for (vcl_itr p = vldc_map.begin(); p != vldc_map.end(); ++p, ++expect) {
00296       VldContext ac = p->first;
00297       long       al = p->second;
00298       if (al != expect) pass = false;
00299       MSG("Vld",Msg::kInfo) 
00300          << "   " << setw(2) << expect << " ? " << setw(2) << al << " : " 
00301          << ac.AsString() 
00302          << endl;
00303    }
00304    if (!pass) fail++;
00305 
00306 
00307    MSG("Vld",Msg::kInfo) << endl
00308       << " Test output to MSG service: " << defctor << endl;
00309 
00310    MSG("Vld",Msg::kInfo) << endl
00311       << "VldValidate::TestContext had " << fail << " failures " 
00312       << endl << endl;
00313 
00314    return (!fail);
00315 }

Bool_t VldValidate::TestFileIO ( void   ) 

Definition at line 342 of file VldValidate.cxx.

References Msg::kInfo, and MSG.

Referenced by RunAllTests().

00343 {
00344    // Test write/read Validity objects to/from a file
00345 
00346    cout << "Test file IO" << endl << endl;
00347 
00348 //   UInt_t sleep_msec = 2000;
00349 
00350    // ****************** OUTPUT *******************************
00351 
00352    TFile fout("vld_io.root","RECREATE");
00353 
00354    VldTimeStamp out_ts; 
00355    VldContext   out_c;
00356    VldRange     out_r;
00357 
00358 //VldTimeStamp not derived from TObject
00359 //   out_ts.Write();
00360    out_c.Write();
00361    out_r.Write();
00362 
00363    fout.ls();
00364    fout.Close();
00365 
00366    // ****************** Pause *******************************
00367 
00368    MSG("Vld",Msg::kInfo) << endl << endl;
00369 //   gSystem->Sleep(sleep_msec);
00370    VldContext pause_c;
00371 
00372    // ****************** INPUT *******************************
00373 
00374    TFile fin("vld_io.root","READ");
00375    fin.ls();
00376 
00377 //   VldTimeStamp *in_ts = dynamic_cast<VldTimeStamp*>(fin.Get("VldTimeStamp"));
00378    VldContext *in_c = dynamic_cast<VldContext*>(fin.Get("VldContext"));
00379 
00380    fin.Close();
00381 
00382    // ****************** Comparison *******************************
00383 
00384    MSG("Vld",Msg::kInfo) << endl << endl;
00385 
00386 //   gSystem->Sleep(sleep_msec);
00387    VldContext final_c;
00388 
00389 //   out_ts.Print();
00390 //   in_ts->Print();
00391 
00392    MSG("Vld",Msg::kInfo) << " wrote  VldContext: " << out_c << endl;
00393    MSG("Vld",Msg::kInfo) << " interm VldContext: " << pause_c << endl;
00394    MSG("Vld",Msg::kInfo) << " read   VldContext: " << (*in_c) << endl;
00395    MSG("Vld",Msg::kInfo) << " final  VldContext: " << final_c << endl;
00396 
00397    Int_t fail = 0;
00398 
00399 //   cout << "default ctor:          ";
00400 //   VldRange defctor;
00401 //   defctor.Print("");
00402 
00403 
00404    MSG("Vld",Msg::kInfo)
00405       << "VldValidate::TestRange had " << fail << " failures " 
00406       << endl << endl;
00407 
00408    return (!fail);
00409 
00410 }

Bool_t VldValidate::TestRange ( void   ) 

Definition at line 318 of file VldValidate.cxx.

References Msg::kInfo, MSG, and VldRange::Print().

Referenced by RunAllTests().

00319 {
00320    // Test VldRange
00321 
00322    cout << "Test VldRange" << endl << endl;
00323 
00324    Int_t fail = 0;
00325 
00326    cout << "default ctor:          ";
00327    VldRange defctor;
00328    defctor.Print("");
00329 
00330    MSG("Vld",Msg::kInfo)
00331       << " Test output to MSG service: " << defctor << endl;
00332 
00333    MSG("Vld",Msg::kInfo)
00334       << "VldValidate::TestRange had " << fail << " failures " 
00335       << endl << endl;
00336 
00337    return (!fail);
00338 
00339 }

Bool_t VldValidate::TestTimeStamp ( void   ) 

Definition at line 78 of file VldValidate.cxx.

References VldTimeStamp::AsString(), CompareTimeStamps(), Munits::day, VldTimeStamp::GetDate(), VldTimeStamp::GetTime(), VldTimeStamp::GetTimeSpec(), VldTimeStamp::GetZoneOffset(), Munits::hour, Msg::kInfo, min, month, MSG, VldTimeStamp::Print(), and Munits::year.

Referenced by RunAllTests().

00079 {
00080    // Test VldTimeStamp behaviour
00081 
00082    cout << "Test VldTimeStamp" << endl << endl;
00083 
00084    Int_t fail = 0;
00085    Int_t tests = 0;
00086 
00087    cout << "default ctor:    " << flush;
00088    VldTimeStamp defctor;
00089    defctor.Print("");
00090 
00091    MSG("Vld",Msg::kInfo)
00092       << " Test output to MSG service: " << defctor << endl << endl;
00093 
00094    time_t nowtime;
00095    time(&nowtime);
00096    long int nsec = 12345;
00097 
00098    struct timespec nowts;
00099    nowts.tv_sec  = nowtime;
00100    nowts.tv_nsec = nsec;
00101 
00102    MSG("Vld",Msg::kInfo) 
00103       << " original timespec:  {" << nowtime << "," << nsec << "} " << endl;
00104 
00105    VldTimeStamp vldnow(nowts);
00106    // do these as separate MSG calls because AsString
00107    // reuses a common buffer space
00108    MSG("Vld",Msg::kInfo)
00109       << " vldnow as timespec: " << vldnow.AsString("2") << endl;
00110    MSG("Vld",Msg::kInfo)
00111       << " vldnow default AsString: " << vldnow.AsString("") << endl;
00112    MSG("Vld",Msg::kInfo)
00113       << " vldnow local   AsString: " << vldnow.AsString("l") << endl;
00114 
00115    struct timespec thents = vldnow.GetTimeSpec();
00116 
00117    MSG("Vld",Msg::kInfo) 
00118       << " recovered timespec: {" << thents.tv_sec << "," << thents.tv_nsec << "} " << endl;
00119 
00120    tests++;
00121    if (nowts.tv_sec != thents.tv_sec || nowts.tv_nsec != thents.tv_nsec) fail++;
00122 
00123 
00124    // test various ctor's
00125    // all should map to Jan 04 2001, 01:26:03 GMT
00126    time_t   mytime = 978571563;
00127    Long_t   arbitrary = 123456; // fake nsec part
00128 
00129    timespec mytimespec = {mytime,arbitrary};
00130    VldTimeStamp vtr(mytime,arbitrary);
00131    VldTimeStamp vtsr(mytimespec);
00132 
00133    Int_t    year  = 2001;
00134    Int_t    month = 1;
00135    Int_t    day   = 4;
00136    Int_t    hour  = 1;
00137    Int_t    min   = 26;
00138    Int_t    sec   = 3;
00139    Int_t    secOffset = vtr.GetZoneOffset();
00140    
00141    VldTimeStamp vl1(year,month,day,hour,min,sec,arbitrary);
00142    VldTimeStamp vl2(year,month,day,hour,min,sec,arbitrary,kFALSE,-secOffset);
00143    VldTimeStamp vl3(year,month,day,hour-8,min,sec,arbitrary,kTRUE,8*60*60);
00144    VldTimeStamp vl4(year,month,day-1,hour+16,min,sec,arbitrary,kTRUE,8*60*60);
00145 // this will only give correct results in PST zone
00146    VldTimeStamp vlpst(year,month,day,hour-8,min,sec,arbitrary,kFALSE);
00147 
00148    VldTimeStamp vly1(year-1900,month,day,hour,min,sec,arbitrary);
00149    VldTimeStamp vly2(year-2000,month,day,hour,min,sec,arbitrary);
00150 
00151    Int_t    date = year*10000 + month*100 + day;
00152    Int_t    time = hour*10000 + min*100 + sec;
00153 
00154    VldTimeStamp vs1(date,time,arbitrary);
00155    VldTimeStamp vs2(date,time,arbitrary,kFALSE,-secOffset);
00156 // these next two aren't a smart way of dealing with local time
00157    VldTimeStamp vs3(date-1,time+160000,arbitrary,kTRUE,8*60*60);
00158    VldTimeStamp vs4(date,time-80000,arbitrary,kTRUE,8*60*60);
00159 // the next two will only give correct results in PST zone
00160    VldTimeStamp vspst1(date,time-80000,arbitrary,kFALSE);
00161    VldTimeStamp vspst2(date-1,time+160000,arbitrary,kFALSE);
00162    VldTimeStamp vsy1(date-19000000,time,arbitrary);
00163    VldTimeStamp vsy2(date-20000000,time,arbitrary);
00164 
00165    MSG("Vld",Msg::kInfo)
00166       << " current TimeOffset is " << vtr.GetZoneOffset() << endl;
00167 
00168    MSG("Vld",Msg::kInfo) << endl;
00169    MSG("Vld",Msg::kInfo) << " std (vtr) " << vtr.AsString()  << endl;
00170 
00171    TString byhand = "Thu, 04 Jan 2001 01:26:03 +0000 (GMT) +   123456 nsec";
00172    TString byclass = vtr.AsString();
00173    tests++;
00174    if (byhand != byclass) {
00175       MSG("Vld",Msg::kInfo) << " strings don't match!" << endl;
00176       fail++;
00177    }
00178    else {
00179       MSG("Vld",Msg::kInfo) << " strings match as they should " << endl;
00180    }
00181 
00182    tests++;   if (!CompareTimeStamps(" vtsr     ",vtsr,vtr)) fail++;
00183    tests++;   if (!CompareTimeStamps(" vl1      ",vl1,vtr)) fail++;
00184    tests++;   if (!CompareTimeStamps(" vl2      ",vl2,vtr)) fail++;
00185    tests++;   if (!CompareTimeStamps(" vl3      ",vl3,vtr)) fail++;
00186    tests++;   if (!CompareTimeStamps(" vl4      ",vl4,vtr)) fail++;
00187    tests++;   if (!CompareTimeStamps(" vly1     ",vly1,vtr)) fail++;
00188    tests++;   if (!CompareTimeStamps(" vly2     ",vly2,vtr)) fail++;
00189    tests++;   if (!CompareTimeStamps(" vs1      ",vs1,vtr)) fail++;
00190    tests++;   if (!CompareTimeStamps(" vs2      ",vs2,vtr)) fail++;
00191    tests++;   if (!CompareTimeStamps(" vs3      ",vs3,vtr)) fail++;
00192    tests++;   if (!CompareTimeStamps(" vs4      ",vs4,vtr)) fail++;
00193    tests++;   if (!CompareTimeStamps(" vsy1     ",vsy1,vtr)) fail++;
00194    tests++;   if (!CompareTimeStamps(" vsy2     ",vsy2,vtr)) fail++;
00195 
00196    if (secOffset == 28800) {
00197       tests++;   if (!CompareTimeStamps(" vlpst    ",vlpst,vtr)) fail++;
00198       tests++;   if (!CompareTimeStamps(" vspst1   ",vspst1,vtr)) fail++;
00199       tests++;   if (!CompareTimeStamps(" vspst2   ",vspst2,vtr)) fail++;
00200    }
00201 
00202    MSG("Vld",Msg::kInfo) << " next test expects to be a mismatch" << endl;
00203    CompareTimeStamps(" now is unlikely to match arbitrary time ",vldnow,vtr);
00204 
00205    MSG("Vld",Msg::kInfo) << " Alternative formats" << endl;
00206    MSG("Vld",Msg::kInfo) << " \"\"       " << vtr.AsString("")   << endl;
00207    MSG("Vld",Msg::kInfo) << " \"l\"      " << vtr.AsString("l")  << endl;
00208    MSG("Vld",Msg::kInfo) << " \"c\"      " << vtr.AsString("c")  << endl;
00209    MSG("Vld",Msg::kInfo) << " \"lc\"     " << vtr.AsString("lc") << endl;
00210    MSG("Vld",Msg::kInfo) << " \"2\"      " << vtr.AsString("2")  << endl;
00211 
00212    tests++; if (vtr.GetDate() != date) fail++;
00213    tests++; if (vtr.GetTime() != time) fail++;
00214 
00215    MsgFormat i6("%6d");
00216 
00217    MSG("Vld",Msg::kInfo) << endl
00218       << "  GMT    GetDate: " << vtr.GetDate()
00219       << "   GetTime: " << i6(vtr.GetTime()) << endl;
00220    MSG("Vld",Msg::kInfo)
00221       << "  local  GetDate: " << vtr.GetDate(kFALSE)
00222       << "   GetTime: " << i6(vtr.GetTime(kFALSE)) << endl;
00223 
00224    MSG("Vld",Msg::kInfo) << endl
00225       << "VldValidate::TestTimeStamp had " << fail 
00226       << " failures in " << tests << " tests"
00227       << endl << endl;
00228 
00229    return (!fail);
00230 
00231 }


The documentation for this class was generated from the following files:

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1