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

DemoRecordModule.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // DemoRecordModule.cxx
00004 //
00005 // A JobControl Module for demonstrating record construction.
00006 //
00008 #include <map>
00009 #include <iostream>
00010 using std::endl;
00011 #include "TNamed.h"
00012 #include "Record/test/DemoRecordModule.h"
00013 #include "MessageService/MsgService.h"
00014 #include "JobControl/JobCModuleRegistry.h"
00015 #include "JobControl/JobCommand.h"
00016 #include "MinosObjectMap/MomNavigator.h"
00017 #include "RawData/RawRecord.h"
00018 #include "RawData/RawHeader.h"
00019 #include "RawData/RawDaqSnarlHeader.h"
00020 #include "Record/RecPhysicsHeader.h"
00021 #include "Record/RecDataRecord.h"
00022 
00023 #include <cassert>
00024 
00025 ClassImp(DemoRecordModule)
00026 
00027 //   Definition of static data members
00028 //   *********************************
00029 
00030 CVSID("$Id: DemoRecordModule.cxx,v 1.4 2005/05/18 03:02:57 schubert Exp $");
00031 JOBMODULE(DemoRecordModule, "DemoRecordModule",
00032          "A module for demonstrating record construction.");
00033 
00034 
00035 // Definition of methods (alphabetical order)
00036 // ***************************************************
00037 
00038 JobCResult DemoRecordModule::Ana(const MomNavigator *mom) {
00039 
00040   JobCResult result(JobCResult::kPassed);  
00041   MSG("DemoRecord",Msg::kVerbose) << "DemoRecordModule::Ana" << endl;
00042 
00043   // Check that mom exists.
00044   assert(mom);
00045 
00046   // Retrieve record
00047   RecDataRecord<RecPhysicsHeader> *record 
00048   = dynamic_cast<RecDataRecord<RecPhysicsHeader>*>
00049     (mom->GetFragment("RecDataRecord<RecPhysicsHeader>"));
00050   if ( !record ) {
00051     MSG("DemoRecord",Msg::kWarning) << "No RecDataRecord in Mom " <<endl;
00052     result.SetWarning().SetFailed();
00053     return result;
00054   }
00055   MSG("DemoRecord",Msg::kInfo) 
00056     << "DemoRecordModule::Ana retrieved selected record:\n" << *record << endl;
00057   return result;
00058   
00059 }
00060 
00061 JobCResult DemoRecordModule::Reco(MomNavigator *mom) {
00062   //
00063   //  Purpose:  Create record.
00064   //
00065   //  Arguments: none.
00066   //  
00067   //  Return: none.
00068   //
00069   //  Contact:   S. Kasahara
00070   // 
00071 
00072 
00073   JobCResult result(JobCResult::kPassed);  
00074   MSG("DemoRecord",Msg::kVerbose) << "DemoRecordModule::Reco" << endl;
00075 
00076   // Check that mom exists.
00077   assert(mom);
00078 
00079   // Create a RecDataRecord<RecPhysicsHeader> from a RawRecord (DaqSnarl) 
00080   // Should iterate, but this is just a demo
00081   RawRecord *rawRec = dynamic_cast<RawRecord*>(mom->GetFragment("RawRecord"));
00082   if ( !rawRec ) {
00083     MSG("RawRecord",Msg::kWarning) << "No RawRecord in Mom " <<endl;
00084     result.SetWarning().SetFailed();
00085     return result;
00086   }
00087 
00088   const RawDaqSnarlHeader* rawHdr = dynamic_cast<const RawDaqSnarlHeader*>
00089                               (rawRec -> GetHeader());
00090   RecPhysicsHeader* newHdr = new RecPhysicsHeader(rawHdr->GetVldContext(),
00091         rawHdr->GetRun(),rawHdr->GetSubRun(),rawHdr->GetRunType(),
00092         rawHdr->GetErrorCode(),rawHdr->GetSnarl(),rawHdr->GetTrigSrc(),
00093         rawHdr->GetTimeFrameNum(),rawHdr->GetRemoteSpillType());
00094 
00095   // Create new record
00096   RecDataRecord<RecPhysicsHeader>* newRec 
00097     = new RecDataRecord<RecPhysicsHeader>(*newHdr);
00098 
00099   // Objects pushed in snarl have periodicity of 3 snarls:
00100   // 0) No components
00101   // 1) An object TNamed w/objectname MyObject1
00102   // 2) Two objects i)TNamed w/objectname MyObject1
00103   //               ii)TNamed w/objectname MyObject2
00104   // This is to be able to test the HasComponent feature
00105   if ( rawHdr->GetSnarl() % 3 == 1 || rawHdr->GetSnarl() % 3 == 2 ) {
00106     TNamed* named = new TNamed("MyObject1","");
00107     newRec->AdoptComponent(named); 
00108   }  
00109   if ( rawHdr->GetSnarl() % 3 == 2 ) {
00110     TNamed* named = new TNamed("MyObject2","");
00111     newRec->AdoptComponent(named);
00112   }
00113  
00114   // And pass it to Mom, mom now has memory management responsibility
00115   MSG("DemoRecord",Msg::kInfo) 
00116     << "DemoRecordModule::Reco created record:\n" << *newRec << endl;
00117   mom->AdoptFragment(newRec);
00118 
00119   return result;
00120 
00121 }
00122 
00123 void DemoRecordModule::BeginJob() {
00124   //
00125   //  Purpose:  Configure module at beginning of job.
00126   //
00127   //  Arguments: none.
00128   //  
00129   //  Return: none.
00130   //
00131   //  Contact:   S. Kasahara
00132   // 
00133 
00134   MSG("DemoRecord", Msg::kVerbose) << "DemoRecordModule::BeginJob" << endl;
00135 
00136   // Configure module
00137  
00138 }
00139 
00140 void DemoRecordModule::Config(const Registry& r) {
00141   //
00142   //  Purpose:  Configure the module based on the contents of the registry.
00143   //
00144   //  Arguments: none.
00145   //  
00146   //  Return: none.
00147   //
00148   //  Contact:   S. Kasahara
00149   // 
00150 
00151   MSG("DemoRecord",Msg::kDebug) << "Config DemoRecordModule with r=" << r << endl;
00152 
00153 }
00154 
00155 const Registry& DemoRecordModule::DefaultConfig() const {
00156   //
00157   //  Purpose:  Load default values into configuration registry.
00158   //
00159   //  Arguments: none.
00160   //  
00161   //  Return: registry of default configuration values.
00162   //
00163   //  Contact:   S. Kasahara
00164   // 
00165 
00166   static Registry r;
00167   r.SetName("DemoRecord.config");
00168 
00169   r.UnLockValues();
00170 
00171   MSG("DemoRecord",Msg::kDebug) << "Loading default config.\n" << endl;
00172 
00173   // r.Set("variable","argument");
00174 
00175   r.LockValues();
00176   return r;
00177 
00178 }
00179 
00180 DemoRecordModule::DemoRecordModule() { 
00181   //
00182   //  Purpose:  Default constructor.
00183   //
00184   //  Arguments: none.
00185   //
00186   //  Return:    n/a.
00187   //
00188   //  Contact:   S. Kasahara
00189   // 
00190   //  Notes: none.
00191   // 
00192 
00193   MSG("DemoRecord", Msg::kVerbose) << "DemoRecordModule::Constructor" << endl;
00194 
00195 }
00196 
00197 DemoRecordModule::~DemoRecordModule() {
00198   //
00199   //  Purpose:  Destructor.  
00200   //
00201   //  Contact:   S. Kasahara
00202   // 
00203 
00204   MSG("DemoRecord", Msg::kVerbose) << "DemoRecordModule::Destructor" << endl;
00205 
00206 }
00207 
00208 
00209 
00210 
00211 

Generated on Fri Mar 28 15:31:00 2008 for loon by  doxygen 1.3.9.1