AgilentReader Class Reference

#include <AgilentReader.h>

List of all members.

Public Member Functions

 AgilentReader ()
 ~AgilentReader ()
void Reset ()
void SetFileLocations ()
void LoadSpillData (int)
void FillSpill (int)

Public Attributes

std::vector< int > vUnixTime_MI60_triggertime
std::vector< double > vData_MI60_triggertime
TString file_MI60_triggertime
std::vector< int > vUnixTime_RWCM_timestamp
std::vector< TString > vData_RWCM_timestamp
TString file_RWCM_timestamp
std::vector< int > vUnixTime_ND_SGATETM_PPSFO
std::vector< double > vData_ND_SGATETM_PPSFO
TString file_ND_SGATETM_PPSFO
TString currentFile
std::string cDate
Int_t unixTime
Double_t MI60_triggertime
TString RWCM_timestamp
Double_t ND_SGATETM_PPSFO

Private Member Functions

void ExtractMI60triggertime ()
void ExtractRWCMtimestamp ()
void ExtractSGATETM_PPSFO ()
int search (std::vector< int >, int) const
int FillAgilentVectors (TString, std::vector< int > &, std::vector< double > &)
int FillTriggertimeVectors (TString, std::vector< int > &, std::vector< double > &)
int FillRWCMtimestampVectors (TString, std::vector< int > &, std::vector< TString > &)

Detailed Description

Definition at line 8 of file AgilentReader.h.


Constructor & Destructor Documentation

AgilentReader::AgilentReader (  ) 

Definition at line 10 of file AgilentReader.cxx.

References Reset(), and SetFileLocations().

00011 {
00012   this->Reset();
00013   this->SetFileLocations();
00014 }

AgilentReader::~AgilentReader (  ) 

Definition at line 17 of file AgilentReader.cxx.

00018 {
00019 }


Member Function Documentation

void AgilentReader::ExtractMI60triggertime (  )  [private]

Definition at line 224 of file AgilentReader.cxx.

References MI60_triggertime, search(), unixTime, vData_MI60_triggertime, and vUnixTime_MI60_triggertime.

Referenced by FillSpill().

00225 {
00226   int index = 0;
00227   if (vUnixTime_MI60_triggertime.size()>0 && unixTime > vUnixTime_MI60_triggertime.front()){
00228     index = (search(vUnixTime_MI60_triggertime, unixTime+1) );
00229     if(index){
00230       Double_t value = vData_MI60_triggertime.at(index);
00231       MI60_triggertime = value;
00232     }
00233   }
00234 }

void AgilentReader::ExtractRWCMtimestamp (  )  [private]

Definition at line 236 of file AgilentReader.cxx.

References RWCM_timestamp, search(), unixTime, vData_RWCM_timestamp, and vUnixTime_RWCM_timestamp.

Referenced by FillSpill().

00237 {
00238   if (vUnixTime_RWCM_timestamp.size()>0 && unixTime > vUnixTime_RWCM_timestamp.front()){
00239     int index = (search(vUnixTime_RWCM_timestamp, unixTime) );
00240     if(index){
00241       TString value = vData_RWCM_timestamp.at(index);
00242       RWCM_timestamp = value.Data();
00243     }
00244   }
00245 }

void AgilentReader::ExtractSGATETM_PPSFO (  )  [private]

Definition at line 247 of file AgilentReader.cxx.

References ND_SGATETM_PPSFO, search(), unixTime, vData_ND_SGATETM_PPSFO, and vUnixTime_ND_SGATETM_PPSFO.

Referenced by FillSpill().

00248 {
00249   int index = 0;
00250   if (vUnixTime_ND_SGATETM_PPSFO.size()>0 && unixTime > vUnixTime_ND_SGATETM_PPSFO.front()){
00251     index = (search(vUnixTime_ND_SGATETM_PPSFO, unixTime+1) );
00252     if(index){
00253       Double_t value = vData_ND_SGATETM_PPSFO.at(index);
00254       ND_SGATETM_PPSFO = value;
00255     }
00256   }
00257 }

int AgilentReader::FillAgilentVectors ( TString  filename,
std::vector< int > &  vUnixTime,
std::vector< double > &  vData 
) [private]

Definition at line 274 of file AgilentReader.cxx.

References Munits::second.

Referenced by LoadSpillData().

