Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

RunFileModule.cxx

Go to the documentation of this file.
00001 
00002 // $Id: RunFileModule.cxx,v 1.9 2006/02/01 20:04:12 rhatcher Exp $
00003 //
00004 // RunFileModule is a JobCModule that writes out to the run file
00005 //
00006 // Author: B. Speakman 2004.10.23
00007 //
00009 #include <fstream>
00010 #include <iostream>
00011 #include <math.h>
00012 
00013 #include "TFile.h"
00014 #include "TString.h"
00015 #include "TSystem.h"
00016 #include "TTimeStamp.h"
00017 
00018 #include "CandData/CandRecord.h"
00019 #include "CandData/CandHeader.h"
00020 
00021 #include "JobControl/JobCModuleRegistry.h"
00022 #include "MessageService/MsgService.h"
00023 #include "MinosObjectMap/MomNavigator.h"
00024 #include "Plex/PlexSEIdAltL.h"
00025 #include "Plex/PlexHandle.h"
00026 
00027 #include "RawData/RawRecord.h"
00028 #include "RawData/RawDaqSnarlHeader.h"
00029 #include "RawData/RawDigit.h"
00030 #include "RawData/RawDigitDataBlock.h"
00031 #include "RawData/RawDaqHeaderBlock.h"
00032 
00033 #include "RunFileModule.h"
00034 #include "UtilRSM.h"
00035 #include "RSM.h"
00036 
00037 using namespace std;
00038 
00039 ClassImp(RunFileModule)
00040 
00041 CVSID("$Id: RunFileModule.cxx,v 1.9 2006/02/01 20:04:12 rhatcher Exp $");
00042 JOBMODULE(RunFileModule, "RunFileModule", "build run files");
00043 
00044 RunFileModule::RunFileModule() {
00045   RSMSyn << "RunFileModule::RunFileModule" << endl;
00046   fRunNum = 0;
00047   fSubRunNum = 0;
00048   fOutMode = ios::out | ios::app;
00049   fRunOUT = false;
00050 }
00051 
00052 RunFileModule::~RunFileModule() {
00053   RSMSyn << "RunFileModule::~RunFileModule" << endl;
00054 }
00055 
00056 void RunFileModule::RunFileOUT() {
00057   RSMDeb << "RunFileModule::RunFileOUT" << endl;
00058 
00059   if (fRunOUT) {
00060     RSMErr << "Multiple output attempt for: " <<
00061       fRunNum << "-" << fSubRunNum << endl;
00062     return;
00063   }
00064 
00065   if (fRunNum==0 && fSubRunNum==0) {
00066     RSMDeb << "Output attempt for: " <<
00067       fRunNum << "-" << fSubRunNum << endl;
00068     return;
00069   }
00070 
00071   ofstream fout(fRunFileFull.c_str(),fOutMode);
00072 
00073   char det = 'F';
00074   if(fDet==Detector::kFar) det = 'F';
00075   if(fDet==Detector::kNear) det = 'N';
00076   char file_out[25];
00077   sprintf(file_out,"%c%08d_%04d.mdaq.root",det,fRunNum,fSubRunNum);
00078   fout << file_out << endl;
00079   fout.close();
00080 
00081   fRunOUT = true;
00082 
00083   //remove the .building_[] file
00084   gSystem->Unlink(fBuildFileFull.c_str());
00085 
00086   return;
00087 }
00088 
00089 void RunFileModule::BuildFileOUT() {
00090   RSMDeb << "RunFileModule::BuildFileOUT" << endl;
00091 
00092   if (fRunNum==0 && fSubRunNum==0) {
00093     RSMDeb << "Output attempt for: " <<
00094       fRunNum << "-" << fSubRunNum << endl;
00095     return;
00096   }
00097 
00098   ofstream fout(fBuildFileFull.c_str(),fOutMode);
00099 
00100   char det = 'F';
00101   if(fDet==Detector::kFar) det = 'F';
00102   if(fDet==Detector::kNear) det = 'N';
00103   char file_out[25];
00104   sprintf(file_out,"%c%08d_%04d.mdaq.root",det,fRunNum,fSubRunNum);
00105   fout << file_out << endl;
00106   fout.close();
00107   return;
00108 }
00109 
00110 JobCResult RunFileModule::Ana(const MomNavigator *mom) {
00111   JobCResult result(JobCResult::kPassed);// The default result
00112 
00113   RawRecord* rawrec=0;
00114 
00115   TIter momitr = const_cast<MomNavigator*>(mom)->FragmentIter();
00116   TObject* momobj=0;
00117   while ((momobj=momitr())) {
00118     if ((rawrec=dynamic_cast<RawRecord*>(momobj))) {
00119       const RawDaqHeader* dhdr =
00120         dynamic_cast<const RawDaqHeader*>(rawrec->GetRawHeader());
00121 
00122       if (fRunNum!=dhdr->GetRun() || fSubRunNum!=dhdr->GetSubRun()) {
00123         RSMDeb << "Run change: " <<
00124           fRunNum << "-" << fSubRunNum << " -> " <<
00125           dhdr->GetRun() << "-" << dhdr->GetSubRun() << endl;
00126         RunFileOUT();
00127 
00128         fRunOUT = false;
00129         fRunNum = dhdr->GetRun();
00130         fSubRunNum = dhdr->GetSubRun();
00131         fDet = dhdr->GetVldContext().GetDetector();
00132         BuildFileOUT();
00133       }
00134     }
00135   }
00136   return result;
00137 }
00138 
00139 void RunFileModule::BeginJob() {
00140   RSMSyn << "RunFileModule::BeginJob" << endl;
00141   fRunNum = 0;
00142   fSubRunNum = 0;
00143   fOutMode = ios::out | ios::app;
00144   fRunOUT = false;
00145 }
00146 
00147 void RunFileModule::EndJob() {
00148   RSMSyn << "RunFileModule::EndJob" << endl;
00149 
00150   RSMDeb << "Final output in EndJob: " <<
00151     fRunNum << "-" << fSubRunNum << endl;
00152   RunFileOUT();
00153 }
00154 
00155 const Registry& RunFileModule::DefaultConfig() const {
00156   RSMSyn << "RunFileModule::DefaultConfig" << endl;
00157 
00158   static Registry r;
00159 
00160   string name = this->JobCModule::GetName();
00161   r.SetName((name+".config.default").c_str());
00162   r.UnLockValues();
00163 
00164   r.Set("RunFileName","GenericMode.run");
00165   r.Set("RunFileDir","./");
00166 
00167   r.LockValues();
00168 
00169   return r;
00170 }
00171 
00172 void RunFileModule::Config(const Registry& r) {
00173   RSMSyn << "RunFileModule::Config" << endl;
00174   const char* tmps = 0;
00175 
00176   if(r.Get("RunFileName",tmps)) fRunFileName=tmps;
00177   if(r.Get("RunFileDir",tmps)) fRunFileDir=tmps;
00178 
00179   if(!UtilRSM::CheckDir(fRunFileDir.c_str())) exit(0);
00180 
00181   fRunFileFull = fRunFileDir + "/" + fRunFileName;
00182   fBuildFileFull = fRunFileDir + "/.building_" + fRunFileName;
00183 }

Generated on Mon Feb 15 11:07:32 2010 for loon by  doxygen 1.3.9.1