analyzer.cxx File Reference

#include <stdio.h>
#include <sys/time.h>
#include <iostream>
#include <assert.h>
#include <signal.h>
#include "TMidasOnline.h"
#include "TMidasEvent.h"
#include "TMidasFile.h"
#include "XmlOdb.h"
#include <TSystem.h>
#include <TROOT.h>
#include <TApplication.h>
#include <TTimer.h>
#include <TFile.h>
#include <TDirectory.h>
#include <TGClient.h>
#include <TGFrame.h>
#include <TFolder.h>
#include "Globals.h"
#include <TH1D.h>
#include <TGMenu.h>
Include dependency graph for analyzer.cxx:

Go to the source code of this file.

Classes

class  MyPeriodic
class  MainWindow

Defines

#define M_FILE_EXIT   0

Functions

double GetTimeSec ()
void startRun (int transition, int run, int time)
void endRun (int transition, int run, int time)
void HandleSample (int ichan, void *ptr, int wsize)
void HandleMidasEvent (TMidasEvent &event)
void eventHandler (const void *pheader, const void *pdata, int size)
int ProcessMidasFile (TApplication *app, const char *fname)
int ShowMem (const char *label)
void help ()
int main (int argc, char *argv[])

Variables

int gRunNumber = 0
bool gIsRunning = false
bool gIsPedestalsRun = false
bool gIsOffline = false
int gEventCutoff = 0
TDirectorygOnlineHistDir = NULL
TFile * gOutputFile = NULL
VirtualOdbgOdb = NULL
static bool gEnableShowMem = false

Define Documentation

#define M_FILE_EXIT   0

Definition at line 400 of file analyzer.cxx.

Referenced by MainWindow::MainWindow(), and MainWindow::ProcessMessage().


Function Documentation

void endRun ( int  transition,
int  run,
int  time 
)

Definition at line 135 of file analyzer.cxx.

References gIsRunning, gManaHistosFolder, gOutputFile, and gRunNumber.

Referenced by MainWindow::CloseWindow(), MainWindow::ProcessMessage(), and ProcessMidasFile().

00136 {
00137   gIsRunning = false;
00138   gRunNumber = run;
00139 
00140 #ifdef HAVE_MIDASSERVER
00141   if (gManaHistosFolder)
00142     gManaHistosFolder->Clear();
00143 #endif
00144 
00145   if (gOutputFile)
00146     {
00147       gOutputFile->Write();
00148       gOutputFile->Close();             //close the histogram file
00149       gOutputFile = NULL;
00150     }
00151 
00152   printf("End of run %d\n",run);
00153 }

Here is the caller graph for this function:

void eventHandler ( const void *  pheader,
const void *  pdata,
int  size 
)

Definition at line 232 of file analyzer.cxx.

References TMidasEvent::GetEventHeader(), and HandleMidasEvent().

00233 {
00234   TMidasEvent event;
00235   memcpy(event.GetEventHeader(), pheader, sizeof(TMidas_EVENT_HEADER));
00236   event.SetData(size, (char*)pdata);
00237   event.SetBankList();
00238   HandleMidasEvent(event);
00239 }

Here is the call graph for this function:

double GetTimeSec (  ) 

Definition at line 54 of file analyzer.cxx.

Referenced by MyPeriodic::MyPeriodic(), TPeriodicClass::Notify(), MyPeriodic::Notify(), and TPeriodicClass::TPeriodicClass().

00055 {
00056   struct timeval tv;
00057   gettimeofday(&tv,NULL);
00058   return tv.tv_sec + 0.000001*tv.tv_usec;
00059 }

Here is the caller graph for this function:

void HandleMidasEvent ( TMidasEvent event  ) 

Definition at line 189 of file analyzer.cxx.

References gIsPedestalsRun, gIsRunning, and HandleSample().

Referenced by eventHandler(), and ProcessMidasFile().

