Fill_MBSpill.cxx File Reference

#include "Riostream.h"
#include "TFile.h"
#include "TTree.h"
#include "TSystem.h"
#include "TMath.h"
#include <map>
#include <algorithm>
#include <vector>
#include <iostream>
#include "Validity/VldTimeStamp.h"
#include "DatabaseInterface/DbiWriter.h"
#include "MiniBooNEAna/MBSpill.h"
#include "Conventions/Munits.h"

Go to the source code of this file.

Functions

void Fill_MBSpill ()

Function Documentation

void Fill_MBSpill (  ) 

Definition at line 18 of file Fill_MBSpill.cxx.

References VldRange::AsString(), DbiWriter< T >::Close(), exit(), gSystem(), Munits::hour, SimFlag::kData, and Detector::kNear.

00018                    {
00019   //Dbi::SetLogLevel(2);
00020   //Char_t dirname[]="/afs/fnal.gov/files/data/minos/d77/shanahan/SpillTimes/";
00021   Char_t dirname[]="/afs/fnal.gov/files/data/minos/d69/tjyang/test/timing/new/";
00022   void *dirhandle = gSystem->OpenDirectory(gSystem->ExpandPathName(dirname));
00023   
00024   Int_t nfiles = 0;
00025   Char_t *file;
00026   Char_t path_file[100];
00027 
00028 
00029   map<VldTimeStamp, MBSpill> spills;
00030   map<VldTimeStamp, MBSpill>::iterator p;
00031 
00032   Double_t fTableDuration = 8.0*Munits::hour;
00033 
00034 
00035  //Loop over the filenames inside the directory
00036   while ( ( file = const_cast<char*>(gSystem->GetDirEntry(dirhandle)) ) ) {
00037     ifstream in;
00038     if (strstr(file,"spill_info_") != 0) {
00039       strcpy(path_file,dirname);
00040       strcat(path_file,file);
00041       in.open(path_file);
00042       cout<<"open file:"<<path_file<<endl;
00043       nfiles++;
00044       int sec,nsec;
00045       float pot,hI;
00046       while (1) {
00047         in >> sec >> nsec >> pot >> hI;
00048         if (!in.good()) break;
00049         MBSpill mbspill(sec,nsec,pot,hI);
00050         VldTimeStamp ts((time_t)sec,nsec);
00051         p=spills.find(ts);
00052         if (p != spills.end()){
00053           if (pot>p->second.GetPOT()){//replace the existing one
00054             spills.erase(p);
00055             spills.insert(pair<VldTimeStamp,MBSpill>(ts,mbspill));
00056           }
00057         }
00058         else if (TMath::Abs(hI)>10) {//remove bad spills
00059           spills.insert(pair<VldTimeStamp,MBSpill>(ts,mbspill));
00060         }
00061       }
00062     }
00063     in.close();
00064   }
00065   
00066   
00067   if (spills.size()==0) {
00068     cout<<"no data found, check directory"<<endl;
00069     exit(0);
00070   }
00071   
00072   cout<<nfiles<<" files found."<<endl;
00073   
00074   p = spills.begin();
00075   VldTimeStamp fStart = p->first;
00076   VldTimeStamp fEnd = fStart;
00077   cout<<"Start "<<" "<<fStart<<" End "<<fEnd<<endl;
00078   vector<MBSpill> spills_chunk;
00079   while (p!=spills.end()){
00080     spills_chunk.push_back(p->second);
00081     fEnd = p->first;
00082     if((double)(fEnd-fStart) > fTableDuration && spills_chunk.size()){
00083       VldTimeStamp vldCreate = fStart;
00084       VldRange range( (int)Detector::kNear,
00085                       (int)SimFlag::kData,
00086                       fStart,
00087                       fEnd,
00088                       "MiniBooNE spill information"
00089                       );
00090       cout<<"Starting write: " << range.AsString() << endl;
00091       DbiWriter<MBSpill> writer (range,
00092                                  -1, //Aggregate
00093                                  0,  // task
00094                                  vldCreate, // Creation date
00095                                  0,   // db no
00096                                  "MiniBooNE spill information"
00097                                  );
00098       //writer.SetRequireGlobalSeqno(1);
00099       for (UInt_t i = 0; i<spills_chunk.size(); i++){
00100         writer << spills_chunk[i];
00101       }
00102       writer.Close();
00103       spills_chunk.clear();
00104       fStart = fEnd;
00105       fEnd = fStart;      
00106     }
00107     p++;
00108   }
00109 
00110   if(spills_chunk.size()){
00111     VldTimeStamp vldCreate = fStart;
00112     VldRange range( (int)Detector::kNear,
00113                     (int)SimFlag::kData,
00114                     fStart,
00115                     fEnd,
00116                     "MiniBooNE spill information"
00117                     );
00118     cout<<"Starting write: " << range.AsString() << endl;
00119     DbiWriter<MBSpill> writer (range,
00120                                -1, //Aggregate
00121                                0,  // task
00122                                vldCreate, // Creation date
00123                                0,   // db no
00124                                "MiniBooNE spill information"
00125                                );
00126     for (UInt_t i = 0; i<spills_chunk.size(); i++){
00127       writer << spills_chunk[i];
00128     }
00129     writer.Close();
00130     spills_chunk.clear();
00131     
00132   }
00133 
00134 }


Generated on 24 Jul 2018 for loon by  doxygen 1.6.1