//-------------------------------------------------------------------------- // Description: // ----------- // Class InitStntupleModule : books tree and does other initializations // for STNTUPLE // // Nov 23 2000 P.Murat //------------------------------------------------------------------------ #ifdef __GNUG__ #pragma implementation #endif #include #include #include "evt/Event.hh" #include #include #include #include "TH1.h" #include "TProfile.h" #include "TTree.h" #include "AbsEnv/AbsEnv.hh" #include "Alignment/CotBeam.hh" #include "Alignment/SvxBeam.hh" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "DBManager/IoEntry.hh" #include "DBManager/ConControl.hh" #include "DBObjects/private/dbOTL.hh" #include "DBObjects/private/utilsOTL.hh" #include "CalibDB/RunListKey.hh" #include "CLHEP/Matrix/SymMatrix.h" #include "CLHEP/Matrix/Vector.h" #include "CLHEP/Geometry/Point3D.h" #include "CLHEP/Geometry/Vector3D.h" ClassImp(InitStntupleModule) //------------------------------------------------------------------------------ // constructors //------------------------------------------------------------------------------ InitStntupleModule::InitStntupleModule(const char* name, const char* desc): StntupleModule (name,desc) , fBeamHistoryCode ("beamHistoryCode" ,this, -1, -1, 1000) { commands()->append(&fBeamHistoryCode); fBeamHistoryCode.addDescription("\tPreferred beamline history code"); //----------------------------------------------------------------------------- // dont create subdirectories for the modules: they will have different folders //----------------------------------------------------------------------------- RootHistModule::fgMakeSubdirs = 0; fLastRun = -1; fSvxBeam = 0; fCotBeam = 0; } //------------------------------------------------------------------------------ InitStntupleModule::~InitStntupleModule() { // do not need to delete anything } //------------------------------------------------------------------------------ AppResult InitStntupleModule::beginJob(AbsEvent* event) { // book the tree, for ROOT 3 kludge split mode: set it always to // "non-split,old" // header block, however is always written in split mode fgTree = new TTree("STNTUPLE", "STNTUPLE"); AddDataBlock("HeaderBlock","TStnHeaderBlock", StntupleInitHeaderBlock, fBufferSize.value(), 99, // fSplitMode.value(), always split fCompressionLevel.value()); SetResolveLinksMethod("HeaderBlock",StntupleHeaderBlockLinks); //----------------------------------------------------------------------------- // open connections for the dead channel database // when these are added to a used set, the "oftol.." argument can be deleted //----------------------------------------------------------------------------- fCesMgr = new CESDeadChannels_mgr("ofotl_prd_read","CESDeadChannels"); fCesPtr = new CESDeadChannelsContainer_ptr(); fPesMgr = new PESDeadChannels_mgr("ofotl_prd_read","PESDeadChannels"); fPesPtr = new PESDeadChannelsContainer_ptr(); fCprMgr = new CPRDeadChannels_mgr("ofotl_prd_read","CPRDeadChannels"); fCprPtr = new CPRDeadChannelsContainer_ptr(); fCcrMgr = new CCRDeadChannels_mgr("ofotl_prd_read","CCRDeadChannels"); fCcrPtr = new CCRDeadChannelsContainer_ptr(); //----------------------------------------------------------------------------- // set beam history code to use //----------------------------------------------------------------------------- StntupleBeamManager* bm = StntupleBeamManager::Instance(); bm->SetHistoryCode(fBeamHistoryCode.value()); return AppResult::OK; } //_____________________________________________________________________________ Int_t InitStntupleModule::InitBeamPositions() { // AbsEnv* env = AbsEnv::instance(); int run_num = env->runNumber(); int mc_flag = env->monteFlag(); StntupleBeamManager* bm = StntupleBeamManager::Instance(); bm->BeginRun(run_num,mc_flag); return 0; } //------------------------------------------------------------------------------ Int_t InitStntupleModule::ProcessNewRun(AbsEvent* event) { InitRunSummary (); InitBeamPositions (); InitTriggerTable (); InitDeadList (); TStntuple::Init(AbsEnv::instance()->runNumber()); return 0; } //------------------------------------------------------------------------------ AppResult InitStntupleModule::beginRun( AbsEvent* Event ) { // fetch calibration constants for a new run AbsEnv* env = AbsEnv::instance(); int runnum = env->runNumber(); int mc_flag = env->monteFlag(); if (runnum != fLastRun) { ProcessNewRun(Event); fLastRun = runnum; } return AppResult::OK; } //------------------------------------------------------------------------------ Int_t InitStntupleModule::InitRunSummary() { // TStnDBManager* dbm = TStnDBManager::Instance(); TStnRunSummary* run_sum = (TStnRunSummary*) dbm->GetTable("RunSummary"); AbsEnv* env = AbsEnv::instance(); if (env->monteFlag() == false) { OTLCon_ptr handle; if (ConControl::instance()->getConnection(handle,"database_oracle_offline")) { string query; query = "SELECT RS.MYRONMODE, RS.L1EARLY, "; query += "TO_CHAR((B0INTEGRATEDLUMI_TERMINATE-B0INTEGRATEDLUMI_ACTIVATE),"; query += "'999990.999'), "; query += "TO_CHAR((B0INTEGRATEDLIVELUMI_TERMINATE-B0INTEGRATEDLIVELUMI_ACTIVATE),'999990.999'), "; query += "b0luminosity_activate, b0luminosity_terminate, "; query += "TO_CHAR(RC.CREATETIME,'YYYY.MM.DD'), TO_CHAR(RC.ACTIVATETIME,'HH24:MI:SS'), "; query += "RUNDB.CLOCK_TO_TIME(RC.LIVETIME), "; query += "RS.PHYSICSTABLENAME||' ['||RS.PHYSICSTABLETAG||','"; query += "||RS.L3TAGSET||']',"; query += "RC.CHECKED_STATUS, "; query += "RC.BEAM_STATUS, RST.GOODRUN_STATUS, RST.OFFLINE_STATUS, "; query += "RST.CLC_STATUS, RST.CAL_STATUS, RST.SMX_STATUS, "; query += "RST.COT_STATUS, RST.SVX_STATUS, RST.ISL_STATUS, RST.L00_STATUS, "; query += "RST.CMU_STATUS, RST.CMP_STATUS, RST.CMX_STATUS, RST.IMU_STATUS, "; query += "RST.TOF_STATUS, "; query += "RST.L1T_STATUS, RST.L2T_STATUS, RST.L3T_STATUS, RST.SVT_STATUS, "; query += "RST.MNP_STATUS, RST.BSC_STATUS, "; query += "RST.CSMX_STATUS, RST.PSMX_STATUS, "; query += "RST.CLC_OFFLINE, RST.CAL_OFFLINE, RST.SMX_OFFLINE, "; query += "RST.COT_OFFLINE, RST.SVX_OFFLINE, RST.ISL_OFFLINE, RST.L00_OFFLINE, "; query += "RST.CMU_OFFLINE, RST.CMP_OFFLINE, RST.CMX_OFFLINE, RST.IMU_OFFLINE, "; query += "RST.TOF_OFFLINE, "; query += "RST.L1T_OFFLINE, RST.L2T_OFFLINE, RST.L3T_OFFLINE, RST.SVT_OFFLINE, "; query += "RST.MNP_OFFLINE, RST.BSC_OFFLINE "; query += "FROM RUNCONFIGURATIONS RC,RUNSETS RS,RUN_STATUS RST WHERE RC.RUNNUMBER = "; char text[100]; sprintf(text,"%i",gblEnv->runNumber()); query += text; query += " AND RC.RS_NAME=RS.NAME"; otl_stream i(2,query.c_str(),*handle); float lumi_tev , lumi_tape, livetime, b0initlumi, b0termlumi; string slumi_tev; string slumi_tape; // string slumi_offl; string day; string time; string slivetime; string trigger_table_name; int iw; unsigned long myron_mode, l1_early; unsigned long chk_status, beam_status, goodrun_status, offline_status_bit; unsigned long clc_status, cal_status, smx_status, cot_status, svx_status, isl_status, l00_status, cmu_status, cmp_status, cmx_status, imu_status, tof_status, l1t_status, l2t_status, l3t_status, svt_status, mpl_status, bsc_status, ces_status, pes_status; unsigned long clc_offline, cal_offline, smx_offline, cot_offline, svx_offline, isl_offline, l00_offline, cmu_offline, cmp_offline, cmx_offline, imu_offline, tof_offline, l1t_offline, l2t_offline, l3t_offline, svt_offline, mpl_offline, bsc_offline, ces_offline, pes_offline; while(!i.eof()) { i >> (long& ) myron_mode; i >> (long& ) l1_early; i >> (string&) slumi_tev; i >> (string&) slumi_tape; i >> (float& ) b0initlumi; i >> (float& ) b0termlumi; i >> (string&) day; i >> (string&) time; i >> (string&) slivetime; i >> (string&) trigger_table_name; i >> (long& ) chk_status; i >> (long& ) beam_status; i >> (long& ) goodrun_status; i >> (long& ) offline_status_bit; i >> (long& ) clc_status; i >> (long& ) cal_status; i >> (long& ) smx_status; i >> (long& ) cot_status; i >> (long& ) svx_status; i >> (long& ) isl_status; i >> (long& ) l00_status; i >> (long& ) cmu_status; i >> (long& ) cmp_status; i >> (long& ) cmx_status; i >> (long& ) imu_status; i >> (long& ) tof_status; i >> (long& ) l1t_status; i >> (long& ) l2t_status; i >> (long& ) l3t_status; i >> (long& ) svt_status; i >> (long& ) mpl_status; i >> (long& ) bsc_status; i >> (long& ) ces_status; i >> (long& ) pes_status; i >> (long& ) clc_offline; i >> (long& ) cal_offline; i >> (long& ) smx_offline; i >> (long& ) cot_offline; i >> (long& ) svx_offline; i >> (long& ) isl_offline; i >> (long& ) l00_offline; i >> (long& ) cmu_offline; i >> (long& ) cmp_offline; i >> (long& ) cmx_offline; i >> (long& ) imu_offline; i >> (long& ) tof_offline; i >> (long& ) l1t_offline; i >> (long& ) l2t_offline; i >> (long& ) l3t_offline; i >> (long& ) svt_offline; i >> (long& ) mpl_offline; i >> (long& ) ces_offline; i >> (long& ) pes_offline; run_sum->SetRunNumber(env->runNumber()); run_sum->SetMyronMode(myron_mode); run_sum->SetL1Early (l1_early); run_sum->SetTriggerTableName(trigger_table_name.data()); lumi_tev = atof(slumi_tev.data()); lumi_tape = atof(slumi_tape.data()); livetime = atof(slivetime.data()); run_sum->SetLumiTev(lumi_tev); run_sum->SetLumiTape(lumi_tape); run_sum->SetB0InitLumi(b0initlumi); run_sum->SetB0TermLumi(b0termlumi); run_sum->SetLivetime(livetime); run_sum->SetDate(day.c_str()); run_sum->SetTime(time.c_str()); run_sum->SetBeamStatus(beam_status); run_sum->SetGoodRunStatus(goodrun_status); //----------------------------------------------------------------------------- // form bit-packed online status word //----------------------------------------------------------------------------- iw = ( ((goodrun_status & 0x1) ) | ((chk_status & 0x1) << 2) | ((beam_status & 0x1) << 3) | ((offline_status_bit & 0x1) << 4) | ((clc_status & 0x1) << 5) | ((cal_status & 0x1) << 6) | ((smx_status & 0x1) << 7) | ((cot_status & 0x1) << 8) | ((svx_status & 0x1) << 9) | ((isl_status & 0x1) << 10) | ((l00_status & 0x1) << 11) | ((cmu_status & 0x1) << 12) | ((cmp_status & 0x1) << 13) | ((cmx_status & 0x1) << 14) | ((imu_status & 0x1) << 15) | ((tof_status & 0x1) << 16) | ((l1t_status & 0x1) << 17) | ((l2t_status & 0x1) << 18) | ((l3t_status & 0x1) << 19) | ((svt_status & 0x1) << 20) | ((mpl_status & 0x1) << 21) | ((bsc_status & 0x1) << 22) | ((ces_status & 0x1) << 23) | ((pes_status & 0x1) << 24) ); run_sum->SetStatusWord(iw); //----------------------------------------------------------------------------- // form bit-packed offline status word //----------------------------------------------------------------------------- iw = ( ((clc_offline & 0x1) << 5) | ((cal_offline & 0x1) << 6) | ((smx_offline & 0x1) << 7) | ((cot_offline & 0x1) << 8) | ((svx_offline & 0x1) << 9) | ((isl_offline & 0x1) << 10) | ((l00_offline & 0x1) << 11) | ((cmu_offline & 0x1) << 12) | ((cmp_offline & 0x1) << 13) | ((cmx_offline & 0x1) << 14) | ((imu_offline & 0x1) << 15) | ((tof_offline & 0x1) << 16) | ((l1t_offline & 0x1) << 17) | ((l2t_offline & 0x1) << 18) | ((l3t_offline & 0x1) << 19) | ((svt_offline & 0x1) << 20) | ((mpl_offline & 0x1) << 21) | ((bsc_offline & 0x1) << 22) | ((ces_offline & 0x1) << 23) | ((pes_offline & 0x1) << 24) ); run_sum->SetOfflineStatusWord(iw); if (i.status()!= 0) { i.report_error(); } } //----------------------------------------------------------------------------- // do offline luminosity //----------------------------------------------------------------------------- query = "select rs.lum_integral_online, rs.lum_integral_offline "; query += Form("from filecatalog.cdf2_runsections rs where rs.run_number = %i", gblEnv->runNumber()); otl_stream i2(2,query.c_str(),*handle); //----------------------------------------------------------------------------- // now loop over the runsections //----------------------------------------------------------------------------- float lumi_online, lumi_offline, lumi_sum_online, lumi_sum_offline; lumi_sum_online = 0.; lumi_sum_offline = 0.; while(!i2.eof()) { i2 >> (float&) lumi_online; i2 >> (float&) lumi_offline; if (i2.status() == 0) { lumi_sum_online += lumi_online; lumi_sum_offline += lumi_offline; } else { i2.report_error(); } } run_sum->SetOnlineLumiRS (lumi_sum_online); run_sum->SetOfflineLumiRS(lumi_sum_offline); } } return 0; } //------------------------------------------------------------------------------ Int_t InitStntupleModule::InitTriggerTable() { string trigger_name; string trigger_table_name; unsigned long bit; unsigned long level; unsigned long trigger_tag; unsigned long trigger_table_tag; int trigger_id; // delete all the previous definitions TStnDBManager* dbm = TStnDBManager::Instance(); TStnTriggerTable* trigger_table; trigger_table = (TStnTriggerTable*)dbm->GetTable("TriggerTable"); trigger_table->Delete(); if (gblEnv->monteFlag() == false || (gblEnv->monteFlag() == true && gblEnv->runNumber() >100000)) { OTLCon_ptr handle; if (ConControl::instance()->getConnection(handle,"database_oracle_offline")) { ostringstream ost; ost << " SELECT UNIQUE TBM.BIT_NO, TBM.TRIGGER_LEVEL, TN.TRIGGER_ID," << " TBM.TRIGGER_NAME, TBM.TRIGGER_TAG TRG, DPT.PHYSICS_TABLE_NAME," << " DPT.PHYSICS_TABLE_TAG " << " FROM RUNCONFIGURATIONS RC," << " RUNSETS RS," << " DATASETS_PHYSICS_TABLES DPT," << " DATASETS_TRIGGER_PATHS DTP," << " TRIGGER_NAMES_TRIGGER_PATHS TP," << " TRIGGER_BITMASKS TBM," << " TRIGGER_NAMES TN" << " WHERE RC.RUNNUMBER = " << gblEnv->runNumber() << " AND RC.RS_NAME = RS.NAME " << " AND RS.PHYSICSTABLENAME = DPT.PHYSICS_TABLE_NAME " << " AND RS.PHYSICSTABLETAG = DPT.PHYSICS_TABLE_TAG " << " AND DPT.DATASET_NAME = DTP.DATASET_NAME " << " AND DPT.DATASET_TAG = DTP.DATASET_TAG " << " AND DTP.PATH_NAME = TP.PATH_NAME " << " AND DTP.PATH_TAG = TP.PATH_TAG " << " AND TP.TRIGGER_LEVEL = TBM.TRIGGER_LEVEL " << " AND TP.TRIGGER_NAME = TBM.TRIGGER_NAME " << " AND TP.TRIGGER_TAG = TBM.TRIGGER_TAG " << " AND TN.TRIGGER_LEVEL = TBM.TRIGGER_LEVEL " << " AND TN.TRIGGER_NAME = TBM.TRIGGER_NAME " << " AND TN.TRIGGER_TAG = TBM.TRIGGER_TAG " << " AND DPT.PHYSICS_TABLE_NAME = TBM.PHYSICS_TABLE_NAME " << " AND DPT.PHYSICS_TABLE_TAG = TBM.PHYSICS_TABLE_TAG " << " ORDER BY BIT_NO, TRG"; otl_stream i( 2,ost.str().data(),*handle); while(!i.eof()) { i >> (long& ) bit; i >> (long& ) level; i >> (int& ) trigger_id; i >> (string&) trigger_name; i >> (long& ) trigger_tag; i >> (string&) trigger_table_name; i >> (long& ) trigger_table_tag; if(i.status()!= 0) { i.report_error(); } else { trigger_table->AddTrigger(new TStnTrigger(bit, level, trigger_id, trigger_name.data(), trigger_tag)); } } trigger_table->SetName(trigger_table_name.data()); trigger_table->SetTag (trigger_table_tag); // L3 bit query ostringstream ost2; ost2 << " SELECT UNIQUE DTP.PATH_NAME, DTP.PATH_TAG, TP.PATH_ID, PB.PATH_BIT " << " FROM RUNCONFIGURATIONS RC, RUNSETS RS, PATH_BITMASK PB, " << " VALID_TAG_SETS VT, L3_TCLS L3T, PHYSICS_TABLES PT, " << " DATASETS_PHYSICS_TABLES DPT, DATASETS_TRIGGER_PATHS DTP, " << " TRIGGER_PATHS TP " << " WHERE RC.RUNNUMBER = " << gblEnv->runNumber() << " AND RC.RS_NAME = RS.NAME " << " AND RS.L3TAGSET = VT.L3TAGSET " << " AND VT.TCL_TAG = L3T.TCL_TAG " << " AND L3T.PHYSICS_TABLE_NAME = PT.PHYSICS_TABLE_NAME " << " AND L3T.PHYSICS_TABLE_TAG = PT.PHYSICS_TABLE_TAG " << " AND PT.PHYSICS_TABLE_NAME = DPT.PHYSICS_TABLE_NAME " << " AND PT.PHYSICS_TABLE_TAG = DPT.PHYSICS_TABLE_TAG " << " AND DPT.DATASET_NAME = DTP.DATASET_NAME " << " AND DPT.DATASET_TAG = DTP.DATASET_TAG " << " AND TP.PATH_NAME = DTP.PATH_NAME " << " AND TP.PATH_TAG = DTP.PATH_TAG " << " AND PB.PATH_NAME = TP.PATH_NAME " << " AND PB.PATH_TAG = TP.PATH_TAG " << " AND PB.PHYSICS_TABLE_NAME = DPT.PHYSICS_TABLE_NAME " << " AND PB.PHYSICS_TABLE_TAG = DPT.PHYSICS_TABLE_TAG " << " ORDER BY DTP.PATH_NAME "; otl_stream i2( 1,ost2.str().data(),*handle); while(!i2.eof()) { i2 >> (string&) trigger_name; i2 >> (long& ) trigger_tag; // this is the name on which one sorts i2 >> (int& ) trigger_id; i2 >> (long& ) bit; //printf("%d %s\n",bit,trigger_name); if(i2.status()!= 0) i2.report_error(); else { trigger_table->AddTrigger(new TStnTrigger(bit, 3, trigger_id, trigger_name.data(), trigger_tag)); } bit++; } } } return 0; } //------------------------------------------------------------------------------ Int_t InitStntupleModule::InitDeadList() { AbsEnv* env = AbsEnv::instance(); int run_number = env->runNumber(); int status=0; TStnDBManager* dbm = TStnDBManager::Instance(); TStnDeadList* deadList = (TStnDeadList*) dbm->GetTable("DeadList"); deadList->SetRunNumber(run_number); //eventually dbrun will be simply run_number int dbrun; int ind; Short_t* array; RunListKey qk; // CES dbrun = 139200; qk.setRun(dbrun); if(fCesMgr->isValid()) { if((fCesMgr->get(qk,*fCesPtr)==Result::success)) { CESDeadChannelsContainer::iterator it = (*fCesPtr)->begin(); deadList->SetNCesEntries((*fCesPtr)->size()); array = deadList->CesArray(); ind = 0; while(it!=(*fCesPtr)->end()) { array[ind++] = it->channelID(); it++; } } else status = 1; } else status = 1; // PES dbrun = ( run_number<146000 ? 139200: 146100 ); qk.setRun(dbrun); if(fPesMgr->isValid()) { if((fPesMgr->get(qk,*fPesPtr)==Result::success)) { PESDeadChannelsContainer::iterator it = (*fPesPtr)->begin(); deadList->SetNPesEntries((*fPesPtr)->size()); array = deadList->PesArray(); ind = 0; while(it!=(*fPesPtr)->end()) { array[ind++] = it->channelID(); it++; } } else status = 1; } else status = 1; // CPR dbrun = 139200; qk.setRun(dbrun); if(fCprMgr->isValid()) { if((fCprMgr->get(qk,*fCprPtr)==Result::success)) { CPRDeadChannelsContainer::iterator it = (*fCprPtr)->begin(); deadList->SetNCprEntries((*fCprPtr)->size()); array = deadList->CprArray(); ind = 0; while(it!=(*fCprPtr)->end()) { array[ind++] = it->channelID(); it++; } } else status = 1; } else status = 1; // CCR dbrun = 139200; qk.setRun(dbrun); if(fCcrMgr->isValid()) { if((fCcrMgr->get(qk,*fCcrPtr)==Result::success)) { CCRDeadChannelsContainer::iterator it = (*fCcrPtr)->begin(); deadList->SetNCcrEntries((*fCcrPtr)->size()); array = deadList->CcrArray(); ind = 0; while(it!=(*fCcrPtr)->end()) { array[ind++] = it->channelID(); it++; } } else status = 1; } else status = 1; return status; } //------------------------------------------------------------------------------ AppResult InitStntupleModule::event( AbsEvent* event ) { // event entry point: initialize all the registered data blocks with the event // data // it is assumed that the tree itself is filled in FillStntupleModule // order in which branches are filled may be important - for example, // it is better to fill track branch before the electron branch, // missing Et branch logically is the last one // assume that InitStntupleModule is executed before any other STNTUPLE-related // module // it decides whether we are about to close the file and to open a new one //----------------------------------------------------------------------------- // connect to the error reporting facility //----------------------------------------------------------------------------- TStnErrorLogger* logger = Event()->GetErrorLogger(); logger->Connect("Report(Int_t, const char*)", "StntupleModule", this, "LogError(const char*)"); //----------------------------------------------------------------------------- // initialization //----------------------------------------------------------------------------- Event()->Init(event,0); //----------------------------------------------------------------------------- // disconnect from the error reporting signal and return back to AC++ //----------------------------------------------------------------------------- logger->Disconnect("Report(Int_t,const char*)", this,"LogError(const char*)"); return AppResult::OK; } //------------------------------------------------------------------------------ AppResult InitStntupleModule::endRun( AbsEvent* aRun ) { return AppResult::OK; }