00190 {
00191   int eventId = event.GetEventId();
00192 
00193   if (false&&(eventId == 1))
00194     {
00195       void *ptr;
00196       int size = event.LocateBank(NULL, "CHA3", &ptr);
00197       if (ptr)
00198         HandleSample(3, ptr, size);
00199     }
00200   if (false&&(eventId == 1)&&(gIsRunning==true)&&(gIsPedestalsRun==false)) // SIS data
00201     {
00202       //printf("SIS event\n");
00203       //event.Print();
00204       //void *ptr;
00205       //int size = event.LocateBank(event.GetData(),"MCS",&ptr);
00206       //HandleSIS(kMaxSisChannels,size,ptr);
00207     }
00208   else if (false&&(eventId == 2)&&(gIsRunning==true)) // ADC data
00209     {
00210       //printf("ADC event\n");
00211       //event.Print();
00212       //void *ptr;
00213       //int size = event.LocateBank(event.GetData(),"ADC",&ptr);
00214       //HandleBeamADC(kMaxADCChannels,size,ptr,event);
00215     }
00216   else if (false&&(eventId==5)&&(gIsRunning==true)&&(gIsPedestalsRun==false))// Scaler data
00217     {
00218       //event.Print();
00219       //void *sclrptr;
00220       //int sclrsize = event.LocateBank(event.GetData(),"SCLR",&sclrptr);
00221       //void *scrtptr;
00222       //int scrtsize = event.LocateBank(event.GetData(),"SCRT",&scrtptr);
00223       //HandleScaler(kMaxScalerChannels,sclrsize,sclrptr,scrtsize,scrtptr,event);
00224     }
00225   else
00226     {
00227       // unknown event type
00228       event.Print();
00229     }
00230 }

Here is the call graph for this function:

Here is the caller graph for this function:

void HandleSample ( int  ichan,
void *  ptr,
int  wsize 
)

Definition at line 157 of file analyzer.cxx.

References gDirectory, TDirectory::Get(), gManaHistosFolder, and gOutputFile.

Referenced by HandleMidasEvent().

00158 {
00159   uint16_t *samples = (uint16_t*) ptr;
00160   int numSamples = wsize;
00161 
00162   if (numSamples != 512)
00163     return;
00164 
00165   char name[256];
00166   sprintf(name, "channel%d", ichan);
00167 
00168   if (gOutputFile)
00169     gOutputFile->cd();
00170 
00171   TH1D* samplePlot = (TH1D*)gDirectory->Get(name);
00172 
00173   if (!samplePlot)
00174     {
00175       printf("Create [%s]\n", name);
00176       samplePlot = new TH1D(name, name, numSamples, 0, numSamples);
00177       //samplePlot->SetMinimum(0);
00178 #ifdef HAVE_MIDASSERVER
00179       if (gManaHistosFolder)
00180         gManaHistosFolder->Add(samplePlot);
00181 #endif
00182     }
00183 
00184   for(int ti=0; ti<numSamples; ti++)
00185     samplePlot->SetBinContent(ti, samples[ti]);
00186 }

Here is the call graph for this function:

Here is the caller graph for this function:

void help (  ) 

Definition at line 499 of file analyzer.cxx.

Referenced by main().

00500 {
00501   printf("\nUsage:\n");
00502   printf("\n./analyzer.exe [-h] [-Hhostname] [-Eexptname] [-eMaxEvents] [-P9091] [-p9090] [-m] [-g] [file1 file2 ...]\n");
00503   printf("\n");
00504   printf("\t-h: print this help message\n");
00505   printf("\t-T: test mode - start and serve a test histogram\n");
00506   printf("\t-Hhostname: connect to MIDAS experiment on given host\n");
00507   printf("\t-Eexptname: connect to this MIDAS experiment\n");
00508   printf("\t-P: Start the TNetDirectory server on specified tcp port (for use with roody -Plocalhost:9091)\n");
00509   printf("\t-p: Start the old midas histogram server on specified tcp port (for use with roody -Hlocalhost:9090)\n");
00510   printf("\t-e: Number of events to read from input data files\n");
00511   printf("\t-m: Enable memory leak debugging\n");
00512   printf("\t-g: Enable graphics display when processing data files\n");
00513   printf("\n");
00514   printf("Example1: analyze online data: ./analyzer.exe -P9091\n");
00515   printf("Example2: analyze existing data: ./analyzer.exe /data/alpha/current/run00500.mid\n");
00516   exit(1);
00517 }

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 521 of file analyzer.cxx.