00275 {
00276   vUnixTime.clear();
00277   vData.clear();
00278 
00279   std::ifstream agilentFile(filename.Data());
00280   
00281   if (!agilentFile){
00282     std::cout << "Warning: no agilent file found at " << filename << std::endl;
00283     return -1;
00284   }
00285   else std::cout << "Opening " << filename<< std::endl;
00286 
00287   Int_t lastSecond = 0;
00288   Double_t lastDatum = 0;
00289   std::string lastDateTime="";
00290   
00291   //variables for reading from the stream
00292   std::string date, dateTime, dud; Double_t datum = -999;
00293   
00294   int lineNumber = 0;
00295   time_t second = 0;
00296   while (true){
00297     agilentFile >> date >> dateTime >> dud >> datum;
00298     if (agilentFile.eof()) break;
00299     lineNumber++;
00300     
00301     std::string timestamp = date + " " + dateTime;
00302     struct tm tm;
00303     if ( strptime(timestamp.c_str(), "%Y-%m-%d %H:%M:%S", &tm) != NULL ){
00304       second = timegm(&tm);
00305       //FIXME: this is a poor way of checking for formatting errors.
00306       //     Should not have to ignore the rest of the file.
00307       if (second==lastSecond && datum==lastDatum && dateTime == lastDateTime){
00308         std::cout<<"Formatting error on line "<< lineNumber << "."<<std::endl;
00309         std::cout<<"Trying to ignore..."<<std::endl;
00310         getline(agilentFile, dud);
00311       }
00312       
00313       lastSecond = second;
00314       lastDatum = datum;
00315       lastDateTime = dateTime;
00316 
00317       vUnixTime.push_back(second);
00318       vData.push_back(datum);
00319 
00320       //test that all our files are covering the same time period
00321       if (lineNumber==1) std::cout<<"First timestamp in file: "<< second<<std::endl;
00322     }
00323   }
00324   std::cout<<"Last timestamp in file: "<< second<<std::endl;
00325   std::cout<<"File has "<<vUnixTime.size()<<" entries."<<std::endl;
00326   return 0;
00327 }

int AgilentReader::FillRWCMtimestampVectors ( TString  filename,
std::vector< int > &  vUnixTime,
std::vector< TString > &  vData 
) [private]

Definition at line 154 of file AgilentReader.cxx.

References Munits::second.

Referenced by LoadSpillData().

00155 {
00156   vUnixTime.clear();
00157   vData.clear();
00158   
00159   std::ifstream agilentFile(filename.Data());
00160   
00161   if (!agilentFile){
00162     std::cout << "Warning: no agilent file found at " << filename << std::endl;
00163     return -1;
00164   }
00165   else{
00166     std::cout << "Opening " << filename<< std::endl;
00167   }
00168   
00169   TString timestamp = "nowt";
00170   TString lastTimestamp = "";
00171   std::string dud="";
00172 
00173   int second = -999;
00174   int lastSecond = 0;
00175 
00176   int lineNumber = 0;
00177   while (true){
00178     agilentFile >> timestamp;
00179     if (agilentFile.eof()) break;
00180     lineNumber++;
00181     
00182     //FIXME: this is a poor way of checking for formatting errors.
00183     //     Should not have to ignore the rest of the file.
00184     //     Also, last line is being read twice (gives false formatting error)
00185     if (second==lastSecond && timestamp==lastTimestamp){
00186       std::cout<<"Formatting error on line "<< lineNumber << "."<<std::endl;
00187       std::cout<<"Trying to ignore..."<<std::endl;
00188       getline(agilentFile, dud);
00189     }
00190 
00191     TString secondString(timestamp(9,10));
00192     second = secondString.Atoi();
00193 
00194     lastSecond = second;
00195     lastTimestamp = timestamp;
00196     
00197     if (second>0){
00198       vUnixTime.push_back(second);
00199       vData.push_back(timestamp);
00200       if (lineNumber==1) std::cout<<"First timestamp in file: "<< second<<std::endl;
00201     }
00202   }
00203   if (vUnixTime.size()>0) std::cout<<"Last timestamp in file: "<< vUnixTime.back() <<std::endl;
00204   std::cout<<"File has "<<vUnixTime.size()<<" entries."<<std::endl;
00205   return 0;
00206 }

void AgilentReader::FillSpill ( int  second  ) 

Definition at line 209 of file AgilentReader.cxx.

References ExtractMI60triggertime(), ExtractRWCMtimestamp(), ExtractSGATETM_PPSFO(), LoadSpillData(), Reset(), and unixTime.

00210 {
00211   this->Reset();
00212   unixTime = second;
00213   
00214   this->LoadSpillData(unixTime);
00215   
00216   ExtractSGATETM_PPSFO();
00217   ExtractMI60triggertime();
00218   ExtractRWCMtimestamp();
00219 }

