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

DemoDaq.cc

Go to the documentation of this file.
00001 #include "TROOT.h"
00002 #include "TTabCom.h"
00003 #include "TTree.h"
00004 #include "Persistency/test/DemoDaqOutputModule.h"
00005 #include "MessageService/MsgService.h"
00006 #include "MinosObjectMap/MomNavigator.h"
00007 #include "RawData/RawRecord.h"
00008 #include "RawData/RawDaqSnarlHeader.h"
00009 #include "RawData/RawDigitDataBlock.h"
00010 
00011 TROOT root("DemoDaq","MINOS Persistency Package Demo Daq");
00012 MomNavigator* FillEntry(Int_t entry); 
00013 
00014 CVSID("$Id: DemoDaq.cc,v 1.12 2007/11/11 05:10:38 rhatcher Exp $");
00016 //
00017 // This demo program illustrates how the Daq could make use
00018 // of the persistency package classes to persist raw data to file.
00019 // This demo uses the DemoDaqOutputModule class 
00020 // to interface to the persistency package classes.
00021 //
00022 // Argument:  nent = number of entries to generate (default = 1000)
00023 //
00024 // S. Kasahara  04/2001
00025 //
00027 
00028 int main(int argc, char **argv) {
00029 
00030   // gDebug = TTabCom::kDebug;  // Activate for extra debug printout
00031 
00032   MsgStream& ms = MSGSTREAM("Per",Msg::kInfo);
00033   ms.SetLogLevel(Msg::kInfo);
00034 
00035   Int_t nent = 1000;  // default number of entries
00036   if (argc > 1) {
00037     nent = atoi(argv[1]);
00038   }
00039 
00040   DemoDaqOutputModule daqmod;  // create a daq output module object
00041 
00042 
00043   daqmod.BeginJob();  // performs output stream initialization
00044 
00045   ms << "\nThis demo shows how the Daq could make use of the\n"
00046      << "persistency classes to write data to file. " 
00047      << nent << " RawRecords\n"
00048      << "are artificially filled and written to stream DaqSnarl in\n"
00049      << "file testdaq.root.\n" << endl;
00050 
00051   //TTree::SetMaxTreeSize(10000); // to force file change
00052   bool openok = daqmod.BeginFile("testdaq.root",Per::kRecreate);   
00053 
00054   if( !openok ) {
00055     ms << "Output file failed to open.  Demo program requires\n"
00056        << " ability to write to current working directory. Please check\n"
00057        << " write access and try again." << endl;
00058     daqmod.EndJob();
00059     return 0;
00060   }
00061   else {
00062     ms << "Successfully opened output file testdaq.root.\n"
00063        << "Status of output stream manager before filling entries:\n\n" 
00064        << daqmod << endl;
00065   }
00066 
00067   ms.SetLogLevel(Msg::kDebug);
00068   // Begin entry loop
00069   MomNavigator* mom; //"mom" is a container for all records produced in the entry
00070   for (Int_t ient=0; ient < nent; ient++) {
00071     mom = FillEntry(ient);  // artificially fills records  
00072     if ( mom ) daqmod.Put(mom); //records are persisted to the output streams
00073     delete mom; // clean up records managed by mom. 
00074   }
00075   
00076   ms << "\nStatus of output stream manager after filling "<< nent
00077      << " entries in stream DaqSnarl:\n\n" << daqmod << endl;
00078 
00079   daqmod.EndFile(); // close file on all managed streams
00080 
00081   daqmod.EndJob(); // close all streams
00082 
00083   return 0;
00084 
00085 }
00086 
00087 MomNavigator* FillEntry(Int_t snarl) {
00088   //
00089   // Function FillEntry artificially fills a DaqSnarl and loads it
00090   // into a MomNavigator object.
00091   //
00092 
00093   // Create daq frame header
00094   Int_t run = 1; // run number
00095   Short_t subrun = 1; // subrun number
00096   Short_t runtype = 1;
00097   Detector::Detector_t dtype = Detector::kCalib;  // detector type
00098   SimFlag::SimFlag_t simflg = SimFlag::kData;  // data source
00099   VldTimeStamp tstamp((time_t)(snarl+1),0); // time stamp 
00100   VldContext vldc(dtype,simflg,tstamp);
00101   UInt_t trigsrc = 0x01;  // physics trigger
00102   UInt_t errcode = 1; //error code 
00103   UInt_t timeframe = 2;
00104   UInt_t nrawdigits = 10;
00105   UInt_t spilltype = 0;
00106   RawDaqSnarlHeader* hdr = new RawDaqSnarlHeader(vldc,run,subrun,runtype,
00107               timeframe,snarl,trigsrc,errcode,nrawdigits,spilltype);
00108   // Construct daq frame record passing it the header
00109   RawRecord* record = new RawRecord(hdr);
00110 
00111   // Construct block of data words
00112   const Int_t nwords = 100;
00113   Int_t array[nwords];
00114   for (Int_t iwrd = 0; iwrd < nwords; iwrd++) {
00115     array[iwrd]=1;
00116   }
00117   RawDigitDataBlock* dblock = new RawDigitDataBlock(array);
00118   
00119   record -> AdoptRawBlock(dblock);
00120 
00121   // Give record to Mom to be adopted, record, header, & datablock will be
00122   // deleted when Mom is deleted.
00123   MomNavigator* mom = new MomNavigator();
00124   mom -> AdoptFragment(record);
00125 
00126   // We could also create and store in Mom other records produced in this
00127   // entry
00128   return mom;
00129 
00130 }
00131 
00132 
00133 

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