References TDirectory::cd(), XmlServer::Export(), gEventCutoff, gIsOffline, help(), ProcessMidasFile(), XmlServer::SetVerbose(), XmlServer::Start(), StartMidasServer(), and StartNetDirectoryServer().

00522 {
00523    setbuf(stdout,NULL);
00524    setbuf(stderr,NULL);
00525  
00526    signal(SIGILL,  SIG_DFL);
00527    signal(SIGBUS,  SIG_DFL);
00528    signal(SIGSEGV, SIG_DFL);
00529    signal(SIGPIPE, SIG_DFL);
00530  
00531    std::vector<std::string> args;
00532    for (int i=0; i<argc; i++)
00533      {
00534        if (strcmp(argv[i],"-h")==0)
00535          help(); // does not return
00536        args.push_back(argv[i]);
00537      }
00538 
00539    TApplication *app = new TApplication("rootana", &argc, argv);
00540 
00541    if(gROOT->IsBatch()) {
00542         printf("Cannot run in batch mode\n");
00543         return 1;
00544    }
00545 
00546    bool forceEnableGraphics = false;
00547    bool testMode = false;
00548    int  oldTcpPort = 0;
00549    int  tcpPort = 0;
00550    int  xmlTcpPort = 0;
00551    const char* hostname = NULL;
00552    const char* exptname = NULL;
00553 
00554    for (unsigned int i=1; i<args.size(); i++) // loop over the commandline options
00555      {
00556        const char* arg = args[i].c_str();
00557        //printf("argv[%d] is %s\n",i,arg);
00558            
00559        if (strncmp(arg,"-e",2)==0)  // Event cutoff flag (only applicable in offline mode)
00560          gEventCutoff = atoi(arg+2);
00561        else if (strncmp(arg,"-m",2)==0) // Enable memory debugging
00562          gEnableShowMem = true;
00563        else if (strncmp(arg,"-p",2)==0) // Set the histogram server port
00564          oldTcpPort = atoi(arg+2);
00565        else if (strncmp(arg,"-P",2)==0) // Set the histogram server port
00566          tcpPort = atoi(arg+2);
00567        else if (strncmp(arg,"-X",2)==0) // Set the histogram server port
00568          xmlTcpPort = atoi(arg+2);
00569        else if (strcmp(arg,"-T")==0)
00570          testMode = true;
00571        else if (strcmp(arg,"-g")==0)
00572          forceEnableGraphics = true;
00573        else if (strncmp(arg,"-H",2)==0)
00574          hostname = strdup(arg+2);
00575        else if (strncmp(arg,"-E",2)==0)
00576          exptname = strdup(arg+2);
00577        else if (strcmp(arg,"-h")==0)
00578          help(); // does not return
00579        else if (arg[0] == '-')
00580          help(); // does not return
00581     }
00582     
00583    MainWindow mainWindow(gClient->GetRoot(), 200, 300);
00584 
00585    gROOT->cd();
00586    gOnlineHistDir = new TDirectory("rootana", "rootana online plots");
00587 
00588 #ifdef HAVE_MIDASSERVER
00589    if (oldTcpPort)
00590      StartMidasServer(oldTcpPort);
00591 #else
00592    if (oldTcpPort)
00593      fprintf(stderr,"ERROR: No support for the old midas server!\n");
00594 #endif
00595 #ifdef HAVE_LIBNETDIRECTORY
00596    if (tcpPort)
00597      StartNetDirectoryServer(tcpPort, gOnlineHistDir);
00598 #else
00599    if (tcpPort)
00600      fprintf(stderr,"ERROR: No support for the TNetDirectory server!\n");
00601 #endif
00602 #ifdef HAVE_XMLSERVER
00603    XmlServer* xmlServer = NULL;
00604    if (xmlTcpPort)
00605      {
00606         xmlServer = new XmlServer();
00607         xmlServer->SetVerbose(true);
00608         xmlServer->Start(xmlTcpPort);
00609         xmlServer->Export(gOnlineHistDir, gOnlineHistDir->GetName());
00610      }
00611 #else
00612    if (xmlTcpPort)
00613      fprintf(stderr,"ERROR: No support for the XML Server!\n");
00614 #endif
00615          
00616    gIsOffline = false;
00617 
00618    for (unsigned int i=1; i<args.size(); i++)
00619      {
00620        const char* arg = args[i].c_str();
00621 
00622        if (arg[0] != '-')  
00623          {  
00624            gIsOffline = true;
00625            //gEnableGraphics = false;
00626            //gEnableGraphics |= forceEnableGraphics;
00627            ProcessMidasFile(app,arg);
00628          }
00629      }
00630 
00631    if (testMode)
00632      {
00633        gOnlineHistDir->cd();
00634        TH1D* hh = new TH1D("test", "test", 100, 0, 100);
00635        hh->Fill(1);
00636        hh->Fill(10);
00637        hh->Fill(50);
00638 
00639        app->Run(kTRUE);
00640        return 0;
00641      }
00642 
00643    // if we processed some data files,
00644    // do not go into online mode.
00645    if (gIsOffline)
00646      return 0;
00647            
00648    gIsOffline = false;
00649    //gEnableGraphics = true;
00650 #ifdef HAVE_MIDAS
00651    ProcessMidasOnline(app, hostname, exptname);
00652 #endif
00653    
00654    return 0;
00655 }