int AgilentReader::FillTriggertimeVectors ( TString  filename,
std::vector< int > &  vUnixTime,
std::vector< double > &  vData 
) [private]

Definition at line 98 of file AgilentReader.cxx.

References Munits::second.

Referenced by LoadSpillData().

00099 {
00100   //opens up a single data file and reads contents into memory
00101 
00102   vUnixTime.clear();
00103   vData.clear();
00104   
00105   std::ifstream agilentFile(filename.Data());
00106   
00107   if (!agilentFile){
00108     std::cout << "Warning: no agilent file found at " << filename << std::endl;
00109     return -1;
00110   }
00111   else{
00112     std::cout << "Opening " << filename<< std::endl;
00113   }
00114   
00115   Int_t lastSecond = 0;
00116   Double_t lastDatum = 0;
00117   std::string lastDateTime="";
00118   
00119   //Find the difference between PPSs immediately before the event
00120   std::string date, dateTime, dud;
00121   
00122   Double_t datum = -999;
00123   int second;
00124   int fraction;
00125 
00126   int lineNumber = 0;
00127   while (true){
00128     agilentFile >> second >> fraction >> datum;
00129     if (agilentFile.eof()) break;
00130     lineNumber++;
00131     
00132     if (second==lastSecond && datum==lastDatum && dateTime == lastDateTime){
00133       std::cout<<"Formatting error on line "<< lineNumber << "."<<std::endl;
00134       std::cout<<"Trying to ignore..."<<std::endl;
00135       getline(agilentFile, dud);
00136     }
00137     
00138     lastSecond = second;
00139     lastDatum = datum;
00140     lastDateTime = dateTime;
00141     
00142     vUnixTime.push_back(second);
00143     vData.push_back(datum);
00144 
00145     if (lineNumber==1) std::cout<<"First timestamp in file: "<< second<<std::endl;
00146     
00147   }
00148   std::cout<<"Last timestamp in file: "<< second<<std::endl;
00149   std::cout<<"File has "<<vUnixTime.size()<<" entries."<<std::endl;
00150   return 0;
00151 }

void AgilentReader::LoadSpillData ( int  startTime  ) 

Definition at line 42 of file AgilentReader.cxx.

References cDate, currentFile, file_MI60_triggertime, file_ND_SGATETM_PPSFO, file_RWCM_timestamp, FillAgilentVectors(), FillRWCMtimestampVectors(), FillTriggertimeVectors(), Form(), vData_MI60_triggertime, vData_ND_SGATETM_PPSFO, vData_RWCM_timestamp, vUnixTime_MI60_triggertime, vUnixTime_ND_SGATETM_PPSFO, and vUnixTime_RWCM_timestamp.

Referenced by FillSpill().

00043 {
00044   
00045   time_t start = startTime;
00046   struct tm* ptm;
00047   ptm = gmtime(&start); //UTC
00048    
00049   TString sDate = Form("%d-%02d-%02d", (ptm->tm_year)+1900,
00050                       ptm->tm_mon+1, (ptm->tm_mday));
00051 
00052   cDate = std::string(sDate.Data());
00053  
00054   if (currentFile == sDate) return;
00055   
00056   //seeing as this one is reset at 00:00 CDT, need to also load the
00057   //data for the day before!
00058   //make sure to keep them ordered so that binary search will work
00059   std::vector<int> vExtraUnixTime;
00060   std::vector<double> vExtraSGATE;
00061   TString earlyDate = Form("%d-%02d-%02d", (ptm->tm_year)+1900,
00062                            (ptm->tm_mon)+1, (ptm->tm_mday)-1);
00063 
00064   FillAgilentVectors(this->file_ND_SGATETM_PPSFO + earlyDate,
00065                      this->vUnixTime_ND_SGATETM_PPSFO,
00066                      this->vData_ND_SGATETM_PPSFO);
00067   FillAgilentVectors(this->file_ND_SGATETM_PPSFO + sDate,
00068                      vExtraUnixTime,
00069                      vExtraSGATE);
00070   //now concatenate:
00071   vUnixTime_ND_SGATETM_PPSFO.insert(vUnixTime_ND_SGATETM_PPSFO.end(),vExtraUnixTime.begin(),vExtraUnixTime.end());
00072   vData_ND_SGATETM_PPSFO.insert(vData_ND_SGATETM_PPSFO.end(),vExtraSGATE.begin(),vExtraSGATE.end());
00073   //and check that we've done it ok:
00074   std::cout<<"First timestamp in SGATE data: "<<vUnixTime_ND_SGATETM_PPSFO.front()<<std::endl
00075            <<"And last: "<<vUnixTime_ND_SGATETM_PPSFO.back()<<std::endl;
00076 
00077   /*
00078   for (int i = 0; i<vData_ND_SGATETM_PPSFO.size(); i++){
00079     std::cout << vUnixTime_ND_SGATETM_PPSFO[i] << " "
00080               << vData_ND_SGATETM_PPSFO[i] << std::endl;
00081   }
00082   */
00083 
00084   FillTriggertimeVectors(this->file_MI60_triggertime + sDate,
00085                      this->vUnixTime_MI60_triggertime,
00086                      this->vData_MI60_triggertime);
00087   
00088 
00089   FillRWCMtimestampVectors(this->file_RWCM_timestamp + sDate + ".txt",
00090                            this->vUnixTime_RWCM_timestamp,
00091                            this->vData_RWCM_timestamp);
00092   
00093   currentFile = sDate;
00094   
00095 }

