Attachment 'TempRootTreeGenerator.cc'

Download

   1 #include "TempRootTreeGenerator.hh"
   2 #include "TROOT.h"
   3 #include "lcio.h"
   4 #include "EVENT/LCCollection.h"
   5 #include "EUDAQTempSensorBlock.hh"
   6 #include <iostream>
   7 #include <map>
   8 #include <string>
   9 #include <vector>
  10 #include <cfloat>
  11 
  12 #include "TFile.h"
  13 #include "TTree.h"
  14 
  15 using namespace std;
  16 using namespace lcio;
  17 
  18 namespace CALICE {
  19     
  20   TempRootTreeGenerator aTempRootTreeGenerator;
  21     
  22   map<TTree*, TempRootTreeGenerator*> TempRootTreeGenerator::_treeFillerMap;
  23   map<TTree*, TempRootTreeGenerator*> TempRootTreeGenerator::_treeOwnerMap;
  24   map<TFile*, TempRootTreeGenerator*> TempRootTreeGenerator::_fileOwnerMap;
  25     
  26   TempRootTreeGenerator::TempRootTreeGenerator() : Processor("TempRootTreeGenerator")
  27   {
  28     _description = "Processor to generate root tree with Event built";
  29         
  30     registerProcessorParameter("InputCollectionName",
  31 			       "Name of the input collection of TempSensorData",
  32 			       _inputColName,
  33 			       std::string("TemperatureSensor"));
  34         
  35     registerProcessorParameter("OutputRootFileName",
  36 			       "Name of the output root file",
  37 			       _rootFileName,
  38 			       std::string("Temperature.root"));
  39 
  40     registerProcessorParameter("BranchPrefix",
  41 			       "Name of the prefix of the branch",
  42 			       _prefix,
  43 			       std::string(""));
  44 
  45         
  46   }
  47     
  48   TempRootTreeGenerator::~TempRootTreeGenerator() {}
  49     
  50   void TempRootTreeGenerator::init()
  51   {
  52         
  53     _rootFile = gROOT->GetFile(_rootFileName.c_str());
  54     if ( _rootFile == NULL )
  55       {
  56 	_rootFile      = new TFile(_rootFileName.c_str(), "RECREATE");
  57 	_fileOwnerMap[ _rootFile ] = this;
  58       }
  59         
  60     _rootFile->cd();
  61     _treeTempSensorBlock = dynamic_cast<TTree*>( _rootFile->Get("TemperatureSensor"));
  62         
  63     if ( _treeTempSensorBlock != NULL )
  64       streamlog_out(DEBUG) << "Reuse tree ["<< "TemperatureSensor" <<"] " << endl;
  65     if ( _treeTempSensorBlock == NULL )
  66       {
  67 	_treeTempSensorBlock = new TTree( "TemperatureSensor" , "all information");
  68 	_treeOwnerMap[_treeTempSensorBlock] = this;
  69       }
  70         
  71     bool firstProcessor = (_treeFillerMap[ _treeTempSensorBlock ] == NULL );
  72     _treeFillerMap[ _treeTempSensorBlock ] = this;
  73         
  74     if ( firstProcessor )
  75       {
  76 	_treeTempSensorBlock->Branch( "eventNumber", &eventNumber, "EventNumber/I");
  77 	_treeTempSensorBlock->Branch( "runNumber", &runNumber, "RunNumber/I");
  78 	_treeTempSensorBlock->Branch( "Timestamp", &Timestamp, "Timestamp/I");
  79       }
  80         
  81     registerBranches(_treeTempSensorBlock);
  82   }
  83     
  84   void TempRootTreeGenerator::registerBranches( TTree* hostTree )
  85   {
  86     hostTree->Branch( string(_prefix + "nLayers").c_str(), &_hFill.nLayers,  string(_prefix+"nLayers/I").c_str());
  87     hostTree->Branch( string(_prefix + "T1").c_str(), &_hFill.T1, string(_prefix+"T1["+_prefix+"nLayers]/F").c_str() );
  88     hostTree->Branch( string(_prefix + "T2").c_str(), &_hFill.T2, string(_prefix+"T2["+_prefix+"nLayers]/F").c_str() );
  89     hostTree->Branch( string(_prefix + "T3").c_str(), &_hFill.T3, string(_prefix+"T3["+_prefix+"nLayers]/F").c_str() );
  90     hostTree->Branch( string(_prefix + "T4").c_str(), &_hFill.T4, string(_prefix+"T4["+_prefix+"nLayers]/F").c_str() );
  91     hostTree->Branch( string(_prefix + "T5").c_str(), &_hFill.T5, string(_prefix+"T5["+_prefix+"nLayers]/F").c_str() );
  92     hostTree->Branch( string(_prefix + "T6").c_str(), &_hFill.T6, string(_prefix+"T6["+_prefix+"nLayers]/F").c_str() );
  93     hostTree->Branch( string(_prefix + "TDIF").c_str(), &_hFill.TDIF, string(_prefix+"TDIF["+_prefix+"nLayers]/F").c_str() );
  94     hostTree->Branch( string(_prefix + "TPWR").c_str(), &_hFill.TPWR, string(_prefix+"TPWR["+_prefix+"nLayers]/F").c_str() );
  95 
  96   }
  97       
  98   void TempRootTreeGenerator::processEvent(LCEvent* evt)
  99   {
 100         
 101     LCCollection* col ;
 102     try
 103       {
 104 	//fetch Labview data raw collection
 105 	col = evt->getCollection( _inputColName ) ;
 106 
 107 	runNumber   = evt->getRunNumber();
 108 	eventNumber = evt->getEventNumber();
 109 	//Timestamp   = evt->getTimeStamp();
 110         Timestamp= col->getParameters().getIntVal("Timestamp_i");//TimeStamp();//airqui                                                                                         
 111 
 112 	std::cout<<"runNumber= "<<runNumber<<" eventNumber= "<<eventNumber<<" Timestamp= "<< Timestamp<<endl;
 113 	nLayers = 0;
 114 	  
 115 	for(int ielm = 0; ielm < col->getNumberOfElements(); ielm++)
 116 	  {
 117 	    LCObject *obj = col->getElementAt(ielm);
 118 	    EUDAQTempSensorBlock lBlock(obj);
 119 	    //	    std::cout<<col->getNumberOfElements()<<endl;
 120 	    float t1=lBlock.GetT1()/10.;
 121             float t2=lBlock.GetT2()/10.;
 122             float t3=lBlock.GetT3()/10.;
 123             float t4=lBlock.GetT4()/10.;
 124             float t5=lBlock.GetT5()/10.;
 125             float t6=lBlock.GetT6()/10.;
 126             float tdif=lBlock.GetTDIF();
 127             float tpwr=lBlock.GetTPWR();
 128 
 129 	    _hFill.T1[nLayers] = t1;
 130 	    _hFill.T2[nLayers] = t2;
 131 	    _hFill.T3[nLayers] = t3;
 132 	    _hFill.T4[nLayers] = t4;
 133 	    _hFill.T5[nLayers] = t5;
 134 	    _hFill.T6[nLayers] = t6;
 135 	    _hFill.TDIF[nLayers] = tdif;
 136 	    _hFill.TPWR[nLayers] = tpwr;
 137 	    if(lBlock.GetT6()==307) cout<<" t5="<<t5<<" t6="<<t6<<" tpwr="<<tpwr<<endl;
 138 	    nLayers ++;
 139 
 140 	  }
 141                   
 142 	_hFill.nLayers = nLayers;
 143    
 144 	
 145       
 146       
 147 	if ( _treeFillerMap[_treeTempSensorBlock] == this )
 148 	  {
 149 	    TFile* oldfile = _treeTempSensorBlock->GetCurrentFile();
 150 	    _treeTempSensorBlock->Fill();
 151 	    TFile* newfile = _treeTempSensorBlock->GetCurrentFile();
 152 	    if (oldfile!=newfile)
 153 	      {
 154 		TempRootTreeGenerator* owner = _fileOwnerMap[oldfile];
 155 		_fileOwnerMap.erase( oldfile );
 156 		_fileOwnerMap[newfile]=owner;
 157 	      }
 158 	  }
 159       }
 160     catch (  DataNotAvailableException err )
 161       {
 162 	//	    std::cout <<  "TempRootTreeGenerator WARNING: Collection "<< _inputColName
 163 	//	 << " not available in event "<< evt->getEventNumber() << endl;
 164 	return;
 165       }
 166         
 167   }
 168     
 169   void TempRootTreeGenerator::end()
 170   {
 171         
 172     if ( _treeOwnerMap[_treeTempSensorBlock] == this )
 173       {
 174 	TFile* treeFile = _treeTempSensorBlock->GetCurrentFile();	
 175 	treeFile->Write();
 176 	delete _treeTempSensorBlock;
 177 	_treeTempSensorBlock=NULL;
 178       }
 179         
 180     if ( _fileOwnerMap[_rootFile] == this )
 181       {
 182 	_rootFile->Write();
 183 	_rootFile->Close();
 184 	//delete _outFile;
 185 	_rootFile=NULL;
 186       }
 187   }
 188     
 189   const double TempRootTreeGenerator::INVALID = -FLT_MAX;
 190     
 191 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2015-12-04 14:25:26, 107.6 KB) [[attachment:Ahc2HardwareConnection.png]]
  • [get | view] (2015-11-16 12:20:59, 65.8 KB) [[attachment:August_Mapping.txt]]
  • [get | view] (2015-08-25 17:58:29, 3.6 KB) [[attachment:EUDAQEventBuilder.xml]]
  • [get | view] (2015-08-25 18:01:29, 6.1 KB) [[attachment:EUDAQMarlin]]
  • [get | view] (2015-08-25 18:02:31, 2.3 KB) [[attachment:EUDAQTemperature.xml]]
  • [get | view] (2015-08-18 10:01:22, 2.3 KB) [[attachment:EUDAQTemperatureReading.xml]]
  • [get | view] (2015-08-04 15:30:18, 960.8 KB) [[attachment:EUDAQUserManual.pdf]]
  • [get | view] (2015-08-25 17:58:04, 46.0 KB) [[attachment:EventBuilding.png]]
  • [get | view] (2015-12-14 14:31:16, 45.3 KB) [[attachment:GainJuly.png]]
  • [get | view] (2015-11-16 12:19:19, 63.3 KB) [[attachment:July_Mapping.txt]]
  • [get | view] (2016-04-07 13:08:15, 805.6 KB) [[attachment:MIPJuly.png]]
  • [get | view] (2016-04-07 13:13:08, 686.5 KB) [[attachment:MIPModule3.png]]
  • [get | view] (2015-12-04 14:10:09, 91.1 KB) [[attachment:ModuleDescription_LeftReadout.txt]]
  • [get | view] (2015-12-04 14:10:22, 31.0 KB) [[attachment:ModuleDescription_RightReadout.txt]]
  • [get | view] (2015-12-04 14:09:55, 31.1 KB) [[attachment:ModuleDescription_TopReadout.txt]]
  • [get | view] (2015-12-04 15:26:54, 12.2 KB) [[attachment:PedestalJuly.png]]
  • [get | view] (2015-08-18 10:01:57, 6.2 KB) [[attachment:TempRootTreeGenerator.cc]]
  • [get | view] (2015-08-18 10:01:46, 1.5 KB) [[attachment:TempRootTreeGenerator.hh]]
  • [get | view] (2015-08-18 10:02:14, 70.4 KB) [[attachment:Temp_Average__ALL_allGeV_TimeStamp.png]]
  • [get | view] (2016-04-05 09:30:01, 34.1 KB) [[attachment:dataflow.png]]
  • [get | view] (2016-04-06 15:31:08, 15.7 KB) [[attachment:steering_Electron_SPSJuly.xml]]
  • [get | view] (2016-08-02 13:01:38, 18.5 KB) [[attachment:steering_Muon_SPSJuly.xml]]
  • [get | view] (2016-04-06 15:31:00, 15.5 KB) [[attachment:steering_Pion_SPSJuly.xml]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.