Here is the call graph for this function:

int ProcessMidasFile ( TApplication *  app,
const char *  fname 
)

Definition at line 241 of file analyzer.cxx.

References TMidasFile::Close(), endRun(), TMidasEvent::GetData(), TMidasEvent::GetSerialNumber(), gEventCutoff, gRunNumber, HandleMidasEvent(), TMidasFile::Open(), TMidasFile::Read(), and startRun().

Referenced by main().

00242 {
00243   TMidasFile f;
00244   bool tryOpen = f.Open(fname);
00245 
00246   if (!tryOpen)
00247     {
00248       printf("Cannot open input file \"%s\"\n",fname);
00249       return -1;
00250     }
00251 
00252   int i=0;
00253   while (1)
00254     {
00255       TMidasEvent event;
00256       if (!f.Read(&event))
00257         break;
00258 
00259       int eventId = event.GetEventId();
00260       //printf("Have an event of type %d\n",eventId);
00261 
00262       if ((eventId & 0xFFFF) == 0x8000)
00263         {
00264           // begin run
00265           event.Print();
00266 
00267           //char buf[256];
00268           //memset(buf,0,sizeof(buf));
00269           //memcpy(buf,event.GetData(),255);
00270           //printf("buf is [%s]\n",buf);
00271 
00272           //
00273           // Load ODB contents from the ODB XML file
00274           //
00275           if (gOdb)
00276             delete gOdb;
00277           gOdb = new XmlOdb(event.GetData(),event.GetDataSize());
00278 
00279           startRun(0,event.GetSerialNumber(),0);
00280         }
00281       else if ((eventId & 0xFFFF) == 0x8001)
00282         {
00283           // end run
00284           event.Print();
00285         }
00286       else if ((eventId & 0xFFFF) == 0x8002) 
00287         { 
00288           // log message 
00289           event.Print(); 
00290           printf("Log message: %s\n", event.GetData()); 
00291         } 
00292       else
00293         {
00294           event.SetBankList();
00295           //event.Print();
00296           HandleMidasEvent(event);
00297         }
00298         
00299       if((i%500)==0)
00300         {
00301           //resetClock2time();
00302           printf("Processing event %d\n",i);
00303           //SISperiodic();
00304           //StepThroughSISBuffer();
00305         }
00306       
00307       i++;
00308       if ((gEventCutoff!=0)&&(i>=gEventCutoff))
00309         {
00310           printf("Reached event %d, exiting loop.\n",i);
00311           break;
00312         }
00313     }
00314   
00315   f.Close();
00316 
00317   endRun(0,gRunNumber,0);
00318 
00319   // start the ROOT GUI event loop
00320   //  app->Run(kTRUE);
00321 
00322   return 0;
00323 }

