ATLAS Offline Software
LArDigits2Ntuple.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 
10 LArDigits2Ntuple::LArDigits2Ntuple(const std::string& name, ISvcLocator* pSvcLocator):
11  LArCond2NtupleBase(name, pSvcLocator),
12  m_ipass(0),
13  m_event(0)
14 {
15  m_ntTitle = "LArDigits";
16  m_ntpath = "/NTUPLES/FILE1/LARDIGITS";
17 }
18 
20 = default;
21 
22 
24 {
25  ATH_MSG_DEBUG( "in initialize" );
26 
27  ATH_MSG_DEBUG(" IS it SC?? " << m_isSC );
28 
30 
31  StatusCode sc = m_nt->addItem("IEvent",m_IEvent);
32  if (sc!=StatusCode::SUCCESS) {
33  ATH_MSG_ERROR( "addItem 'IEvent' failed" );
34  return sc;
35  }
36 
37  if(m_contKey.key().size()) {
38  sc = m_nt->addItem("samples",m_Nsamples,m_samples);
39  if (sc!=StatusCode::SUCCESS) {
40  ATH_MSG_ERROR( "addItem 'samples' failed" );
41  return sc;
42  }
43  }
44 
45  sc = m_nt->addItem("Nsamples",m_ntNsamples,0,32);
46  if (sc!=StatusCode::SUCCESS) {
47  ATH_MSG_ERROR( "addItem 'Nsamples' failed" );
48  return sc;
49  }
50 
51  if(m_fillBCID){
52  sc = m_nt->addItem("BCID",m_bcid);
53  if (sc!=StatusCode::SUCCESS) {
54  ATH_MSG_ERROR( "addItem 'BCID' failed" );
55  return sc;
56  }
57  }
58 
59  sc = m_nt->addItem("ELVL1Id",m_ELVL1Id);
60  if (sc!=StatusCode::SUCCESS) {
61  ATH_MSG_ERROR( "addItem 'ELVL1Id' failed" );
62  return sc;
63  }
64 
65  if(!m_isSC){
66  sc = m_nt->addItem("Gain",m_gain,-1,3);
67  if (sc!=StatusCode::SUCCESS) {
68  ATH_MSG_ERROR( "addItem 'Gain' failed" );
69  return sc;
70  }
71  }
72 
73  if(m_fillLB){
74  NTuplePtr nt(ntupleSvc(),m_ntpath+"Evnt");
75  if (!nt) {
76  nt=ntupleSvc()->book(m_ntpath+"Evnt",CLID_ColumnWiseTuple,m_ntTitle+"Evnt");
77  }
78  if (!nt){
79  ATH_MSG_ERROR( "Booking of NTuple at "<< m_ntpath << " and name " << m_ntTitle << " failed" );
80  return StatusCode::FAILURE;
81  }
82 
83  m_evt_nt=nt;
84 
85  sc = m_evt_nt->addItem("IEvent",m_IEventEvt);
86  if (sc!=StatusCode::SUCCESS) {
87  ATH_MSG_ERROR( "addItem 'IEvent' failed" );
88  return sc;
89  }
90 
91  sc=m_evt_nt->addItem("LB",m_LB);
92  if (sc.isFailure()) {
93  ATH_MSG_ERROR( "addItem 'LB' failed" );
94  return sc;
95  }
96  }
99 
100  m_ipass = 0;
101  m_event = 0;
102 
103  return StatusCode::SUCCESS;
104 
105 }
106 
108 {
109 
110  const EventContext& ctx = Gaudi::Hive::currentContext();
111  if(m_contKey.key().empty()) return StatusCode::SUCCESS;
112 
113  StatusCode sc;
114 
115  ATH_MSG_DEBUG( "LArDigits2Ntuple in execute" );
116  m_event++;
117  unsigned long long thisevent;
118  unsigned long thisbcid = 0;
119  unsigned long thisELVL1Id = 0;
120 
121  thisevent = ctx.eventID().event_number();
122 
123  // Get BCID from FEB header
124  if ( !m_isSC ){ // we are not processing SC data, Feb header could be accessed
126  if (! hdrCont.isValid()) {
127  ATH_MSG_WARNING( "No LArFEB container found in TDS" );
128  }
129  else {
130  ATH_MSG_DEBUG( "LArFEB container found");
131  if(m_fillBCID) thisbcid = (*hdrCont->begin())->BCId() ;
132  ATH_MSG_DEBUG( "BCID FROM FEB HEADER " << thisbcid );
133  thisELVL1Id = (*hdrCont->begin())->ELVL1Id();
134  ATH_MSG_DEBUG( "NSAMPLES FROM FEB HEADER " << (*hdrCont->begin())->NbSamples() );
135  }
136  }else{
137  // This should be used for main readout later, once TDAQ fill event headers also in calib. runs properly
138  thisbcid = ctx.eventID().bunch_crossing_id();
139  }
140 
142  if(!hdlDigit.isValid()) {
143  ATH_MSG_WARNING( "Unable to retrieve LArDigitContainer with key " << m_contKey << " from DetectorStore. " );
144  return StatusCode::SUCCESS;
145  } else
146  ATH_MSG_DEBUG( "Got LArDigitContainer with key " << m_contKey.key() );
147 
148  const LArDigitContainer DigitContainer = *hdlDigit;
149 
150  if(!hdlDigit.cptr()) {
151  ATH_MSG_WARNING( "No digits in this event ?");
152  return StatusCode::SUCCESS;
153  }
154 
155  for( const LArDigit *digi : DigitContainer ){
156 
157  if(m_fillBCID) m_bcid = thisbcid;
158  m_ELVL1Id = thisELVL1Id;
159  m_IEvent = thisevent;
160 
161  unsigned int trueMaxSample = digi->nsamples();
162 
163  if (!m_isSC){
164  m_gain = digi->gain();
165  if(m_gain < CaloGain::INVALIDGAIN || m_gain > CaloGain::LARNGAIN) m_gain = CaloGain::LARNGAIN;
166  }
167  if(trueMaxSample>m_Nsamples){
168  if(!m_ipass){
169  ATH_MSG_WARNING( "The number of digi samples in data is larger than the one specified by JO: " << trueMaxSample << " > " << m_Nsamples << " --> only " << m_Nsamples << " will be available in the ntuple " );
170  m_ipass = 1;
171  }
172  trueMaxSample = m_Nsamples;
173  }
174  else if(trueMaxSample<m_Nsamples){
175  if(!m_ipass){
176  ATH_MSG_WARNING( "The number of digi samples in data is lower than the one specified by JO: " << trueMaxSample << " > " << m_Nsamples << " --> only " << trueMaxSample << " will be available in the ntuple " );
177  m_ipass = 1;
178  }
179  }
180  m_ntNsamples = trueMaxSample;
181  ATH_MSG_DEBUG( "The number of digi samples in data "<< m_Nsamples );
182 
183  fillFromIdentifier(digi->hardwareID());
184 
185  if(m_isSC && m_fillEMB && m_barrel_ec !=0) continue;
186  if(m_isSC && m_fillEndcap && m_barrel_ec !=1) continue;
187 
188  if(m_FTlist.size() > 0) { // should do a selection
189  if(std::find(std::begin(m_FTlist), std::end(m_FTlist), m_FT) == std::end(m_FTlist)) { // is our FT in list ?
190  continue;
191  }
192  }
193 
194  if(m_Slotlist.size() > 0) { // should do a selection
195  if(std::find(std::begin(m_Slotlist), std::end(m_Slotlist), m_slot) == std::end(m_Slotlist)) { // is our slot in list ?
196  continue;
197  }
198  }
199  for(unsigned i = 0; i<trueMaxSample;++i) m_samples[i] = digi->samples().at(i);
200 
201 
202  ATH_CHECK( ntupleSvc()->writeRecord(m_nt) );
203  }// over cells
204 
205 
206  if(m_fillLB) {
207  m_IEventEvt = thisevent;
208  m_LB = ctx.eventID().lumi_block();
209 
210  sc = ntupleSvc()->writeRecord(m_evt_nt);
211  if (sc != StatusCode::SUCCESS) {
212  ATH_MSG_ERROR( "writeRecord failed" );
213  return sc;
214  }
215  }
216 
217  ATH_MSG_DEBUG( "LArDigits2Ntuple has finished." );
218  return StatusCode::SUCCESS;
219 }// end finalize-method.
LArDigits2Ntuple::m_evt_nt
NTuple::Tuple * m_evt_nt
Definition: LArDigits2Ntuple.h:45
LArDigits2Ntuple::m_LArFebHeaderContainerKey
SG::ReadHandleKey< LArFebHeaderContainer > m_LArFebHeaderContainerKey
Definition: LArDigits2Ntuple.h:51
LArDigits2Ntuple::m_IEventEvt
NTuple::Item< unsigned long long > m_IEventEvt
Definition: LArDigits2Ntuple.h:47
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
LArCond2NtupleBase::m_slot
NTuple::Item< long > m_slot
Definition: LArCond2NtupleBase.h:72
LArDigits2Ntuple::LArDigits2Ntuple
LArDigits2Ntuple(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArDigits2Ntuple.cxx:10
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
LArDigits2Ntuple::m_Nsamples
Gaudi::Property< unsigned int > m_Nsamples
Definition: LArDigits2Ntuple.h:29
LArDigits2Ntuple::m_fillBCID
Gaudi::Property< bool > m_fillBCID
Definition: LArDigits2Ntuple.h:34
LArDigits2Ntuple::m_fillEMB
Gaudi::Property< bool > m_fillEMB
Definition: LArDigits2Ntuple.h:32
LArDigits2Ntuple::m_fillLB
Gaudi::Property< bool > m_fillLB
Definition: LArDigits2Ntuple.h:35
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
LArDigits2Ntuple::m_fillEndcap
Gaudi::Property< bool > m_fillEndcap
Definition: LArDigits2Ntuple.h:33
LArDigits2Ntuple::m_IEvent
NTuple::Item< unsigned long long > m_IEvent
Definition: LArDigits2Ntuple.h:41
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
CaloGain::LARNGAIN
@ LARNGAIN
Definition: CaloGain.h:19
LArCond2NtupleBase::initialize
StatusCode initialize()
Definition: LArCond2NtupleBase.cxx:33
LArDigits2Ntuple::m_ntNsamples
NTuple::Item< long > m_ntNsamples
Definition: LArDigits2Ntuple.h:37
LArDigits2Ntuple::m_ELVL1Id
NTuple::Item< unsigned long > m_ELVL1Id
Definition: LArDigits2Ntuple.h:40
LArCond2NtupleBase
Definition: LArCond2NtupleBase.h:32
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
LArCond2NtupleBase::m_barrel_ec
NTuple::Item< long > m_barrel_ec
Definition: LArCond2NtupleBase.h:72
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
LArDigits2Ntuple::m_event
long m_event
Definition: LArDigits2Ntuple.h:27
LArDigits2Ntuple::m_FTlist
Gaudi::Property< std::vector< unsigned int > > m_FTlist
Definition: LArDigits2Ntuple.h:30
LArDigits2Ntuple::m_bcid
NTuple::Item< short > m_bcid
Definition: LArDigits2Ntuple.h:39
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArDigits2Ntuple::execute
virtual StatusCode execute()
Definition: LArDigits2Ntuple.cxx:107
LArDigit
Liquid Argon digit base class.
Definition: LArDigit.h:25
LArDigits2Ntuple::m_gain
NTuple::Item< short > m_gain
Definition: LArDigits2Ntuple.h:38
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
LArCond2NtupleBase::m_ntpath
std::string m_ntpath
Definition: LArCond2NtupleBase.h:65
LArCond2NtupleBase::m_nt
NTuple::Tuple * m_nt
Definition: LArCond2NtupleBase.h:68
LArSCDigit.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
LArDigits2Ntuple.h
LArDigits2Ntuple::m_ipass
int m_ipass
Definition: LArDigits2Ntuple.h:26
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
LArDigits2Ntuple::m_Slotlist
Gaudi::Property< std::vector< unsigned int > > m_Slotlist
Definition: LArDigits2Ntuple.h:31
HWIdentifier.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArCond2NtupleBase::m_ntTitle
std::string m_ntTitle
Definition: LArCond2NtupleBase.h:65
LArDigits2Ntuple::m_contKey
SG::ReadHandleKey< LArDigitContainer > m_contKey
Definition: LArDigits2Ntuple.h:50
LArDigitContainer.h
LArCond2NtupleBase::fillFromIdentifier
bool fillFromIdentifier(const HWIdentifier &id)
Definition: LArCond2NtupleBase.cxx:288
LArDigits2Ntuple::initialize
virtual StatusCode initialize()
Definition: LArDigits2Ntuple.cxx:23
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArCond2NtupleBase::m_isSC
Gaudi::Property< bool > m_isSC
Definition: LArCond2NtupleBase.h:55
LArDigits2Ntuple::m_samples
NTuple::Array< short > m_samples
Definition: LArDigits2Ntuple.h:42
LArDigitContainer
Container class for LArDigit.
Definition: LArDigitContainer.h:24
beamspotnt.nt
def nt
Definition: bin/beamspotnt.py:1063
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
LArCond2NtupleBase::m_FT
NTuple::Item< long > m_FT
Definition: LArCond2NtupleBase.h:72
LArDigits2Ntuple::m_LB
NTuple::Item< short > m_LB
Definition: LArDigits2Ntuple.h:48
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
LArDigits2Ntuple::~LArDigits2Ntuple
~LArDigits2Ntuple()