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

JobCInput.cxx

Go to the documentation of this file.
00001 
00002 // $Id: JobCInput.cxx,v 1.18 2009/01/05 06:10:20 schubert Exp $
00003 //
00004 // A module used for getting data into and emtpy data record. This
00005 // module is implemented in terms of any of a variety of
00006 // user/framework provided inputs modules
00007 //
00008 // This is essentially a wrapper class. Its methods just push off the
00009 // call down the to the object which actually implements the input
00010 // module
00011 // 
00012 // messier@huhepl.harvard.edu
00014 #include "JobControl/JobCInput.h"
00015 #include "MessageService/MsgService.h"
00016 #include "JobControl/JobCModuleRegistry.h"
00017 CVSID("$Id: JobCInput.cxx,v 1.18 2009/01/05 06:10:20 schubert Exp $");
00018 
00019 ClassImp(JobCInput)
00020 
00021 // static const JobCResult gsW = JobCResult::kWarning;
00022 
00023 JobCInput::JobCInput() : fImpl(0) { }
00024 
00025 //......................................................................
00026 
00027 JobCInput::~JobCInput() 
00028 { 
00029   if (fImpl) { 
00030     fImpl->EndJob();
00031     delete fImpl; fImpl = 0; 
00032   }
00033 }
00034 
00035 //...................................................................... 
00036 
00037 JobCResult JobCInput::Get()
00038 { 
00039   if (this->CheckImpl()) {
00040     JobCResult r = fImpl->Get();
00041 #ifdef SITE_HAS_SIGC
00042     this->SigGet();
00043 #endif
00044     return r;
00045   }
00046   return JobCResult::kEndOfInputStream;
00047 }
00048 
00049 //...................................................................... 
00050 
00051 JobCResult JobCInput::Next(int n)
00052 {
00053   if (this->CheckImpl()) {
00054     JobCResult r = fImpl->Next(n); 
00055 #ifdef SITE_HAS_SIGC
00056     this->SigNext();
00057 #endif
00058     return r;
00059   }
00060   return JobCResult::kError;
00061 }
00062 
00063 //...................................................................... 
00064 
00065 JobCResult JobCInput::Prev(int n) 
00066 {
00067   if (this->CheckImpl()){
00068     JobCResult r = fImpl->Prev(n); 
00069 #ifdef SITE_HAS_SIGC
00070     this->SigPrev();
00071 #endif
00072     return r;
00073   }
00074   return JobCResult::kError;
00075 }
00076 
00077 //...................................................................... 
00078 
00079 JobCResult JobCInput::GoTo(int r, int s, int d) 
00080 {
00081   if (this->CheckImpl()) {
00082     JobCResult re = fImpl->GoTo(r,s,d); 
00083 #ifdef SITE_HAS_SIGC
00084     this->SigGoTo();
00085 #endif
00086     return re;
00087   }
00088   return JobCResult::kError;
00089 }
00090 
00091 
00092 //...................................................................... 
00093 
00094 Int_t JobCInput::GetCurrentRun() const
00095 {
00096  if (this->CheckImpl()) 
00097    return fImpl->GetCurrentRun();
00098  return -1;
00099 }
00100 
00101 //...................................................................... 
00102 
00103 Int_t JobCInput::GetLastRun() const
00104 {
00105  if (this->CheckImpl()) 
00106    return fImpl->GetLastRun();
00107  return -1;
00108 }
00109 
00110 //...................................................................... 
00111 
00112 const char* JobCInput::GetCurrentFile(const char* streamname) const
00113 {
00114     if (this->CheckImpl()) 
00115         return fImpl->GetCurrentFile(streamname);
00116     return 0;
00117 }
00118 
00119 //...................................................................... 
00120 
00121 const char* JobCInput::GetLastFile(const char* streamname) const
00122 {
00123     if (this->CheckImpl()) 
00124         return fImpl->GetLastFile(streamname);
00125     return 0;
00126 }
00127 
00128 //...................................................................... 
00129 
00130 Int_t JobCInput::GetCurrentSnarl() const
00131 {
00132  if (this->CheckImpl()) 
00133    return fImpl->GetCurrentSnarl();
00134  return -1;
00135 }
00136 
00137 //...................................................................... 
00138 
00139 JobCResult JobCInput::GoTo(const VldContext& vld)
00140 {
00141   if (this->CheckImpl()) {
00142     JobCResult r = fImpl->GoTo(vld);
00143 #ifdef SITE_HAS_SIGC
00144     this->SigGoTo();
00145 #endif
00146     return r;
00147   }
00148   return JobCResult::kError;
00149 }
00150 
00151 //...................................................................... 
00152 
00153 void JobCInput::List(const char* streamlist) const 
00154 {
00155   if (this->CheckImpl()) fImpl->List(streamlist);
00156 }
00157 
00158 //...................................................................... 
00159 
00160 void JobCInput::AddFile(const char* filename, const char* streamlist, int at) 
00161 {
00162   if (this->CheckImpl()) fImpl->AddFile(filename,streamlist,at);
00163 }
00164 
00165 //...................................................................... 
00166 
00167 void JobCInput::RemoveFile(const char* filename, const char* streamlist) 
00168 {
00169   if (this->CheckImpl()) fImpl->RemoveFile(filename,streamlist);
00170 }
00171 
00172 //...................................................................... 
00173 
00174 void JobCInput::Select(const char* stream, const char* cut, bool isrequired) 
00175 {
00176   if (this->CheckImpl()) fImpl->Select(stream,cut,isrequired);
00177 }
00178 
00179 //...................................................................... 
00180 
00181 void JobCInput::SetSequenceMode(const char* stream,Per::ESequenceMode seqmode) 
00182 {
00183   if (this->CheckImpl()) fImpl->SetSequenceMode(stream,seqmode);
00184 }
00185 
00186 //...................................................................... 
00187 
00188 void JobCInput::SetPerOwnedDisabled(const char* stream,bool perowneddisabled) 
00189 {
00190   if (this->CheckImpl()) fImpl->SetPerOwnedDisabled(stream,perowneddisabled);
00191 }
00192 
00193 //...................................................................... 
00194 
00195 void JobCInput::SetTestMode(const char* stream,bool testmode) 
00196 {
00197   if (this->CheckImpl()) fImpl->SetTestMode(stream,testmode);
00198 }
00199 
00200 //...................................................................... 
00201 
00202 void JobCInput::SetWindow(const char* stream, double lower, double upper) 
00203 {
00204   if (this->CheckImpl()) fImpl->SetWindow(stream,lower,upper);
00205 }
00206 
00207 //...................................................................... 
00208 
00209 void JobCInput::SetMaxFileRepeat(const char* stream, int numRepeat)
00210 {
00211   if (this->CheckImpl()) fImpl->SetMaxFileRepeat(stream,numRepeat);
00212 }
00213 
00214 //...................................................................... 
00215 
00216 void JobCInput::SetMeanMom(const char* stream, double mean)
00217 {
00218   if (this->CheckImpl()) fImpl->SetMeanMom(stream,mean);
00219 }
00220 
00221 //...................................................................... 
00222 
00223 void JobCInput::SetPushRandom(const char* stream, bool setRandom)
00224 {
00225   if (this->CheckImpl()) fImpl->SetPushRandom(stream,setRandom);
00226 }
00227 
00228 //...................................................................... 
00229 
00230 void JobCInput::SetRandomSeed(int rSeed)
00231 {
00232   if (this->CheckImpl()) fImpl->SetRandomSeed(rSeed);
00233 }
00234 
00235 //...................................................................... 
00236 
00237 void JobCInput::DefineStream(const char* stream, const char* tree) 
00238 {
00239   if (this->CheckImpl()) fImpl->DefineStream(stream,tree);
00240 }
00241 
00242 //...................................................................... 
00243   
00244 JobCResult JobCInput::NextFile(int n, const char* streamlist) 
00245 {
00246   if (this->CheckImpl()) return fImpl->NextFile(n,streamlist);
00247   return JobCResult::kError;
00248 }
00249 
00250 //...................................................................... 
00251 
00252 JobCResult JobCInput::PrevFile(int n, const char* streamlist) 
00253 {
00254   if (this->CheckImpl()) return fImpl->PrevFile(n, streamlist);
00255   return JobCResult::kError;
00256 }
00257 
00258 //...................................................................... 
00259 
00260 JobCResult JobCInput::GoToFile(int i, const char* streamlist) 
00261 {
00262   if (this->CheckImpl())  return fImpl->GoToFile(i, streamlist);
00263   return JobCResult::kError;
00264 }
00265 
00266 //...................................................................... 
00267 
00268 JobCResult JobCInput::GoToFile(const char* filename, const char* streamlist) 
00269 {
00270   if (this->CheckImpl()) return fImpl->GoToFile(filename, streamlist);
00271   return JobCResult::kError;
00272 }
00273 
00274 //...................................................................... 
00275 
00276 void JobCInput::Use(const char* name) 
00277 {
00278 //======================================================================
00279 // Set the input module to implement this class
00280 //======================================================================
00281 
00282   // Use the name to lookup the proxy
00283   JobCModuleProxy* jmp = JobCModuleRegistry::Instance().LookUp(name);
00284   if (jmp==0) {
00285     MSG("JobC",Msg::kWarning) <<
00286       "No module '"<< name <<"' has been linked in." << std::endl;
00287     return;
00288   }
00289 
00290   // Use the proxy to instantiate a module
00291   JobCModule* m = jmp->CreateModule();
00292   if (m==0) {
00293     MSG("JobC",Msg::kWarning) <<
00294       "CreateModule(" << jmp->GetName() << ")" << std::endl;
00295     return;
00296   }
00297 
00298   // Try to cast the module as an input module
00299   JobCInputModule* inmod = dynamic_cast<JobCInputModule*>(m);
00300   if (inmod==0) {
00301     MSG("JobC",Msg::kError) << 
00302       "Module '" << jmp->GetName() << 
00303       "' cannot be used as an input module." << std::endl;
00304     delete m; m = 0;
00305     return;
00306   }
00307 
00308   // Switch to the new implementation
00309   if (fImpl) { 
00310     fImpl->EndJob();
00311     delete fImpl; fImpl = 0; 
00312   }
00313   fImpl = inmod;
00314 
00315   // Set up the new module
00316   assert(this->GetMom());
00317   fImpl->SetMom(this->GetMom());
00318   fImpl->BeginJob();
00319 }
00320 
00321 //......................................................................   
00322 
00323 const Registry& JobCInput::DefaultConfig() const
00324 {
00325   MSG("JobC",Msg::kDebug) << "JobCInput::DefaultConfig()\n";
00326 
00327   if (this->CheckImpl()) return fImpl->DefaultConfig();
00328 
00329   MSG("JobC",Msg::kDebug) << "Using dummy config!\n";
00330   static Registry r; // A dummy config...
00331   return r;
00332 }
00333 
00334 //......................................................................   
00335 
00336 Registry& JobCInput::GetConfig()
00337 {
00338 //======================================================================
00339 // To make the JobCInput fit transparently over the module that
00340 // actually implements the input module we don't ever want to talk to
00341 // JobCInput::fConfig we want to talk to fImpl->fConfig. JobCModule
00342 // has been written very carefully to never reference fConfig directly
00343 // but only through this method...
00344 //======================================================================
00345   if (this->CheckImpl()) return fImpl->GetConfig();
00346   
00347   MSG("JobC",Msg::kDebug) << "Returning dummy config!\n";
00348   static Registry r; // A dummy config...
00349   return r;
00350 }
00351 
00352 
00353 //......................................................................   
00354 
00355 // Save a little typing. This macro works for void m(void)
00356 #define IMP(m) { if (this->CheckImpl()) fImpl->m(); }
00357 void JobCInput::BeginJob()  { IMP(BeginJob)  }
00358 void JobCInput::EndJob()    { IMP(EndJob)    }
00359 void JobCInput::BeginFile() { IMP(BeginFile) }
00360 void JobCInput::EndFile()   { IMP(EndFile)   }
00361 void JobCInput::BeginRun()  { IMP(BeginRun)  }
00362 void JobCInput::EndRun()    { IMP(EndRun)    }
00363 void JobCInput::Help()      { IMP(Help)      }
00364 void JobCInput::Report()    { IMP(Report)    }
00365 void JobCInput::Reset()     { IMP(Reset)     }
00366 #undef IMP
00367 
00368 //......................................................................   
00369 
00370 // Save a litte typing. This macro works for void m(a)
00371 #define IMP(m,a) { if (this->CheckImpl()) fImpl->m(a); }
00372 void JobCInput::Config(const Registry& r)   { IMP(Config,r) }
00373 void JobCInput::Cmd(const char* c)          { IMP(Cmd,c)    }
00374 void JobCInput::HandleCommand(JobCommand *c){ IMP(HandleCommand,c) }
00375 #undef IMP
00376 // JobCResult JobCInput::Get(MomNavigator *m)       { return gsW; }
00377 // JobCResult JobCInput::Put(const MomNavigator *m) { return gsW; }
00378 
00379 //......................................................................   
00380 
00381 int JobCInput::CheckImpl() const
00382 {
00383 //======================================================================
00384 // Check if we have a valid pointer to an input module
00385 //======================================================================
00386   if (fImpl==0) {
00387     MSG("JobC",Msg::kWarning) <<
00388       "No implementation provided for Input module. Try this:"
00389       " Input.Use(\"Input\")" << std::endl;
00390     return 0;
00391   }
00392   return 1;
00393 }
00394 
00395 

Generated on Mon Feb 15 11:06:49 2010 for loon by  doxygen 1.3.9.1