Here is the call graph for this function:

Here is the caller graph for this function:

int ShowMem ( const char *  label  ) 

Definition at line 480 of file analyzer.cxx.

00481 {
00482   if (!gEnableShowMem)
00483     return 0;
00484 
00485   FILE* fp = fopen("/proc/self/statm","r");
00486   if (!fp)
00487     return 0;
00488 
00489   int mem = 0;
00490   fscanf(fp,"%d",&mem);
00491   fclose(fp);
00492 
00493   if (label)
00494     printf("memory at %s is %d\n", label, mem);
00495 
00496   return mem;
00497 }

void startRun ( int  transition,
int  run,
int  time 
)

Definition at line 104 of file analyzer.cxx.

References gIsPedestalsRun, gIsRunning, gOutputFile, gRunNumber, NetDirectoryExport(), and VirtualOdb::odbReadBool().

Referenced by ProcessMidasFile().

00105 {
00106   gIsRunning = true;
00107   gRunNumber = run;
00108   gIsPedestalsRun = gOdb->odbReadBool("/experiment/edit on start/Pedestals run");
00109   printf("Begin run: %d, pedestal run: %d\n", gRunNumber, gIsPedestalsRun);
00110     
00111   if(gOutputFile!=NULL)
00112   {
00113     gOutputFile->Write();
00114     gOutputFile->Close();
00115     gOutputFile=NULL;
00116   }  
00117 
00118   char filename[1024];
00119   sprintf(filename, "output%05d.root", run);
00120   gOutputFile = new TFile(filename, "RECREATE");
00121   
00122   //if (gOutputFile && !gOutputFile->IsOpen())
00123   //gOutputFile = NULL;
00124 
00125   assert(gOutputFile);
00126   assert(gOutputFile->IsOpen());
00127 
00128   //printf("gOutputFile: %p, isOpen %d\n", gOutputFile, gOutputFile->IsOpen());
00129 
00130 #ifdef HAVE_LIBNETDIRECTORY
00131   NetDirectoryExport(gOutputFile, "outputFile");
00132 #endif
00133 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

bool gEnableShowMem = false [static]

Definition at line 478 of file analyzer.cxx.

int gEventCutoff = 0

Definition at line 46 of file analyzer.cxx.

Referenced by main(), and ProcessMidasFile().

bool gIsOffline = false

Definition at line 45 of file analyzer.cxx.

Referenced by main().

bool gIsPedestalsRun = false

Definition at line 44 of file analyzer.cxx.

Referenced by HandleMidasEvent(), and startRun().

bool gIsRunning = false
VirtualOdb* gOdb = NULL

Definition at line 50 of file analyzer.cxx.

Definition at line 48 of file analyzer.cxx.

TFile* gOutputFile = NULL

Definition at line 49 of file analyzer.cxx.

Referenced by endRun(), HandleSample(), and startRun().

int gRunNumber = 0

Generated on 12 Feb 2016 for ROOT Analyzer by  doxygen 1.6.1