void AgilentReader::Reset ( void   ) 

Definition at line 21 of file AgilentReader.cxx.

References MI60_triggertime, ND_SGATETM_PPSFO, RWCM_timestamp, and unixTime.

Referenced by AgilentReader(), and FillSpill().

00021                          {
00022   unixTime = -999;
00023   RWCM_timestamp = TString();
00024   MI60_triggertime = -999;
00025   ND_SGATETM_PPSFO = -999;
00026 }

int AgilentReader::search ( std::vector< int >  v,
int  second 
) const [private]

Definition at line 262 of file AgilentReader.cxx.

Referenced by ExtractMI60triggertime(), ExtractRWCMtimestamp(), and ExtractSGATETM_PPSFO().

00263 {
00264   if (v.size()==0) return 0;
00265   if ( second > v.back() || second < v.front() ) return 0;
00266 
00267   std::vector<int>::iterator low = lower_bound(v.begin(), v.end(), second);
00268   int iFound = int(low - v.begin());
00269   if (*low == second) return iFound;
00270   else return 0;
00271 }

void AgilentReader::SetFileLocations (  ) 

Definition at line 29 of file AgilentReader.cxx.

References currentFile, file_MI60_triggertime, file_ND_SGATETM_PPSFO, and file_RWCM_timestamp.

Referenced by AgilentReader().

00030 {
00031   TString MI60_dir = "/minos/data/tof_data/MI60/";
00032   file_RWCM_timestamp = "/minos/data/users/joconnor/rwcmTimestampFiles/rwcmTimestampFile";
00033   file_MI60_triggertime = MI60_dir + "agilent_triggertime_";
00034 
00035   TString ND_dir = "/minos/data/tof_data/ND/data/";
00036   file_ND_SGATETM_PPSFO     = ND_dir + "agilent-ND-TIC10/agilent-ND-TIC10.dat.";
00037   
00038   currentFile = "";
00039 }


Member Data Documentation

std::string AgilentReader::cDate

Definition at line 31 of file AgilentReader.h.

Referenced by LoadSpillData().

Definition at line 30 of file AgilentReader.h.

Referenced by LoadSpillData(), and SetFileLocations().

Definition at line 20 of file AgilentReader.h.

Referenced by LoadSpillData(), and SetFileLocations().

Definition at line 28 of file AgilentReader.h.

Referenced by LoadSpillData(), and SetFileLocations().

Definition at line 24 of file AgilentReader.h.

Referenced by LoadSpillData(), and SetFileLocations().

Definition at line 36 of file AgilentReader.h.

Referenced by ExtractMI60triggertime(), and Reset().

Definition at line 38 of file AgilentReader.h.

Referenced by ExtractSGATETM_PPSFO(), and Reset().

Definition at line 37 of file AgilentReader.h.

Referenced by ExtractRWCMtimestamp(), and Reset().

Definition at line 19 of file AgilentReader.h.

Referenced by ExtractMI60triggertime(), and LoadSpillData().

Definition at line 27 of file AgilentReader.h.

Referenced by ExtractSGATETM_PPSFO(), and LoadSpillData().

Definition at line 23 of file AgilentReader.h.

Referenced by ExtractRWCMtimestamp(), and LoadSpillData().

Definition at line 18 of file AgilentReader.h.

Referenced by ExtractMI60triggertime(), and LoadSpillData().

Definition at line 26 of file AgilentReader.h.

Referenced by ExtractSGATETM_PPSFO(), and LoadSpillData().

Definition at line 22 of file AgilentReader.h.

Referenced by ExtractRWCMtimestamp(), and LoadSpillData().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1